1 # Rules.make for busybox
3 # Copyright (C) 1999-2005 by Erik Andersen <andersen@codepoet.org>
5 # Licensed under GPLv2, see the file LICENSE in this tarball for details.
8 # Pull in the user's busybox configuration
9 ifeq ($(filter $(noconfig_targets),$(MAKECMDGOALS)),)
10 -include $(top_builddir)/.config
14 ifeq ($(HAVE_DOT_CONFIG),y)
19 #--------------------------------------------------------
25 VERSION :=$(MAJOR_VERSION).$(MINOR_VERSION).$(SUBLEVEL_VERSION)$(EXTRAVERSION)
26 BUILDTIME := $(shell TZ=UTC date -u "+%Y.%m.%d-%H:%M%z")
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 #--------------------------------------------------------
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)))
53 ifdef PACKAGE_BE_VERBOSE
54 PACKAGE_BE_VERBOSE := $(shell echo $(PACKAGE_BE_VERBOSE) | $(SED) "s/[[:alpha:]]*//g")
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)
63 # What OS are you compiling busybox for? This allows you to include
64 # OS specific things, syscall overrides, etc.
67 # Select the compiler needed to build binaries for your development system
69 HOSTCFLAGS= -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer
71 # Ensure consistent sort order, 'gcc -print-search-dirs' behavior, etc.
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)))
80 # To compile vs some other alternative libc, you may need to use/adjust
81 # the following lines to meet your needs...
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
88 # For other libraries, you are on your own. But these may (or may not) help...
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")
94 WARNINGS=-Wall -Wstrict-prototypes -Wshadow
95 CFLAGS+=-I$(top_builddir)/include -I$(top_srcdir)/include
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))
106 # Note: spaces are significant here!
107 # Check if CC version is equal to given MAJOR,MINOR. Returns empty if false.
109 $(shell [ $(CC_MAJOR) -eq $(1) -a $(CC_MINOR) -eq $(2) ] && echo y)
111 # Check if CC version is greater or equal than given MAJOR,MINOR
113 $(shell [ $(CC_MAJOR) -ge $(1) -a $(CC_MINOR) -ge $(2) ] && echo y)
115 # Check if CC version is less or equal than given MAJOR,MINOR
117 $(shell [ $(CC_MAJOR) -le $(1) -a $(CC_MINOR) -le $(2) ] && echo y)
120 # Workaround bugs in make-3.80 for eval in conditionals
122 $(shell [ $(1) = $(2) ] 2> /dev/null && echo y)
125 $(shell [ $(1) != $(2) ] 2> /dev/null && echo y)
128 #--------------------------------------------------------
129 export VERSION BUILDTIME HOSTCC HOSTCFLAGS CROSS CC AR AS LD NM STRIP CPP
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
137 ifeq ($(strip $(__TARGET_ARCH)),)
138 __TARGET_ARCH:=$(shell $(CC) -dumpmachine | sed -e s'/-.*//' \
140 -e 's/sparc.*/sparc/' \
142 -e 's/m68k.*/m68k/' \
143 -e 's/ppc/powerpc/g' \
144 -e 's/v850.*/v850/g' \
146 -e 's/mips-.*/mips/' \
147 -e 's/mipsel-.*/mipsel/' \
148 -e 's/cris.*/cris/' \
152 $(call check_gcc,CFLAGS,-funsigned-char,)
153 $(call check_gcc,CFLAGS,-mmax-stack-frame=256,)
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...
160 # use '-Os' optimization if available, else use -O2
161 $(call check_gcc,OPTIMIZATIONS,-Os,-O2)
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,)))
168 $(if $(call is_eq,$(CONFIG_BUILD_AT_ONCE),y),\
169 $(call check_gcc,OPTIMIZATIONS,-funit-at-a-time,))
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,))
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,)
180 $(call check_ld,PROG_LDFLAGS,--gc-sections,)
182 # Some nice architecture specific optimizations
183 ifeq ($(__TARGET_ARCH),arm)
184 OPTIMIZATIONS+=-fstrict-aliasing
187 $(if $(call is_eq,$(__TARGET_ARCH),i386),\
188 $(call check_gcc,OPTIMIZATIONS,-march=i386,))
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=0 -falign-jumps=0 -falign-loops=0,\
194 -malign-functions=0 -malign-jumps=0 -malign-loops=0))
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,)\
203 $(call check_gcc,OPTIMIZATIONS,-fno-branch-count-reg,))
205 $(call check_gcc,OPTIMIZATIONS,-fomit-frame-pointer,)
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.
216 ifeq ($(CONFIG_LFS),y)
217 # For large file summit support
218 CFLAGS+=-D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
220 ifeq ($(CONFIG_DMALLOC),y)
221 # For testing mem leaks with dmalloc
225 ifeq ($(CONFIG_EFENCE),y)
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
237 CFLAGS+=$(WARNINGS) $(OPTIMIZATIONS) -D_GNU_SOURCE -DNDEBUG
238 STRIPCMD:=$(STRIP) -s --remove-section=.note --remove-section=.comment
240 $(if $(call is_eq,$(CONFIG_STATIC),y),\
241 $(call check_gcc,PROG_CFLAGS,-static,))
243 $(call check_gcc,CFLAGS_SHARED,-shared,)
244 LIB_CFLAGS+=$(CFLAGS_SHARED)
246 $(if $(call is_eq,$(CONFIG_BUILD_LIBBUSYBOX),y),\
247 $(call check_gcc,CFLAGS_PIC,-fPIC,))
249 ifeq ($(CONFIG_SELINUX),y)
250 LIBRARIES += -lselinux
253 ifeq ($(strip $(PREFIX)),)
254 PREFIX:=`pwd`/_install
257 CFLAGS += $(CROSS_CFLAGS)
259 CFLAGS += -DINIT_SCRIPT='"$(BB_INIT_SCRIPT)"'
262 # Put user-supplied flags at the end, where they
263 # have a chance of winning.
264 CFLAGS += $(CFLAGS_EXTRA)
266 #------------------------------------------------------------
267 # Installation options
268 ifeq ($(strip $(CONFIG_INSTALL_APPLET_HARDLINKS)),y)
269 INSTALL_OPTS=--hardlinks
271 ifeq ($(strip $(CONFIG_INSTALL_APPLET_SYMLINKS)),y)
272 INSTALL_OPTS=--symlinks
274 ifeq ($(strip $(CONFIG_INSTALL_APPLET_DONT)),y)
279 #------------------------------------------------------------
282 # object potentially used in shared object
283 ifeq ($(strip $(CONFIG_BUILD_LIBBUSYBOX)),y)
284 # single-object extension
286 # multi-object extension
293 #------------------------------------------------------------
294 # Make the output nice and tight
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
302 export MAKE_IS_SILENT=n
303 ifneq ($(findstring s,$(MAKEFLAGS)),)
304 export MAKE_IS_SILENT=y
308 ifneq ($(V)$(VERBOSE),)
318 $(subst $(top_builddir)/,,$(subst ../,,$@))
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 = @
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)
378 ifdef rules-mak-rules
379 .SUFFIXES: .c .S .o .os .om .osm .oS .so .a .s .i .E
382 %.o: %.c ; $(compile.c)
383 %.os: %.c ; $(compile.c) $(CFLAGS_PIC)
385 %.os: ; $(compile.c) $(CFLAGS_PIC)
387 %.osm: ; $(compile.m) $(CFLAGS_PIC)
389 endif # rules-mak-rules