3 # Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
5 # Licensed under GPLv2, see the file LICENSE in this tarball for details.
8 #--------------------------------------------------------------
9 # You shouldn't need to mess with anything beyond this point...
10 #--------------------------------------------------------------
11 noconfig_targets := menuconfig config oldconfig randconfig \
12 defconfig allyesconfig allnoconfig allbareconfig \
15 # the toplevel sourcedir
17 top_srcdir:=$(shell cd $(dir $(firstword $(MAKEFILE_LIST))) && pwd)
19 # toplevel directory of the object-tree
21 top_builddir:=$(CURDIR)
24 export srctree=$(top_srcdir)
25 vpath %/Config.in $(srctree)
27 DIRS:=applets archival archival/libunarchive coreutils console-tools \
28 debianutils editors findutils init miscutils modutils networking \
29 networking/libiproute networking/udhcp procps loginutils shell \
30 sysklogd util-linux e2fsprogs libpwdgrp coreutils/libcoreutils libbb
32 SRC_DIRS:=$(patsubst %,$(top_srcdir)/%,$(DIRS))
34 # That's our default target when none is given on the command line
39 # see if we are in verbose mode
42 PACKAGE_BE_VERBOSE := $(VERBOSE)
46 PACKAGE_BE_VERBOSE := $(V)
50 ifeq ("$(origin O)", "command line")
51 PACKAGE_OUTPUTDIR := $(shell cd $(O) && pwd)
52 top_builddir := $(PACKAGE_OUTPUTDIR)
55 # If no alternate output-dir was specified, we build in cwd
56 PACKAGE_OUTPUTDIR := $(top_builddir)
59 #######################################################################
60 # Try to workaround bugs in make
62 # Workaround for bugs in make-3.80
63 # eval is broken if it is in a conditional
65 #$ cat 3.80-eval-in-cond.mak
68 # all:: ; @echo worked
73 #$ make -f 3.80-eval-in-cond.mak
75 #$ make -f 3.80-eval-in-cond.mak BAR=set
76 #3.80-eval-in-cond.mak:5: *** missing `endif'. Stop.
78 # This was fixed in December 2003.
80 $(eval $(1)+=$(if $(2),$(if $(shell $(CC) $(2) -S -o /dev/null -xc /dev/null > /dev/null 2>&1 && echo y),$(2),$(if $(3),$(3))),$(if $(3),$(3))))
84 $(eval $(1)+=$(if $(2),$(if $(shell $(LD) $(2) -o /dev/null -b binary /dev/null > /dev/null 2>&1 && echo y),$(shell echo \-Wl,$(2)),$(if $(3),$(3))),$(if $(3),$(3))))
87 #######################################################################
90 -include $(top_srcdir)/Rules.mak
92 # Handle building out of tree
93 ifneq ($(top_builddir),$(top_srcdir))
94 all_tree := $(patsubst %,$(top_builddir)/%,$(DIRS) scripts scripts/config include include/config)
98 saved-output := $(PACKAGE_OUTPUTDIR)
100 $(if $(wildcard $(PACKAGE_OUTPUTDIR)),, \
101 $(error output directory "$(saved-output)" does not exist))
103 .PHONY: $(filter $(noconfig_targets),$(MAKECMDGOALS))
105 $(PACKAGE_OUTPUTDIR)/Rules.mak:
107 @echo top_srcdir=$(top_srcdir) >> $@
108 @echo top_builddir=$(PACKAGE_OUTPUTDIR) >> $@
109 @echo include $$\(top_srcdir\)/Rules.mak >> $@
111 $(PACKAGE_OUTPUTDIR)/Makefile:
113 @echo top_srcdir=$(top_srcdir) >> $@
114 @echo top_builddir=$(PACKAGE_OUTPUTDIR) >> $@
115 @echo PACKAGE_SOURCEDIR='$$(top_srcdir)' >> $@
116 @echo include '$$(PACKAGE_SOURCEDIR)'/Makefile >> $@
119 buildtree := $(all_tree) $(PACKAGE_OUTPUTDIR)/Rules.mak $(PACKAGE_OUTPUTDIR)/Makefile
121 # We only need a copy of the Makefile for the config targets and reuse
122 # the rest from the source directory, i.e. we do not cp ALL_MAKEFILES.
123 scripts/config/Makefile: $(top_srcdir)/scripts/config/Makefile | $(buildtree)
124 @cp $(top_srcdir)/scripts/config/Makefile $@
127 all_tree := include/config
130 buildtree := $(all_tree)
131 endif # ifneq ($(PACKAGE_OUTPUTDIR),$(top_srcdir))
135 @echo ' clean - delete temporary files created by build'
136 @echo ' distclean - delete all non-source files (including .config)'
139 @echo ' all - Executable and documentation'
140 @echo ' busybox - the swiss-army executable'
141 @echo ' doc - docs/BusyBox.{txt,html,1}'
143 @echo 'Configuration:'
144 @echo ' allnoconfig - disable all symbols in .config'
145 @echo ' allyesconfig - enable all symbols in .config (see defconfig)'
146 @echo ' allbareconfig - enable all applets without any sub-features'
147 @echo ' config - text based configurator (of last resort)'
148 @echo ' defconfig - set .config to largest generic configuration'
149 @echo ' menuconfig - interactive curses-based configurator'
150 @echo ' oldconfig - resolve any unresolved symbols in .config'
152 @echo 'Installation:'
153 @echo ' install - install busybox into $prefix'
157 @echo ' check - run the test suite for all applets'
158 @echo ' randconfig - generate a random configuration'
159 @echo ' release - create a distribution tarball'
160 @echo ' sizes - show size of all enabled busybox symbols'
163 @echo ' V=<number> - print verbose make output (default: unset)'
164 @echo ' 0 print CC invocations'
166 @echo ' 2 also print when make enters a directory'
167 @echo ' 3 also verbosely print shell invocations'
169 ifneq ($(strip $(HAVE_DOT_CONFIG)),y)
170 # Default target if none was requested explicitly
171 all: defconfig menuconfig ;
173 ifneq ($(filter-out $(noconfig_targets),$(MAKECMDGOALS)),)
174 # warn if no configuration exists and we are asked to build a non-config target
177 @echo "No $(top_builddir)/$@ found!"
178 @echo "Please refer to 'make help', section Configuration."
182 # Avoid implicit rule to kick in by using an empty command
183 .config: $(buildtree) ;
185 endif # ifneq ($(strip $(HAVE_DOT_CONFIG)),y)
189 # ---------------------------------------------------------------------------
191 CONFIG_CONFIG_IN = $(top_srcdir)/Config.in
193 scripts/config/conf: scripts/config/Makefile
194 $(Q)$(MAKE) -C scripts/config conf
196 scripts/config/mconf: scripts/config/Makefile
197 $(Q)$(MAKE) -C scripts/config ncurses conf mconf
199 menuconfig: scripts/config/mconf
200 @./scripts/config/mconf $(CONFIG_CONFIG_IN)
202 config: scripts/config/conf
203 @./scripts/config/conf $(CONFIG_CONFIG_IN)
205 oldconfig: scripts/config/conf
206 @./scripts/config/conf -o $(CONFIG_CONFIG_IN)
208 randconfig: scripts/config/conf
209 @./scripts/config/conf -r $(CONFIG_CONFIG_IN)
211 allyesconfig: scripts/config/conf
212 @./scripts/config/conf -y $(CONFIG_CONFIG_IN)
213 @$(SED) -i -r -e "s/^(USING_CROSS_COMPILER)=.*/# \1 is not set/" .config
214 @./scripts/config/conf -o $(CONFIG_CONFIG_IN)
216 allnoconfig: scripts/config/conf
217 @./scripts/config/conf -n $(CONFIG_CONFIG_IN)
219 # defconfig is allyesconfig minus any features that are specialized enough
220 # or cause enough behavior change that the user really should switch them on
221 # manually if that's what they want. Sort of "maximum sane config".
223 defconfig: scripts/config/conf
224 @./scripts/config/conf -y $(CONFIG_CONFIG_IN)
225 @$(SED) -i -r -e "s/^(USING_CROSS_COMPILER|CONFIG_(DEBUG.*|STATIC|SELINUX|BUILD_(AT_ONCE|LIBBUSYBOX)|FEATURE_(DEVFS|FULL_LIBBUSYBOX|SHARED_BUSYBOX|MTAB_SUPPORT|CLEAN_UP|UDHCP_DEBUG)|INSTALL_NO_USR))=.*/# \1 is not set/" .config
226 @./scripts/config/conf -o $(CONFIG_CONFIG_IN)
228 allbareconfig: scripts/config/conf
229 @./scripts/config/conf -y $(CONFIG_CONFIG_IN)
230 @$(SED) -i -r -e "s/^(USING_CROSS_COMPILER|CONFIG_(DEBUG|STATIC|SELINUX|DEVFSD|NC_GAPING_SECURITY_HOLE|BUILD_AT_ONCE)).*/# \1 is not set/" .config
231 @$(SED) -i -e "/FEATURE/s/=.*//;/^[^#]/s/.*FEATURE.*/# \0 is not set/;" .config
232 @echo "CONFIG_FEATURE_BUFFERS_GO_ON_STACK=y" >> .config
233 @./scripts/config/conf -o $(CONFIG_CONFIG_IN)
235 ifeq ($(strip $(HAVE_DOT_CONFIG)),y)
238 -include $(top_builddir)/.config.cmd
240 endif # ifeq ($(strip $(HAVE_DOT_CONFIG)),y)
242 # convert $(DIRS) to upper case. Use sed instead of tr since we're already
244 DIRS_UPPER:=$(shell echo $(DIRS) | $(SED) 'h;y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/')
246 # First populate the variables ..._OBJ-y ...OBJ-m et al
247 $(foreach d,$(DIRS_UPPER),$(eval $(notdir $(d))-y:=))
248 $(foreach d,$(DIRS_UPPER),$(eval $(notdir $(d))-m:=))
250 include $(patsubst %,%/Makefile.in,$(SRC_DIRS))
252 # Then we need the dependencies for ..._OBJ
255 # write patterns for both .os and .o
256 $(if $($(1)_OBJ.os),$($(1)_OBJ.os:.os=.o): $(top_builddir)/$(2)/%.o: $(top_srcdir)/$(2)/%.c)
258 $(if $($(1)_OBJ$(os)),$($(1)_OBJ$(os)): $(top_builddir)/$(2)/%$(os): $(top_srcdir)/$(2)/%.c)
259 $(if $($(1)_OBJ),$($(1)_OBJ): $(top_builddir)/$(2)/%.o: $(top_srcdir)/$(2)/%.c)
261 lib-obj-y+=$($(1)_OBJ) $($(1)_OBJ.o) $($(1)_OBJ.os)
262 lib-mobj-y+=$($(1)_MOBJ.o) $($(1)_MOBJ.os)
263 bin-obj-y+=$($(1)_OBJ:.os=.o) $($(1)_OBJ.o:.os=.o) $($(1)_OBJ.os:.os=.o)
264 bin-mobj-y+=$($(1)_MOBJ.o:.osm=.om) $($(1)_MOBJ.os:.osm=.om)
266 # The actual directory patterns for .o*
267 $(foreach d,$(DIRS),$(eval $(call dir_pattern.o,$(subst /,_,$(d)),$(d))))
269 ifeq ($(strip $(HAVE_DOT_CONFIG)),y)
270 # Finally pull in the dependencies (headers and other includes) of the
271 # individual object files
272 -include $(top_builddir)/.depend
277 all: busybox busybox.links doc ;
279 # Two modes of operation: legacy and IMA
280 # Legacy mode builds each object through an individual invocation of CC
281 # IMA compiles all sources at once (aka IPO aka IPA etc.)
283 ifeq ($(strip $(CONFIG_BUILD_AT_ONCE)),y)
284 # We are not building .o
287 # Which parts of the internal libs are requested?
288 # Per default we only want what was actually selected.
289 # -a denotes all while -y denotes the selected ones.
290 ifeq ($(strip $(CONFIG_FEATURE_FULL_LIBBUSYBOX)),y)
291 LIBRARY_DEFINE:=$(LIBRARY_DEFINE-a)
292 LIBRARY_SRC :=$(LIBRARY_SRC-a)
293 else # CONFIG_FEATURE_FULL_LIBBUSYBOX
294 LIBRARY_DEFINE:=$(LIBRARY_DEFINE-y)
295 LIBRARY_SRC :=$(LIBRARY_SRC-y)
296 endif # CONFIG_FEATURE_FULL_LIBBUSYBOX
297 APPLET_SRC:=$(APPLET_SRC-y)
298 APPLETS_DEFINE:=$(APPLETS_DEFINE-y)
299 else # CONFIG_BUILD_AT_ONCE
300 # no --combine, build archives out of the individual .o
301 # This was the old way the binary was built.
302 libbusybox-obj:=$(archival_libunarchive_OBJ$(os)) \
303 $(networking_libiproute_OBJ$(os)) \
304 $(libpwdgrp_MOBJ$(os)) \
305 $(coreutils_libcoreutils_OBJ$(os)) \
306 $(libbb_OBJ$(os)) $(libbb_MOBJ$(os))
308 ifeq ($(strip $(CONFIG_FEATURE_SHARED_BUSYBOX)),y)
309 # linking against libbusybox, so don't build the .o already contained in the .so
310 bin-obj-y:=$(filter-out $(libbusybox-obj) $(libbusybox-obj:.os=.o),$(bin-obj-y))
311 bin-mobj-y:=$(filter-out $(libbusybox-obj) $(libbusybox-obj:.osm=.om),$(bin-mobj-y))
312 endif # CONFIG_FEATURE_SHARED_BUSYBOX
313 endif # CONFIG_BUILD_AT_ONCE
315 # build an .a to keep .hash et al small
316 ifneq ($(bin-obj-y)$(bin-mobj-y),)
317 applets.a:=$(bin-obj-y) $(bin-mobj-y)
320 applets.a: $(applets.a)
325 ifeq ($(strip $(CONFIG_BUILD_LIBBUSYBOX)),y)
326 LD_LIBBUSYBOX:=libbusybox.so
327 LIBBUSYBOX_SONAME:=$(LD_LIBBUSYBOX).$(MAJOR_VERSION).$(MINOR_VERSION).$(SUBLEVEL_VERSION)
328 DO_INSTALL_LIBS:=$(LD_LIBBUSYBOX) \
329 $(LD_LIBBUSYBOX).$(MAJOR_VERSION) \
330 $(LD_LIBBUSYBOX).$(MAJOR_VERSION).$(MINOR_VERSION)
332 endif # CONFIG_BUILD_LIBBUSYBOX
334 ifeq ($(strip $(CONFIG_BUILD_AT_ONCE)),y)
335 ifneq ($(strip $(CONFIG_FEATURE_SHARED_BUSYBOX)),y)
336 # --combine but not linking against libbusybox, so compile lib*.c
337 BUSYBOX_SRC := $(LIBRARY_SRC)
338 BUSYBOX_DEFINE:= $(LIBRARY_DEFINE)
339 endif # !CONFIG_FEATURE_SHARED_BUSYBOX
340 $(LIBBUSYBOX_SONAME): $(LIBRARY_SRC)
341 else # CONFIG_BUILD_AT_ONCE
342 $(LIBBUSYBOX_SONAME): $(libbusybox-obj)
343 endif # CONFIG_BUILD_AT_ONCE
346 ifeq ($(strip $(CONFIG_FEATURE_SHARED_BUSYBOX)),y)
347 LDBUSYBOX:=-L$(top_builddir) -lbusybox
350 ifeq ($(strip $(CONFIG_BUILD_LIBBUSYBOX)),y)
351 $(LIBBUSYBOX_SONAME):
353 $(error MAJOR_VERSION needed for $@ is not defined)
355 $(do_link) $(LIB_CFLAGS) $(LIB_LDFLAGS) $(CFLAGS_COMBINE) \
356 -Wl,-soname=$(LD_LIBBUSYBOX).$(MAJOR_VERSION) \
357 -Wl,-z,combreloc $(LIB_LDFLAGS) \
360 $(LIBRARY_DEFINE) $(^) \
362 @rm -f $(DO_INSTALL_LIBS)
363 @for i in $(DO_INSTALL_LIBS); do ln -s $(@) $$i ; done
366 endif # ifeq ($(strip $(CONFIG_BUILD_LIBBUSYBOX)),y)
368 busybox_unstripped: $(top_builddir)/.depend $(LIBBUSYBOX_SONAME) $(BUSYBOX_SRC) $(APPLET_SRC) $(bin-obj.a)
369 $(do_link) $(PROG_CFLAGS) $(PROG_LDFLAGS) $(CFLAGS_COMBINE) \
370 $(foreach f,$(^:.o=.c),$(CFLAGS-$(notdir $(patsubst %/$,%,$(dir $(f))))-$(notdir $(f)))) \
372 -o $@ -Wl,--start-group \
373 $(APPLETS_DEFINE) $(APPLET_SRC) \
374 $(BUSYBOX_DEFINE) $(BUSYBOX_SRC) \
376 $(LDBUSYBOX) $(LIBRARIES) \
379 busybox: busybox_unstripped
380 $(Q)cp busybox_unstripped busybox
383 busybox.links: $(top_srcdir)/applets/busybox.mkll include/bb_config.h $(top_srcdir)/include/applets.h
386 install: $(top_srcdir)/applets/install.sh busybox busybox.links
387 $(Q)DO_INSTALL_LIBS="$(strip $(LIBBUSYBOX_SONAME) $(DO_INSTALL_LIBS))" \
388 $(SHELL) $< $(PREFIX) $(INSTALL_OPTS)
389 ifeq ($(strip $(CONFIG_FEATURE_SUID)),y)
392 @echo --------------------------------------------------
393 @echo You will probably need to make your busybox binary
394 @echo setuid root to ensure all configured applets will
396 @echo --------------------------------------------------
400 uninstall: busybox.links
401 rm -f $(PREFIX)/bin/busybox
402 for i in `cat busybox.links` ; do rm -f $(PREFIX)$$i; done
403 ifneq ($(strip $(DO_INSTALL_LIBS)),n)
404 for i in $(LIBBUSYBOX_SONAME) $(DO_INSTALL_LIBS); do \
405 rm -f $(PREFIX)$$i; \
410 bindir=$(top_builddir) srcdir=$(top_srcdir)/testsuite \
411 $(top_srcdir)/testsuite/runtest $(CHECK_VERBOSE)
413 sizes: busybox_unstripped
414 $(NM) --size-sort $(<)
416 # Documentation Targets
417 doc: docs/busybox.pod docs/BusyBox.txt docs/BusyBox.1 docs/BusyBox.html ;
419 docs/busybox.pod : $(top_srcdir)/docs/busybox_header.pod $(top_srcdir)/include/usage.h $(top_srcdir)/docs/busybox_footer.pod $(top_srcdir)/docs/autodocifier.pl
422 $(Q)-( cat $(top_srcdir)/docs/busybox_header.pod ; \
423 $(top_srcdir)/docs/autodocifier.pl $(top_srcdir)/include/usage.h ; \
424 cat $(top_srcdir)/docs/busybox_footer.pod ; ) > docs/busybox.pod
426 docs/BusyBox.txt: docs/busybox.pod
429 $(Q)-pod2text $< > $@
431 docs/BusyBox.1: docs/busybox.pod
434 $(Q)-pod2man --center=BusyBox --release="version $(VERSION)" \
437 docs/BusyBox.html: docs/busybox.net/BusyBox.html
440 $(Q)-rm -f docs/BusyBox.html
441 $(Q)-cp docs/busybox.net/BusyBox.html docs/BusyBox.html
443 docs/busybox.net/BusyBox.html: docs/busybox.pod
444 $(Q)-mkdir -p docs/busybox.net
445 $(Q)-pod2html --noindex $< > \
446 docs/busybox.net/BusyBox.html
449 # The nifty new dependency stuff
450 scripts/bb_mkdep: $(top_srcdir)/scripts/bb_mkdep.c
453 DEP_INCLUDES := include/bb_config.h
455 ifeq ($(strip $(CONFIG_BBCONFIG)),y)
456 DEP_INCLUDES += include/bbconfigopts.h
458 include/bbconfigopts.h: .config
460 $(Q)$(top_srcdir)/scripts/config/mkconfigs > $@
463 depend dep: $(top_builddir)/.depend ;
464 $(top_builddir)/.depend: $(buildtree) scripts/bb_mkdep $(DEP_INCLUDES)
467 $(Q)scripts/bb_mkdep $(MKDEP_ARGS) \
468 -I $(top_srcdir)/include $(top_srcdir) > $@.tmp
471 include/bb_config.h: .config
473 @$(top_builddir)/scripts/config/conf -o $(CONFIG_CONFIG_IN)
475 endif # ifeq ($(strip $(HAVE_DOT_CONFIG)),y)
478 - rm -f docs/busybox.dvi docs/busybox.ps \
479 docs/busybox.pod docs/busybox.net/busybox.html \
480 docs/busybox pod2htm* *.gdb *.elf *~ core .*config.log \
481 docs/BusyBox.txt docs/BusyBox.1 docs/BusyBox.html \
482 docs/busybox.net/BusyBox.html busybox.links \
483 $(DO_INSTALL_LIBS) $(LIBBUSYBOX_SONAME) \
485 - rm -r -f _install testsuite/links
486 - find . -name .\*.flags -exec rm -f {} \;
487 - find . -name \*.o -exec rm -f {} \;
488 - find . -name \*.om -exec rm -f {} \;
489 - find . -name \*.os -exec rm -f {} \;
490 - find . -name \*.a -exec rm -f {} \;
493 - $(MAKE) -C scripts/config clean
494 - rm -f scripts/bb_mkdep
495 - rm -r -f include/config $(DEP_INCLUDES)
496 - find . -name .depend'*' -exec rm -f {} \;
497 rm -f .config .config.old .config.cmd
499 release: distclean #doc
501 rm -r -f $(PROG)-$(VERSION); \
502 cp -a busybox $(PROG)-$(VERSION); \
504 find $(PROG)-$(VERSION)/ -type d \
507 -exec rm -r -f {} \; ; \
509 find $(PROG)-$(VERSION)/ -type f \
512 -exec rm -f {} \; ; \
514 tar -cvzf $(PROG)-$(VERSION).tar.gz $(PROG)-$(VERSION)/;
519 # keep these in sync with noconfig_targets above!
520 .PHONY: dummy subdirs check test depend dep buildtree \
521 menuconfig config oldconfig randconfig \
522 defconfig allyesconfig allnoconfig allbareconfig \