source: trunk/mindi-busybox/Rules.mak @ 929

Last change on this file since 929 was 904, checked in by bruno, 13 years ago

merge -r890:902 $SVN_M/branches/stable

File size: 14.7 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,)
268    CHECKED_LDFLAGS += $(call check_ld,$(LD),--gc-sections,)
269endif
270
271ifneq ($(strip $(CONFIG_DEBUG_PESSIMIZE)),y)
272    CFLAGS += $(OPTIMIZATION)
273endif
274
275# warn a bit more verbosely for non-release versions
276ifneq ($(EXTRAVERSION),)
277    CHECKED_CFLAGS+=$(call check_cc,$(CC),-Wstrict-prototypes,)
278    CHECKED_CFLAGS+=$(call check_cc,$(CC),-Wmissing-prototypes,)
279    CHECKED_CFLAGS+=$(call check_cc,$(CC),-Wmissing-declarations,)
280    CHECKED_CFLAGS+=$(call check_cc,$(CC),-Wunused,)
281    CHECKED_CFLAGS+=$(call check_cc,$(CC),-Winit-self,)
282    CHECKED_CFLAGS+=$(call check_cc,$(CC),-Wshadow,)
283    CHECKED_CFLAGS+=$(call check_cc,$(CC),-Wcast-align,)
284endif
285STRIPCMD:=$(call check_strip,$(STRIP),-s --remove-section=.note --remove-section=.comment,$(STRIP))
286ifeq ($(strip $(CONFIG_STATIC)),y)
287    PROG_CFLAGS += $(call check_cc,$(CC),-static,)
288endif
289CFLAGS_SHARED := $(call check_cc,$(CC),-shared,)
290LIB_CFLAGS+=$(CFLAGS_SHARED)
291
292ifeq ($(strip $(CONFIG_BUILD_LIBBUSYBOX)),y)
293    CFLAGS_PIC:= $(call check_cc,$(CC),-fPIC,)
294    LIB_CFLAGS+=$(CFLAGS_PIC)
295endif
296
297ifeq ($(strip $(CONFIG_SELINUX)),y)
298    LIBRARIES += -lselinux -lsepol
299endif
300
301ifeq ($(strip $(PREFIX)),)
302    PREFIX:=`pwd`/_install
303endif
304
305ifneq ($(strip $(CONFIG_GETOPT_LONG)),y)
306    CFLAGS += -D__need_getopt
307endif
308
309# Additional complications due to support for pristine source dir.
310# Include files in the build directory should take precedence over
311# the copy in top_srcdir, both during the compilation phase and the
312# shell script that finds the list of object files.
313# Work in progress by <ldoolitt@recycle.lbl.gov>.
314
315
316OBJECTS:=$(APPLET_SOURCES:.c=.o) busybox.o usage.o applets.o
317CFLAGS  += $(CHECKED_CFLAGS) $(CROSS_CFLAGS)
318LDFLAGS += $(CHECKED_LDFLAGS)
319
320ifdef BB_INIT_SCRIPT
321    CFLAGS += -DINIT_SCRIPT='"$(BB_INIT_SCRIPT)"'
322endif
323
324# Put user-supplied flags at the end, where they
325# have a chance of winning.
326-include $(top_builddir)/.config.mak
327
328#------------------------------------------------------------
329# Installation options
330ifeq ($(strip $(CONFIG_INSTALL_APPLET_HARDLINKS)),y)
331INSTALL_OPTS=--hardlinks
332endif
333ifeq ($(strip $(CONFIG_INSTALL_APPLET_SYMLINKS)),y)
334INSTALL_OPTS=--symlinks
335endif
336ifeq ($(strip $(CONFIG_INSTALL_APPLET_DONT)),y)
337INSTALL_OPTS=
338endif
339
340#------------------------------------------------------------
341# Make the output nice and tight
342MAKEFLAGS += --no-print-directory
343export MAKE_IS_SILENT=n
344ifneq ($(findstring s,$(MAKEFLAGS)),)
345export MAKE_IS_SILENT=y
346SECHO := @-false
347DISP  := sil
348Q     := @
349else
350ifneq ($(BUILD_VERBOSE),)
351SECHO := @-false
352DISP  := ver
353Q     :=
354else
355SECHO := @echo
356DISP  := pur
357Q     := @
358endif
359endif
360
361show_objs = $(subst $(top_builddir)/,,$(subst ../,,$@))
362pur_disp_compile.c = echo "  "CC $(show_objs)
363pur_disp_compile.h = echo "  "HOSTCC $(show_objs)
364pur_disp_strip     = echo "  "STRIP $(show_objs)
365pur_disp_link      = echo "  "LINK $(show_objs)
366pur_disp_link.h    = echo "  "HOSTLINK $(show_objs)
367pur_disp_ar        = echo "  "AR $(ARFLAGS) $(show_objs)
368pur_disp_elf2flt   = echo "  "ELF2FLT $(ELF2FLTFLAGS) $(show_objs)
369sil_disp_compile.c = true
370sil_disp_compile.h = true
371sil_disp_strip     = true
372sil_disp_link      = true
373sil_disp_link.h    = true
374sil_disp_ar        = true
375sil_disp_elf2flt   = true
376ver_disp_compile.c = echo $(cmd_compile.c)
377ver_disp_compile.h = echo $(cmd_compile.h)
378ver_disp_strip     = echo $(cmd_strip)
379ver_disp_link      = echo $(cmd_link)
380ver_disp_link.h    = echo $(cmd_link.h)
381ver_disp_ar        = echo $(cmd_ar)
382ver_disp_elf2flt   = echo $(cmd_elf2flt)
383disp_compile.c     = $($(DISP)_disp_compile.c)
384disp_compile.h     = $($(DISP)_disp_compile.h)
385disp_strip         = $($(DISP)_disp_strip)
386disp_link          = $($(DISP)_disp_link)
387disp_link.h        = $($(DISP)_disp_link.h)
388disp_ar            = $($(DISP)_disp_ar)
389disp_gen           = $(SECHO) "  "GEN $@ ; true
390disp_doc           = $(SECHO) "  "DOC $(subst docs/,,$@) ; true
391disp_elf2flt       = $($(DISP)_disp_elf2flt)
392cmd_compile.c      = $(CC) $(CFLAGS) $(EXTRA_CFLAGS) -c -o $@ $<
393cmd_compile.h      = $(HOSTCC) $(HOSTCFLAGS) $(INCS) -c -o $@ $<
394cmd_strip          = $(STRIPCMD) $@
395cmd_link           = $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(LDFLAGS) \
396            $(PROG_CFLAGS) $(PROG_LDFLAGS) $(CFLAGS_COMBINE) \
397            -o $@ $(LD_START_GROUP)  \
398            $(APPLETS_DEFINE) $(APPLET_SRC) \
399            $(BUSYBOX_DEFINE) $(BUSYBOX_SRC) $(libraries-y) \
400            $(LDBUSYBOX) $(LIBRARIES) \
401            $(LD_END_GROUP)
402cmd_link.so        = $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(LDFLAGS) \
403            $(LIB_CFLAGS) $(CFLAGS_COMBINE) $(LIB_LDFLAGS) \
404            -o $(@) $(LD_START_GROUP) $(LD_WHOLE_ARCHIVE) \
405            $(LIBRARY_DEFINE) $(^) \
406            $(LD_NO_WHOLE_ARCHIVE) $(LD_END_GROUP)
407cmd_link.h         = $(HOSTCC) $(HOSTCFLAGS) $(INCS) $< -o $@
408cmd_ar             = $(AR) $(ARFLAGS) $@ $^
409cmd_elf2flt        = $(ELF2FLT) $(ELF2FLTFLAGS) $< -o $@
410compile.c          = @$(disp_compile.c) ; $(cmd_compile.c)
411compile.h          = @$(disp_compile.h) ; $(cmd_compile.h)
412do_strip           = @$(disp_strip)     ; $(cmd_strip)
413do_link            = @$(disp_link)      ; $(cmd_link)
414do_link.so         = @$(disp_link)      ; $(cmd_link.so)
415do_link.h          = @$(disp_link.h)    ; $(cmd_link.h)
416do_ar              = @$(disp_ar)        ; $(cmd_ar)
417do_elf2flt         = @$(disp_elf2flt)   ; $(cmd_elf2flt)
418
419uppercase = $(shell echo $1 | $(SED) -e "y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/")
420%.a:
421    @if test -z "$($(call uppercase,$*)_DIR)" ; then \
422        echo "Invalid target $@" ; \
423        exit 1 ; \
424    fi
425    $(Q)$(MAKE) $($(call uppercase,$*)_DIR)$@
426
427.PHONY: dummy
Note: See TracBrowser for help on using the repository browser.