source: MondoRescue/branches/2.2.5/mindi-busybox/Rules.mak@ 1764

Last change on this file since 1764 was 1004, checked in by Bruno Cornec, 17 years ago

Fix a known bug for busybox where -gc-section in makefile + static for link creates a buggy busybox with glibc (the real bugs seems to be in glibc)
Cf: http://lwn.net/Articles/208775/

File size: 14.8 KB
Line 
1# Rules.make for busybox
2#
3# Copyright (C) 1999-2005 by Erik Andersen <andersen@codepoet.org>
4#
5# Licensed under GPLv2, see the file LICENSE in this tarball for details.
6#
7
8# Pull in the user's busybox configuration
9ifeq ($(filter $(noconfig_targets),$(MAKECMDGOALS)),)
10-include $(top_builddir)/.config
11endif
12
13#--------------------------------------------------------
14PROG := busybox
15MAJOR_VERSION :=1
16MINOR_VERSION :=2
17SUBLEVEL_VERSION:=2
18EXTRAVERSION :=
19VERSION :=$(MAJOR_VERSION).$(MINOR_VERSION).$(SUBLEVEL_VERSION)$(EXTRAVERSION)
20BUILDTIME := $(shell TZ=UTC date -u "+%Y.%m.%d-%H:%M%z")
21
22
23#--------------------------------------------------------
24# 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:
27# make CROSS=powerpc-linux- top_srcdir="$HOME/busybox" PREFIX=/mnt/app
28#--------------------------------------------------------
29
30# 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
33# your compiler is broken, you should not need to specify TARGET_ARCH
34CROSS =$(strip $(subst ",, $(strip $(CROSS_COMPILER_PREFIX))))
35# be gentle to vi coloring.. "))
36CC = $(CROSS)gcc
37AR = $(CROSS)ar
38AS = $(CROSS)as
39LD = $(CROSS)ld
40NM = $(CROSS)nm
41STRIP = $(CROSS)strip
42ELF2FLT = $(CROSS)elf2flt
43CPP = $(CC) -E
44SED ?= sed
45BZIP2 ?= bzip2
46
47
48# What OS are you compiling busybox for? This allows you to include
49# OS specific things, syscall overrides, etc.
50TARGET_OS=linux
51
52# Ensure consistent sort order, 'gcc -print-search-dirs' behavior, etc.
53LC_ALL:= C
54
55# This must bind late because srcdir is reset for every source subdirectory.
56INCS:=-I$(top_builddir)/include -I$(top_srcdir)/include
57CFLAGS=$(INCS) -I$(srcdir) -D_GNU_SOURCE
58CFLAGS+=$(CHECKED_CFLAGS)
59ARFLAGS=cru
60
61# gcc centric. Perhaps fiddle with findstring gcc,$(CC) for the rest
62# get the CC MAJOR/MINOR version
63CC_MAJOR:=$(shell printf "%02d" $(shell echo __GNUC__ | $(CC) -E -xc - | tail -n 1))
64CC_MINOR:=$(shell printf "%02d" $(shell echo __GNUC_MINOR__ | $(CC) -E -xc - | tail -n 1))
65
66#--------------------------------------------------------
67export VERSION BUILDTIME HOSTCC HOSTCFLAGS CROSS CC AR AS LD NM STRIP CPP
68ifeq ($(strip $(TARGET_ARCH)),)
69TARGET_ARCH:=$(shell $(CC) -dumpmachine | $(SED) -e s'/-.*//' \
70 -e 's/i.86/i386/' \
71 -e 's/sparc.*/sparc/' \
72 -e 's/arm.*/arm/g' \
73 -e 's/m68k.*/m68k/' \
74 -e 's/ppc/powerpc/g' \
75 -e 's/v850.*/v850/g' \
76 -e 's/sh[234]/sh/' \
77 -e 's/mips-.*/mips/' \
78 -e 's/mipsel-.*/mipsel/' \
79 -e 's/cris.*/cris/' \
80 )
81endif
82
83# A nifty macro to make testing gcc features easier, but note that everything
84# that uses this _must_ use := or it will be re-evaluated everytime it is
85# referenced.
86ifeq ($(strip $(BUILD_VERBOSE)),2)
87VERBOSE_CHECK_CC=echo CC=\"$(1)\" check_cc $(2) >&2;
88endif
89check_cc=$(shell \
90 $(VERBOSE_CHECK_CC) \
91 if [ "x$(1)" != "x" ] && [ "x$(2)" != "x" ]; then \
92 echo "int i;" > ./conftest.c; \
93 if $(1) $(2) -c -o conftest.o conftest.c > /dev/null 2>&1; \
94 then echo "$(2)"; else echo "$(3)"; fi ; \
95 rm -f conftest.c conftest.o; \
96 fi)
97
98ifneq ($(filter $(nocheck_targets),$(MAKECMDGOALS)),)
99check_cc:=
100endif
101
102# A not very robust macro to check for available ld flags
103ifeq ($(strip $(BUILD_VERBOSE)),2)
104VERBOSE_CHECK_LD=echo LD=\"$(1)\" check_ld $(2) >&2;
105endif
106check_ld=$(shell \
107 $(VERBOSE_CHECK_LD) \
108 if [ "x$(1)" != "x" ] && [ "x$(2)" != "x" ]; then \
109 $(1) -o /dev/null -b binary /dev/null > /dev/null 2>&1 && \
110 echo "-Wl,$(2)" ; \
111 fi)
112
113ifneq ($(filter $(nocheck_targets),$(MAKECMDGOALS)),)
114check_ld:=
115endif
116
117# A not very robust macro to check for available strip flags
118ifeq ($(strip $(BUILD_VERBOSE)),2)
119VERBOSE_CHECK_STRIP=echo STRIPCMD=\"$(1)\" check_strip $(2) >&2;
120endif
121check_strip=$(shell \
122 $(VERBOSE_CHECK_STRIP) \
123 if [ "x$(1)" != "x" ] && [ "x$(2)" != "x" ]; then \
124 echo "int i;" > ./conftest.c ; \
125 $(CC) -c -o conftest.o conftest.c > /dev/null 2>&1 ; \
126 $(1) $(2) conftest.o > /dev/null 2>&1 && \
127 echo "$(1) $(2)" || echo "$(3)"; \
128 rm -f conftest.c conftest.o > /dev/null 2>&1 ; \
129 fi)
130
131ifneq ($(filter $(nocheck_targets),$(MAKECMDGOALS)),)
132check_strip:=
133endif
134
135
136# Select the compiler needed to build binaries for your development system
137HOSTCC = gcc
138HOSTCFLAGS:=$(call check_cc,$(HOSTCC),-Wall,)
139HOSTCFLAGS+=$(call check_cc,$(HOSTCC),-Wstrict-prototypes,)
140HOSTCFLAGS+=$(call check_cc,$(HOSTCC),-O2,)
141HOSTCFLAGS+=$(call check_cc,$(HOSTCC),-fomit-frame-pointer,)
142
143LD_WHOLE_ARCHIVE:=$(shell echo "int i;" > conftest.c ; \
144 $(CC) -c -o conftest.o conftest.c ; \
145 echo "int main(void){return 0;}" > conftest_main.c ; \
146 $(CC) -c -o conftest_main.o conftest_main.c ; \
147 $(AR) $(ARFLAGS) conftest.a conftest.o ; \
148 $(CC) -Wl,--whole-archive conftest.a -Wl,--no-whole-archive \
149 conftest_main.o -o conftest > /dev/null 2>&1 \
150 && echo "-Wl,--whole-archive" ; \
151 rm conftest_main.o conftest_main.c conftest.o conftest.c \
152 conftest.a conftest > /dev/null 2>&1 ; )
153ifneq ($(findstring whole-archive,$(LD_WHOLE_ARCHIVE)),)
154LD_NO_WHOLE_ARCHIVE:= -Wl,--no-whole-archive
155endif
156
157LD_START_GROUP:=$(shell echo "int bar(void){return 0;}" > conftest.c ; \
158 $(CC) -c -o conftest.o conftest.c ; \
159 echo "int main(void){return bar();}" > conftest_main.c ; \
160 $(CC) -c -o conftest_main.o conftest_main.c ; \
161 $(AR) $(ARFLAGS) conftest.a conftest.o ; \
162 $(CC) -Wl,--start-group conftest.a conftest_main.o -Wl,--end-group \
163 -o conftest > /dev/null 2>&1 && echo "-Wl,--start-group" ; \
164 rm conftest_main.o conftest_main.c conftest.o conftest.c \
165 conftest.a conftest > /dev/null 2>&1 ; )
166ifneq ($(findstring start-group,$(LD_START_GROUP)),)
167LD_END_GROUP:= -Wl,--end-group
168endif
169
170CHECKED_LDFLAGS := $(call check_ld,$(LD),--warn-common,)
171
172# Pin CHECKED_CFLAGS with := so it's only evaluated once.
173CHECKED_CFLAGS:=$(call check_cc,$(CC),-Wall,)
174CHECKED_CFLAGS+=$(call check_cc,$(CC),-Wstrict-prototypes,)
175CHECKED_CFLAGS+=$(call check_cc,$(CC),-Wshadow,)
176CHECKED_CFLAGS+=$(call check_cc,$(CC),-funsigned-char,)
177CHECKED_CFLAGS+=$(call check_cc,$(CC),-mmax-stack-frame=256,)
178CHECKED_CFLAGS+=$(call check_cc,$(CC),-fno-builtin-strlen)
179
180# Preemptively pin this too.
181PROG_CFLAGS:=
182
183
184#--------------------------------------------------------
185# Arch specific compiler optimization stuff should go here.
186# Unless you want to override the defaults, do not set anything
187# for OPTIMIZATION...
188
189# use '-Os' optimization if available, else use -O2
190OPTIMIZATION:=$(call check_cc,$(CC),-Os,-O2)
191
192ifeq ($(CONFIG_BUILD_AT_ONCE),y)
193# gcc 2.95 exits with 0 for "unrecognized option"
194ifeq ($(strip $(shell [ $(CC_MAJOR) -ge 3 ] ; echo $$?)),0)
195 CFLAGS_COMBINE:=$(call check_cc,$(CC),--combine,)
196endif
197OPTIMIZATION+=$(call check_cc,$(CC),-funit-at-a-time,)
198OPTIMIZATION+=$(call check_cc,$(CC),-fgcse-after-reload,)
199ifneq ($(CONFIG_BUILD_LIBBUSYBOX),y)
200# http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25795
201# This prevents us from using -fwhole-program when we build the lib
202PROG_CFLAGS+=$(call check_cc,$(CC),-fwhole-program,)
203endif # CONFIG_BUILD_LIBBUSYBOX
204endif # CONFIG_BUILD_AT_ONCE
205
206LIB_LDFLAGS:=$(call check_ld,$(LD),--enable-new-dtags,)
207#LIB_LDFLAGS+=$(call check_ld,$(LD),--reduce-memory-overheads,)
208#LIB_LDFLAGS+=$(call check_ld,$(LD),--as-needed,)
209#LIB_LDFLAGS+=$(call check_ld,$(LD),--warn-shared-textrel,)
210
211
212# Some nice architecture specific optimizations
213ifeq ($(strip $(TARGET_ARCH)),arm)
214 OPTIMIZATION+=-fstrict-aliasing
215endif
216ifeq ($(strip $(TARGET_ARCH)),i386)
217 OPTIMIZATION+=$(call check_cc,$(CC),-march=i386,)
218# gcc-4.0 and older seem to benefit from these
219#ifneq ($(strip $(shell [ $(CC_MAJOR) -ge 4 -a $(CC_MINOR) -ge 1 ] ; echo $$?)),0)
220 OPTIMIZATION+=$(call check_cc,$(CC),-mpreferred-stack-boundary=2,)
221 OPTIMIZATION+=$(call check_cc,$(CC),-falign-functions=1 -falign-jumps=1 -falign-loops=1,\
222 -malign-functions=0 -malign-jumps=0 -malign-loops=0)
223#endif # gcc-4.0 and older
224
225# gcc-4.1 and beyond seem to benefit from these
226ifeq ($(strip $(shell [ $(CC_MAJOR) -ge 4 -a $(CC_MINOR) -ge 1 ] ; echo $$?)),0)
227 # turn off flags which hurt -Os
228 OPTIMIZATION+=$(call check_cc,$(CC),-fno-tree-loop-optimize,)
229 OPTIMIZATION+=$(call check_cc,$(CC),-fno-tree-dominator-opts,)
230 OPTIMIZATION+=$(call check_cc,$(CC),-fno-strength-reduce,)
231
232 OPTIMIZATION+=$(call check_cc,$(CC),-fno-branch-count-reg,)
233endif # gcc-4.1 and beyond
234endif
235OPTIMIZATION+=$(call check_cc,$(CC),-fomit-frame-pointer,)
236OPTIMIZATION+=$(call check_cc,$(CC),-ffunction-sections -fdata-sections,)
237
238#
239#--------------------------------------------------------
240# If you're going to do a lot of builds with a non-vanilla configuration,
241# it makes sense to adjust parameters above, so you can type "make"
242# by itself, instead of following it by the same half-dozen overrides
243# every time. The stuff below, on the other hand, is probably less
244# prone to casual user adjustment.
245#
246
247ifeq ($(strip $(CONFIG_LFS)),y)
248 # For large file summit support
249 CFLAGS+=-D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
250endif
251ifeq ($(strip $(CONFIG_DMALLOC)),y)
252 # For testing mem leaks with dmalloc
253 CFLAGS+=-DDMALLOC
254 LIBRARIES:=-ldmalloc
255else
256 ifeq ($(strip $(CONFIG_EFENCE)),y)
257 LIBRARIES:=-lefence
258 endif
259endif
260
261# Debugging info
262
263ifeq ($(strip $(CONFIG_DEBUG)),y)
264 CFLAGS +=-g
265else
266 CFLAGS +=-DNDEBUG
267 CHECKED_LDFLAGS += $(call check_ld,$(LD),--sort-common,)
268ifneq ($(strip $(CONFIG_STATIC)),y)
269 CHECKED_LDFLAGS += $(call check_ld,$(LD),--gc-sections,)
270endif
271endif
272
273ifneq ($(strip $(CONFIG_DEBUG_PESSIMIZE)),y)
274 CFLAGS += $(OPTIMIZATION)
275endif
276
277# warn a bit more verbosely for non-release versions
278ifneq ($(EXTRAVERSION),)
279 CHECKED_CFLAGS+=$(call check_cc,$(CC),-Wstrict-prototypes,)
280 CHECKED_CFLAGS+=$(call check_cc,$(CC),-Wmissing-prototypes,)
281 CHECKED_CFLAGS+=$(call check_cc,$(CC),-Wmissing-declarations,)
282 CHECKED_CFLAGS+=$(call check_cc,$(CC),-Wunused,)
283 CHECKED_CFLAGS+=$(call check_cc,$(CC),-Winit-self,)
284 CHECKED_CFLAGS+=$(call check_cc,$(CC),-Wshadow,)
285 CHECKED_CFLAGS+=$(call check_cc,$(CC),-Wcast-align,)
286endif
287STRIPCMD:=$(call check_strip,$(STRIP),-s --remove-section=.note --remove-section=.comment,$(STRIP))
288ifeq ($(strip $(CONFIG_STATIC)),y)
289 PROG_CFLAGS += $(call check_cc,$(CC),-static,)
290endif
291CFLAGS_SHARED := $(call check_cc,$(CC),-shared,)
292LIB_CFLAGS+=$(CFLAGS_SHARED)
293
294ifeq ($(strip $(CONFIG_BUILD_LIBBUSYBOX)),y)
295 CFLAGS_PIC:= $(call check_cc,$(CC),-fPIC,)
296 LIB_CFLAGS+=$(CFLAGS_PIC)
297endif
298
299ifeq ($(strip $(CONFIG_SELINUX)),y)
300 LIBRARIES += -lselinux -lsepol
301endif
302
303ifeq ($(strip $(PREFIX)),)
304 PREFIX:=`pwd`/_install
305endif
306
307ifneq ($(strip $(CONFIG_GETOPT_LONG)),y)
308 CFLAGS += -D__need_getopt
309endif
310
311# Additional complications due to support for pristine source dir.
312# Include files in the build directory should take precedence over
313# the copy in top_srcdir, both during the compilation phase and the
314# shell script that finds the list of object files.
315# Work in progress by <ldoolitt@recycle.lbl.gov>.
316
317
318OBJECTS:=$(APPLET_SOURCES:.c=.o) busybox.o usage.o applets.o
319CFLAGS += $(CHECKED_CFLAGS) $(CROSS_CFLAGS)
320LDFLAGS += $(CHECKED_LDFLAGS)
321
322ifdef BB_INIT_SCRIPT
323 CFLAGS += -DINIT_SCRIPT='"$(BB_INIT_SCRIPT)"'
324endif
325
326# Put user-supplied flags at the end, where they
327# have a chance of winning.
328-include $(top_builddir)/.config.mak
329
330#------------------------------------------------------------
331# Installation options
332ifeq ($(strip $(CONFIG_INSTALL_APPLET_HARDLINKS)),y)
333INSTALL_OPTS=--hardlinks
334endif
335ifeq ($(strip $(CONFIG_INSTALL_APPLET_SYMLINKS)),y)
336INSTALL_OPTS=--symlinks
337endif
338ifeq ($(strip $(CONFIG_INSTALL_APPLET_DONT)),y)
339INSTALL_OPTS=
340endif
341
342#------------------------------------------------------------
343# Make the output nice and tight
344MAKEFLAGS += --no-print-directory
345export MAKE_IS_SILENT=n
346ifneq ($(findstring s,$(MAKEFLAGS)),)
347export MAKE_IS_SILENT=y
348SECHO := @-false
349DISP := sil
350Q := @
351else
352ifneq ($(BUILD_VERBOSE),)
353SECHO := @-false
354DISP := ver
355Q :=
356else
357SECHO := @echo
358DISP := pur
359Q := @
360endif
361endif
362
363show_objs = $(subst $(top_builddir)/,,$(subst ../,,$@))
364pur_disp_compile.c = echo " "CC $(show_objs)
365pur_disp_compile.h = echo " "HOSTCC $(show_objs)
366pur_disp_strip = echo " "STRIP $(show_objs)
367pur_disp_link = echo " "LINK $(show_objs)
368pur_disp_link.h = echo " "HOSTLINK $(show_objs)
369pur_disp_ar = echo " "AR $(ARFLAGS) $(show_objs)
370pur_disp_elf2flt = echo " "ELF2FLT $(ELF2FLTFLAGS) $(show_objs)
371sil_disp_compile.c = true
372sil_disp_compile.h = true
373sil_disp_strip = true
374sil_disp_link = true
375sil_disp_link.h = true
376sil_disp_ar = true
377sil_disp_elf2flt = true
378ver_disp_compile.c = echo $(cmd_compile.c)
379ver_disp_compile.h = echo $(cmd_compile.h)
380ver_disp_strip = echo $(cmd_strip)
381ver_disp_link = echo $(cmd_link)
382ver_disp_link.h = echo $(cmd_link.h)
383ver_disp_ar = echo $(cmd_ar)
384ver_disp_elf2flt = echo $(cmd_elf2flt)
385disp_compile.c = $($(DISP)_disp_compile.c)
386disp_compile.h = $($(DISP)_disp_compile.h)
387disp_strip = $($(DISP)_disp_strip)
388disp_link = $($(DISP)_disp_link)
389disp_link.h = $($(DISP)_disp_link.h)
390disp_ar = $($(DISP)_disp_ar)
391disp_gen = $(SECHO) " "GEN $@ ; true
392disp_doc = $(SECHO) " "DOC $(subst docs/,,$@) ; true
393disp_elf2flt = $($(DISP)_disp_elf2flt)
394cmd_compile.c = $(CC) $(CFLAGS) $(EXTRA_CFLAGS) -c -o $@ $<
395cmd_compile.h = $(HOSTCC) $(HOSTCFLAGS) $(INCS) -c -o $@ $<
396cmd_strip = $(STRIPCMD) $@
397cmd_link = $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(LDFLAGS) \
398 $(PROG_CFLAGS) $(PROG_LDFLAGS) $(CFLAGS_COMBINE) \
399 -o $@ $(LD_START_GROUP) \
400 $(APPLETS_DEFINE) $(APPLET_SRC) \
401 $(BUSYBOX_DEFINE) $(BUSYBOX_SRC) $(libraries-y) \
402 $(LDBUSYBOX) $(LIBRARIES) \
403 $(LD_END_GROUP)
404cmd_link.so = $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(LDFLAGS) \
405 $(LIB_CFLAGS) $(CFLAGS_COMBINE) $(LIB_LDFLAGS) \
406 -o $(@) $(LD_START_GROUP) $(LD_WHOLE_ARCHIVE) \
407 $(LIBRARY_DEFINE) $(^) \
408 $(LD_NO_WHOLE_ARCHIVE) $(LD_END_GROUP)
409cmd_link.h = $(HOSTCC) $(HOSTCFLAGS) $(INCS) $< -o $@
410cmd_ar = $(AR) $(ARFLAGS) $@ $^
411cmd_elf2flt = $(ELF2FLT) $(ELF2FLTFLAGS) $< -o $@
412compile.c = @$(disp_compile.c) ; $(cmd_compile.c)
413compile.h = @$(disp_compile.h) ; $(cmd_compile.h)
414do_strip = @$(disp_strip) ; $(cmd_strip)
415do_link = @$(disp_link) ; $(cmd_link)
416do_link.so = @$(disp_link) ; $(cmd_link.so)
417do_link.h = @$(disp_link.h) ; $(cmd_link.h)
418do_ar = @$(disp_ar) ; $(cmd_ar)
419do_elf2flt = @$(disp_elf2flt) ; $(cmd_elf2flt)
420
421uppercase = $(shell echo $1 | $(SED) -e "y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/")
422%.a:
423 @if test -z "$($(call uppercase,$*)_DIR)" ; then \
424 echo "Invalid target $@" ; \
425 exit 1 ; \
426 fi
427 $(Q)$(MAKE) $($(call uppercase,$*)_DIR)$@
428
429.PHONY: dummy
Note: See TracBrowser for help on using the repository browser.