aboutsummaryrefslogtreecommitdiff
path: root/Rules.mak
diff options
context:
space:
mode:
Diffstat (limited to 'Rules.mak')
-rw-r--r--Rules.mak361
1 files changed, 187 insertions, 174 deletions
diff --git a/Rules.mak b/Rules.mak
index a6f111695..2e9aa27e6 100644
--- a/Rules.mak
+++ b/Rules.mak
@@ -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
13unexport EXTRA_AFLAGS 13# General Public License for more details.
14unexport EXTRA_CFLAGS 14#
15unexport EXTRA_LDFLAGS 15# You should have received a copy of the GNU General Public License
16unexport EXTRA_ARFLAGS 16# along with this program; if not, write to the Free Software
17unexport SUBDIRS 17# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18unexport SUB_DIRS 18#
19unexport ALL_SUB_DIRS 19
20unexport O_TARGET 20PROG := busybox
21 21VERSION := 0.61.pre
22unexport obj-y 22BUILDTIME := $(shell TZ=UTC date -u "+%Y.%m.%d-%H:%M%z")
23unexport obj-n 23HOSTCC := gcc
24unexport obj- 24HOSTCFLAGS:= -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer
25unexport export-objs 25
26unexport subdir-y 26
27unexport subdir-n 27# What OS are you compiling busybox for? This allows you to include
28unexport subdir- 28# OS specific things, syscall overrides, etc.
29 29TARGET_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
33first_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
36SUB_DIRS := $(subdir-y) 36# If you want to add some simple compiler switches (like -march=i686),
37ALL_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 39CFLAGS_EXTRA:=
40# 40
41# Common rules 41# If you want a static binary, turn this on.
42# 42DOSTATIC:=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 46DODEBUG:=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 58DODMALLOC:=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 62DOEFENCE:=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.
65ifdef 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 $@ $< 71DOLFS:=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.
76BB_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-".
80CROSS:=
81CC := $(CROSS)gcc
82AR := $(CROSS)ar
83AS := $(CROSS)as
84LD := $(CROSS)ld
85NM := $(CROSS)nm
86STRIP := $(CROSS)strip
87CPP := $(CC) -E
88MAKEFILES := $(TOPDIR).config
89export 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
115OPTIMIZATION:=${shell if $(CC) -Os -S -o /dev/null -xc /dev/null \
116 >/dev/null 2>&1; then echo "-Os"; else echo "-O2" ; fi}
117GCC_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}
119OPTIMIZATIONS:=$(OPTIMIZATION) -fomit-frame-pointer $(GCC_STACK_BOUNDRY) #-fstrict-aliasing -march=i386 -mcpu=i386 -malign-functions=0 -malign-jumps=0
120WARNINGS:=-Wall -Wstrict-prototypes -Wshadow
121CFLAGS:=-I$(TOPDIR)include
122ARFLAGS:=-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
133ifeq ($(strip $(DOLFS)),true)
134 # For large file summit support
135 CFLAGS+=-D_FILE_OFFSET_BITS=64 -D__USE_FILE_OFFSET64
136endif
137ifeq ($(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
143else
144 ifeq ($(strip $(DOEFENCE)),true)
145 LIBRARIES:=-lefence
146 # Force debug=true, since this is useless when not debugging...
147 DODEBUG:=true
148 endif
149endif
150ifeq ($(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
154else
155 CFLAGS += $(WARNINGS) $(OPTIMIZATIONS) -D_GNU_SOURCE
156 LDFLAGS += -s -Wl,-warn-common
157 STRIPCMD:=$(STRIP) --remove-section=.note --remove-section=.comment
158endif
159ifeq ($(strip $(DOSTATIC)),true)
160 LDFLAGS += --static
73endif 161endif
74 162
75%.lst: %.c 163ifndef $(PREFIX)
76 $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$@) -g -c -o $*.o $< 164 PREFIX:=`pwd`/_install
77 $(TOPDIR)/scripts/makelst $* $(TOPDIR) $(OBJDUMP) 165endif
78#
79#
80#
81all_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 173ifneq ($(strip $(BB_SRC_DIR)),)
85# 174 VPATH:=$(BB_SRC_DIR)
86ifdef O_TARGET 175endif
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
99endif # O_TARGET
100 176
101# 177CFLAGS += -DBB_VER='"$(VERSION)"'
102# Rule to compile a set of .o files into one .a file 178CFLAGS += -DBB_BT='"$(BUILDTIME)"'
103# 179OBJECTS:=$(APPLET_SOURCES:.c=.o) busybox.o usage.o applets.o
104ifdef L_TARGET 180CFLAGS += $(CROSS_CFLAGS)
105$(L_TARGET): $(obj-y) 181ifdef 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
113endif 183endif
114 184
185# Put user-supplied flags at the end, where they
186# have a chance of winning.
187CFLAGS += $(CFLAGS_EXTRA)
115 188
116# 189%.o: %.c
117# This make dependencies quickly 190 $(CC) $(CFLAGS) $(EXTRA_CFLAGS) -c -o $@ $<
118# 191
192ifdef _FASTDEP_ALL_SUB_DIRS
119fastdep: dummy 193fastdep: dummy
120 $(TOPDIR)/scripts/mkdep $(CFLAGS) $(EXTRA_CFLAGS) -- $(wildcard *.[chS]) > .depend 194 $(TOPDIR)scripts/mkdep $(CFLAGS) $(EXTRA_CFLAGS_nostdinc) -- $(wildcard *.[chS]) > .depend
121ifdef ALL_SUB_DIRS 195ifdef 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)"
123endif 197endif
124 198
125ifdef _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
128endif 201endif
129 202
130 203.PHONY: dummy
131#
132# A rule to make subdirectories
133#
134subdir-list = $(sort $(patsubst %,_subdir_%,$(SUB_DIRS)))
135sub_dirs: dummy $(subdir-list)
136
137ifdef SUB_DIRS
138$(subdir-list) : dummy
139 $(MAKE) -C $(patsubst _subdir_%,%,$@)
140endif
141
142#
143# A rule to do nothing
144#
145dummy:
146
147#
148# This is useful for testing
149#
150script:
151 $(SCRIPT)
152
153#
154# include dependency files if they exist
155#
156ifneq ($(wildcard .depend),)
157include .depend
158endif
159
160ifneq ($(wildcard $(TOPDIR)/.hdepend),)
161include $(TOPDIR)/.hdepend
162endif
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#
169FILES_FLAGS_UP_TO_DATE :=
170 205
171# For use in expunging commas from flags, which mung our checking.
172comma = ,
173 206
174FILES_FLAGS_EXIST := $(wildcard .*.flags) 207.EXPORT_ALL_VARIABLES:
175ifneq ($(FILES_FLAGS_EXIST),)
176include $(FILES_FLAGS_EXIST)
177endif
178 208
179FILES_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).
189FILES_FLAGS_CHANGED := $(strip \
190 $(filter-out $(patsubst %.S, %.o, $(wildcard *.S) $(IGNORE_FLAGS_OBJS)), \
191 $(FILES_FLAGS_CHANGED)))
192
193ifneq ($(FILES_FLAGS_CHANGED),)
194$(FILES_FLAGS_CHANGED): dummy
195endif