shell: add TODO comment about BASE#nnn literals
[oweals/busybox.git] / Makefile.flags
index 7e1c6030c7dee8268bfb20e2711c874afbcb1025..6f6142cc5d39ae8d95c34734d2a4cc5e14aaa3ee 100644 (file)
@@ -15,7 +15,7 @@ CPPFLAGS += \
        -include include/autoconf.h \
        -D_GNU_SOURCE -DNDEBUG \
        $(if $(CONFIG_LFS),-D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64) \
-       -D"BB_VER=KBUILD_STR($(BB_VER))" -DBB_BT=AUTOCONF_TIMESTAMP
+       -D"BB_VER=KBUILD_STR($(BB_VER))"
 
 CFLAGS += $(call cc-option,-Wall,)
 CFLAGS += $(call cc-option,-Wshadow,)
@@ -25,6 +25,7 @@ CFLAGS += $(call cc-option,-Wstrict-prototypes,)
 CFLAGS += $(call cc-option,-Wunused -Wunused-parameter,)
 CFLAGS += $(call cc-option,-Wunused-function -Wunused-value,)
 CFLAGS += $(call cc-option,-Wmissing-prototypes -Wmissing-declarations,)
+CFLAGS += $(call cc-option,-Wno-format-security,)
 # warn about C99 declaration after statement
 CFLAGS += $(call cc-option,-Wdeclaration-after-statement,)
 # If you want to add more -Wsomething above, make sure that it is
@@ -52,6 +53,12 @@ CFLAGS += $(call cc-option,-fno-builtin-strlen -finline-limit=0 -fomit-frame-poi
 CFLAGS += $(call cc-option,-fno-guess-branch-probability,)
 CFLAGS += $(call cc-option,-funsigned-char -static-libgcc,)
 CFLAGS += $(call cc-option,-falign-functions=1 -falign-jumps=1 -falign-labels=1 -falign-loops=1,)
+# Defeat .eh_frame bloat (gcc 4.6.3 x86-32 defconfig: 20% smaller busybox binary):
+CFLAGS += $(call cc-option,-fno-unwind-tables,)
+CFLAGS += $(call cc-option,-fno-asynchronous-unwind-tables,)
+# No automatic printf->puts,putchar conversions
+# (try disabling this and comparing assembly, it's instructive)
+CFLAGS += $(call cc-option,-fno-builtin-printf,)
 
 # FIXME: These warnings are at least partially to be concerned about and should
 # be fixed..
@@ -68,12 +75,23 @@ else
 CFLAGS += $(call cc-option,-Os,$(call cc-option,-O2,))
 endif
 endif
+ifeq ($(CONFIG_DEBUG_SANITIZE),y)
+CFLAGS += $(call cc-option,-fsanitize=address,)
+CFLAGS += $(call cc-option,-fsanitize=leak,)
+CFLAGS += $(call cc-option,-fsanitize=undefined,)
+endif
 
 # If arch/$(ARCH)/Makefile did not override it (with, say, -fPIC)...
 ARCH_FPIC ?= -fpic
 ARCH_FPIE ?= -fpie
 ARCH_PIE ?= -pie
 
+# Usage: $(eval $(call pkg_check_modules,VARIABLE-PREFIX,MODULES))
+define pkg_check_modules
+$(1)_CFLAGS := $(shell $(PKG_CONFIG) $(PKG_CONFIG_FLAGS) --cflags $(2))
+$(1)_LIBS := $(shell $(PKG_CONFIG) $(PKG_CONFIG_FLAGS) --libs $(2))
+endef
+
 ifeq ($(CONFIG_BUILD_LIBBUSYBOX),y)
 # on i386: 14% smaller libbusybox.so
 # (code itself is 9% bigger, we save on relocs/PLT/GOT)
@@ -85,6 +103,7 @@ endif
 
 ifeq ($(CONFIG_STATIC),y)
 CFLAGS_busybox += -static
+PKG_CONFIG_FLAGS += --static
 endif
 
 ifeq ($(CONFIG_PIE),y)
@@ -97,19 +116,48 @@ CFLAGS += $(strip $(subst ",,$(CONFIG_EXTRA_CFLAGS)))
 #"))
 endif
 
-ifneq ($(CONFIG_CROSS_COMPILER_PREFIX),"arm-linux-androideabi-")
+# Note: both "" (string consisting of two quote chars) and empty string
+# are possible, and should be skipped below.
+ifneq ($(subst "",,$(CONFIG_SYSROOT)),)
+CFLAGS += --sysroot=$(CONFIG_SYSROOT)
+export SYSROOT=$(CONFIG_SYSROOT)
+endif
+
+# Android has no separate crypt library
+# gcc-4.2.1 fails if we try to feed C source on stdin:
+#  echo 'int main(void){return 0;}' | $(CC) $(CFLAGS) -lcrypt -o /dev/null -xc -
+# fall back to using a temp file:
+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)
+ifeq ($(CRYPT_AVAILABLE),y)
 LDLIBS += m crypt
 else
-# Android libc has no crypt. TODO: make a generic CONFIG_LINK_WITH_CRYPT option?
 LDLIBS += m
 endif
 
+# libpam may use libpthread, libdl and/or libaudit.
+# On some platforms that requires an explicit -lpthread, -ldl, -laudit.
+# However, on *other platforms* it fails when some of those flags
+# given needlessly. On some systems, crypt needs pthread.
+#
+# I even had a system where a runtime test for pthread
+# (similar to CRYPT_AVAILABLE test above) was not reliable.
+#
+# Do not propagate this mess by adding libraries to CONFIG_PAM/CRYPT_AVAILABLE blocks.
+# Add libraries you need to CONFIG_EXTRA_LDLIBS instead.
+
 ifeq ($(CONFIG_PAM),y)
 LDLIBS += pam pam_misc
 endif
 
 ifeq ($(CONFIG_SELINUX),y)
-LDLIBS += selinux sepol
+SELINUX_PC_MODULES = libselinux libsepol
+$(eval $(call pkg_check_modules,SELINUX,$(SELINUX_PC_MODULES)))
+CPPFLAGS += $(SELINUX_CFLAGS)
+LDLIBS += $(if $(SELINUX_LIBS),$(SELINUX_LIBS:-l%=%),$(SELINUX_PC_MODULES:lib%=%))
+endif
+
+ifeq ($(CONFIG_FEATURE_NSLOOKUP_BIG),y)
+LDLIBS += resolv
 endif
 
 ifeq ($(CONFIG_EFENCE),y)
@@ -130,6 +178,16 @@ ifneq (,$(findstring $(W_ELF2FLT),$(LDFLAGS) $(CFLAGS_busybox)))
 SKIP_STRIP = y
 endif
 
+ifneq ($(CONFIG_EXTRA_LDFLAGS),)
+LDFLAGS += $(strip $(subst ",,$(CONFIG_EXTRA_LDFLAGS)))
+#"))
+endif
+
+ifneq ($(CONFIG_EXTRA_LDLIBS),)
+LDLIBS += $(strip $(subst ",,$(CONFIG_EXTRA_LDLIBS)))
+#"))
+endif
+
 # Busybox is a stack-fatty so make sure we increase default size
 # TODO: use "make stksizes" to find & fix big stack users
 # (we stole scripts/checkstack.pl from the kernel... thanks guys!)