Makefile.flags 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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. -D"BB_VER=KBUILD_STR($(BB_VER))" -DBB_BT=AUTOCONF_TIMESTAMP
  16. CFLAGS += $(call cc-option,-Wall,)
  17. CFLAGS += $(call cc-option,-Wshadow,)
  18. CFLAGS += $(call cc-option,-Wwrite-strings,)
  19. CFLAGS += $(call cc-option,-Wundef,)
  20. CFLAGS += $(call cc-option,-Wstrict-prototypes,)
  21. CFLAGS += $(call cc-option,-Wunused -Wunused-parameter,)
  22. CFLAGS += $(call cc-option,-Wunused-function -Wunused-value,)
  23. CFLAGS += $(call cc-option,-Wmissing-prototypes -Wmissing-declarations,)
  24. # warn about C99 declaration after statement
  25. CFLAGS += $(call cc-option,-Wdeclaration-after-statement,)
  26. # If you want to add more -Wsomething above, make sure that it is
  27. # still possible to build bbox without warnings.
  28. ifeq ($(CONFIG_WERROR),y)
  29. CFLAGS += $(call cc-option,-Werror,)
  30. ## TODO:
  31. ## gcc version 4.4.0 20090506 (Red Hat 4.4.0-4) (GCC) is a PITA:
  32. ## const char *ptr; ... off_t v = *(off_t*)ptr; -> BOOM
  33. ## and no easy way to convince it to shut the hell up.
  34. ## We have a lot of such things all over the place.
  35. ## Classic *(off_t*)(void*)ptr does not work,
  36. ## and I am unwilling to do crazy gcc specific ({ void *ppp = ...; })
  37. ## stuff in macros. This would obfuscate the code too much.
  38. ## Maybe try __attribute__((__may_alias__))?
  39. #CFLAGS += $(call cc-ifversion, -eq, 0404, -fno-strict-aliasing)
  40. endif
  41. # gcc 3.x emits bogus "old style proto" warning on find.c:alloc_action()
  42. CFLAGS += $(call cc-ifversion, -ge, 0400, -Wold-style-definition)
  43. CFLAGS += $(call cc-option,-fno-builtin-strlen -finline-limit=0 -fomit-frame-pointer -ffunction-sections -fdata-sections,)
  44. # -fno-guess-branch-probability: prohibit pseudo-random guessing
  45. # of branch probabilities (hopefully makes bloatcheck more stable):
  46. CFLAGS += $(call cc-option,-fno-guess-branch-probability,)
  47. CFLAGS += $(call cc-option,-funsigned-char -static-libgcc,)
  48. CFLAGS += $(call cc-option,-falign-functions=1 -falign-jumps=1 -falign-labels=1 -falign-loops=1,)
  49. # FIXME: These warnings are at least partially to be concerned about and should
  50. # be fixed..
  51. #CFLAGS += $(call cc-option,-Wconversion,)
  52. ifneq ($(CONFIG_DEBUG),y)
  53. CFLAGS += $(call cc-option,-Os,$(call cc-option,-O2,))
  54. else
  55. CFLAGS += $(call cc-option,-g,)
  56. #CFLAGS += "-D_FORTIFY_SOURCE=2"
  57. ifeq ($(CONFIG_DEBUG_PESSIMIZE),y)
  58. CFLAGS += $(call cc-option,-O0,)
  59. else
  60. CFLAGS += $(call cc-option,-Os,$(call cc-option,-O2,))
  61. endif
  62. endif
  63. # If arch/$(ARCH)/Makefile did not override it (with, say, -fPIC)...
  64. ARCH_FPIC ?= -fpic
  65. ARCH_FPIE ?= -fpie
  66. ARCH_PIE ?= -pie
  67. # Usage: $(eval $(call pkg_check_modules,VARIABLE-PREFIX,MODULES))
  68. define pkg_check_modules
  69. $(1)_CFLAGS := $(shell $(PKG_CONFIG) $(PKG_CONFIG_FLAGS) --cflags $(2))
  70. $(1)_LIBS := $(shell $(PKG_CONFIG) $(PKG_CONFIG_FLAGS) --libs $(2))
  71. endef
  72. ifeq ($(CONFIG_BUILD_LIBBUSYBOX),y)
  73. # on i386: 14% smaller libbusybox.so
  74. # (code itself is 9% bigger, we save on relocs/PLT/GOT)
  75. CFLAGS += $(ARCH_FPIC)
  76. # and another 4% reduction of libbusybox.so:
  77. # (external entry points must be marked EXTERNALLY_VISIBLE)
  78. CFLAGS += $(call cc-option,-fvisibility=hidden)
  79. endif
  80. ifeq ($(CONFIG_STATIC),y)
  81. CFLAGS_busybox += -static
  82. PKG_CONFIG_FLAGS += --static
  83. endif
  84. ifeq ($(CONFIG_PIE),y)
  85. CFLAGS_busybox += $(ARCH_PIE)
  86. CFLAGS += $(ARCH_FPIE)
  87. endif
  88. ifneq ($(CONFIG_EXTRA_CFLAGS),)
  89. CFLAGS += $(strip $(subst ",,$(CONFIG_EXTRA_CFLAGS)))
  90. #"))
  91. endif
  92. # Note: both "" (string consisting of two quote chars) and empty string
  93. # are possible, and should be skipped below.
  94. ifneq ($(subst "",,$(CONFIG_SYSROOT)),)
  95. CFLAGS += --sysroot=$(CONFIG_SYSROOT)
  96. export SYSROOT=$(CONFIG_SYSROOT)
  97. endif
  98. # Android has no separate crypt library
  99. # gcc-4.2.1 fails if we try to feed C source on stdin:
  100. # echo 'int main(void){return 0;}' | $(CC) $(CFLAGS) -lcrypt -o /dev/null -xc -
  101. # fall back to using a temp file:
  102. CRYPT_AVAILABLE := $(shell echo 'int main(void){return 0;}' >crypttest.c; $(CC) $(CFLAGS) -lcrypt -o /dev/null crypttest.c >/dev/null 2>&1 && echo "y"; rm crypttest.c)
  103. ifeq ($(CRYPT_AVAILABLE),y)
  104. LDLIBS += m crypt
  105. else
  106. LDLIBS += m
  107. endif
  108. ifeq ($(CONFIG_PAM),y)
  109. # libpam uses libpthread, so for static builds busybox must be linked to
  110. # libpthread. On some platforms that requires an explicit -lpthread, so
  111. # it should be in LDLIBS. For non-static builds, scripts/trylink will
  112. # take care of removing -lpthread if possible. (Not bothering to check
  113. # CONFIG_STATIC because even in a non-static build it could be that the
  114. # only libpam available is libpam.a, so -lpthread could still be
  115. # needed.)
  116. LDLIBS += pam pam_misc pthread
  117. endif
  118. ifeq ($(CONFIG_SELINUX),y)
  119. SELINUX_PC_MODULES = libselinux libsepol
  120. $(eval $(call pkg_check_modules,SELINUX,$(SELINUX_PC_MODULES)))
  121. CPPFLAGS += $(SELINUX_CFLAGS)
  122. LDLIBS += $(if $(SELINUX_LIBS),$(SELINUX_LIBS:-l%=%),$(SELINUX_PC_MODULES:lib%=%))
  123. endif
  124. ifeq ($(CONFIG_EFENCE),y)
  125. LDLIBS += efence
  126. endif
  127. ifeq ($(CONFIG_DMALLOC),y)
  128. LDLIBS += dmalloc
  129. endif
  130. # If a flat binary should be built, CFLAGS_busybox="-elf2flt"
  131. # env var should be set for make invocation.
  132. # Here we check whether CFLAGS_busybox indeed contains that flag.
  133. # (For historical reasons, we also check LDFLAGS, which doesn't
  134. # seem to be entirely correct variable to put "-elf2flt" into).
  135. W_ELF2FLT = -elf2flt
  136. ifneq (,$(findstring $(W_ELF2FLT),$(LDFLAGS) $(CFLAGS_busybox)))
  137. SKIP_STRIP = y
  138. endif
  139. ifneq ($(CONFIG_EXTRA_LDFLAGS),)
  140. EXTRA_LDFLAGS += $(strip $(subst ",,$(CONFIG_EXTRA_LDFLAGS)))
  141. #"))
  142. endif
  143. ifneq ($(CONFIG_EXTRA_LDLIBS),)
  144. LDLIBS += $(strip $(subst ",,$(CONFIG_EXTRA_LDLIBS)))
  145. #"))
  146. endif
  147. # Busybox is a stack-fatty so make sure we increase default size
  148. # TODO: use "make stksizes" to find & fix big stack users
  149. # (we stole scripts/checkstack.pl from the kernel... thanks guys!)
  150. # Reduced from 20k to 16k in 1.9.0.
  151. FLTFLAGS += -s 16000