Denis Vlasenko | 7d219aa | 2006-10-05 10:17:08 +0000 | [diff] [blame] | 1 | # ========================================================================== |
Denis Vlasenko | da8f43f | 2006-10-09 19:47:38 +0000 | [diff] [blame] | 2 | # Build system |
Denis Vlasenko | 7d219aa | 2006-10-05 10:17:08 +0000 | [diff] [blame] | 3 | # ========================================================================== |
| 4 | |
| 5 | BB_VER = $(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION) |
Denis Vlasenko | def8898 | 2007-10-07 17:06:01 +0000 | [diff] [blame] | 6 | export BB_VER |
Mike Frysinger | 5b5bcf2 | 2007-06-19 15:58:02 +0000 | [diff] [blame] | 7 | SKIP_STRIP = n |
Denis Vlasenko | 7d219aa | 2006-10-05 10:17:08 +0000 | [diff] [blame] | 8 | |
Denis Vlasenko | bf11e89 | 2006-11-26 22:17:46 +0000 | [diff] [blame] | 9 | # -std=gnu99 needed for [U]LLONG_MAX on some systems |
Bernhard Reutner-Fischer | 82f8788 | 2007-01-23 11:39:13 +0000 | [diff] [blame] | 10 | CPPFLAGS += $(call cc-option,-std=gnu99,) |
Denis Vlasenko | 9dca07d | 2007-01-27 14:03:15 +0000 | [diff] [blame] | 11 | |
Denis Vlasenko | 7039a66 | 2006-10-08 17:54:47 +0000 | [diff] [blame] | 12 | CPPFLAGS += \ |
| 13 | -Iinclude -Ilibbb \ |
Denis Vlasenko | 4b04f54 | 2008-05-08 16:26:49 +0000 | [diff] [blame] | 14 | $(if $(KBUILD_SRC),-Iinclude2 -I$(srctree)/include -I$(srctree)/libbb) \ |
Denis Vlasenko | 7039a66 | 2006-10-08 17:54:47 +0000 | [diff] [blame] | 15 | -include include/autoconf.h \ |
| 16 | -D_GNU_SOURCE -DNDEBUG \ |
| 17 | $(if $(CONFIG_LFS),-D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64) \ |
Bernhard Reutner-Fischer | feea1b9 | 2006-12-06 21:51:59 +0000 | [diff] [blame] | 18 | -D"BB_VER=KBUILD_STR($(BB_VER))" -DBB_BT=AUTOCONF_TIMESTAMP |
| 19 | |
Denis Vlasenko | 5599502 | 2008-05-18 22:28:26 +0000 | [diff] [blame] | 20 | CFLAGS += $(call cc-option,-Wall,) |
| 21 | CFLAGS += $(call cc-option,-Wshadow,) |
| 22 | CFLAGS += $(call cc-option,-Wwrite-strings,) |
| 23 | CFLAGS += $(call cc-option,-Wundef,) |
| 24 | CFLAGS += $(call cc-option,-Wstrict-prototypes,) |
Denis Vlasenko | 68404f1 | 2008-03-17 09:00:54 +0000 | [diff] [blame] | 25 | CFLAGS += $(call cc-option,-Wunused -Wunused-parameter,) |
Denis Vlasenko | e251337 | 2008-05-15 21:44:46 +0000 | [diff] [blame] | 26 | CFLAGS += $(call cc-option,-Wmissing-prototypes -Wmissing-declarations,) |
Denis Vlasenko | 5599502 | 2008-05-18 22:28:26 +0000 | [diff] [blame] | 27 | # warn about C99 declaration after statement |
| 28 | CFLAGS += $(call cc-option,-Wdeclaration-after-statement,) |
Denis Vlasenko | e251337 | 2008-05-15 21:44:46 +0000 | [diff] [blame] | 29 | # If you want to add more -Wsomething above, make sure that it is |
| 30 | # still possible to build bbox without warnings. |
Denis Vlasenko | c562bb7 | 2007-01-29 17:08:51 +0000 | [diff] [blame] | 31 | |
Denis Vlasenko | 4bb3189 | 2007-02-01 01:51:36 +0000 | [diff] [blame] | 32 | ifeq ($(CONFIG_WERROR),y) |
| 33 | CFLAGS += $(call cc-option,-Werror,) |
| 34 | endif |
Denis Vlasenko | c562bb7 | 2007-01-29 17:08:51 +0000 | [diff] [blame] | 35 | # gcc 3.x emits bogus "old style proto" warning on find.c:alloc_action() |
| 36 | CFLAGS += $(call cc-ifversion, -ge, 0400, -Wold-style-definition) |
| 37 | |
Denis Vlasenko | bd8390a | 2008-06-12 20:23:03 +0000 | [diff] [blame] | 38 | CFLAGS += $(call cc-option,-fno-builtin-strlen -finline-limit=0 -fomit-frame-pointer -ffunction-sections -fdata-sections,) |
Denis Vlasenko | e0eebc1 | 2007-01-27 13:44:53 +0000 | [diff] [blame] | 39 | # -fno-guess-branch-probability: prohibit pseudo-random guessing |
Denis Vlasenko | 9dca07d | 2007-01-27 14:03:15 +0000 | [diff] [blame] | 40 | # of branch probabilities (hopefully makes bloatcheck more stable): |
| 41 | CFLAGS += $(call cc-option,-fno-guess-branch-probability,) |
| 42 | CFLAGS += $(call cc-option,-funsigned-char -static-libgcc,) |
Denis Vlasenko | e0eebc1 | 2007-01-27 13:44:53 +0000 | [diff] [blame] | 43 | CFLAGS += $(call cc-option,-falign-functions=1 -falign-jumps=1 -falign-labels=1 -falign-loops=1,) |
Bernhard Reutner-Fischer | 82f8788 | 2007-01-23 11:39:13 +0000 | [diff] [blame] | 44 | |
Bernhard Reutner-Fischer | fdcd7c4 | 2007-01-22 17:50:21 +0000 | [diff] [blame] | 45 | # FIXME: These warnings are at least partially to be concerned about and should |
| 46 | # be fixed.. |
Bernhard Reutner-Fischer | e6ce824 | 2008-08-05 19:06:35 +0000 | [diff] [blame] | 47 | #CFLAGS += $(call cc-option,-Wconversion,) |
Bernhard Reutner-Fischer | 9729e65 | 2006-12-13 17:44:24 +0000 | [diff] [blame] | 48 | |
Denis Vlasenko | bd8390a | 2008-06-12 20:23:03 +0000 | [diff] [blame] | 49 | ifneq ($(CONFIG_DEBUG),y) |
| 50 | CFLAGS += $(call cc-option,-Os,) |
| 51 | else |
| 52 | CFLAGS += $(call cc-option,-g,) |
Bernhard Reutner-Fischer | e6ce824 | 2008-08-05 19:06:35 +0000 | [diff] [blame] | 53 | #CFLAGS += "-D_FORTIFY_SOURCE=2" |
Denis Vlasenko | bd8390a | 2008-06-12 20:23:03 +0000 | [diff] [blame] | 54 | ifeq ($(CONFIG_DEBUG_PESSIMIZE),y) |
| 55 | CFLAGS += $(call cc-option,-O0,) |
| 56 | else |
| 57 | CFLAGS += $(call cc-option,-Os,) |
| 58 | endif |
Bernhard Reutner-Fischer | 9729e65 | 2006-12-13 17:44:24 +0000 | [diff] [blame] | 59 | endif |
| 60 | |
Denis Vlasenko | 1da86d2 | 2008-06-04 11:28:24 +0000 | [diff] [blame] | 61 | # If arch/$(ARCH)/Makefile did not override it (with, say, -fPIC)... |
| 62 | ARCH_FPIC ?= -fpic |
| 63 | ARCH_FPIE ?= -fpie |
| 64 | ARCH_PIE ?= -pie |
| 65 | |
Denis Vlasenko | 9b49a5e | 2007-10-11 10:05:36 +0000 | [diff] [blame] | 66 | ifeq ($(CONFIG_BUILD_LIBBUSYBOX),y) |
Denis Vlasenko | 8d82cf7 | 2007-10-11 10:02:52 +0000 | [diff] [blame] | 67 | # on i386: 14% smaller libbusybox.so |
| 68 | # (code itself is 9% bigger, we save on relocs/PLT/GOT) |
Denis Vlasenko | 1da86d2 | 2008-06-04 11:28:24 +0000 | [diff] [blame] | 69 | CFLAGS += $(ARCH_FPIC) |
Denis Vlasenko | 9b49a5e | 2007-10-11 10:05:36 +0000 | [diff] [blame] | 70 | # and another 4% reduction of libbusybox.so: |
| 71 | # (external entry points must be marked EXTERNALLY_VISIBLE) |
| 72 | CFLAGS += $(call cc-option,-fvisibility=hidden) |
Denis Vlasenko | 8d82cf7 | 2007-10-11 10:02:52 +0000 | [diff] [blame] | 73 | endif |
| 74 | |
Bernhard Reutner-Fischer | c1feac6 | 2007-01-08 16:29:15 +0000 | [diff] [blame] | 75 | ifeq ($(CONFIG_STATIC),y) |
Denis Vlasenko | 1da86d2 | 2008-06-04 11:28:24 +0000 | [diff] [blame] | 76 | CFLAGS_busybox += -static |
| 77 | endif |
| 78 | |
| 79 | ifeq ($(CONFIG_PIE),y) |
| 80 | CFLAGS_busybox += $(ARCH_PIE) |
| 81 | CFLAGS += $(ARCH_FPIE) |
Bernhard Reutner-Fischer | c1feac6 | 2007-01-08 16:29:15 +0000 | [diff] [blame] | 82 | endif |
Denis Vlasenko | d46d3c2 | 2007-02-06 19:28:50 +0000 | [diff] [blame] | 83 | |
Bernhard Reutner-Fischer | f6107c7 | 2009-01-22 13:27:14 +0000 | [diff] [blame^] | 84 | ifneq ($(CONFIG_EXTRA_CFLAGS),) |
| 85 | CFLAGS += $(strip $(subst ",,$(CONFIG_EXTRA_CFLAGS))) |
| 86 | #")) |
| 87 | endif |
| 88 | |
Denis Vlasenko | def8898 | 2007-10-07 17:06:01 +0000 | [diff] [blame] | 89 | LDLIBS += m crypt |
Denis Vlasenko | d6e81c7 | 2007-08-21 10:58:18 +0000 | [diff] [blame] | 90 | |
| 91 | ifeq ($(CONFIG_PAM),y) |
Denis Vlasenko | 76a6b23 | 2007-10-07 17:05:42 +0000 | [diff] [blame] | 92 | LDLIBS += pam pam_misc |
Denis Vlasenko | d6e81c7 | 2007-08-21 10:58:18 +0000 | [diff] [blame] | 93 | endif |
| 94 | |
Denis Vlasenko | d46d3c2 | 2007-02-06 19:28:50 +0000 | [diff] [blame] | 95 | ifeq ($(CONFIG_SELINUX),y) |
Denis Vlasenko | 76a6b23 | 2007-10-07 17:05:42 +0000 | [diff] [blame] | 96 | LDLIBS += selinux sepol |
Denis Vlasenko | d46d3c2 | 2007-02-06 19:28:50 +0000 | [diff] [blame] | 97 | endif |
Bernhard Reutner-Fischer | 58a275b | 2007-03-28 15:00:27 +0000 | [diff] [blame] | 98 | |
| 99 | ifeq ($(CONFIG_EFENCE),y) |
Denis Vlasenko | 76a6b23 | 2007-10-07 17:05:42 +0000 | [diff] [blame] | 100 | LDLIBS += efence |
Bernhard Reutner-Fischer | 58a275b | 2007-03-28 15:00:27 +0000 | [diff] [blame] | 101 | endif |
| 102 | |
| 103 | ifeq ($(CONFIG_DMALLOC),y) |
Denis Vlasenko | 76a6b23 | 2007-10-07 17:05:42 +0000 | [diff] [blame] | 104 | LDLIBS += dmalloc |
Bernhard Reutner-Fischer | 58a275b | 2007-03-28 15:00:27 +0000 | [diff] [blame] | 105 | endif |
| 106 | |
Denis Vlasenko | 401de64 | 2008-06-06 16:11:12 +0000 | [diff] [blame] | 107 | # If a flat binary should be built, CFLAGS_busybox="-Wl,-elf2flt" |
| 108 | # env var should be set for make invocation. |
| 109 | # Here we check whether CFLAGS_busybox indeed contains that flag. |
| 110 | # (For historical reasons, we also check LDFLAGS, which doesn't |
| 111 | # seem to be entirely correct variable to put "-Wl,-elf2flt" into). |
| 112 | W_ELF2FLT = -Wl,-elf2flt |
| 113 | ifneq (,$(findstring $(W_ELF2FLT),$(LDFLAGS) $(CFLAGS_busybox))) |
Mike Frysinger | 5b5bcf2 | 2007-06-19 15:58:02 +0000 | [diff] [blame] | 114 | SKIP_STRIP = y |
| 115 | endif |
| 116 | |
Mike Frysinger | c7b10dc | 2007-04-05 21:10:59 +0000 | [diff] [blame] | 117 | # Busybox is a stack-fatty so make sure we increase default size |
Denis Vlasenko | 931de89 | 2007-06-21 12:43:45 +0000 | [diff] [blame] | 118 | # TODO: use "make stksizes" to find & fix big stack users |
| 119 | # (we stole scripts/checkstack.pl from the kernel... thanks guys!) |
Denis Vlasenko | fcfb5c0 | 2007-12-24 12:16:24 +0000 | [diff] [blame] | 120 | # Reduced from 20k to 16k in 1.9.0. |
| 121 | FLTFLAGS += -s 16000 |