blob: 2f34bfbd202ff17874aac44185a41bf397ed9910 [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-Fischer60182252006-03-29 22:22:37 +000016MINOR_VERSION :=2
17SUBLEVEL_VERSION:=0
18EXTRAVERSION :=-pre0
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-Fischer5c071bc2005-10-05 07:40:46 +000027# make CROSS=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
Eric Andersenc9f20d92002-12-05 08:41:41 +000030# If you are running a cross compiler, you will want to set 'CROSS'
31# 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-Fischere28d1d62006-05-26 13:22:57 +000034CROSS =$(strip $(subst ",, $(strip $(CROSS_COMPILER_PREFIX))))
35# be gentle to vi coloring.. "))
Eric Andersen5912acb2003-11-05 11:34:26 +000036CC = $(CROSS)gcc
37AR = $(CROSS)ar
38AS = $(CROSS)as
39LD = $(CROSS)ld
40NM = $(CROSS)nm
41STRIP = $(CROSS)strip
Mike Frysinger586ea612006-04-21 01:18:07 +000042ELF2FLT = $(CROSS)elf2flt
Eric Andersen5912acb2003-11-05 11:34:26 +000043CPP = $(CC) -E
Bernhard Reutner-Fischer5d261262006-03-01 22:54:48 +000044SED ?= sed
Bernhard Reutner-Fischere28d1d62006-05-26 13:22:57 +000045BZIP2 ?= bzip2
Bernhard Reutner-Fischer8c7a7e62005-10-13 10:40:18 +000046
Eric Andersen85208e22002-04-12 12:05:57 +000047
Eric Andersenc9f20d92002-12-05 08:41:41 +000048# What OS are you compiling busybox for? This allows you to include
49# OS specific things, syscall overrides, etc.
Eric Andersen5912acb2003-11-05 11:34:26 +000050TARGET_OS=linux
Eric Andersen85208e22002-04-12 12:05:57 +000051
Eric Andersenc7bda1c2004-03-15 08:29:22 +000052# Ensure consistent sort order, 'gcc -print-search-dirs' behavior, etc.
Eric Andersen85d9d802003-01-14 09:12:39 +000053LC_ALL:= C
54
Eric Andersenc9f20d92002-12-05 08:41:41 +000055# If you want to add some simple compiler switches (like -march=i686),
56# especially from the command line, use this instead of CFLAGS directly.
Bernhard Reutner-Fischerdf100942006-03-13 19:04:00 +000057# For optimization overrides, it's better still to set OPTIMIZATION.
Eric Andersenc9f20d92002-12-05 08:41:41 +000058CFLAGS_EXTRA=$(subst ",, $(strip $(EXTRA_CFLAGS_OPTIONS)))
Bernhard Reutner-Fischere5de3842006-06-10 14:58:33 +000059# be gentle to vi coloring.. ")
Eric Andersenc7bda1c2004-03-15 08:29:22 +000060
Eric Andersen85208e22002-04-12 12:05:57 +000061# To compile vs some other alternative libc, you may need to use/adjust
62# the following lines to meet your needs...
63#
64# If you are using Red Hat 6.x with the compatible RPMs (for developing under
65# Red Hat 5.x and glibc 2.0) uncomment the following. Be sure to read about
66# using the compatible RPMs (compat-*) at http://www.redhat.com !
67#LIBCDIR:=/usr/i386-glibc20-linux
68#
Eric Andersen0a14c9f2003-07-22 08:56:01 +000069# For other libraries, you are on your own. But these may (or may not) help...
Eric Andersen85208e22002-04-12 12:05:57 +000070#LDFLAGS+=-nostdlib
71#LIBRARIES:=$(LIBCDIR)/lib/libc.a -lgcc
Rob Landley4a070d12005-12-01 17:01:43 +000072#CROSS_CFLAGS+=-nostdinc -I$(LIBCDIR)/include -I$(GCCINCDIR) -funsigned-char
Bernhard Reutner-Fischere28d1d62006-05-26 13:22:57 +000073#GCCINCDIR:=$(shell gcc -print-search-dirs | $(SED) -ne "s/install: \(.*\)/\1include/gp")
Eric Andersen85208e22002-04-12 12:05:57 +000074
Rob Landley5076eb42006-04-19 20:32:27 +000075# This must bind late because srcdir is reset for every source subdirectory.
Bernhard Reutner-Fischer45d54582006-05-08 20:20:32 +000076INCS:=-I$(top_builddir)/include -I$(top_srcdir)/include
Rob Landleyc503df52006-05-09 22:08:56 +000077CFLAGS=$(INCS) -I$(srcdir) -D_GNU_SOURCE
Rob Landley5076eb42006-04-19 20:32:27 +000078CFLAGS+=$(CHECKED_CFLAGS)
Bernhard Reutner-Fischer07a79e72006-03-09 09:03:37 +000079ARFLAGS=cru
Eric Andersen85208e22002-04-12 12:05:57 +000080
Bernhard Reutner-Fischere0b87782005-12-13 11:52:46 +000081# gcc centric. Perhaps fiddle with findstring gcc,$(CC) for the rest
Bernhard Reutner-Fischerdf100942006-03-13 19:04:00 +000082# get the CC MAJOR/MINOR version
Bernhard Reutner-Fischere0b87782005-12-13 11:52:46 +000083CC_MAJOR:=$(shell printf "%02d" $(shell echo __GNUC__ | $(CC) -E -xc - | tail -n 1))
84CC_MINOR:=$(shell printf "%02d" $(shell echo __GNUC_MINOR__ | $(CC) -E -xc - | tail -n 1))
85
Eric Andersenc9f20d92002-12-05 08:41:41 +000086#--------------------------------------------------------
Bernhard Reutner-Fischer1c943eb2005-09-26 16:01:43 +000087export VERSION BUILDTIME HOSTCC HOSTCFLAGS CROSS CC AR AS LD NM STRIP CPP
Bernhard Reutner-Fischerdf100942006-03-13 19:04:00 +000088ifeq ($(strip $(TARGET_ARCH)),)
Bernhard Reutner-Fischere28d1d62006-05-26 13:22:57 +000089TARGET_ARCH:=$(shell $(CC) -dumpmachine | $(SED) -e s'/-.*//' \
Eric Andersen5b0f9e42002-06-23 04:50:49 +000090 -e 's/i.86/i386/' \
91 -e 's/sparc.*/sparc/' \
92 -e 's/arm.*/arm/g' \
93 -e 's/m68k.*/m68k/' \
94 -e 's/ppc/powerpc/g' \
95 -e 's/v850.*/v850/g' \
96 -e 's/sh[234]/sh/' \
Eric Andersenc9f20d92002-12-05 08:41:41 +000097 -e 's/mips-.*/mips/' \
98 -e 's/mipsel-.*/mipsel/' \
99 -e 's/cris.*/cris/' \
100 )
Eric Andersen5912acb2003-11-05 11:34:26 +0000101endif
Eric Andersenc9f20d92002-12-05 08:41:41 +0000102
Rob Landley5076eb42006-04-19 20:32:27 +0000103# A nifty macro to make testing gcc features easier, but note that everything
Bernhard Reutner-Fischere28d1d62006-05-26 13:22:57 +0000104# that uses this _must_ use := or it will be re-evaluated everytime it is
105# referenced.
Bernhard Reutner-Fischer7b8ff222006-06-13 14:20:17 +0000106ifeq ($(strip $(BUILD_VERBOSE)),2)
Bernhard Reutner-Fischere28d1d62006-05-26 13:22:57 +0000107VERBOSE_CHECK_CC=echo CC=\"$(1)\" check_cc $(2) >&2;
Rob Landley5076eb42006-04-19 20:32:27 +0000108endif
Bernhard Reutner-Fischere28d1d62006-05-26 13:22:57 +0000109check_cc=$(shell \
110 $(VERBOSE_CHECK_CC) \
111 if [ "x$(1)" != "x" ] && [ "x$(2)" != "x" ]; then \
112 echo "int i;" > ./conftest.c; \
113 if $(1) $(2) -c -o conftest.o conftest.c > /dev/null 2>&1; \
114 then echo "$(2)"; else echo "$(3)"; fi ; \
115 rm -f conftest.c conftest.o; \
Bernhard Reutner-Fischerdf100942006-03-13 19:04:00 +0000116 fi)
117
Bernhard Reutner-Fischer081b1ac2006-06-11 16:41:10 +0000118ifneq ($(filter $(nocheck_targets),$(MAKECMDGOALS)),)
Bernhard Reutner-Fischere5de3842006-06-10 14:58:33 +0000119check_cc:=
120endif
121
Bernhard Reutner-Fischerdf100942006-03-13 19:04:00 +0000122# A not very robust macro to check for available ld flags
Bernhard Reutner-Fischer7b8ff222006-06-13 14:20:17 +0000123ifeq ($(strip $(BUILD_VERBOSE)),2)
Bernhard Reutner-Fischere28d1d62006-05-26 13:22:57 +0000124VERBOSE_CHECK_LD=echo LD=\"$(1)\" check_ld $(2) >&2;
125endif
Bernhard Reutner-Fischerdf100942006-03-13 19:04:00 +0000126check_ld=$(shell \
Bernhard Reutner-Fischere28d1d62006-05-26 13:22:57 +0000127 $(VERBOSE_CHECK_LD) \
128 if [ "x$(1)" != "x" ] && [ "x$(2)" != "x" ]; then \
129 $(1) -o /dev/null -b binary /dev/null > /dev/null 2>&1 && \
130 echo "-Wl,$(2)" ; \
Bernhard Reutner-Fischerdf100942006-03-13 19:04:00 +0000131 fi)
132
Bernhard Reutner-Fischer081b1ac2006-06-11 16:41:10 +0000133ifneq ($(filter $(nocheck_targets),$(MAKECMDGOALS)),)
Bernhard Reutner-Fischere5de3842006-06-10 14:58:33 +0000134check_ld:=
135endif
136
Bernhard Reutner-Fischere28d1d62006-05-26 13:22:57 +0000137# A not very robust macro to check for available strip flags
Bernhard Reutner-Fischer7b8ff222006-06-13 14:20:17 +0000138ifeq ($(strip $(BUILD_VERBOSE)),2)
Bernhard Reutner-Fischere28d1d62006-05-26 13:22:57 +0000139VERBOSE_CHECK_STRIP=echo STRIPCMD=\"$(1)\" check_strip $(2) >&2;
140endif
141check_strip=$(shell \
142 $(VERBOSE_CHECK_STRIP) \
143 if [ "x$(1)" != "x" ] && [ "x$(2)" != "x" ]; then \
144 echo "int i;" > ./conftest.c ; \
145 $(CC) -c -o conftest.o conftest.c > /dev/null 2>&1 ; \
146 $(1) $(2) conftest.o > /dev/null 2>&1 && \
147 echo "$(1) $(2)" || echo "$(3)"; \
148 rm -f conftest.c conftest.o > /dev/null 2>&1 ; \
149 fi)
150
Bernhard Reutner-Fischer081b1ac2006-06-11 16:41:10 +0000151ifneq ($(filter $(nocheck_targets),$(MAKECMDGOALS)),)
Bernhard Reutner-Fischere5de3842006-06-10 14:58:33 +0000152check_strip:=
153endif
Bernhard Reutner-Fischere28d1d62006-05-26 13:22:57 +0000154
155
156# Select the compiler needed to build binaries for your development system
157HOSTCC = gcc
158HOSTCFLAGS:=$(call check_cc,$(HOSTCC),-Wall,)
159HOSTCFLAGS+=$(call check_cc,$(HOSTCC),-Wstrict-prototypes,)
160HOSTCFLAGS+=$(call check_cc,$(HOSTCC),-O2,)
161HOSTCFLAGS+=$(call check_cc,$(HOSTCC),-fomit-frame-pointer,)
162
163LD_WHOLE_ARCHIVE:=$(shell echo "int i;" > conftest.c ; \
164 $(CC) -c -o conftest.o conftest.c ; \
165 echo "int main(void){return 0;}" > conftest_main.c ; \
166 $(CC) -c -o conftest_main.o conftest_main.c ; \
167 $(AR) $(ARFLAGS) conftest.a conftest.o ; \
168 $(CC) -Wl,--whole-archive conftest.a -Wl,--no-whole-archive \
169 conftest_main.o -o conftest > /dev/null 2>&1 \
170 && echo "-Wl,--whole-archive" ; \
171 rm conftest_main.o conftest_main.c conftest.o conftest.c \
172 conftest.a conftest > /dev/null 2>&1 ; )
173ifneq ($(findstring whole-archive,$(LD_WHOLE_ARCHIVE)),)
174LD_NO_WHOLE_ARCHIVE:= -Wl,--no-whole-archive
175endif
176
177LD_START_GROUP:=$(shell echo "int bar(void){return 0;}" > conftest.c ; \
178 $(CC) -c -o conftest.o conftest.c ; \
179 echo "int main(void){return bar();}" > conftest_main.c ; \
180 $(CC) -c -o conftest_main.o conftest_main.c ; \
181 $(AR) $(ARFLAGS) conftest.a conftest.o ; \
182 $(CC) -Wl,--start-group conftest.a conftest_main.o -Wl,--end-group \
183 -o conftest > /dev/null 2>&1 && echo "-Wl,--start-group" ; \
Bernhard Reutner-Fischer07736812006-05-29 20:01:52 +0000184 rm conftest_main.o conftest_main.c conftest.o conftest.c \
Bernhard Reutner-Fischere28d1d62006-05-26 13:22:57 +0000185 conftest.a conftest > /dev/null 2>&1 ; )
186ifneq ($(findstring start-group,$(LD_START_GROUP)),)
187LD_END_GROUP:= -Wl,--end-group
188endif
189
190CHECKED_LDFLAGS := $(call check_ld,$(LD),--warn-common,)
191
Rob Landley5076eb42006-04-19 20:32:27 +0000192# Pin CHECKED_CFLAGS with := so it's only evaluated once.
Bernhard Reutner-Fischere28d1d62006-05-26 13:22:57 +0000193CHECKED_CFLAGS:=$(call check_cc,$(CC),-Wall,)
194CHECKED_CFLAGS+=$(call check_cc,$(CC),-Wstrict-prototypes,)
195CHECKED_CFLAGS+=$(call check_cc,$(CC),-Wshadow,)
196CHECKED_CFLAGS+=$(call check_cc,$(CC),-funsigned-char,)
197CHECKED_CFLAGS+=$(call check_cc,$(CC),-mmax-stack-frame=256,)
198CHECKED_CFLAGS+=$(call check_cc,$(CC),-fno-builtin-strlen)
Bernhard Reutner-Fischerdf100942006-03-13 19:04:00 +0000199
Rob Landley5076eb42006-04-19 20:32:27 +0000200# Preemptively pin this too.
201PROG_CFLAGS:=
202
Bernhard Reutner-Fischer7ca61b62006-01-15 14:04:57 +0000203
Eric Andersen5b0f9e42002-06-23 04:50:49 +0000204#--------------------------------------------------------
205# Arch specific compiler optimization stuff should go here.
206# Unless you want to override the defaults, do not set anything
Bernhard Reutner-Fischerdf100942006-03-13 19:04:00 +0000207# for OPTIMIZATION...
Eric Andersen5b0f9e42002-06-23 04:50:49 +0000208
209# use '-Os' optimization if available, else use -O2
Bernhard Reutner-Fischere28d1d62006-05-26 13:22:57 +0000210OPTIMIZATION:=$(call check_cc,$(CC),-Os,-O2)
Eric Andersen5b0f9e42002-06-23 04:50:49 +0000211
Bernhard Reutner-Fischerdf100942006-03-13 19:04:00 +0000212ifeq ($(CONFIG_BUILD_AT_ONCE),y)
Bernhard Reutner-Fischer7ca61b62006-01-15 14:04:57 +0000213# gcc 2.95 exits with 0 for "unrecognized option"
Bernhard Reutner-Fischerdf100942006-03-13 19:04:00 +0000214ifeq ($(strip $(shell [ $(CC_MAJOR) -ge 3 ] ; echo $$?)),0)
Bernhard Reutner-Fischere28d1d62006-05-26 13:22:57 +0000215 CFLAGS_COMBINE:=$(call check_cc,$(CC),--combine,)
Bernhard Reutner-Fischerdf100942006-03-13 19:04:00 +0000216endif
Bernhard Reutner-Fischere28d1d62006-05-26 13:22:57 +0000217OPTIMIZATION+=$(call check_cc,$(CC),-funit-at-a-time,)
218OPTIMIZATION+=$(call check_cc,$(CC),-fgcse-after-reload,)
Bernhard Reutner-Fischer3737c032006-04-28 20:02:29 +0000219ifneq ($(CONFIG_BUILD_LIBBUSYBOX),y)
Bernhard Reutner-Fischerd1ba9162006-03-21 11:06:43 +0000220# http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25795
Bernhard Reutner-Fischer3737c032006-04-28 20:02:29 +0000221# This prevents us from using -fwhole-program when we build the lib
Bernhard Reutner-Fischere28d1d62006-05-26 13:22:57 +0000222PROG_CFLAGS+=$(call check_cc,$(CC),-fwhole-program,)
Bernhard Reutner-Fischer3737c032006-04-28 20:02:29 +0000223endif # CONFIG_BUILD_LIBBUSYBOX
Bernhard Reutner-Fischerdf100942006-03-13 19:04:00 +0000224endif # CONFIG_BUILD_AT_ONCE
Bernhard Reutner-Fischer7ca61b62006-01-15 14:04:57 +0000225
Bernhard Reutner-Fischere28d1d62006-05-26 13:22:57 +0000226LIB_LDFLAGS:=$(call check_ld,$(LD),--enable-new-dtags,)
227#LIB_LDFLAGS+=$(call check_ld,$(LD),--reduce-memory-overheads,)
228#LIB_LDFLAGS+=$(call check_ld,$(LD),--as-needed,)
229#LIB_LDFLAGS+=$(call check_ld,$(LD),--warn-shared-textrel,)
Bernhard Reutner-Fischer08a1b502006-01-27 15:45:56 +0000230
231
Eric Andersen5b0f9e42002-06-23 04:50:49 +0000232# Some nice architecture specific optimizations
Bernhard Reutner-Fischerdf100942006-03-13 19:04:00 +0000233ifeq ($(strip $(TARGET_ARCH)),arm)
234 OPTIMIZATION+=-fstrict-aliasing
235endif
236ifeq ($(strip $(TARGET_ARCH)),i386)
Bernhard Reutner-Fischere28d1d62006-05-26 13:22:57 +0000237 OPTIMIZATION+=$(call check_cc,$(CC),-march=i386,)
Bernhard Reutner-Fischerd9969ea2006-03-03 20:31:33 +0000238# gcc-4.0 and older seem to benefit from these
Bernhard Reutner-Fischerdf100942006-03-13 19:04:00 +0000239#ifneq ($(strip $(shell [ $(CC_MAJOR) -ge 4 -a $(CC_MINOR) -ge 1 ] ; echo $$?)),0)
Bernhard Reutner-Fischere28d1d62006-05-26 13:22:57 +0000240 OPTIMIZATION+=$(call check_cc,$(CC),-mpreferred-stack-boundary=2,)
241 OPTIMIZATION+=$(call check_cc,$(CC),-falign-functions=1 -falign-jumps=1 -falign-loops=1,\
Bernhard Reutner-Fischerdf100942006-03-13 19:04:00 +0000242 -malign-functions=0 -malign-jumps=0 -malign-loops=0)
243#endif # gcc-4.0 and older
Bernhard Reutner-Fischer7ca61b62006-01-15 14:04:57 +0000244
245# gcc-4.1 and beyond seem to benefit from these
Bernhard Reutner-Fischerdf100942006-03-13 19:04:00 +0000246ifeq ($(strip $(shell [ $(CC_MAJOR) -ge 4 -a $(CC_MINOR) -ge 1 ] ; echo $$?)),0)
247 # turn off flags which hurt -Os
Bernhard Reutner-Fischere28d1d62006-05-26 13:22:57 +0000248 OPTIMIZATION+=$(call check_cc,$(CC),-fno-tree-loop-optimize,)
249 OPTIMIZATION+=$(call check_cc,$(CC),-fno-tree-dominator-opts,)
250 OPTIMIZATION+=$(call check_cc,$(CC),-fno-strength-reduce,)
Bernhard Reutner-Fischer7ca61b62006-01-15 14:04:57 +0000251
Bernhard Reutner-Fischere28d1d62006-05-26 13:22:57 +0000252 OPTIMIZATION+=$(call check_cc,$(CC),-fno-branch-count-reg,)
Bernhard Reutner-Fischerdf100942006-03-13 19:04:00 +0000253endif # gcc-4.1 and beyond
254endif
Bernhard Reutner-Fischere28d1d62006-05-26 13:22:57 +0000255OPTIMIZATION+=$(call check_cc,$(CC),-fomit-frame-pointer,)
Rob Landley7900b7b2006-06-13 16:17:16 +0000256OPTIMIZATION+=$(call check_cc,$(CC),-ffunction-sections -fdata-sections,)
Eric Andersen5b0f9e42002-06-23 04:50:49 +0000257
Eric Andersen85208e22002-04-12 12:05:57 +0000258#
259#--------------------------------------------------------
260# If you're going to do a lot of builds with a non-vanilla configuration,
261# it makes sense to adjust parameters above, so you can type "make"
262# by itself, instead of following it by the same half-dozen overrides
263# every time. The stuff below, on the other hand, is probably less
264# prone to casual user adjustment.
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000265#
Eric Andersen85208e22002-04-12 12:05:57 +0000266
Bernhard Reutner-Fischerdf100942006-03-13 19:04:00 +0000267ifeq ($(strip $(CONFIG_LFS)),y)
Eric Andersen85208e22002-04-12 12:05:57 +0000268 # For large file summit support
Eric Andersenecfa2902002-09-22 12:09:44 +0000269 CFLAGS+=-D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
Eric Andersen85208e22002-04-12 12:05:57 +0000270endif
Bernhard Reutner-Fischerdf100942006-03-13 19:04:00 +0000271ifeq ($(strip $(CONFIG_DMALLOC)),y)
Eric Andersen85208e22002-04-12 12:05:57 +0000272 # For testing mem leaks with dmalloc
273 CFLAGS+=-DDMALLOC
274 LIBRARIES:=-ldmalloc
Eric Andersen85208e22002-04-12 12:05:57 +0000275else
Bernhard Reutner-Fischerdf100942006-03-13 19:04:00 +0000276 ifeq ($(strip $(CONFIG_EFENCE)),y)
Eric Andersen85208e22002-04-12 12:05:57 +0000277 LIBRARIES:=-lefence
Eric Andersen85208e22002-04-12 12:05:57 +0000278 endif
279endif
Rob Landleyc503df52006-05-09 22:08:56 +0000280
281# Debugging info
282
Bernhard Reutner-Fischerdf100942006-03-13 19:04:00 +0000283ifeq ($(strip $(CONFIG_DEBUG)),y)
Rob Landleyc503df52006-05-09 22:08:56 +0000284 CFLAGS +=-g
Eric Andersen85208e22002-04-12 12:05:57 +0000285else
Rob Landleyc503df52006-05-09 22:08:56 +0000286 CFLAGS +=-DNDEBUG
Bernhard Reutner-Fischere28d1d62006-05-26 13:22:57 +0000287 CHECKED_LDFLAGS += $(call check_ld,$(LD),--sort-common,)
Rob Landley7900b7b2006-06-13 16:17:16 +0000288 CHECKED_LDFLAGS += $(call check_ld,--gc-sections,)
Mike Frysingerc70240c2006-03-10 23:20:48 +0000289endif
Rob Landleyc503df52006-05-09 22:08:56 +0000290
291ifneq ($(strip $(CONFIG_DEBUG_PESSIMIZE)),y)
Rob Landleyc503df52006-05-09 22:08:56 +0000292 CFLAGS += $(OPTIMIZATION)
293endif
294
Bernhard Reutner-Fischerabaef652006-03-29 22:28:27 +0000295# warn a bit more verbosely for non-release versions
296ifneq ($(EXTRAVERSION),)
Bernhard Reutner-Fischere28d1d62006-05-26 13:22:57 +0000297 CHECKED_CFLAGS+=$(call check_cc,$(CC),-Wstrict-prototypes,)
298 CHECKED_CFLAGS+=$(call check_cc,$(CC),-Wmissing-prototypes,)
299 CHECKED_CFLAGS+=$(call check_cc,$(CC),-Wmissing-declarations,)
300 CHECKED_CFLAGS+=$(call check_cc,$(CC),-Wunused,)
301 CHECKED_CFLAGS+=$(call check_cc,$(CC),-Winit-self,)
302 CHECKED_CFLAGS+=$(call check_cc,$(CC),-Wshadow,)
303 CHECKED_CFLAGS+=$(call check_cc,$(CC),-Wcast-align,)
Bernhard Reutner-Fischerabaef652006-03-29 22:28:27 +0000304endif
Bernhard Reutner-Fischere28d1d62006-05-26 13:22:57 +0000305STRIPCMD:=$(call check_strip,$(STRIP),-s --remove-section=.note --remove-section=.comment,$(STRIP))
Bernhard Reutner-Fischerdf100942006-03-13 19:04:00 +0000306ifeq ($(strip $(CONFIG_STATIC)),y)
Bernhard Reutner-Fischere28d1d62006-05-26 13:22:57 +0000307 PROG_CFLAGS += $(call check_cc,$(CC),-static,)
Bernhard Reutner-Fischerdf100942006-03-13 19:04:00 +0000308endif
Bernhard Reutner-Fischere28d1d62006-05-26 13:22:57 +0000309CFLAGS_SHARED := $(call check_cc,$(CC),-shared,)
Bernhard Reutner-Fischer81b94962006-01-31 11:29:22 +0000310LIB_CFLAGS+=$(CFLAGS_SHARED)
Bernhard Reutner-Fischer7ca61b62006-01-15 14:04:57 +0000311
Bernhard Reutner-Fischerdf100942006-03-13 19:04:00 +0000312ifeq ($(strip $(CONFIG_BUILD_LIBBUSYBOX)),y)
Bernhard Reutner-Fischere28d1d62006-05-26 13:22:57 +0000313 CFLAGS_PIC:= $(call check_cc,$(CC),-fPIC,)
Bernhard Reutner-Fischerdf100942006-03-13 19:04:00 +0000314 LIB_CFLAGS+=$(CFLAGS_PIC)
315endif
Eric Andersen85208e22002-04-12 12:05:57 +0000316
Bernhard Reutner-Fischerdf100942006-03-13 19:04:00 +0000317ifeq ($(strip $(CONFIG_SELINUX)),y)
Rob Landleydbd91af2006-03-28 19:40:15 +0000318 LIBRARIES += -lselinux
Bernhard Reutner-Fischer5c071bc2005-10-05 07:40:46 +0000319endif
320
Eric Andersen12f834c2002-10-26 10:17:24 +0000321ifeq ($(strip $(PREFIX)),)
Eric Andersen85208e22002-04-12 12:05:57 +0000322 PREFIX:=`pwd`/_install
323endif
324
Bernhard Reutner-Fischer01d23ad2006-05-26 20:19:22 +0000325ifneq ($(strip $(CONFIG_GETOPT_LONG)),y)
326 CFLAGS += -D__need_getopt
327endif
Bernhard Reutner-Fischere28d1d62006-05-26 13:22:57 +0000328
Bernhard Reutner-Fischerdf100942006-03-13 19:04:00 +0000329# Additional complications due to support for pristine source dir.
330# Include files in the build directory should take precedence over
331# the copy in top_srcdir, both during the compilation phase and the
332# shell script that finds the list of object files.
333# Work in progress by <ldoolitt@recycle.lbl.gov>.
334
335
336OBJECTS:=$(APPLET_SOURCES:.c=.o) busybox.o usage.o applets.o
Bernhard Reutner-Fischere28d1d62006-05-26 13:22:57 +0000337CFLAGS += $(CHECKED_CFLAGS) $(CROSS_CFLAGS)
338LDFLAGS += $(CHECKED_LDFLAGS)
339
Eric Andersen85208e22002-04-12 12:05:57 +0000340ifdef BB_INIT_SCRIPT
341 CFLAGS += -DINIT_SCRIPT='"$(BB_INIT_SCRIPT)"'
342endif
343
344# Put user-supplied flags at the end, where they
345# have a chance of winning.
346CFLAGS += $(CFLAGS_EXTRA)
Eric Andersen4bcdd722001-10-24 05:26:42 +0000347
Rob Landleye0c418e2005-12-15 07:25:54 +0000348#------------------------------------------------------------
349# Installation options
350ifeq ($(strip $(CONFIG_INSTALL_APPLET_HARDLINKS)),y)
351INSTALL_OPTS=--hardlinks
352endif
353ifeq ($(strip $(CONFIG_INSTALL_APPLET_SYMLINKS)),y)
354INSTALL_OPTS=--symlinks
355endif
356ifeq ($(strip $(CONFIG_INSTALL_APPLET_DONT)),y)
357INSTALL_OPTS=
358endif
359
Mike Frysingerb38673f2006-02-02 01:41:53 +0000360#------------------------------------------------------------
361# Make the output nice and tight
Bernhard Reutner-Fischerdf100942006-03-13 19:04:00 +0000362MAKEFLAGS += --no-print-directory
Mike Frysingerb38673f2006-02-02 01:41:53 +0000363export MAKE_IS_SILENT=n
364ifneq ($(findstring s,$(MAKEFLAGS)),)
365export MAKE_IS_SILENT=y
Bernhard Reutner-Fischerdf100942006-03-13 19:04:00 +0000366SECHO := @-false
Mike Frysingerb38673f2006-02-02 01:41:53 +0000367DISP := sil
368Q := @
369else
Bernhard Reutner-Fischer7b8ff222006-06-13 14:20:17 +0000370ifneq ($(BUILD_VERBOSE),)
Bernhard Reutner-Fischerdf100942006-03-13 19:04:00 +0000371SECHO := @-false
Mike Frysingerb38673f2006-02-02 01:41:53 +0000372DISP := ver
373Q :=
374else
Bernhard Reutner-Fischerdf100942006-03-13 19:04:00 +0000375SECHO := @echo
Mike Frysingerb38673f2006-02-02 01:41:53 +0000376DISP := pur
377Q := @
378endif
379endif
380
Bernhard Reutner-Fischerdf100942006-03-13 19:04:00 +0000381show_objs = $(subst $(top_builddir)/,,$(subst ../,,$@))
382pur_disp_compile.c = echo " "CC $(show_objs)
383pur_disp_compile.h = echo " "HOSTCC $(show_objs)
384pur_disp_strip = echo " "STRIP $(show_objs)
385pur_disp_link = echo " "LINK $(show_objs)
Bernhard Reutner-Fischer45d54582006-05-08 20:20:32 +0000386pur_disp_link.h = echo " "HOSTLINK $(show_objs)
Bernhard Reutner-Fischerdf100942006-03-13 19:04:00 +0000387pur_disp_ar = echo " "AR $(ARFLAGS) $(show_objs)
Mike Frysinger586ea612006-04-21 01:18:07 +0000388pur_disp_elf2flt = echo " "ELF2FLT $(ELF2FLTFLAGS) $(show_objs)
Bernhard Reutner-Fischerdf100942006-03-13 19:04:00 +0000389sil_disp_compile.c = true
390sil_disp_compile.h = true
391sil_disp_strip = true
392sil_disp_link = true
Bernhard Reutner-Fischer45d54582006-05-08 20:20:32 +0000393sil_disp_link.h = true
Bernhard Reutner-Fischerdf100942006-03-13 19:04:00 +0000394sil_disp_ar = true
Mike Frysinger586ea612006-04-21 01:18:07 +0000395sil_disp_elf2flt = true
Bernhard Reutner-Fischerdf100942006-03-13 19:04:00 +0000396ver_disp_compile.c = echo $(cmd_compile.c)
397ver_disp_compile.h = echo $(cmd_compile.h)
398ver_disp_strip = echo $(cmd_strip)
399ver_disp_link = echo $(cmd_link)
Bernhard Reutner-Fischer45d54582006-05-08 20:20:32 +0000400ver_disp_link.h = echo $(cmd_link.h)
Bernhard Reutner-Fischerdf100942006-03-13 19:04:00 +0000401ver_disp_ar = echo $(cmd_ar)
Mike Frysinger586ea612006-04-21 01:18:07 +0000402ver_disp_elf2flt = echo $(cmd_elf2flt)
Mike Frysingerb38673f2006-02-02 01:41:53 +0000403disp_compile.c = $($(DISP)_disp_compile.c)
404disp_compile.h = $($(DISP)_disp_compile.h)
405disp_strip = $($(DISP)_disp_strip)
406disp_link = $($(DISP)_disp_link)
Bernhard Reutner-Fischer45d54582006-05-08 20:20:32 +0000407disp_link.h = $($(DISP)_disp_link.h)
Mike Frysingerb38673f2006-02-02 01:41:53 +0000408disp_ar = $($(DISP)_disp_ar)
Bernhard Reutner-Fischerdf100942006-03-13 19:04:00 +0000409disp_gen = $(SECHO) " "GEN $@ ; true
410disp_doc = $(SECHO) " "DOC $(subst docs/,,$@) ; true
Mike Frysinger586ea612006-04-21 01:18:07 +0000411disp_elf2flt = $($(DISP)_disp_elf2flt)
Bernhard Reutner-Fischerdf100942006-03-13 19:04:00 +0000412cmd_compile.c = $(CC) $(CFLAGS) $(EXTRA_CFLAGS) -c -o $@ $<
Bernhard Reutner-Fischer45d54582006-05-08 20:20:32 +0000413cmd_compile.h = $(HOSTCC) $(HOSTCFLAGS) $(INCS) -c -o $@ $<
Mike Frysingerb38673f2006-02-02 01:41:53 +0000414cmd_strip = $(STRIPCMD) $@
Bernhard Reutner-Fischer7b8ff222006-06-13 14:20:17 +0000415cmd_link = $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(LDFLAGS) \
416 $(PROG_CFLAGS) $(PROG_LDFLAGS) $(CFLAGS_COMBINE) \
417 -o $@ $(LD_START_GROUP) \
418 $(APPLETS_DEFINE) $(APPLET_SRC) \
419 $(BUSYBOX_DEFINE) $(BUSYBOX_SRC) $(libraries-y) \
420 $(LDBUSYBOX) $(LIBRARIES) \
421 $(LD_END_GROUP)
422cmd_link.so = $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(LDFLAGS) \
423 $(LIB_CFLAGS) $(CFLAGS_COMBINE) $(LIB_LDFLAGS) \
424 -o $(@) $(LD_START_GROUP) $(LD_WHOLE_ARCHIVE) \
425 $(LIBRARY_DEFINE) $(^) \
426 $(LD_NO_WHOLE_ARCHIVE) $(LD_END_GROUP)
Bernhard Reutner-Fischer45d54582006-05-08 20:20:32 +0000427cmd_link.h = $(HOSTCC) $(HOSTCFLAGS) $(INCS) $< -o $@
Mike Frysingerb38673f2006-02-02 01:41:53 +0000428cmd_ar = $(AR) $(ARFLAGS) $@ $^
Mike Frysinger586ea612006-04-21 01:18:07 +0000429cmd_elf2flt = $(ELF2FLT) $(ELF2FLTFLAGS) $< -o $@
Bernhard Reutner-Fischerdf100942006-03-13 19:04:00 +0000430compile.c = @$(disp_compile.c) ; $(cmd_compile.c)
431compile.h = @$(disp_compile.h) ; $(cmd_compile.h)
432do_strip = @$(disp_strip) ; $(cmd_strip)
433do_link = @$(disp_link) ; $(cmd_link)
Bernhard Reutner-Fischer7b8ff222006-06-13 14:20:17 +0000434do_link.so = @$(disp_link) ; $(cmd_link.so)
Bernhard Reutner-Fischer45d54582006-05-08 20:20:32 +0000435do_link.h = @$(disp_link.h) ; $(cmd_link.h)
Bernhard Reutner-Fischerdf100942006-03-13 19:04:00 +0000436do_ar = @$(disp_ar) ; $(cmd_ar)
Mike Frysinger586ea612006-04-21 01:18:07 +0000437do_elf2flt = @$(disp_elf2flt) ; $(cmd_elf2flt)
Mike Frysingerb38673f2006-02-02 01:41:53 +0000438
Bernhard Reutner-Fischere5de3842006-06-10 14:58:33 +0000439uppercase = $(shell echo $1 | $(SED) -e "y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/")
Mike Frysinger6143c072006-05-10 18:12:16 +0000440%.a:
441 @if test -z "$($(call uppercase,$*)_DIR)" ; then \
442 echo "Invalid target $@" ; \
443 exit 1 ; \
444 fi
445 $(Q)$(MAKE) $($(call uppercase,$*)_DIR)$@
446
Eric Andersen85208e22002-04-12 12:05:57 +0000447.PHONY: dummy