Kill off some unused code that was wasting several k, as noticed by
[oweals/busybox.git] / Rules.mak
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
9 ifeq ($(filter $(noconfig_targets),$(MAKECMDGOALS)),)
10 -include $(top_builddir)/.config
11 endif
12
13 ifeq ($(MAKELEVEL),0)
14 ifeq ($(HAVE_DOT_CONFIG),y)
15 rules-mak-rules:=0
16 endif
17 endif
18
19 #--------------------------------------------------------
20 PROG      := busybox
21 MAJOR_VERSION   :=1
22 MINOR_VERSION   :=1
23 SUBLEVEL_VERSION:=1
24 EXTRAVERSION    :=-pre0
25 VERSION   :=$(MAJOR_VERSION).$(MINOR_VERSION).$(SUBLEVEL_VERSION)$(EXTRAVERSION)
26 BUILDTIME := $(shell TZ=UTC date -u "+%Y.%m.%d-%H:%M%z")
27
28
29 #--------------------------------------------------------
30 # With a modern GNU make(1) (highly recommended, that's what all the
31 # developers use), all of the following configuration values can be
32 # overridden at the command line.  For example:
33 #   make CROSS=powerpc-linux- top_srcdir="$HOME/busybox" PREFIX=/mnt/app
34 #--------------------------------------------------------
35
36 # If you are running a cross compiler, you will want to set 'CROSS'
37 # to something more interesting...  Target architecture is determined
38 # by asking the CC compiler what arch it compiles things for, so unless
39 # your compiler is broken, you should not need to specify __TARGET_ARCH
40 CROSS           =$(subst ",, $(strip $(CROSS_COMPILER_PREFIX)))
41 #")
42 CC             = $(CROSS)gcc
43 AR             = $(CROSS)ar
44 AS             = $(CROSS)as
45 LD             = $(CROSS)ld
46 NM             = $(CROSS)nm
47 STRIP          = $(CROSS)strip
48 CPP            = $(CC) -E
49 SED           ?= sed
50 AWK           ?= awk
51
52
53 ifdef PACKAGE_BE_VERBOSE
54 PACKAGE_BE_VERBOSE := $(shell echo $(PACKAGE_BE_VERBOSE) | $(SED) "s/[[:alpha:]]*//g")
55 endif
56
57 # for make V=3 and above make $(shell) invocations verbose
58 ifeq ($(if $(strip $(PACKAGE_BE_VERBOSE)),$(shell test $(PACKAGE_BE_VERBOSE) -gt 2 ; echo $$?),1),0)
59  SHELL+=-x
60  MKDEP_ARGS:=-w
61 endif
62
63 # What OS are you compiling busybox for?  This allows you to include
64 # OS specific things, syscall overrides, etc.
65 TARGET_OS=linux
66
67 # Select the compiler needed to build binaries for your development system
68 HOSTCC    = gcc
69 HOSTCFLAGS= -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer
70
71 # Ensure consistent sort order, 'gcc -print-search-dirs' behavior, etc.
72 LC_ALL:= C
73
74 # If you want to add some simple compiler switches (like -march=i686),
75 # especially from the command line, use this instead of CFLAGS directly.
76 # For optimization overrides, it's better still to set OPTIMIZATIONS.
77 CFLAGS_EXTRA=$(subst ",, $(strip $(EXTRA_CFLAGS_OPTIONS)))
78 #")
79
80 # To compile vs some other alternative libc, you may need to use/adjust
81 # the following lines to meet your needs...
82 #
83 # If you are using Red Hat 6.x with the compatible RPMs (for developing under
84 # Red Hat 5.x and glibc 2.0) uncomment the following.  Be sure to read about
85 # using the compatible RPMs (compat-*) at http://www.redhat.com !
86 #LIBCDIR:=/usr/i386-glibc20-linux
87 #
88 # For other libraries, you are on your own.  But these may (or may not) help...
89 #LDFLAGS+=-nostdlib
90 #LIBRARIES:=$(LIBCDIR)/lib/libc.a -lgcc
91 #CROSS_CFLAGS+=-nostdinc -I$(LIBCDIR)/include -I$(GCCINCDIR) -funsigned-char
92 #GCCINCDIR:=$(shell gcc -print-search-dirs | sed -ne "s/install: \(.*\)/\1include/gp")
93
94 WARNINGS=-Wall -Wstrict-prototypes -Wshadow
95 CFLAGS+=-I$(top_builddir)/include -I$(top_srcdir)/include
96
97 ARFLAGS=cruP
98
99
100
101 # Get the CC MAJOR/MINOR version
102 # gcc centric. Perhaps fiddle with findstring gcc,$(CC) for the rest
103 CC_MAJOR:=$(shell printf "%02d" $(shell echo __GNUC__ | $(CC) -E -xc - | tail -n 1))
104 CC_MINOR:=$(shell printf "%02d" $(shell echo __GNUC_MINOR__ | $(CC) -E -xc - | tail -n 1))
105
106 # Note: spaces are significant here!
107 # Check if CC version is equal to given MAJOR,MINOR. Returns empty if false.
108 define cc_eq
109 $(shell [ $(CC_MAJOR) -eq $(1) -a $(CC_MINOR) -eq $(2) ] && echo y)
110 endef
111 # Check if CC version is greater or equal than given MAJOR,MINOR
112 define cc_ge
113 $(shell [ $(CC_MAJOR) -ge $(1) -a $(CC_MINOR) -ge $(2) ] && echo y)
114 endef
115 # Check if CC version is less or equal than given MAJOR,MINOR
116 define cc_le
117 $(shell [ $(CC_MAJOR) -le $(1) -a $(CC_MINOR) -le $(2) ] && echo y)
118 endef
119
120 # Workaround bugs in make-3.80 for eval in conditionals
121 define is_eq
122 $(shell [ $(1) = $(2) ] 2> /dev/null && echo y)
123 endef
124 define is_neq
125 $(shell [ $(1) != $(2) ] 2> /dev/null && echo y)
126 endef
127
128 #--------------------------------------------------------
129 export VERSION BUILDTIME HOSTCC HOSTCFLAGS CROSS CC AR AS LD NM STRIP CPP
130
131 # TARGET_ARCH and TARGET_MACH will be passed verbatim to CC with recent
132 # versions of make, so we use __TARGET_ARCH here.
133 # Current builtin rules looks like that:
134 # COMPILE.s = $(AS) $(ASFLAGS) $(TARGET_MACH)
135 # COMPILE.c = $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c
136
137 ifeq ($(strip $(__TARGET_ARCH)),)
138 __TARGET_ARCH:=$(shell $(CC) -dumpmachine | sed -e s'/-.*//' \
139                 -e 's/i.86/i386/' \
140                 -e 's/sparc.*/sparc/' \
141                 -e 's/arm.*/arm/g' \
142                 -e 's/m68k.*/m68k/' \
143                 -e 's/ppc/powerpc/g' \
144                 -e 's/v850.*/v850/g' \
145                 -e 's/sh[234]/sh/' \
146                 -e 's/mips-.*/mips/' \
147                 -e 's/mipsel-.*/mipsel/' \
148                 -e 's/cris.*/cris/' \
149                 )
150 endif
151
152 $(call check_gcc,CFLAGS,-funsigned-char,)
153 $(call check_gcc,CFLAGS,-mmax-stack-frame=256,)
154
155 #--------------------------------------------------------
156 # Arch specific compiler optimization stuff should go here.
157 # Unless you want to override the defaults, do not set anything
158 # for OPTIMIZATIONS...
159
160 # use '-Os' optimization if available, else use -O2
161 $(call check_gcc,OPTIMIZATIONS,-Os,-O2)
162
163 # gcc 2.95 exits with 0 for "unrecognized option"
164 $(if $(call is_eq,$(CONFIG_BUILD_AT_ONCE),y),\
165   $(if $(call cc_ge,3,0),\
166     $(call check_gcc,CFLAGS_COMBINE,--combine,)))
167
168 $(if $(call is_eq,$(CONFIG_BUILD_AT_ONCE),y),\
169   $(call check_gcc,OPTIMIZATIONS,-funit-at-a-time,))
170
171 # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25795
172 #$(if $(call is_eq,$(CONFIG_BUILD_AT_ONCE),y),\
173 #  $(call check_gcc,PROG_CFLAGS,-fwhole-program,))
174
175 $(call check_ld,LIB_LDFLAGS,--enable-new-dtags,)
176 #$(call check_ld,LIB_LDFLAGS,--reduce-memory-overheads,)
177 #$(call check_ld,LIB_LDFLAGS,--as-needed,)
178 #$(call check_ld,LIB_LDFLAGS,--warn-shared-textrel,)
179
180 $(call check_ld,PROG_LDFLAGS,--gc-sections,)
181
182 # Some nice architecture specific optimizations
183 ifeq ($(__TARGET_ARCH),arm)
184     OPTIMIZATIONS+=-fstrict-aliasing
185 endif # arm
186
187 $(if $(call is_eq,$(__TARGET_ARCH),i386),\
188   $(call check_gcc,OPTIMIZATIONS,-march=i386,))
189
190 # gcc-4.0 and older seem to suffer from these
191 $(if $(call cc_le,4,0),\
192   $(call check_gcc,OPTIMIZATIONS,-mpreferred-stack-boundary=2,)\
193   $(call check_gcc,OPTIMIZATIONS,-falign-functions=1 -falign-jumps=1 -falign-loops=1,\
194                 -malign-functions=0 -malign-jumps=0 -malign-loops=0))
195
196 # gcc-4.1 and beyond seem to benefit from these
197 # turn off flags which hurt -Os
198 $(if $(call cc_ge,4,1),\
199   $(call check_gcc,OPTIMIZATIONS,-fno-tree-loop-optimize,)\
200   $(call check_gcc,OPTIMIZATIONS,-fno-tree-dominator-opts,)\
201   $(call check_gcc,OPTIMIZATIONS,-fno-strength-reduce,)\
202 \
203   $(call check_gcc,OPTIMIZATIONS,-fno-branch-count-reg,))
204
205 $(call check_gcc,OPTIMIZATIONS,-fomit-frame-pointer,)
206
207 #
208 #--------------------------------------------------------
209 # If you're going to do a lot of builds with a non-vanilla configuration,
210 # it makes sense to adjust parameters above, so you can type "make"
211 # by itself, instead of following it by the same half-dozen overrides
212 # every time.  The stuff below, on the other hand, is probably less
213 # prone to casual user adjustment.
214 #
215
216 ifeq ($(CONFIG_LFS),y)
217     # For large file summit support
218     CFLAGS+=-D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
219 endif
220 ifeq ($(CONFIG_DMALLOC),y)
221     # For testing mem leaks with dmalloc
222     CFLAGS+=-DDMALLOC
223     LIBRARIES:=-ldmalloc
224 else
225     ifeq ($(CONFIG_EFENCE),y)
226         LIBRARIES:=-lefence
227     endif
228 endif
229
230 $(if $(call is_eq,$(CONFIG_DEBUG),y),\
231  $(call check_ld,LDFLAGS,--warn-common,),\
232  $(call check_ld,LDFLAGS,--warn-common,)$(call check_ld,LDFLAGS,--sort-common,))
233 ifeq ($(CONFIG_DEBUG),y)
234     CFLAGS  +=$(WARNINGS) -g -D_GNU_SOURCE
235     STRIPCMD:=/bin/true -Not_stripping_since_we_are_debugging
236 else
237     CFLAGS+=$(WARNINGS) $(OPTIMIZATIONS) -D_GNU_SOURCE -DNDEBUG
238     STRIPCMD:=$(STRIP) -s --remove-section=.note --remove-section=.comment
239 endif
240 $(if $(call is_eq,$(CONFIG_STATIC),y),\
241     $(call check_gcc,PROG_CFLAGS,-static,))
242
243 $(call check_gcc,CFLAGS_SHARED,-shared,)
244 LIB_CFLAGS+=$(CFLAGS_SHARED)
245
246 $(if $(call is_eq,$(CONFIG_BUILD_LIBBUSYBOX),y),\
247     $(call check_gcc,CFLAGS_PIC,-fPIC,))
248
249 ifeq ($(CONFIG_SELINUX),y)
250     LIBRARIES += -lselinux
251 endif
252
253 ifeq ($(strip $(PREFIX)),)
254     PREFIX:=`pwd`/_install
255 endif
256
257 CFLAGS    += $(CROSS_CFLAGS)
258 ifdef BB_INIT_SCRIPT
259     CFLAGS += -DINIT_SCRIPT='"$(BB_INIT_SCRIPT)"'
260 endif
261
262 # Put user-supplied flags at the end, where they
263 # have a chance of winning.
264 CFLAGS += $(CFLAGS_EXTRA)
265
266 #------------------------------------------------------------
267 # Installation options
268 ifeq ($(strip $(CONFIG_INSTALL_APPLET_HARDLINKS)),y)
269 INSTALL_OPTS=--hardlinks
270 endif
271 ifeq ($(strip $(CONFIG_INSTALL_APPLET_SYMLINKS)),y)
272 INSTALL_OPTS=--symlinks
273 endif
274 ifeq ($(strip $(CONFIG_INSTALL_APPLET_DONT)),y)
275 INSTALL_OPTS=
276 endif
277
278
279 #------------------------------------------------------------
280 # object extensions
281
282 # object potentially used in shared object
283 ifeq ($(strip $(CONFIG_BUILD_LIBBUSYBOX)),y)
284 # single-object extension
285 os:=.os
286 # multi-object extension
287 om:=.osm
288 else
289 os:=.o
290 om:=.om
291 endif
292
293 #------------------------------------------------------------
294 # Make the output nice and tight
295
296 # for make V=2 and above, do print directory
297 ifneq ($(shell test -n "$(strip $(PACKAGE_BE_VERBOSE))" && test $(PACKAGE_BE_VERBOSE) -gt 1 ; echo $$?),0)
298   MAKEFLAGS += --no-print-directory
299 endif
300
301 export MAKEOVERRIDES
302 export MAKE_IS_SILENT=n
303 ifneq ($(findstring s,$(MAKEFLAGS)),)
304 export MAKE_IS_SILENT=y
305 DISP  := sil
306 Q     := @
307 else
308 ifneq ($(V)$(VERBOSE),)
309 DISP  := ver
310 Q     := 
311 else
312 DISP  := pur
313 Q     := @
314 endif
315 endif
316
317 define show_objs
318   $(subst $(top_builddir)/,,$(subst ../,,$@))
319 endef
320 pur_disp_compile.c = @echo "  "CC $(show_objs) ;
321 pur_disp_compile.h = @echo "  "HOSTCC $(show_objs) ;
322 pur_disp_strip     = @echo "  "STRIP $(show_objs) ;
323 pur_disp_link      = @echo "  "LINK $(show_objs) ;
324 pur_disp_link.h    = @echo "  "HOSTLINK $(show_objs) ;
325 pur_disp_ar        = @echo "  "AR $(ARFLAGS) $(show_objs) ;
326 pur_disp_gen       = @echo "  "GEN $@ ;
327 pur_disp_doc       = @echo "  "DOC $(subst docs/,,$@) ;
328 pur_disp_bin       = @echo "  "BIN $(show_objs) ;
329 sil_disp_compile.c = @
330 sil_disp_compile.h = @
331 sil_disp_strip     = @
332 sil_disp_link      = @
333 sil_disp_link.h    = @
334 sil_disp_ar        = @
335 sil_disp_gen       = @
336 sil_disp_doc       = @
337 sil_disp_bin       = @
338 ver_disp_compile.c =
339 ver_disp_compile.h =
340 ver_disp_strip     =
341 ver_disp_link      =
342 ver_disp_link.h    =
343 ver_disp_ar        =
344 ver_disp_gen       =
345 ver_disp_doc       =
346 ver_disp_bin       =
347 disp_compile.c     = $($(DISP)_disp_compile.c)
348 disp_compile.h     = $($(DISP)_disp_compile.h)
349 disp_strip         = $($(DISP)_disp_strip)
350 disp_link          = $($(DISP)_disp_link)
351 disp_link.h        = $($(DISP)_disp_link.h)
352 disp_ar            = $($(DISP)_disp_ar)
353 disp_gen           = $($(DISP)_disp_gen)
354 disp_doc           = $($(DISP)_disp_doc)
355 disp_bin           = $($(DISP)_disp_bin)
356 # CFLAGS-dir        == $(CFLAGS-$(notdir $(@D)))
357 # CFLAGS-dir-file.o == $(CFLAGS-$(notdir $(@D))-$(notdir $(@F)))
358 # CFLAGS-dir-file.c == $(CFLAGS-$(notdir $(<D))-$(notdir $(<F)))
359 # all prerequesites == $(foreach fil,$^,$(CFLAGS-$(notdir $(patsubst %/$,%,$(dir $(fil))))-$(notdir $(fil))))
360 cmd_compile.c      = $(CC) $(CFLAGS) $(EXTRA_CFLAGS) -I$(srcdir) -c -o $@ $< \
361  $(foreach f,$^,$(CFLAGS-$(notdir $(patsubst %/$,%,$(dir $(f))))-$(notdir $(f)))) \
362  $(CFLAGS-$(notdir $(@D))-$(notdir $(@F))) \
363  $(CFLAGS-$(notdir $(@D)))
364 cmd_compile.m      = $(cmd_compile.c) -DL_$(patsubst %$(suffix $(notdir $@)),%,$(notdir $@))
365 cmd_compile.h      = $(HOSTCC) $(HOSTCFLAGS) -c -o $@ $<
366 cmd_strip          = $(STRIPCMD) $@
367 cmd_link           = $(CC) $(CFLAGS) $(EXTRA_CFLAGS) -I$(srcdir) $(LDFLAGS)
368 cmd_link.h         = $(HOSTCC) $(HOSTCFLAGS) $(HOST_LDFLAGS) $^ -o $@
369 cmd_ar             = $(AR) $(ARFLAGS) $@ $^
370 compile.c          = $(disp_compile.c) $(cmd_compile.c)
371 compile.m          = $(disp_compile.c) $(cmd_compile.m)
372 compile.h          = $(disp_compile.h) $(cmd_compile.h)
373 do_strip           = $(disp_strip)     $(cmd_strip)
374 do_link            = $(disp_link)      $(cmd_link)
375 do_link.h          = $(disp_link.h)    $(cmd_link.h)
376 do_ar              = $(disp_ar)        $(cmd_ar)
377
378 ifdef rules-mak-rules
379 .SUFFIXES: .c .S .o .os .om .osm .oS .so .a .s .i .E
380
381 # generic rules
382 %.o:  %.c ; $(compile.c)
383 %.os: %.c ; $(compile.c) $(CFLAGS_PIC)
384 %.o:      ; $(compile.c)
385 %.os:     ; $(compile.c) $(CFLAGS_PIC)
386 %.om:     ; $(compile.m)
387 %.osm:    ; $(compile.m) $(CFLAGS_PIC)
388
389 endif # rules-mak-rules
390
391 .PHONY: dummy
392