aboutsummaryrefslogtreecommitdiff
path: root/Rules.mak
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2006-10-05 10:17:08 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2006-10-05 10:17:08 +0000
commit7d219aab70e6951ab82c27c202cac05016696723 (patch)
tree4c0679bfa391f71aee9b51505a5d3dc8f60a0cf7 /Rules.mak
parent8f8f268cfdecb4cabeb2e649a73afc7a485aeff5 (diff)
downloadbusybox-w32-7d219aab70e6951ab82c27c202cac05016696723.tar.gz
busybox-w32-7d219aab70e6951ab82c27c202cac05016696723.tar.bz2
busybox-w32-7d219aab70e6951ab82c27c202cac05016696723.zip
build system overhaul
Diffstat (limited to 'Rules.mak')
-rw-r--r--Rules.mak436
1 files changed, 0 insertions, 436 deletions
diff --git a/Rules.mak b/Rules.mak
deleted file mode 100644
index e0704989b..000000000
--- a/Rules.mak
+++ /dev/null
@@ -1,436 +0,0 @@
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:=0
18EXTRAVERSION :=-svn
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_COMPILE=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_COMPILE
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
34CC = $(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
41CPP = $(CC) -E
42SED ?= sed
43BZIP2 ?= bzip2
44
45
46# What OS are you compiling busybox for? This allows you to include
47# OS specific things, syscall overrides, etc.
48TARGET_OS=linux
49
50# Ensure consistent sort order, 'gcc -print-search-dirs' behavior, etc.
51LC_ALL:= C
52
53# This must bind late because srcdir is reset for every source subdirectory.
54INCS:=-I$(top_builddir)/include -I$(top_srcdir)/include
55CFLAGS=$(INCS) -I$(srcdir) -D_GNU_SOURCE
56CFLAGS+=$(CHECKED_CFLAGS)
57ARFLAGS=cru
58
59# gcc centric. Perhaps fiddle with findstring gcc,$(CC) for the rest
60# get the CC MAJOR/MINOR version
61CC_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
64#--------------------------------------------------------
65export VERSION BUILDTIME HOSTCC HOSTCFLAGS CROSS_COMPILE CC AR AS LD NM STRIP CPP
66ifeq ($(strip $(TARGET_ARCH)),)
67TARGET_ARCH:=$(shell $(CC) -dumpmachine | $(SED) -e s'/-.*//' \
68 -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/' \
75 -e 's/mips-.*/mips/' \
76 -e 's/mipsel-.*/mipsel/' \
77 -e 's/cris.*/cris/' \
78 )
79endif
80
81# A nifty macro to make testing gcc features easier, but note that everything
82# that uses this _must_ use := or it will be re-evaluated everytime it is
83# referenced.
84ifeq ($(strip $(BUILD_VERBOSE)),2)
85VERBOSE_CHECK_CC=echo CC=\"$(1)\" check_cc $(2) >&2;
86endif
87check_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; \
94 fi)
95
96ifneq ($(filter $(nocheck_targets),$(MAKECMDGOALS)),)
97check_cc:=
98endif
99
100# A not very robust macro to check for available ld flags
101ifeq ($(strip $(BUILD_VERBOSE)),2)
102VERBOSE_CHECK_LD=echo LD=\"$(1)\" check_ld $(2) >&2;
103endif
104check_ld=$(shell \
105 $(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)" ; \
109 fi)
110
111ifneq ($(filter $(nocheck_targets),$(MAKECMDGOALS)),)
112check_ld:=
113endif
114
115# A not very robust macro to check for available strip flags
116ifeq ($(strip $(BUILD_VERBOSE)),2)
117VERBOSE_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
129ifneq ($(filter $(nocheck_targets),$(MAKECMDGOALS)),)
130check_strip:=
131endif
132
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" ; \
162 rm conftest_main.o conftest_main.c conftest.o conftest.c \
163 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,)
169#CHECKED_LDFLAGS := $(call check_ld,$(LD),-static-libgcc,)
170
171# Pin CHECKED_CFLAGS with := so it's only evaluated once.
172CHECKED_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,)
176CHECKED_CFLAGS+=$(call check_cc,$(CC),-fno-builtin-strlen,)
177CHECKED_CFLAGS+=$(call check_cc,$(CC),-finline-limit=0,)
178
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
183
184# Preemptively pin this too.
185PROG_CFLAGS:=
186
187
188#--------------------------------------------------------
189# Arch specific compiler optimization stuff should go here.
190# Unless you want to override the defaults, do not set anything
191# for OPTIMIZATION...
192
193# use '-Os' optimization if available, else use -O2
194OPTIMIZATION:=$(call check_cc,$(CC),-Os,-O2)
195
196ifeq ($(CONFIG_BUILD_AT_ONCE),y)
197# gcc 2.95 exits with 0 for "unrecognized option"
198ifeq ($(strip $(shell [ $(CC_MAJOR) -ge 3 ] ; echo $$?)),0)
199 CFLAGS_COMBINE:=$(call check_cc,$(CC),--combine,)
200endif
201OPTIMIZATION+=$(call check_cc,$(CC),-funit-at-a-time,)
202OPTIMIZATION+=$(call check_cc,$(CC),-fgcse-after-reload,)
203ifneq ($(CONFIG_BUILD_LIBBUSYBOX),y)
204# http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25795
205# This prevents us from using -fwhole-program when we build the lib
206PROG_CFLAGS+=$(call check_cc,$(CC),-fwhole-program,)
207endif # CONFIG_BUILD_LIBBUSYBOX
208endif # CONFIG_BUILD_AT_ONCE
209
210LIB_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,)
214
215
216# Some nice architecture specific optimizations
217ifeq ($(strip $(TARGET_ARCH)),arm)
218 OPTIMIZATION+=-fstrict-aliasing
219endif
220ifeq ($(strip $(TARGET_ARCH)),i386)
221 OPTIMIZATION+=$(call check_cc,$(CC),-march=i386,)
222# gcc-4.0 and older seem to benefit from these
223ifneq ($(strip $(shell [ $(CC_MAJOR) -ge 4 -a $(CC_MINOR) -ge 1 ] ; echo $$?)),0)
224 OPTIMIZATION+=$(call check_cc,$(CC),-mpreferred-stack-boundary=2,)
225 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
230
231# gcc-4.1 and beyond seem to benefit from these
232ifeq ($(strip $(shell [ $(CC_MAJOR) -ge 4 -a $(CC_MINOR) -ge 1 ] ; echo $$?)),0)
233 # turn off flags which hurt -Os
234 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,)
237
238 OPTIMIZATION+=$(call check_cc,$(CC),-fno-branch-count-reg,)
239endif # gcc-4.1 and beyond
240endif
241OPTIMIZATION+=$(call check_cc,$(CC),-fomit-frame-pointer,)
242CHECKED_LDFLAGS += $(call check_ld,$(LD),--sort-common,)
243
244#
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.
251#
252
253ifeq ($(strip $(CONFIG_LFS)),y)
254 # For large file summit support
255 CFLAGS+=-D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
256endif
257ifeq ($(strip $(CONFIG_DMALLOC)),y)
258 # For testing mem leaks with dmalloc
259 CFLAGS+=-DDMALLOC
260 LIBRARIES:=-ldmalloc
261else
262 ifeq ($(strip $(CONFIG_EFENCE)),y)
263 LIBRARIES:=-lefence
264 endif
265endif
266
267# Debugging info
268
269ifeq ($(strip $(CONFIG_DEBUG)),y)
270 CFLAGS +=-g
271else
272 CFLAGS +=-DNDEBUG
273endif
274
275ifneq ($(strip $(CONFIG_DEBUG_PESSIMIZE)),y)
276 CFLAGS += $(OPTIMIZATION)
277endif
278
279# warn a bit more verbosely for non-release versions
280ifneq ($(EXTRAVERSION),)
281 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,)
288endif
289STRIPCMD:=$(call check_strip,$(STRIP),-s --remove-section=.note --remove-section=.comment,$(STRIP))
290ifeq ($(strip $(CONFIG_STATIC)),y)
291 PROG_CFLAGS += $(call check_cc,$(CC),-static,)
292else
293 ifneq ($(strip $(CONFIG_DEBUG)),y)
294 OPTIMIZATION+=$(call check_cc,$(CC),-ffunction-sections -fdata-sections,)
295 CHECKED_LDFLAGS += $(call check_ld,$(LD),--gc-sections,)
296 endif
297endif
298CFLAGS_SHARED := $(call check_cc,$(CC),-shared,)
299LIB_CFLAGS+=$(CFLAGS_SHARED)
300
301ifeq ($(strip $(CONFIG_BUILD_LIBBUSYBOX)),y)
302 CFLAGS_PIC:= $(call check_cc,$(CC),-fPIC,)
303 LIB_CFLAGS+=$(CFLAGS_PIC)
304endif
305
306ifeq ($(strip $(CONFIG_SELINUX)),y)
307 LIBRARIES += -lselinux -lsepol
308endif
309
310ifeq ($(strip $(PREFIX)),)
311 PREFIX:=`pwd`/_install
312endif
313
314ifneq ($(strip $(CONFIG_GETOPT_LONG)),y)
315 CFLAGS += -D__need_getopt
316endif
317
318# 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
326CFLAGS += $(CHECKED_CFLAGS) $(CROSS_CFLAGS)
327LDFLAGS += $(CHECKED_LDFLAGS)
328
329ifdef 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.
335-include $(top_builddir)/.config.mak
336
337#------------------------------------------------------------
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
349#------------------------------------------------------------
350# Make the output nice and tight
351MAKEFLAGS += --no-print-directory
352export MAKE_IS_SILENT=n
353ifneq ($(findstring s,$(MAKEFLAGS)),)
354export MAKE_IS_SILENT=y
355SECHO := @-false
356DISP := sil
357Q := @
358else
359ifneq ($(BUILD_VERBOSE),)
360SECHO := @-false
361DISP := ver
362Q :=
363else
364SECHO := @echo
365DISP := pur
366Q := @
367endif
368endif
369
370show_objs = $(subst $(top_builddir)/,,$(subst ../,,$@))
371pur_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)
399disp_gen = $(SECHO) " "GEN $@ ; true
400disp_doc = $(SECHO) " "DOC $(subst docs/,,$@) ; true
401cmd_compile.c = $(CC) $(CFLAGS) $(EXTRA_CFLAGS) -c -o $@ $<
402cmd_compile.h = $(HOSTCC) $(HOSTCFLAGS) $(INCS) -c -o $@ $<
403cmd_strip = $(STRIPCMD) $@
404cmd_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)
416cmd_link.h = $(HOSTCC) $(HOSTCFLAGS) $(INCS) $< -o $@
417cmd_ar = $(AR) $(ARFLAGS) $@ $^
418cmd_elf2flt = $(ELF2FLT) $(ELF2FLTFLAGS) $< -o $@
419compile.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)
427
428uppercase = $(shell echo $1 | $(SED) -e "y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/")
429%.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
436.PHONY: dummy