blob: e0704989b1f01d078f09cf920a802e64362d73cc [file] [log] [blame]
Eric Andersen85208e22002-04-12 12:05:57 +00001# Rules.make for busybox
Eric Andersen4bcdd722001-10-24 05:26:42 +00002#
Mike Frysinger5a5d0fa2005-11-29 02:53:52 +00003# Copyright (C) 1999-2005 by Erik Andersen <andersen@codepoet.org>
Eric Andersen85208e22002-04-12 12:05:57 +00004#
Mike Frysinger5a5d0fa2005-11-29 02:53:52 +00005# Licensed under GPLv2, see the file LICENSE in this tarball for details.
Eric Andersen4bcdd722001-10-24 05:26:42 +00006#
7
Mike Frysinger004ad112005-11-29 02:52:25 +00008# Pull in the user's busybox configuration
9ifeq ($(filter $(noconfig_targets),$(MAKECMDGOALS)),)
10-include $(top_builddir)/.config
11endif
12
Eric Andersenc9f20d92002-12-05 08:41:41 +000013#--------------------------------------------------------
Eric Andersen85208e22002-04-12 12:05:57 +000014PROG := busybox
Bernhard Reutner-Fischer8c7a7e62005-10-13 10:40:18 +000015MAJOR_VERSION :=1
Bernhard Reutner-Fischer31e2c002006-08-29 20:21:33 +000016MINOR_VERSION :=2
Bernhard Reutner-Fischer60182252006-03-29 22:22:37 +000017SUBLEVEL_VERSION:=0
Bernhard Reutner-Fischer31e2c002006-08-29 20:21:33 +000018EXTRAVERSION :=-svn
Bernhard Reutner-Fischer8c7a7e62005-10-13 10:40:18 +000019VERSION :=$(MAJOR_VERSION).$(MINOR_VERSION).$(SUBLEVEL_VERSION)$(EXTRAVERSION)
Eric Andersen85208e22002-04-12 12:05:57 +000020BUILDTIME := $(shell TZ=UTC date -u "+%Y.%m.%d-%H:%M%z")
Eric Andersen4bcdd722001-10-24 05:26:42 +000021
22
Eric Andersenc9f20d92002-12-05 08:41:41 +000023#--------------------------------------------------------
Eric Andersen85208e22002-04-12 12:05:57 +000024# With a modern GNU make(1) (highly recommended, that's what all the
25# developers use), all of the following configuration values can be
26# overridden at the command line. For example:
Bernhard Reutner-Fischer273430a2006-07-04 08:26:55 +000027# make CROSS_COMPILE=powerpc-linux- top_srcdir="$HOME/busybox" PREFIX=/mnt/app
Eric Andersenc9f20d92002-12-05 08:41:41 +000028#--------------------------------------------------------
Eric Andersen4bcdd722001-10-24 05:26:42 +000029
Bernhard Reutner-Fischer273430a2006-07-04 08:26:55 +000030# If you are running a cross compiler, you will want to set CROSS_COMPILE
Eric Andersenc9f20d92002-12-05 08:41:41 +000031# to something more interesting... Target architecture is determined
32# by asking the CC compiler what arch it compiles things for, so unless
Bernhard Reutner-Fischerdf100942006-03-13 19:04:00 +000033# your compiler is broken, you should not need to specify TARGET_ARCH
Bernhard Reutner-Fischer273430a2006-07-04 08:26:55 +000034CC = $(CROSS_COMPILE)gcc
35AR = $(CROSS_COMPILE)ar
36AS = $(CROSS_COMPILE)as
37LD = $(CROSS_COMPILE)ld
38NM = $(CROSS_COMPILE)nm
39STRIP = $(CROSS_COMPILE)strip
40ELF2FLT = $(CROSS_COMPILE)elf2flt
Eric Andersen5912acb2003-11-05 11:34:26 +000041CPP = $(CC) -E
Bernhard Reutner-Fischer5d261262006-03-01 22:54:48 +000042SED ?= sed
Bernhard Reutner-Fischere28d1d62006-05-26 13:22:57 +000043BZIP2 ?= bzip2
Bernhard Reutner-Fischer8c7a7e62005-10-13 10:40:18 +000044
Eric Andersen85208e22002-04-12 12:05:57 +000045
Eric Andersenc9f20d92002-12-05 08:41:41 +000046# What OS are you compiling busybox for? This allows you to include
47# OS specific things, syscall overrides, etc.
Eric Andersen5912acb2003-11-05 11:34:26 +000048TARGET_OS=linux
Eric Andersen85208e22002-04-12 12:05:57 +000049
Eric Andersenc7bda1c2004-03-15 08:29:22 +000050# Ensure consistent sort order, 'gcc -print-search-dirs' behavior, etc.
Eric Andersen85d9d802003-01-14 09:12:39 +000051LC_ALL:= C
52
Rob Landley5076eb42006-04-19 20:32:27 +000053# This must bind late because srcdir is reset for every source subdirectory.
Bernhard Reutner-Fischer45d54582006-05-08 20:20:32 +000054INCS:=-I$(top_builddir)/include -I$(top_srcdir)/include
Rob Landleyc503df52006-05-09 22:08:56 +000055CFLAGS=$(INCS) -I$(srcdir) -D_GNU_SOURCE
Rob Landley5076eb42006-04-19 20:32:27 +000056CFLAGS+=$(CHECKED_CFLAGS)
Bernhard Reutner-Fischer07a79e72006-03-09 09:03:37 +000057ARFLAGS=cru
Eric Andersen85208e22002-04-12 12:05:57 +000058
Bernhard Reutner-Fischere0b87782005-12-13 11:52:46 +000059# gcc centric. Perhaps fiddle with findstring gcc,$(CC) for the rest
Bernhard Reutner-Fischerdf100942006-03-13 19:04:00 +000060# get the CC MAJOR/MINOR version
Bernhard Reutner-Fischere0b87782005-12-13 11:52:46 +000061CC_MAJOR:=$(shell printf "%02d" $(shell echo __GNUC__ | $(CC) -E -xc - | tail -n 1))
62CC_MINOR:=$(shell printf "%02d" $(shell echo __GNUC_MINOR__ | $(CC) -E -xc - | tail -n 1))
63
Eric Andersenc9f20d92002-12-05 08:41:41 +000064#--------------------------------------------------------
Bernhard Reutner-Fischer273430a2006-07-04 08:26:55 +000065export VERSION BUILDTIME HOSTCC HOSTCFLAGS CROSS_COMPILE CC AR AS LD NM STRIP CPP
Bernhard Reutner-Fischerdf100942006-03-13 19:04:00 +000066ifeq ($(strip $(TARGET_ARCH)),)
Bernhard Reutner-Fischere28d1d62006-05-26 13:22:57 +000067TARGET_ARCH:=$(shell $(CC) -dumpmachine | $(SED) -e s'/-.*//' \
Eric Andersen5b0f9e42002-06-23 04:50:49 +000068 -e 's/i.86/i386/' \
69 -e 's/sparc.*/sparc/' \
70 -e 's/arm.*/arm/g' \
71 -e 's/m68k.*/m68k/' \
72 -e 's/ppc/powerpc/g' \
73 -e 's/v850.*/v850/g' \
74 -e 's/sh[234]/sh/' \
Eric Andersenc9f20d92002-12-05 08:41:41 +000075 -e 's/mips-.*/mips/' \
76 -e 's/mipsel-.*/mipsel/' \
77 -e 's/cris.*/cris/' \
78 )
Eric Andersen5912acb2003-11-05 11:34:26 +000079endif
Eric Andersenc9f20d92002-12-05 08:41:41 +000080
Rob Landley5076eb42006-04-19 20:32:27 +000081# A nifty macro to make testing gcc features easier, but note that everything
Bernhard Reutner-Fischere28d1d62006-05-26 13:22:57 +000082# that uses this _must_ use := or it will be re-evaluated everytime it is
83# referenced.
Bernhard Reutner-Fischer7b8ff222006-06-13 14:20:17 +000084ifeq ($(strip $(BUILD_VERBOSE)),2)
Bernhard Reutner-Fischere28d1d62006-05-26 13:22:57 +000085VERBOSE_CHECK_CC=echo CC=\"$(1)\" check_cc $(2) >&2;
Rob Landley5076eb42006-04-19 20:32:27 +000086endif
Bernhard Reutner-Fischere28d1d62006-05-26 13:22:57 +000087check_cc=$(shell \
88 $(VERBOSE_CHECK_CC) \
89 if [ "x$(1)" != "x" ] && [ "x$(2)" != "x" ]; then \
90 echo "int i;" > ./conftest.c; \
91 if $(1) $(2) -c -o conftest.o conftest.c > /dev/null 2>&1; \
92 then echo "$(2)"; else echo "$(3)"; fi ; \
93 rm -f conftest.c conftest.o; \
Bernhard Reutner-Fischerdf100942006-03-13 19:04:00 +000094 fi)
95
Bernhard Reutner-Fischer081b1ac2006-06-11 16:41:10 +000096ifneq ($(filter $(nocheck_targets),$(MAKECMDGOALS)),)
Bernhard Reutner-Fischere5de3842006-06-10 14:58:33 +000097check_cc:=
98endif
99
Bernhard Reutner-Fischerdf100942006-03-13 19:04:00 +0000100# A not very robust macro to check for available ld flags
Bernhard Reutner-Fischer7b8ff222006-06-13 14:20:17 +0000101ifeq ($(strip $(BUILD_VERBOSE)),2)
Bernhard Reutner-Fischere28d1d62006-05-26 13:22:57 +0000102VERBOSE_CHECK_LD=echo LD=\"$(1)\" check_ld $(2) >&2;
103endif
Bernhard Reutner-Fischerdf100942006-03-13 19:04:00 +0000104check_ld=$(shell \
Bernhard Reutner-Fischere28d1d62006-05-26 13:22:57 +0000105 $(VERBOSE_CHECK_LD) \
106 if [ "x$(1)" != "x" ] && [ "x$(2)" != "x" ]; then \
107 $(1) -o /dev/null -b binary /dev/null > /dev/null 2>&1 && \
108 echo "-Wl,$(2)" ; \
Bernhard Reutner-Fischerdf100942006-03-13 19:04:00 +0000109 fi)
110
Bernhard Reutner-Fischer081b1ac2006-06-11 16:41:10 +0000111ifneq ($(filter $(nocheck_targets),$(MAKECMDGOALS)),)
Bernhard Reutner-Fischere5de3842006-06-10 14:58:33 +0000112check_ld:=
113endif
114
Bernhard Reutner-Fischere28d1d62006-05-26 13:22:57 +0000115# A not very robust macro to check for available strip flags
Bernhard Reutner-Fischer7b8ff222006-06-13 14:20:17 +0000116ifeq ($(strip $(BUILD_VERBOSE)),2)
Bernhard Reutner-Fischere28d1d62006-05-26 13:22:57 +0000117VERBOSE_CHECK_STRIP=echo STRIPCMD=\"$(1)\" check_strip $(2) >&2;
118endif
119check_strip=$(shell \
120 $(VERBOSE_CHECK_STRIP) \
121 if [ "x$(1)" != "x" ] && [ "x$(2)" != "x" ]; then \
122 echo "int i;" > ./conftest.c ; \
123 $(CC) -c -o conftest.o conftest.c > /dev/null 2>&1 ; \
124 $(1) $(2) conftest.o > /dev/null 2>&1 && \
125 echo "$(1) $(2)" || echo "$(3)"; \
126 rm -f conftest.c conftest.o > /dev/null 2>&1 ; \
127 fi)
128
Bernhard Reutner-Fischer081b1ac2006-06-11 16:41:10 +0000129ifneq ($(filter $(nocheck_targets),$(MAKECMDGOALS)),)
Bernhard Reutner-Fischere5de3842006-06-10 14:58:33 +0000130check_strip:=
131endif
Bernhard Reutner-Fischere28d1d62006-05-26 13:22:57 +0000132
133
134# Select the compiler needed to build binaries for your development system
135HOSTCC = gcc
136HOSTCFLAGS:=$(call check_cc,$(HOSTCC),-Wall,)
137HOSTCFLAGS+=$(call check_cc,$(HOSTCC),-Wstrict-prototypes,)
138HOSTCFLAGS+=$(call check_cc,$(HOSTCC),-O2,)
139HOSTCFLAGS+=$(call check_cc,$(HOSTCC),-fomit-frame-pointer,)
140
141LD_WHOLE_ARCHIVE:=$(shell echo "int i;" > conftest.c ; \
142 $(CC) -c -o conftest.o conftest.c ; \
143 echo "int main(void){return 0;}" > conftest_main.c ; \
144 $(CC) -c -o conftest_main.o conftest_main.c ; \
145 $(AR) $(ARFLAGS) conftest.a conftest.o ; \
146 $(CC) -Wl,--whole-archive conftest.a -Wl,--no-whole-archive \
147 conftest_main.o -o conftest > /dev/null 2>&1 \
148 && echo "-Wl,--whole-archive" ; \
149 rm conftest_main.o conftest_main.c conftest.o conftest.c \
150 conftest.a conftest > /dev/null 2>&1 ; )
151ifneq ($(findstring whole-archive,$(LD_WHOLE_ARCHIVE)),)
152LD_NO_WHOLE_ARCHIVE:= -Wl,--no-whole-archive
153endif
154
155LD_START_GROUP:=$(shell echo "int bar(void){return 0;}" > conftest.c ; \
156 $(CC) -c -o conftest.o conftest.c ; \
157 echo "int main(void){return bar();}" > conftest_main.c ; \
158 $(CC) -c -o conftest_main.o conftest_main.c ; \
159 $(AR) $(ARFLAGS) conftest.a conftest.o ; \
160 $(CC) -Wl,--start-group conftest.a conftest_main.o -Wl,--end-group \
161 -o conftest > /dev/null 2>&1 && echo "-Wl,--start-group" ; \
Bernhard Reutner-Fischer07736812006-05-29 20:01:52 +0000162 rm conftest_main.o conftest_main.c conftest.o conftest.c \
Bernhard Reutner-Fischere28d1d62006-05-26 13:22:57 +0000163 conftest.a conftest > /dev/null 2>&1 ; )
164ifneq ($(findstring start-group,$(LD_START_GROUP)),)
165LD_END_GROUP:= -Wl,--end-group
166endif
167
168CHECKED_LDFLAGS := $(call check_ld,$(LD),--warn-common,)
Rob Landley533320c2006-07-31 22:56:17 +0000169#CHECKED_LDFLAGS := $(call check_ld,$(LD),-static-libgcc,)
Bernhard Reutner-Fischere28d1d62006-05-26 13:22:57 +0000170
Rob Landley5076eb42006-04-19 20:32:27 +0000171# Pin CHECKED_CFLAGS with := so it's only evaluated once.
Bernhard Reutner-Fischere28d1d62006-05-26 13:22:57 +0000172CHECKED_CFLAGS:=$(call check_cc,$(CC),-Wall,)
173CHECKED_CFLAGS+=$(call check_cc,$(CC),-Wstrict-prototypes,)
174CHECKED_CFLAGS+=$(call check_cc,$(CC),-Wshadow,)
175CHECKED_CFLAGS+=$(call check_cc,$(CC),-funsigned-char,)
Rob Landley533320c2006-07-31 22:56:17 +0000176CHECKED_CFLAGS+=$(call check_cc,$(CC),-fno-builtin-strlen,)
177CHECKED_CFLAGS+=$(call check_cc,$(CC),-finline-limit=0,)
Bernhard Reutner-Fischera5286432006-09-21 11:54:51 +0000178
179# gcc 2.95 exits with 0 for "unrecognized option"
180ifeq ($(strip $(shell [ $(CC_MAJOR) -ge 3 ] ; echo $$?)),0)
181 CHECKED_CFLAGS+=$(call check_cc,$(CC),-static-libgcc,)
182endif
Bernhard Reutner-Fischerdf100942006-03-13 19:04:00 +0000183
Rob Landley5076eb42006-04-19 20:32:27 +0000184# Preemptively pin this too.
185PROG_CFLAGS:=
186
Bernhard Reutner-Fischer7ca61b62006-01-15 14:04:57 +0000187
Eric Andersen5b0f9e42002-06-23 04:50:49 +0000188#--------------------------------------------------------
189# Arch specific compiler optimization stuff should go here.
190# Unless you want to override the defaults, do not set anything
Bernhard Reutner-Fischerdf100942006-03-13 19:04:00 +0000191# for OPTIMIZATION...
Eric Andersen5b0f9e42002-06-23 04:50:49 +0000192
193# use '-Os' optimization if available, else use -O2
Bernhard Reutner-Fischere28d1d62006-05-26 13:22:57 +0000194OPTIMIZATION:=$(call check_cc,$(CC),-Os,-O2)
Eric Andersen5b0f9e42002-06-23 04:50:49 +0000195
Bernhard Reutner-Fischerdf100942006-03-13 19:04:00 +0000196ifeq ($(CONFIG_BUILD_AT_ONCE),y)
Bernhard Reutner-Fischer7ca61b62006-01-15 14:04:57 +0000197# gcc 2.95 exits with 0 for "unrecognized option"
Bernhard Reutner-Fischerdf100942006-03-13 19:04:00 +0000198ifeq ($(strip $(shell [ $(CC_MAJOR) -ge 3 ] ; echo $$?)),0)
Bernhard Reutner-Fischere28d1d62006-05-26 13:22:57 +0000199 CFLAGS_COMBINE:=$(call check_cc,$(CC),--combine,)
Bernhard Reutner-Fischerdf100942006-03-13 19:04:00 +0000200endif
Bernhard Reutner-Fischere28d1d62006-05-26 13:22:57 +0000201OPTIMIZATION+=$(call check_cc,$(CC),-funit-at-a-time,)
202OPTIMIZATION+=$(call check_cc,$(CC),-fgcse-after-reload,)
Bernhard Reutner-Fischer3737c032006-04-28 20:02:29 +0000203ifneq ($(CONFIG_BUILD_LIBBUSYBOX),y)
Bernhard Reutner-Fischerd1ba9162006-03-21 11:06:43 +0000204# http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25795
Bernhard Reutner-Fischer3737c032006-04-28 20:02:29 +0000205# This prevents us from using -fwhole-program when we build the lib
Bernhard Reutner-Fischere28d1d62006-05-26 13:22:57 +0000206PROG_CFLAGS+=$(call check_cc,$(CC),-fwhole-program,)
Bernhard Reutner-Fischer3737c032006-04-28 20:02:29 +0000207endif # CONFIG_BUILD_LIBBUSYBOX
Bernhard Reutner-Fischerdf100942006-03-13 19:04:00 +0000208endif # CONFIG_BUILD_AT_ONCE
Bernhard Reutner-Fischer7ca61b62006-01-15 14:04:57 +0000209
Bernhard Reutner-Fischere28d1d62006-05-26 13:22:57 +0000210LIB_LDFLAGS:=$(call check_ld,$(LD),--enable-new-dtags,)
211#LIB_LDFLAGS+=$(call check_ld,$(LD),--reduce-memory-overheads,)
212#LIB_LDFLAGS+=$(call check_ld,$(LD),--as-needed,)
213#LIB_LDFLAGS+=$(call check_ld,$(LD),--warn-shared-textrel,)
Bernhard Reutner-Fischer08a1b502006-01-27 15:45:56 +0000214
215
Eric Andersen5b0f9e42002-06-23 04:50:49 +0000216# Some nice architecture specific optimizations
Bernhard Reutner-Fischerdf100942006-03-13 19:04:00 +0000217ifeq ($(strip $(TARGET_ARCH)),arm)
218 OPTIMIZATION+=-fstrict-aliasing
219endif
220ifeq ($(strip $(TARGET_ARCH)),i386)
Bernhard Reutner-Fischere28d1d62006-05-26 13:22:57 +0000221 OPTIMIZATION+=$(call check_cc,$(CC),-march=i386,)
Bernhard Reutner-Fischerd9969ea2006-03-03 20:31:33 +0000222# gcc-4.0 and older seem to benefit from these
Rob Landley533320c2006-07-31 22:56:17 +0000223ifneq ($(strip $(shell [ $(CC_MAJOR) -ge 4 -a $(CC_MINOR) -ge 1 ] ; echo $$?)),0)
Bernhard Reutner-Fischere28d1d62006-05-26 13:22:57 +0000224 OPTIMIZATION+=$(call check_cc,$(CC),-mpreferred-stack-boundary=2,)
Rob Landley533320c2006-07-31 22:56:17 +0000225 OPTIMIZATION+=$(call check_cc,$(CC),-falign-functions=1 -falign-jumps=1 -falign-loops=1, -malign-functions=0 -malign-jumps=0 -malign-loops=0,)
226
227 # gcc 4.1 produces many broken, totally invalid warnings
228 CHECKED_CFLAGS+=$(call check_cc,$(CC),-Werror,)
229endif # gcc-4.0 and older
Bernhard Reutner-Fischer7ca61b62006-01-15 14:04:57 +0000230
231# gcc-4.1 and beyond seem to benefit from these
Bernhard Reutner-Fischerdf100942006-03-13 19:04:00 +0000232ifeq ($(strip $(shell [ $(CC_MAJOR) -ge 4 -a $(CC_MINOR) -ge 1 ] ; echo $$?)),0)
233 # turn off flags which hurt -Os
Bernhard Reutner-Fischere28d1d62006-05-26 13:22:57 +0000234 OPTIMIZATION+=$(call check_cc,$(CC),-fno-tree-loop-optimize,)
235 OPTIMIZATION+=$(call check_cc,$(CC),-fno-tree-dominator-opts,)
236 OPTIMIZATION+=$(call check_cc,$(CC),-fno-strength-reduce,)
Bernhard Reutner-Fischer7ca61b62006-01-15 14:04:57 +0000237
Bernhard Reutner-Fischere28d1d62006-05-26 13:22:57 +0000238 OPTIMIZATION+=$(call check_cc,$(CC),-fno-branch-count-reg,)
Bernhard Reutner-Fischerdf100942006-03-13 19:04:00 +0000239endif # gcc-4.1 and beyond
240endif
Bernhard Reutner-Fischere28d1d62006-05-26 13:22:57 +0000241OPTIMIZATION+=$(call check_cc,$(CC),-fomit-frame-pointer,)
Rob Landleyf5bbc692006-08-30 16:50:00 +0000242CHECKED_LDFLAGS += $(call check_ld,$(LD),--sort-common,)
Eric Andersen5b0f9e42002-06-23 04:50:49 +0000243
Eric Andersen85208e22002-04-12 12:05:57 +0000244#
245#--------------------------------------------------------
246# If you're going to do a lot of builds with a non-vanilla configuration,
247# it makes sense to adjust parameters above, so you can type "make"
248# by itself, instead of following it by the same half-dozen overrides
249# every time. The stuff below, on the other hand, is probably less
250# prone to casual user adjustment.
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000251#
Eric Andersen85208e22002-04-12 12:05:57 +0000252
Bernhard Reutner-Fischerdf100942006-03-13 19:04:00 +0000253ifeq ($(strip $(CONFIG_LFS)),y)
Eric Andersen85208e22002-04-12 12:05:57 +0000254 # For large file summit support
Eric Andersenecfa2902002-09-22 12:09:44 +0000255 CFLAGS+=-D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
Eric Andersen85208e22002-04-12 12:05:57 +0000256endif
Bernhard Reutner-Fischerdf100942006-03-13 19:04:00 +0000257ifeq ($(strip $(CONFIG_DMALLOC)),y)
Eric Andersen85208e22002-04-12 12:05:57 +0000258 # For testing mem leaks with dmalloc
259 CFLAGS+=-DDMALLOC
260 LIBRARIES:=-ldmalloc
Eric Andersen85208e22002-04-12 12:05:57 +0000261else
Bernhard Reutner-Fischerdf100942006-03-13 19:04:00 +0000262 ifeq ($(strip $(CONFIG_EFENCE)),y)
Eric Andersen85208e22002-04-12 12:05:57 +0000263 LIBRARIES:=-lefence
Eric Andersen85208e22002-04-12 12:05:57 +0000264 endif
265endif
Rob Landleyc503df52006-05-09 22:08:56 +0000266
267# Debugging info
268
Bernhard Reutner-Fischerdf100942006-03-13 19:04:00 +0000269ifeq ($(strip $(CONFIG_DEBUG)),y)
Rob Landleyc503df52006-05-09 22:08:56 +0000270 CFLAGS +=-g
Eric Andersen85208e22002-04-12 12:05:57 +0000271else
Rob Landleyc503df52006-05-09 22:08:56 +0000272 CFLAGS +=-DNDEBUG
Mike Frysingerc70240c2006-03-10 23:20:48 +0000273endif
Rob Landleyc503df52006-05-09 22:08:56 +0000274
275ifneq ($(strip $(CONFIG_DEBUG_PESSIMIZE)),y)
Rob Landleyc503df52006-05-09 22:08:56 +0000276 CFLAGS += $(OPTIMIZATION)
277endif
278
Bernhard Reutner-Fischerabaef652006-03-29 22:28:27 +0000279# warn a bit more verbosely for non-release versions
280ifneq ($(EXTRAVERSION),)
Bernhard Reutner-Fischere28d1d62006-05-26 13:22:57 +0000281 CHECKED_CFLAGS+=$(call check_cc,$(CC),-Wstrict-prototypes,)
282 CHECKED_CFLAGS+=$(call check_cc,$(CC),-Wmissing-prototypes,)
283 CHECKED_CFLAGS+=$(call check_cc,$(CC),-Wmissing-declarations,)
284 CHECKED_CFLAGS+=$(call check_cc,$(CC),-Wunused,)
285 CHECKED_CFLAGS+=$(call check_cc,$(CC),-Winit-self,)
286 CHECKED_CFLAGS+=$(call check_cc,$(CC),-Wshadow,)
287 CHECKED_CFLAGS+=$(call check_cc,$(CC),-Wcast-align,)
Bernhard Reutner-Fischerabaef652006-03-29 22:28:27 +0000288endif
Bernhard Reutner-Fischere28d1d62006-05-26 13:22:57 +0000289STRIPCMD:=$(call check_strip,$(STRIP),-s --remove-section=.note --remove-section=.comment,$(STRIP))
Bernhard Reutner-Fischerdf100942006-03-13 19:04:00 +0000290ifeq ($(strip $(CONFIG_STATIC)),y)
Bernhard Reutner-Fischere28d1d62006-05-26 13:22:57 +0000291 PROG_CFLAGS += $(call check_cc,$(CC),-static,)
Rob Landley1fdd83f2006-08-29 21:46:10 +0000292else
293 ifneq ($(strip $(CONFIG_DEBUG)),y)
Rob Landleyf5bbc692006-08-30 16:50:00 +0000294 OPTIMIZATION+=$(call check_cc,$(CC),-ffunction-sections -fdata-sections,)
Rob Landley1fdd83f2006-08-29 21:46:10 +0000295 CHECKED_LDFLAGS += $(call check_ld,$(LD),--gc-sections,)
296 endif
Bernhard Reutner-Fischerdf100942006-03-13 19:04:00 +0000297endif
Bernhard Reutner-Fischere28d1d62006-05-26 13:22:57 +0000298CFLAGS_SHARED := $(call check_cc,$(CC),-shared,)
Bernhard Reutner-Fischer81b94962006-01-31 11:29:22 +0000299LIB_CFLAGS+=$(CFLAGS_SHARED)
Bernhard Reutner-Fischer7ca61b62006-01-15 14:04:57 +0000300
Bernhard Reutner-Fischerdf100942006-03-13 19:04:00 +0000301ifeq ($(strip $(CONFIG_BUILD_LIBBUSYBOX)),y)
Bernhard Reutner-Fischere28d1d62006-05-26 13:22:57 +0000302 CFLAGS_PIC:= $(call check_cc,$(CC),-fPIC,)
Bernhard Reutner-Fischerdf100942006-03-13 19:04:00 +0000303 LIB_CFLAGS+=$(CFLAGS_PIC)
304endif
Eric Andersen85208e22002-04-12 12:05:57 +0000305
Bernhard Reutner-Fischerdf100942006-03-13 19:04:00 +0000306ifeq ($(strip $(CONFIG_SELINUX)),y)
Mike Frysinger6ce8dae2006-08-28 23:24:38 +0000307 LIBRARIES += -lselinux -lsepol
Bernhard Reutner-Fischer5c071bc2005-10-05 07:40:46 +0000308endif
309
Eric Andersen12f834c2002-10-26 10:17:24 +0000310ifeq ($(strip $(PREFIX)),)
Eric Andersen85208e22002-04-12 12:05:57 +0000311 PREFIX:=`pwd`/_install
312endif
313
Bernhard Reutner-Fischer01d23ad2006-05-26 20:19:22 +0000314ifneq ($(strip $(CONFIG_GETOPT_LONG)),y)
315 CFLAGS += -D__need_getopt
316endif
Bernhard Reutner-Fischere28d1d62006-05-26 13:22:57 +0000317
Bernhard Reutner-Fischerdf100942006-03-13 19:04:00 +0000318# Additional complications due to support for pristine source dir.
319# Include files in the build directory should take precedence over
320# the copy in top_srcdir, both during the compilation phase and the
321# shell script that finds the list of object files.
322# Work in progress by <ldoolitt@recycle.lbl.gov>.
323
324
325OBJECTS:=$(APPLET_SOURCES:.c=.o) busybox.o usage.o applets.o
Bernhard Reutner-Fischere28d1d62006-05-26 13:22:57 +0000326CFLAGS += $(CHECKED_CFLAGS) $(CROSS_CFLAGS)
327LDFLAGS += $(CHECKED_LDFLAGS)
328
Eric Andersen85208e22002-04-12 12:05:57 +0000329ifdef BB_INIT_SCRIPT
330 CFLAGS += -DINIT_SCRIPT='"$(BB_INIT_SCRIPT)"'
331endif
332
333# Put user-supplied flags at the end, where they
334# have a chance of winning.
Rob Landley1fa4a942006-06-22 22:05:00 +0000335-include $(top_builddir)/.config.mak
Eric Andersen4bcdd722001-10-24 05:26:42 +0000336
Rob Landleye0c418e2005-12-15 07:25:54 +0000337#------------------------------------------------------------
338# Installation options
339ifeq ($(strip $(CONFIG_INSTALL_APPLET_HARDLINKS)),y)
340INSTALL_OPTS=--hardlinks
341endif
342ifeq ($(strip $(CONFIG_INSTALL_APPLET_SYMLINKS)),y)
343INSTALL_OPTS=--symlinks
344endif
345ifeq ($(strip $(CONFIG_INSTALL_APPLET_DONT)),y)
346INSTALL_OPTS=
347endif
348
Mike Frysingerb38673f2006-02-02 01:41:53 +0000349#------------------------------------------------------------
350# Make the output nice and tight
Bernhard Reutner-Fischerdf100942006-03-13 19:04:00 +0000351MAKEFLAGS += --no-print-directory
Mike Frysingerb38673f2006-02-02 01:41:53 +0000352export MAKE_IS_SILENT=n
353ifneq ($(findstring s,$(MAKEFLAGS)),)
354export MAKE_IS_SILENT=y
Bernhard Reutner-Fischerdf100942006-03-13 19:04:00 +0000355SECHO := @-false
Mike Frysingerb38673f2006-02-02 01:41:53 +0000356DISP := sil
357Q := @
358else
Bernhard Reutner-Fischer7b8ff222006-06-13 14:20:17 +0000359ifneq ($(BUILD_VERBOSE),)
Bernhard Reutner-Fischerdf100942006-03-13 19:04:00 +0000360SECHO := @-false
Mike Frysingerb38673f2006-02-02 01:41:53 +0000361DISP := ver
362Q :=
363else
Bernhard Reutner-Fischerdf100942006-03-13 19:04:00 +0000364SECHO := @echo
Mike Frysingerb38673f2006-02-02 01:41:53 +0000365DISP := pur
366Q := @
367endif
368endif
369
Bernhard Reutner-Fischerdf100942006-03-13 19:04:00 +0000370show_objs = $(subst $(top_builddir)/,,$(subst ../,,$@))
Bernhard Reutner-Fischer99b70682006-08-28 21:21:25 +0000371pur_disp_compile.c = echo " "CC $(show_objs) ;
372pur_disp_compile.h = echo " "HOSTCC $(show_objs) ;
373pur_disp_strip = echo " "STRIP $(show_objs) ;
374pur_disp_link = echo " "LINK $(show_objs) ;
375pur_disp_link.h = echo " "HOSTLINK $(show_objs) ;
376pur_disp_ar = echo " "AR $(ARFLAGS) $(show_objs) ;
377pur_disp_elf2flt = echo " "ELF2FLT $(ELF2FLTFLAGS) $(show_objs) ;
378sil_disp_compile.c =
379sil_disp_compile.h =
380sil_disp_strip =
381sil_disp_link =
382sil_disp_link.h =
383sil_disp_ar =
384sil_disp_elf2flt =
385ver_disp_compile.c =
386ver_disp_compile.h =
387ver_disp_strip =
388ver_disp_link =
389ver_disp_link.h =
390ver_disp_ar =
391ver_disp_elf2flt =
392disp_compile.c = $(Q)$($(DISP)_disp_compile.c)
393disp_compile.h = $(Q)$($(DISP)_disp_compile.h)
394disp_strip = $(Q)$($(DISP)_disp_strip)
395disp_link = $(Q)$($(DISP)_disp_link)
396disp_link.h = $(Q)$($(DISP)_disp_link.h)
397disp_ar = $(Q)$($(DISP)_disp_ar)
398disp_elf2flt = $(Q)$($(DISP)_disp_elf2flt)
Bernhard Reutner-Fischerdf100942006-03-13 19:04:00 +0000399disp_gen = $(SECHO) " "GEN $@ ; true
400disp_doc = $(SECHO) " "DOC $(subst docs/,,$@) ; true
401cmd_compile.c = $(CC) $(CFLAGS) $(EXTRA_CFLAGS) -c -o $@ $<
Bernhard Reutner-Fischer45d54582006-05-08 20:20:32 +0000402cmd_compile.h = $(HOSTCC) $(HOSTCFLAGS) $(INCS) -c -o $@ $<
Mike Frysingerb38673f2006-02-02 01:41:53 +0000403cmd_strip = $(STRIPCMD) $@
Bernhard Reutner-Fischer7b8ff222006-06-13 14:20:17 +0000404cmd_link = $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(LDFLAGS) \
405 $(PROG_CFLAGS) $(PROG_LDFLAGS) $(CFLAGS_COMBINE) \
406 -o $@ $(LD_START_GROUP) \
407 $(APPLETS_DEFINE) $(APPLET_SRC) \
408 $(BUSYBOX_DEFINE) $(BUSYBOX_SRC) $(libraries-y) \
409 $(LDBUSYBOX) $(LIBRARIES) \
410 $(LD_END_GROUP)
411cmd_link.so = $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(LDFLAGS) \
412 $(LIB_CFLAGS) $(CFLAGS_COMBINE) $(LIB_LDFLAGS) \
413 -o $(@) $(LD_START_GROUP) $(LD_WHOLE_ARCHIVE) \
414 $(LIBRARY_DEFINE) $(^) \
415 $(LD_NO_WHOLE_ARCHIVE) $(LD_END_GROUP)
Bernhard Reutner-Fischer45d54582006-05-08 20:20:32 +0000416cmd_link.h = $(HOSTCC) $(HOSTCFLAGS) $(INCS) $< -o $@
Mike Frysingerb38673f2006-02-02 01:41:53 +0000417cmd_ar = $(AR) $(ARFLAGS) $@ $^
Mike Frysinger586ea612006-04-21 01:18:07 +0000418cmd_elf2flt = $(ELF2FLT) $(ELF2FLTFLAGS) $< -o $@
Bernhard Reutner-Fischer99b70682006-08-28 21:21:25 +0000419compile.c = $(disp_compile.c) $(cmd_compile.c)
420compile.h = $(disp_compile.h) $(cmd_compile.h)
421do_strip = $(disp_strip) $(cmd_strip)
422do_link = $(disp_link) $(cmd_link)
423do_link.so = $(disp_link) $(cmd_link.so)
424do_link.h = $(disp_link.h) $(cmd_link.h)
425do_ar = $(disp_ar) $(cmd_ar)
426do_elf2flt = $(disp_elf2flt) $(cmd_elf2flt)
Mike Frysingerb38673f2006-02-02 01:41:53 +0000427
Bernhard Reutner-Fischere5de3842006-06-10 14:58:33 +0000428uppercase = $(shell echo $1 | $(SED) -e "y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/")
Mike Frysinger6143c072006-05-10 18:12:16 +0000429%.a:
430 @if test -z "$($(call uppercase,$*)_DIR)" ; then \
431 echo "Invalid target $@" ; \
432 exit 1 ; \
433 fi
434 $(Q)$(MAKE) $($(call uppercase,$*)_DIR)$@
435
Eric Andersen85208e22002-04-12 12:05:57 +0000436.PHONY: dummy