diff options
Diffstat (limited to 'Rules.mak')
-rw-r--r-- | Rules.mak | 361 |
1 files changed, 187 insertions, 174 deletions
@@ -1,195 +1,208 @@ | |||
1 | # | 1 | # Rules.make for busybox |
2 | # This file contains rules which are shared between multiple Makefiles. | 2 | # |
3 | # | 3 | # Copyright (C) 2002 Erik Andersen <andersee@debian.org> |
4 | 4 | # | |
5 | # | 5 | # This program is free software; you can redistribute it and/or modify |
6 | # False targets. | 6 | # it under the terms of the GNU General Public License as published by |
7 | # | 7 | # the Free Software Foundation; either version 2 of the License, or |
8 | .PHONY: dummy | 8 | # (at your option) any later version. |
9 | 9 | # | |
10 | # | 10 | # This program is distributed in the hope that it will be useful, |
11 | # Special variables which should not be exported | 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | # | 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | unexport EXTRA_AFLAGS | 13 | # General Public License for more details. |
14 | unexport EXTRA_CFLAGS | 14 | # |
15 | unexport EXTRA_LDFLAGS | 15 | # You should have received a copy of the GNU General Public License |
16 | unexport EXTRA_ARFLAGS | 16 | # along with this program; if not, write to the Free Software |
17 | unexport SUBDIRS | 17 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
18 | unexport SUB_DIRS | 18 | # |
19 | unexport ALL_SUB_DIRS | 19 | |
20 | unexport O_TARGET | 20 | PROG := busybox |
21 | 21 | VERSION := 0.61.pre | |
22 | unexport obj-y | 22 | BUILDTIME := $(shell TZ=UTC date -u "+%Y.%m.%d-%H:%M%z") |
23 | unexport obj-n | 23 | HOSTCC := gcc |
24 | unexport obj- | 24 | HOSTCFLAGS:= -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer |
25 | unexport export-objs | 25 | |
26 | unexport subdir-y | 26 | |
27 | unexport subdir-n | 27 | # What OS are you compiling busybox for? This allows you to include |
28 | unexport subdir- | 28 | # OS specific things, syscall overrides, etc. |
29 | 29 | TARGET_OS:=linux | |
30 | # | 30 | |
31 | # Get things started. | 31 | # With a modern GNU make(1) (highly recommended, that's what all the |
32 | # | 32 | # developers use), all of the following configuration values can be |
33 | first_rule: sub_dirs | 33 | # overridden at the command line. For example: |
34 | $(MAKE) all_targets | 34 | # make CROSS=powerpc-linux- BB_SRC_DIR=$HOME/busybox PREFIX=/mnt/app |
35 | 35 | ||
36 | SUB_DIRS := $(subdir-y) | 36 | # If you want to add some simple compiler switches (like -march=i686), |
37 | ALL_SUB_DIRS := $(sort $(subdir-y) $(subdir-n) $(subdir-)) | 37 | # especially from the command line, use this instead of CFLAGS directly. |
38 | 38 | # For optimization overrides, it's better still to set OPTIMIZATION. | |
39 | 39 | CFLAGS_EXTRA:= | |
40 | # | 40 | |
41 | # Common rules | 41 | # If you want a static binary, turn this on. |
42 | # | 42 | DOSTATIC:=false |
43 | 43 | ||
44 | %.s: %.c | 44 | # Set the following to `true' to make a debuggable build. |
45 | $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$@) -S $< -o $@ | 45 | # Leave this set to `false' for production use. |
46 | 46 | DODEBUG:=false | |
47 | %.i: %.c | 47 | |
48 | $(CPP) $(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$@) $< > $@ | 48 | # This enables compiling with dmalloc ( http://dmalloc.com/ ) |
49 | 49 | # which is an excellent public domain mem leak and malloc problem | |
50 | %.o: %.c | 50 | # detector. To enable dmalloc, before running busybox you will |
51 | $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$@) -c -o $@ $< | 51 | # want to first set up your environment. |
52 | @ ( \ | 52 | # eg: `export DMALLOC_OPTIONS=debug=0x34f47d83,inter=100,log=logfile` |
53 | echo 'ifeq ($(strip $(subst $(comma),:,$(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$@))),$$(strip $$(subst $$(comma),:,$$(CFLAGS) $$(EXTRA_CFLAGS) $$(CFLAGS_$@))))' ; \ | 53 | # The debug= value is generated using the following command |
54 | echo 'FILES_FLAGS_UP_TO_DATE += $@' ; \ | 54 | # dmalloc -p log-stats -p log-non-free -p log-bad-space -p log-elapsed-time \ |
55 | echo 'endif' \ | 55 | # -p check-fence -p check-heap -p check-lists -p check-blank \ |
56 | ) > $(dir $@)/.$(notdir $@).flags | 56 | # -p check-funcs -p realloc-copy -p allow-free-null |
57 | 57 | # Do not enable this for production builds... | |
58 | %.o: %.s | 58 | DODMALLOC:=false |
59 | $(AS) $(AFLAGS) $(EXTRA_CFLAGS) -o $@ $< | 59 | |
60 | 60 | # Electric-fence is another very useful malloc debugging library. | |
61 | # Old makefiles define their own rules for compiling .S files, | 61 | # Do not enable this for production builds... |
62 | # but these standard rules are available for any Makefile that | 62 | DOEFENCE:=false |
63 | # wants to use them. Our plan is to incrementally convert all | 63 | |
64 | # the Makefiles to these standard rules. -- rmk, mec | 64 | # If you want large file summit support, turn this on. |
65 | ifdef USE_STANDARD_AS_RULE | 65 | # This has no effect if you don't have a kernel with lfs |
66 | 66 | # support, and a system with libc-2.1.3 or later. | |
67 | %.s: %.S | 67 | # Some of the programs that can benefit from lfs support |
68 | $(CPP) $(AFLAGS) $(EXTRA_AFLAGS) $(AFLAGS_$@) $< > $@ | 68 | # are dd, gzip, mount, tar, and mkfs_minix. |
69 | 69 | # LFS allows you to use the above programs for files | |
70 | %.o: %.S | 70 | # larger than 2GB! |
71 | $(CC) $(AFLAGS) $(EXTRA_AFLAGS) $(AFLAGS_$@) -c -o $@ $< | 71 | DOLFS:=false |
72 | 72 | ||
73 | # If you have a "pristine" source directory, point BB_SRC_DIR to it. | ||
74 | # Experimental and incomplete; tell the mailing list | ||
75 | # <busybox@busybox.net> if you do or don't like it so far. | ||
76 | BB_SRC_DIR:= | ||
77 | |||
78 | # If you are running a cross compiler, you may want to set CROSS | ||
79 | # to something more interesting, like "arm-linux-". | ||
80 | CROSS:= | ||
81 | CC := $(CROSS)gcc | ||
82 | AR := $(CROSS)ar | ||
83 | AS := $(CROSS)as | ||
84 | LD := $(CROSS)ld | ||
85 | NM := $(CROSS)nm | ||
86 | STRIP := $(CROSS)strip | ||
87 | CPP := $(CC) -E | ||
88 | MAKEFILES := $(TOPDIR).config | ||
89 | export VERSION BUILDTIME TOPDIR HOSTCC HOSTCFLAGS CROSS CC AR AS LD NM STRIP CPP | ||
90 | |||
91 | |||
92 | # To compile vs uClibc, just use the compiler wrapper built by uClibc... | ||
93 | # Everything should compile and work as expected these days... | ||
94 | #CC:=/usr/i386-linux-uclibc/usr/bin/i386-uclibc-gcc | ||
95 | |||
96 | # To compile vs some other alternative libc, you may need to use/adjust | ||
97 | # the following lines to meet your needs... | ||
98 | # | ||
99 | # If you are using Red Hat 6.x with the compatible RPMs (for developing under | ||
100 | # Red Hat 5.x and glibc 2.0) uncomment the following. Be sure to read about | ||
101 | # using the compatible RPMs (compat-*) at http://www.redhat.com ! | ||
102 | #LIBCDIR:=/usr/i386-glibc20-linux | ||
103 | # | ||
104 | # The following is used for libc5 (if you install altgcc and libc5-altdev | ||
105 | # on a Debian system). | ||
106 | #LIBCDIR:=/usr/i486-linuxlibc1 | ||
107 | # | ||
108 | # For other libraries, you are on your own... | ||
109 | #LDFLAGS+=-nostdlib | ||
110 | #LIBRARIES:=$(LIBCDIR)/lib/libc.a -lgcc | ||
111 | #CROSS_CFLAGS+=-nostdinc -I$(LIBCDIR)/include -I$(GCCINCDIR) | ||
112 | #GCCINCDIR:=$(shell gcc -print-search-dirs | sed -ne "s/install: \(.*\)/\1include/gp") | ||
113 | |||
114 | # use '-Os' optimization if available, else use -O2 | ||
115 | OPTIMIZATION:=${shell if $(CC) -Os -S -o /dev/null -xc /dev/null \ | ||
116 | >/dev/null 2>&1; then echo "-Os"; else echo "-O2" ; fi} | ||
117 | GCC_STACK_BOUNDRY:=${shell if $(CC) -mpreferred-stack-boundary=2 -S -o /dev/null -xc /dev/null \ | ||
118 | >/dev/null 2>&1; then echo "-mpreferred-stack-boundary=2"; else echo "" ; fi} | ||
119 | OPTIMIZATIONS:=$(OPTIMIZATION) -fomit-frame-pointer $(GCC_STACK_BOUNDRY) #-fstrict-aliasing -march=i386 -mcpu=i386 -malign-functions=0 -malign-jumps=0 | ||
120 | WARNINGS:=-Wall -Wstrict-prototypes -Wshadow | ||
121 | CFLAGS:=-I$(TOPDIR)include | ||
122 | ARFLAGS:=-r | ||
123 | |||
124 | # | ||
125 | #-------------------------------------------------------- | ||
126 | # If you're going to do a lot of builds with a non-vanilla configuration, | ||
127 | # it makes sense to adjust parameters above, so you can type "make" | ||
128 | # by itself, instead of following it by the same half-dozen overrides | ||
129 | # every time. The stuff below, on the other hand, is probably less | ||
130 | # prone to casual user adjustment. | ||
131 | # | ||
132 | |||
133 | ifeq ($(strip $(DOLFS)),true) | ||
134 | # For large file summit support | ||
135 | CFLAGS+=-D_FILE_OFFSET_BITS=64 -D__USE_FILE_OFFSET64 | ||
136 | endif | ||
137 | ifeq ($(strip $(DODMALLOC)),true) | ||
138 | # For testing mem leaks with dmalloc | ||
139 | CFLAGS+=-DDMALLOC | ||
140 | LIBRARIES:=-ldmalloc | ||
141 | # Force debug=true, since this is useless when not debugging... | ||
142 | DODEBUG:=true | ||
143 | else | ||
144 | ifeq ($(strip $(DOEFENCE)),true) | ||
145 | LIBRARIES:=-lefence | ||
146 | # Force debug=true, since this is useless when not debugging... | ||
147 | DODEBUG:=true | ||
148 | endif | ||
149 | endif | ||
150 | ifeq ($(strip $(DODEBUG)),true) | ||
151 | CFLAGS +=$(WARNINGS) -g -D_GNU_SOURCE | ||
152 | LDFLAGS +=-Wl,-warn-common | ||
153 | STRIPCMD:=/bin/true -Not_stripping_since_we_are_debugging | ||
154 | else | ||
155 | CFLAGS += $(WARNINGS) $(OPTIMIZATIONS) -D_GNU_SOURCE | ||
156 | LDFLAGS += -s -Wl,-warn-common | ||
157 | STRIPCMD:=$(STRIP) --remove-section=.note --remove-section=.comment | ||
158 | endif | ||
159 | ifeq ($(strip $(DOSTATIC)),true) | ||
160 | LDFLAGS += --static | ||
73 | endif | 161 | endif |
74 | 162 | ||
75 | %.lst: %.c | 163 | ifndef $(PREFIX) |
76 | $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$@) -g -c -o $*.o $< | 164 | PREFIX:=`pwd`/_install |
77 | $(TOPDIR)/scripts/makelst $* $(TOPDIR) $(OBJDUMP) | 165 | endif |
78 | # | ||
79 | # | ||
80 | # | ||
81 | all_targets: $(O_TARGET) $(L_TARGET) | ||
82 | 166 | ||
167 | # Additional complications due to support for pristine source dir. | ||
168 | # Include files in the build directory should take precedence over | ||
169 | # the copy in BB_SRC_DIR, both during the compilation phase and the | ||
170 | # shell script that finds the list of object files. | ||
171 | # Work in progress by <ldoolitt@recycle.lbl.gov>. | ||
83 | # | 172 | # |
84 | # Rule to compile a set of .o files into one .o file | 173 | ifneq ($(strip $(BB_SRC_DIR)),) |
85 | # | 174 | VPATH:=$(BB_SRC_DIR) |
86 | ifdef O_TARGET | 175 | endif |
87 | $(O_TARGET): $(obj-y) | ||
88 | rm -f $@ | ||
89 | ifneq "$(strip $(obj-y))" "" | ||
90 | $(LD) $(EXTRA_LDFLAGS) -r -o $@ $(filter $(obj-y), $^) | ||
91 | else | ||
92 | $(AR) rcs $@ | ||
93 | endif | ||
94 | @ ( \ | ||
95 | echo 'ifeq ($(strip $(subst $(comma),:,$(EXTRA_LDFLAGS) $(obj-y))),$$(strip $$(subst $$(comma),:,$$(EXTRA_LDFLAGS) $$(obj-y))))' ; \ | ||
96 | echo 'FILES_FLAGS_UP_TO_DATE += $@' ; \ | ||
97 | echo 'endif' \ | ||
98 | ) > $(dir $@)/.$(notdir $@).flags | ||
99 | endif # O_TARGET | ||
100 | 176 | ||
101 | # | 177 | CFLAGS += -DBB_VER='"$(VERSION)"' |
102 | # Rule to compile a set of .o files into one .a file | 178 | CFLAGS += -DBB_BT='"$(BUILDTIME)"' |
103 | # | 179 | OBJECTS:=$(APPLET_SOURCES:.c=.o) busybox.o usage.o applets.o |
104 | ifdef L_TARGET | 180 | CFLAGS += $(CROSS_CFLAGS) |
105 | $(L_TARGET): $(obj-y) | 181 | ifdef BB_INIT_SCRIPT |
106 | rm -f $@ | 182 | CFLAGS += -DINIT_SCRIPT='"$(BB_INIT_SCRIPT)"' |
107 | $(AR) $(EXTRA_ARFLAGS) rcs $@ $(obj-y) | ||
108 | @ ( \ | ||
109 | echo 'ifeq ($(strip $(subst $(comma),:,$(EXTRA_ARFLAGS) $(obj-y))),$$(strip $$(subst $$(comma),:,$$(EXTRA_ARFLAGS) $$(obj-y))))' ; \ | ||
110 | echo 'FILES_FLAGS_UP_TO_DATE += $@' ; \ | ||
111 | echo 'endif' \ | ||
112 | ) > $(dir $@)/.$(notdir $@).flags | ||
113 | endif | 183 | endif |
114 | 184 | ||
185 | # Put user-supplied flags at the end, where they | ||
186 | # have a chance of winning. | ||
187 | CFLAGS += $(CFLAGS_EXTRA) | ||
115 | 188 | ||
116 | # | 189 | %.o: %.c |
117 | # This make dependencies quickly | 190 | $(CC) $(CFLAGS) $(EXTRA_CFLAGS) -c -o $@ $< |
118 | # | 191 | |
192 | ifdef _FASTDEP_ALL_SUB_DIRS | ||
119 | fastdep: dummy | 193 | fastdep: dummy |
120 | $(TOPDIR)/scripts/mkdep $(CFLAGS) $(EXTRA_CFLAGS) -- $(wildcard *.[chS]) > .depend | 194 | $(TOPDIR)scripts/mkdep $(CFLAGS) $(EXTRA_CFLAGS_nostdinc) -- $(wildcard *.[chS]) > .depend |
121 | ifdef ALL_SUB_DIRS | 195 | ifdef ALL_SUB_DIRS |
122 | $(MAKE) $(patsubst %,_sfdep_%,$(ALL_SUB_DIRS)) _FASTDEP_ALL_SUB_DIRS="$(ALL_SUB_DIRS)" | 196 | $(MAKE) $(patsubst %,_sfdep_%,$(ALL_SUB_DIRS)) _FASTDEP_ALL_SUB_DIRS="$(ALL_SUB_DIRS)" |
123 | endif | 197 | endif |
124 | 198 | ||
125 | ifdef _FASTDEP_ALL_SUB_DIRS | ||
126 | $(patsubst %,_sfdep_%,$(_FASTDEP_ALL_SUB_DIRS)): | 199 | $(patsubst %,_sfdep_%,$(_FASTDEP_ALL_SUB_DIRS)): |
127 | $(MAKE) -C $(patsubst _sfdep_%,%,$@) fastdep | 200 | $(MAKE) -C $(patsubst _sfdep_%,%,$@) fastdep |
128 | endif | 201 | endif |
129 | 202 | ||
130 | 203 | .PHONY: dummy | |
131 | # | ||
132 | # A rule to make subdirectories | ||
133 | # | ||
134 | subdir-list = $(sort $(patsubst %,_subdir_%,$(SUB_DIRS))) | ||
135 | sub_dirs: dummy $(subdir-list) | ||
136 | |||
137 | ifdef SUB_DIRS | ||
138 | $(subdir-list) : dummy | ||
139 | $(MAKE) -C $(patsubst _subdir_%,%,$@) | ||
140 | endif | ||
141 | |||
142 | # | ||
143 | # A rule to do nothing | ||
144 | # | ||
145 | dummy: | ||
146 | |||
147 | # | ||
148 | # This is useful for testing | ||
149 | # | ||
150 | script: | ||
151 | $(SCRIPT) | ||
152 | |||
153 | # | ||
154 | # include dependency files if they exist | ||
155 | # | ||
156 | ifneq ($(wildcard .depend),) | ||
157 | include .depend | ||
158 | endif | ||
159 | |||
160 | ifneq ($(wildcard $(TOPDIR)/.hdepend),) | ||
161 | include $(TOPDIR)/.hdepend | ||
162 | endif | ||
163 | 204 | ||
164 | # | ||
165 | # Find files whose flags have changed and force recompilation. | ||
166 | # For safety, this works in the converse direction: | ||
167 | # every file is forced, except those whose flags are positively up-to-date. | ||
168 | # | ||
169 | FILES_FLAGS_UP_TO_DATE := | ||
170 | 205 | ||
171 | # For use in expunging commas from flags, which mung our checking. | ||
172 | comma = , | ||
173 | 206 | ||
174 | FILES_FLAGS_EXIST := $(wildcard .*.flags) | 207 | .EXPORT_ALL_VARIABLES: |
175 | ifneq ($(FILES_FLAGS_EXIST),) | ||
176 | include $(FILES_FLAGS_EXIST) | ||
177 | endif | ||
178 | 208 | ||
179 | FILES_FLAGS_CHANGED := $(strip \ | ||
180 | $(filter-out $(FILES_FLAGS_UP_TO_DATE), \ | ||
181 | $(O_TARGET) $(L_TARGET) $(active-objs) \ | ||
182 | )) | ||
183 | |||
184 | # A kludge: .S files don't get flag dependencies (yet), | ||
185 | # because that will involve changing a lot of Makefiles. Also | ||
186 | # suppress object files explicitly listed in $(IGNORE_FLAGS_OBJS). | ||
187 | # This allows handling of assembly files that get translated into | ||
188 | # multiple object files (see arch/ia64/lib/idiv.S, for example). | ||
189 | FILES_FLAGS_CHANGED := $(strip \ | ||
190 | $(filter-out $(patsubst %.S, %.o, $(wildcard *.S) $(IGNORE_FLAGS_OBJS)), \ | ||
191 | $(FILES_FLAGS_CHANGED))) | ||
192 | |||
193 | ifneq ($(FILES_FLAGS_CHANGED),) | ||
194 | $(FILES_FLAGS_CHANGED): dummy | ||
195 | endif | ||