3
0

Makefile.flags 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. # ==========================================================================
  2. # Build system
  3. # ==========================================================================
  4. BB_VER = $(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
  5. export BB_VER
  6. SKIP_STRIP ?= n
  7. # -std=gnu99 needed for [U]LLONG_MAX on some systems
  8. CPPFLAGS += $(call cc-option,-std=gnu99,)
  9. CPPFLAGS += \
  10. -Iinclude -Ilibbb \
  11. $(if $(KBUILD_SRC),-Iinclude2 -I$(srctree)/include -I$(srctree)/libbb) \
  12. -include include/autoconf.h \
  13. -D_GNU_SOURCE -DNDEBUG \
  14. $(if $(CONFIG_LFS),-D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64) \
  15. $(if $(CONFIG_TIME64),-D_TIME_BITS=64) \
  16. -DBB_VER=$(squote)$(quote)$(BB_VER)$(quote)$(squote)
  17. CFLAGS += $(call cc-option,-Wall,)
  18. CFLAGS += $(call cc-option,-Wshadow,)
  19. CFLAGS += $(call cc-option,-Wwrite-strings,)
  20. CFLAGS += $(call cc-option,-Wundef,)
  21. CFLAGS += $(call cc-option,-Wstrict-prototypes,)
  22. CFLAGS += $(call cc-option,-Wunused -Wunused-parameter,)
  23. CFLAGS += $(call cc-option,-Wunused-function -Wunused-value,)
  24. CFLAGS += $(call cc-option,-Wmissing-prototypes -Wmissing-declarations,)
  25. CFLAGS += $(call cc-option,-Wno-format-security,)
  26. # warn about C99 declaration after statement
  27. CFLAGS += $(call cc-option,-Wdeclaration-after-statement,)
  28. # If you want to add more -Wsomething above, make sure that it is
  29. # still possible to build bbox without warnings.
  30. ifeq ($(CONFIG_WERROR),y)
  31. CFLAGS += $(call cc-option,-Werror,)
  32. ## TODO:
  33. ## gcc version 4.4.0 20090506 (Red Hat 4.4.0-4) (GCC) is a PITA:
  34. ## const char *ptr; ... off_t v = *(off_t*)ptr; -> BOOM
  35. ## and no easy way to convince it to shut the hell up.
  36. ## We have a lot of such things all over the place.
  37. ## Classic *(off_t*)(void*)ptr does not work,
  38. ## and I am unwilling to do crazy gcc specific ({ void *ppp = ...; })
  39. ## stuff in macros. This would obfuscate the code too much.
  40. ## Maybe try __attribute__((__may_alias__))?
  41. #CFLAGS += $(call cc-ifversion, -eq, 0404, -fno-strict-aliasing)
  42. endif
  43. # gcc 3.x emits bogus "old style proto" warning on find.c:alloc_action()
  44. CFLAGS += $(call cc-ifversion, -ge, 0400, -Wold-style-definition)
  45. ifneq ($(lastword $(subst -, ,$(CC))),clang)
  46. # "clang-9: warning: optimization flag '-finline-limit=0' is not supported
  47. CFLAGS += $(call cc-option,-finline-limit=0,)
  48. endif
  49. CFLAGS += $(call cc-option,-fno-builtin-strlen -fomit-frame-pointer -ffunction-sections -fdata-sections,)
  50. # -fno-guess-branch-probability: prohibit pseudo-random guessing
  51. # of branch probabilities (hopefully makes bloatcheck more stable):
  52. CFLAGS += $(call cc-option,-fno-guess-branch-probability,)
  53. CFLAGS += $(call cc-option,-funsigned-char,)
  54. ifeq ($(CONFIG_STATIC_LIBGCC),y)
  55. # Disable it, for example, if you get
  56. # "clang-9: warning: argument unused during compilation: '-static-libgcc'"
  57. CFLAGS += $(call cc-option,-static-libgcc,)
  58. endif
  59. CFLAGS += $(call cc-option,-falign-functions=1,)
  60. ifneq ($(lastword $(subst -, ,$(CC))),clang)
  61. # "clang-9: warning: optimization flag '-falign-jumps=1' is not supported" (and same for other two)
  62. CFLAGS += $(call cc-option,-falign-jumps=1 -falign-labels=1 -falign-loops=1,)
  63. endif
  64. # Defeat .eh_frame bloat (gcc 4.6.3 x86-32 defconfig: 20% smaller busybox binary):
  65. CFLAGS += $(call cc-option,-fno-unwind-tables,)
  66. CFLAGS += $(call cc-option,-fno-asynchronous-unwind-tables,)
  67. # No automatic printf->puts,putchar conversions
  68. # (try disabling this and comparing assembly, it's instructive)
  69. CFLAGS += $(call cc-option,-fno-builtin-printf,)
  70. # clang-9 does not like "str" + N and "if (CONFIG_ITEM && cond)" constructs
  71. ifeq ($(lastword $(subst -, ,$(CC))),clang)
  72. CFLAGS += $(call cc-option,-Wno-string-plus-int -Wno-constant-logical-operand)
  73. endif
  74. # FIXME: These warnings are at least partially to be concerned about and should
  75. # be fixed..
  76. #CFLAGS += $(call cc-option,-Wconversion,)
  77. ifneq ($(CONFIG_DEBUG),y)
  78. CFLAGS += $(call cc-option,-Oz,$(call cc-option,-Os,$(call cc-option,-O2,)))
  79. else
  80. CFLAGS += $(call cc-option,-g,)
  81. #CFLAGS += "-D_FORTIFY_SOURCE=2"
  82. ifeq ($(CONFIG_DEBUG_PESSIMIZE),y)
  83. CFLAGS += $(call cc-option,-O0,)
  84. else
  85. CFLAGS += $(call cc-option,-Oz,$(call cc-option,-Os,$(call cc-option,-O2,)))
  86. endif
  87. endif
  88. ifeq ($(CONFIG_DEBUG_SANITIZE),y)
  89. CFLAGS += $(call cc-option,-fsanitize=address,)
  90. CFLAGS += $(call cc-option,-fsanitize=leak,)
  91. CFLAGS += $(call cc-option,-fsanitize=undefined,)
  92. endif
  93. # If arch/$(ARCH)/Makefile did not override it (with, say, -fPIC)...
  94. ARCH_FPIC ?= -fpic
  95. ARCH_FPIE ?= -fpie
  96. ARCH_PIE ?= -pie
  97. # Usage: $(eval $(call pkg_check_modules,VARIABLE-PREFIX,MODULES))
  98. define pkg_check_modules
  99. $(1)_CFLAGS := $(shell $(PKG_CONFIG) $(PKG_CONFIG_FLAGS) --cflags $(2))
  100. $(1)_LIBS := $(shell $(PKG_CONFIG) $(PKG_CONFIG_FLAGS) --libs $(2))
  101. endef
  102. ifeq ($(CONFIG_BUILD_LIBBUSYBOX),y)
  103. # on i386: 14% smaller libbusybox.so
  104. # (code itself is 9% bigger, we save on relocs/PLT/GOT)
  105. CFLAGS += $(ARCH_FPIC)
  106. # and another 4% reduction of libbusybox.so:
  107. # (external entry points must be marked EXTERNALLY_VISIBLE)
  108. CFLAGS += $(call cc-option,-fvisibility=hidden)
  109. endif
  110. ifeq ($(CONFIG_STATIC),y)
  111. CFLAGS_busybox += -static
  112. PKG_CONFIG_FLAGS += --static
  113. endif
  114. ifeq ($(CONFIG_PIE),y)
  115. CFLAGS_busybox += $(ARCH_PIE)
  116. CFLAGS += $(ARCH_FPIE)
  117. endif
  118. ifneq ($(CONFIG_EXTRA_CFLAGS),)
  119. CFLAGS += $(strip $(subst ",,$(CONFIG_EXTRA_CFLAGS)))
  120. #"))
  121. endif
  122. # Note: both "" (string consisting of two quote chars) and empty string
  123. # are possible, and should be skipped below.
  124. ifneq ($(subst "",,$(CONFIG_SYSROOT)),)
  125. CFLAGS += --sysroot=$(CONFIG_SYSROOT)
  126. export SYSROOT=$(CONFIG_SYSROOT)
  127. endif
  128. # libm may be needed for dc, awk, ntpd
  129. LDLIBS += m
  130. # Android has no separate crypt library
  131. # gcc-4.2.1 fails if we try to feed C source on stdin:
  132. # echo 'int main(void){return 0;}' | $(CC) $(CFLAGS) -lcrypt -o /dev/null -xc -
  133. # fall back to using a temp file:
  134. CRYPT_AVAILABLE := $(shell echo 'int main(void){return 0;}' >bb_libtest.c; $(CC) $(CFLAGS) $(CFLAGS_busybox) -lcrypt -o /dev/null bb_libtest.c >/dev/null 2>&1 && echo "y"; rm bb_libtest.c)
  135. RT_AVAILABLE := $(shell echo 'int main(void){return 0;}' >bb_libtest.c; $(CC) $(CFLAGS) $(CFLAGS_busybox) -lrt -o /dev/null bb_libtest.c >/dev/null 2>&1 && echo "y"; rm bb_libtest.c)
  136. ifeq ($(CRYPT_AVAILABLE),y)
  137. LDLIBS += crypt
  138. endif
  139. # librt may be needed for clock_gettime()
  140. ifeq ($(RT_AVAILABLE),y)
  141. LDLIBS += rt
  142. endif
  143. # libpam may use libpthread, libdl and/or libaudit.
  144. # On some platforms that requires an explicit -lpthread, -ldl, -laudit.
  145. # However, on *other platforms* it fails when some of those flags
  146. # given needlessly. On some systems, crypt needs pthread.
  147. #
  148. # I even had a system where a runtime test for pthread
  149. # (similar to CRYPT_AVAILABLE test above) was not reliable.
  150. #
  151. # Do not propagate this mess by adding libraries to CONFIG_PAM/CRYPT_AVAILABLE blocks.
  152. # Add libraries you need to CONFIG_EXTRA_LDLIBS instead.
  153. ifeq ($(CONFIG_PAM),y)
  154. LDLIBS += pam pam_misc
  155. endif
  156. ifeq ($(CONFIG_SELINUX),y)
  157. SELINUX_PC_MODULES = libselinux libsepol
  158. $(eval $(call pkg_check_modules,SELINUX,$(SELINUX_PC_MODULES)))
  159. CPPFLAGS += $(SELINUX_CFLAGS)
  160. LDLIBS += $(if $(SELINUX_LIBS),$(SELINUX_LIBS:-l%=%),$(SELINUX_PC_MODULES:lib%=%))
  161. endif
  162. ifeq ($(CONFIG_FEATURE_NSLOOKUP_BIG),y)
  163. ifneq (,$(findstring linux,$(shell $(CC) $(CFLAGS) -dumpmachine)))
  164. LDLIBS += resolv
  165. endif
  166. ifneq (,$(findstring gnu,$(shell $(CC) $(CFLAGS) -dumpmachine)))
  167. LDLIBS += resolv
  168. endif
  169. endif
  170. ifeq ($(CONFIG_EFENCE),y)
  171. LDLIBS += efence
  172. endif
  173. ifeq ($(CONFIG_DMALLOC),y)
  174. LDLIBS += dmalloc
  175. endif
  176. # If a flat binary should be built, CFLAGS_busybox="-elf2flt"
  177. # env var should be set for make invocation.
  178. # Here we check whether CFLAGS_busybox indeed contains that flag.
  179. # (For historical reasons, we also check LDFLAGS, which doesn't
  180. # seem to be entirely correct variable to put "-elf2flt" into).
  181. W_ELF2FLT = -elf2flt
  182. ifneq (,$(findstring $(W_ELF2FLT),$(LDFLAGS) $(CFLAGS_busybox)))
  183. SKIP_STRIP = y
  184. endif
  185. ifneq ($(CONFIG_EXTRA_LDFLAGS),)
  186. LDFLAGS += $(strip $(subst ",,$(CONFIG_EXTRA_LDFLAGS)))
  187. #"))
  188. endif
  189. # Busybox is a stack-fatty so make sure we increase default size
  190. # TODO: use "make stksizes" to find & fix big stack users
  191. # (we stole scripts/checkstack.pl from the kernel... thanks guys!)
  192. # Reduced from 20k to 16k in 1.9.0.
  193. FLTFLAGS += -s 16000