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 \
16 # make-3.79.1 didn't support MAKEFILE_LIST
17 # for building out-of-tree, users of make-3.79 still have to pass top_srcdir=
18 # to make: make -f /srcs/busybox/Makefile top_srcdir=/srcs/busybox
22 # the toplevel sourcedir
24 top_srcdir:=$(shell cd $(dir $(firstword $(MAKEFILE_LIST))) && pwd)
26 # toplevel directory of the object-tree
28 top_builddir:=$(CURDIR)
31 export srctree=$(top_srcdir)
32 vpath %/Config.in $(srctree)
34 DIRS:=applets archival archival/libunarchive coreutils console-tools \
35 debianutils editors findutils init miscutils modutils networking \
36 networking/libiproute networking/udhcp procps loginutils shell \
37 sysklogd util-linux e2fsprogs libpwdgrp coreutils/libcoreutils libbb
39 SRC_DIRS:=$(patsubst %,$(top_srcdir)/%,$(DIRS))
41 # That's our default target when none is given on the command line
46 # see if we are in verbose mode
49 PACKAGE_BE_VERBOSE := $(VERBOSE)
53 PACKAGE_BE_VERBOSE := $(V)
57 ifeq ("$(origin O)", "command line")
58 PACKAGE_OUTPUTDIR := $(shell cd $(O) && pwd)
59 top_builddir := $(PACKAGE_OUTPUTDIR)
62 # If no alternate output-dir was specified, we build in cwd
63 PACKAGE_OUTPUTDIR := $(top_builddir)
66 #######################################################################
67 # Try to workaround bugs in make
69 # make-3.79.1 didn't understand order-only prerequisites ('|').
70 # Just treat them as normal prerequisites. Note that this will lead to
72 ifeq ($(MAKE_VERSION),3.79.1)
76 # Workaround for bugs in make-3.80
77 # eval is broken if it is in a conditional
79 #$ cat 3.80-eval-in-cond.mak
82 # all:: ; @echo worked
87 #$ make -f 3.80-eval-in-cond.mak
89 #$ make -f 3.80-eval-in-cond.mak BAR=set
90 #3.80-eval-in-cond.mak:5: *** missing `endif'. Stop.
92 # This was fixed in December 2003.
94 $(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))))
98 $(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))))
101 #######################################################################
103 -include $(top_srcdir)/Rules.mak
105 # Handle building out of tree
106 ifneq ($(top_builddir),$(top_srcdir))
107 all_tree := $(patsubst %,$(top_builddir)/%,$(DIRS) scripts scripts/config include include/config)
111 saved-output := $(PACKAGE_OUTPUTDIR)
113 $(if $(wildcard $(PACKAGE_OUTPUTDIR)),, \
114 $(error output directory "$(saved-output)" does not exist))
116 .PHONY: $(filter $(noconfig_targets),$(MAKECMDGOALS))
118 $(PACKAGE_OUTPUTDIR)/Rules.mak:
120 @echo top_srcdir=$(top_srcdir) >> $@
121 @echo top_builddir=$(PACKAGE_OUTPUTDIR) >> $@
122 @echo include $$\(top_srcdir\)/Rules.mak >> $@
124 $(PACKAGE_OUTPUTDIR)/Makefile:
126 @echo top_srcdir=$(top_srcdir) >> $@
127 @echo top_builddir=$(PACKAGE_OUTPUTDIR) >> $@
128 @echo PACKAGE_SOURCEDIR='$$(top_srcdir)' >> $@
129 @echo include '$$(PACKAGE_SOURCEDIR)'/Makefile >> $@
132 buildtree := $(all_tree) $(PACKAGE_OUTPUTDIR)/Rules.mak $(PACKAGE_OUTPUTDIR)/Makefile
134 # We only need a copy of the Makefile for the config targets and reuse
135 # the rest from the source directory, i.e. we do not cp ALL_MAKEFILES.
136 scripts/config/Makefile: $(top_srcdir)/scripts/config/Makefile | $(buildtree)
137 @cp $(top_srcdir)/scripts/config/Makefile $@
140 all_tree := include/config
143 buildtree := $(all_tree)
144 endif # ifneq ($(PACKAGE_OUTPUTDIR),$(top_srcdir))
148 @echo ' clean - delete temporary files created by build'
149 @echo ' distclean - delete all non-source files (including .config)'
152 @echo ' all - Executable and documentation'
153 @echo ' busybox - the swiss-army executable'
154 @echo ' doc - docs/BusyBox.{txt,html,1}'
156 @echo 'Configuration:'
157 @echo ' allnoconfig - disable all symbols in .config'
158 @echo ' allyesconfig - enable all symbols in .config (see defconfig)'
159 @echo ' allbareconfig - enable all applets without any sub-features'
160 @echo ' config - text based configurator (of last resort)'
161 @echo ' defconfig - set .config to largest generic configuration'
162 @echo ' menuconfig - interactive curses-based configurator'
163 @echo ' oldconfig - resolve any unresolved symbols in .config'
165 @echo 'Installation:'
166 @echo ' install - install busybox into $prefix'
170 @echo ' check - run the test suite for all applets'
171 @echo ' randconfig - generate a random configuration'
172 @echo ' release - create a distribution tarball'
173 @echo ' sizes - show size of all enabled busybox symbols'
176 @echo ' V=<number> - print verbose make output (default: unset)'
177 @echo ' 0 print CC invocations'
179 @echo ' 2 also print when make enters a directory'
180 @echo ' 3 also verbosely print shell invocations'
182 ifneq ($(strip $(HAVE_DOT_CONFIG)),y)
183 # Default target if none was requested explicitly
184 all: defconfig menuconfig ;
186 ifneq ($(filter-out $(noconfig_targets),$(MAKECMDGOALS)),)
187 # warn if no configuration exists and we are asked to build a non-config target
190 @echo "No $(top_builddir)/$@ found!"
191 @echo "Please refer to 'make help', section Configuration."
195 # Avoid implicit rule to kick in by using an empty command
196 .config: $(buildtree) ;
198 endif # ifneq ($(strip $(HAVE_DOT_CONFIG)),y)
202 # ---------------------------------------------------------------------------
204 CONFIG_CONFIG_IN = $(top_srcdir)/Config.in
206 scripts/config/conf: scripts/config/Makefile
207 $(Q)$(MAKE) -C scripts/config conf
209 scripts/config/mconf: scripts/config/Makefile
210 $(Q)$(MAKE) -C scripts/config ncurses conf mconf
212 menuconfig: scripts/config/mconf
213 @./scripts/config/mconf $(CONFIG_CONFIG_IN)
215 config: scripts/config/conf
216 @./scripts/config/conf $(CONFIG_CONFIG_IN)
218 oldconfig: scripts/config/conf
219 @./scripts/config/conf -o $(CONFIG_CONFIG_IN)
221 randconfig: scripts/config/conf
222 @./scripts/config/conf -r $(CONFIG_CONFIG_IN)
224 allyesconfig: scripts/config/conf
225 @./scripts/config/conf -y $(CONFIG_CONFIG_IN)
226 @$(SED) -i -r -e "s/^(USING_CROSS_COMPILER)=.*/# \1 is not set/" .config
227 @./scripts/config/conf -o $(CONFIG_CONFIG_IN)
229 allnoconfig: scripts/config/conf
230 @./scripts/config/conf -n $(CONFIG_CONFIG_IN)
232 # defconfig is allyesconfig minus any features that are specialized enough
233 # or cause enough behavior change that the user really should switch them on
234 # manually if that's what they want. Sort of "maximum sane config".
236 defconfig: scripts/config/conf
237 @./scripts/config/conf -y $(CONFIG_CONFIG_IN)
238 @$(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
239 @./scripts/config/conf -o $(CONFIG_CONFIG_IN)
241 allbareconfig: scripts/config/conf
242 @./scripts/config/conf -y $(CONFIG_CONFIG_IN)
243 @$(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
244 @$(SED) -i -e "/FEATURE/s/=.*//;/^[^#]/s/.*FEATURE.*/# \0 is not set/;" .config
245 @echo "CONFIG_FEATURE_BUFFERS_GO_ON_STACK=y" >> .config
246 @./scripts/config/conf -o $(CONFIG_CONFIG_IN)
248 ifeq ($(strip $(HAVE_DOT_CONFIG)),y)
251 -include $(top_builddir)/.config.cmd
253 endif # ifeq ($(strip $(HAVE_DOT_CONFIG)),y)
255 # convert $(DIRS) to upper case. Use sed instead of tr since we're already
257 DIRS_UPPER:=$(shell echo $(DIRS) | $(SED) 'h;y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/')
259 # First populate the variables ..._OBJ-y et al
260 $(foreach d,$(DIRS_UPPER),$(eval $(notdir $(d))-y:=))
262 include $(patsubst %,%/Makefile.in,$(SRC_DIRS))
264 # Then we need the dependencies for ..._OBJ
267 $(if $($(1)_OBJ.os),$($(1)_OBJ.os:.os=.o): $(top_builddir)/$(2)/%.o: $(top_srcdir)/$(2)/%.c)
269 $(if $($(1)_OBJ$(os)),$($(1)_OBJ$(os)): $(top_builddir)/$(2)/%$(os): $(top_srcdir)/$(2)/%.c)
270 $(if $($(1)_OBJ),$($(1)_OBJ): $(top_builddir)/$(2)/%.o: $(top_srcdir)/$(2)/%.c)
273 # The actual directory patterns for .o*
274 $(foreach d,$(DIRS),$(eval $(call dir_pattern.o,$(subst /,_,$(d)),$(d))))
277 $($(1)$(2)) $($(1)$(2).o) $($(1)$(2).os)
279 bin-obj-y:=$(subst .os,.o,$(foreach d,$(DIRS),$(call file_lists,$(subst /,_,$(d)),_OBJ)))
280 bin-mobj-y:=$(subst .osm,.om,$(foreach d,$(DIRS),$(call file_lists,$(subst /,_,$(d)),_MOBJ)))
282 ifeq ($(strip $(HAVE_DOT_CONFIG)),y)
283 # Finally pull in the dependencies (headers and other includes) of the
284 # individual object files
285 -include $(top_builddir)/.depend
287 $(top_builddir)/applets/applets.o: $(top_builddir)/.config
290 all: busybox busybox.links doc ;
292 # Two modes of operation: legacy and IMA
293 # Legacy mode builds each object through an individual invocation of CC
294 # IMA compiles all sources at once (aka IPO aka IPA etc.)
296 ifeq ($(strip $(CONFIG_BUILD_AT_ONCE)),y)
297 # We are not building .o
300 # Which parts of the internal libs are requested?
301 # Per default we only want what was actually selected.
302 # -a denotes all while -y denotes the selected ones.
303 ifeq ($(strip $(CONFIG_FEATURE_FULL_LIBBUSYBOX)),y)
304 LIBRARY_DEFINE:=$(LIBRARY_DEFINE-a)
305 LIBRARY_SRC :=$(LIBRARY_SRC-a)
306 else # CONFIG_FEATURE_FULL_LIBBUSYBOX
307 LIBRARY_DEFINE:=$(LIBRARY_DEFINE-y)
308 LIBRARY_SRC :=$(LIBRARY_SRC-y)
309 endif # CONFIG_FEATURE_FULL_LIBBUSYBOX
310 APPLET_SRC:=$(APPLET_SRC-y)
311 APPLETS_DEFINE:=$(APPLETS_DEFINE-y)
312 else # CONFIG_BUILD_AT_ONCE
313 # no --combine, build archives out of the individual .o
314 # This was the old way the binary was built.
315 libbusybox-obj:=$(archival_libunarchive_OBJ$(os)) \
316 $(networking_libiproute_OBJ$(os)) \
317 $(libpwdgrp_MOBJ$(os)) \
318 $(coreutils_libcoreutils_OBJ$(os)) \
319 $(libbb_OBJ$(os)) $(libbb_MOBJ$(os))
321 ifeq ($(strip $(CONFIG_FEATURE_SHARED_BUSYBOX)),y)
322 # linking against libbusybox, so don't build the .o already contained in the .so
323 bin-obj-y:=$(filter-out $(libbusybox-obj) $(libbusybox-obj:.os=.o),$(bin-obj-y))
324 bin-mobj-y:=$(filter-out $(libbusybox-obj) $(libbusybox-obj:.osm=.om),$(bin-mobj-y))
325 endif # CONFIG_FEATURE_SHARED_BUSYBOX
326 endif # CONFIG_BUILD_AT_ONCE
328 # build an .a to keep .hash et al small
329 ifneq ($(bin-obj-y)$(bin-mobj-y),)
330 applets.a:=$(bin-obj-y) $(bin-mobj-y)
333 applets.a: $(applets.a)
340 ifeq ($(strip $(CONFIG_BUILD_LIBBUSYBOX)),y)
341 LD_LIBBUSYBOX:=libbusybox.so
342 LIBBUSYBOX_SONAME:=$(LD_LIBBUSYBOX).$(MAJOR_VERSION).$(MINOR_VERSION).$(SUBLEVEL_VERSION)
343 DO_INSTALL_LIBS:=$(LD_LIBBUSYBOX) \
344 $(LD_LIBBUSYBOX).$(MAJOR_VERSION) \
345 $(LD_LIBBUSYBOX).$(MAJOR_VERSION).$(MINOR_VERSION)
347 endif # CONFIG_BUILD_LIBBUSYBOX
349 ifeq ($(strip $(CONFIG_BUILD_AT_ONCE)),y)
350 ifneq ($(strip $(CONFIG_FEATURE_SHARED_BUSYBOX)),y)
351 # --combine but not linking against libbusybox, so compile lib*.c
352 BUSYBOX_SRC := $(LIBRARY_SRC)
353 BUSYBOX_DEFINE:= $(LIBRARY_DEFINE)
354 endif # !CONFIG_FEATURE_SHARED_BUSYBOX
355 $(LIBBUSYBOX_SONAME): $(LIBRARY_SRC)
356 else # CONFIG_BUILD_AT_ONCE
357 $(LIBBUSYBOX_SONAME): $(libbusybox-obj)
358 endif # CONFIG_BUILD_AT_ONCE
361 ifeq ($(strip $(CONFIG_FEATURE_SHARED_BUSYBOX)),y)
362 LDBUSYBOX:=-L$(top_builddir) -lbusybox
365 ifeq ($(strip $(CONFIG_BUILD_LIBBUSYBOX)),y)
366 $(LIBBUSYBOX_SONAME):
368 $(error MAJOR_VERSION needed for $@ is not defined)
370 $(do_link) $(LIB_CFLAGS) $(LIB_LDFLAGS) $(CFLAGS_COMBINE) \
371 -Wl,-soname=$(LD_LIBBUSYBOX).$(MAJOR_VERSION) \
372 -Wl,-z,combreloc $(LIB_LDFLAGS) \
375 $(LIBRARY_DEFINE) $(^) \
377 @rm -f $(DO_INSTALL_LIBS)
378 @for i in $(DO_INSTALL_LIBS); do ln -s $(@) $$i ; done
381 endif # ifeq ($(strip $(CONFIG_BUILD_LIBBUSYBOX)),y)
383 busybox_unstripped: $(top_builddir)/.depend $(LIBBUSYBOX_SONAME) $(BUSYBOX_SRC) $(APPLET_SRC) $(bin-obj.a)
384 $(do_link) $(PROG_CFLAGS) $(PROG_LDFLAGS) $(CFLAGS_COMBINE) \
385 $(foreach f,$(^:.o=.c),$(CFLAGS-$(notdir $(patsubst %/$,%,$(dir $(f))))-$(notdir $(f)))) \
387 -o $@ -Wl,--start-group \
388 $(APPLETS_DEFINE) $(APPLET_SRC) \
389 $(BUSYBOX_DEFINE) $(BUSYBOX_SRC) \
391 $(LDBUSYBOX) $(LIBRARIES) \
394 busybox: busybox_unstripped
395 $(Q)cp busybox_unstripped busybox
398 busybox.links: $(top_srcdir)/applets/busybox.mkll include/bb_config.h $(top_srcdir)/include/applets.h
401 install: $(top_srcdir)/applets/install.sh busybox busybox.links
402 $(Q)DO_INSTALL_LIBS="$(strip $(LIBBUSYBOX_SONAME) $(DO_INSTALL_LIBS))" \
403 $(SHELL) $< $(PREFIX) $(INSTALL_OPTS)
404 ifeq ($(strip $(CONFIG_FEATURE_SUID)),y)
407 @echo --------------------------------------------------
408 @echo You will probably need to make your busybox binary
409 @echo setuid root to ensure all configured applets will
411 @echo --------------------------------------------------
415 uninstall: busybox.links
416 rm -f $(PREFIX)/bin/busybox
417 for i in `cat busybox.links` ; do rm -f $(PREFIX)$$i; done
418 ifneq ($(strip $(DO_INSTALL_LIBS)),n)
419 for i in $(LIBBUSYBOX_SONAME) $(DO_INSTALL_LIBS); do \
420 rm -f $(PREFIX)$$i; \
425 bindir=$(top_builddir) srcdir=$(top_srcdir)/testsuite \
426 $(top_srcdir)/testsuite/runtest $(CHECK_VERBOSE)
428 sizes: busybox_unstripped
429 $(NM) --size-sort $(<)
431 # Documentation Targets
432 doc: docs/busybox.pod docs/BusyBox.txt docs/BusyBox.1 docs/BusyBox.html ;
434 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
437 $(Q)-( cat $(top_srcdir)/docs/busybox_header.pod ; \
438 $(top_srcdir)/docs/autodocifier.pl $(top_srcdir)/include/usage.h ; \
439 cat $(top_srcdir)/docs/busybox_footer.pod ; ) > docs/busybox.pod
441 docs/BusyBox.txt: docs/busybox.pod
444 $(Q)-pod2text $< > $@
446 docs/BusyBox.1: docs/busybox.pod
449 $(Q)-pod2man --center=BusyBox --release="version $(VERSION)" \
452 docs/BusyBox.html: docs/busybox.net/BusyBox.html
455 $(Q)-rm -f docs/BusyBox.html
456 $(Q)-cp docs/busybox.net/BusyBox.html docs/BusyBox.html
458 docs/busybox.net/BusyBox.html: docs/busybox.pod
459 $(Q)-mkdir -p docs/busybox.net
460 $(Q)-pod2html --noindex $< > \
461 docs/busybox.net/BusyBox.html
464 # The nifty new dependency stuff
465 scripts/bb_mkdep: $(top_srcdir)/scripts/bb_mkdep.c
468 DEP_INCLUDES := include/bb_config.h
470 ifeq ($(strip $(CONFIG_BBCONFIG)),y)
471 DEP_INCLUDES += include/bbconfigopts.h
473 include/bbconfigopts.h: .config
475 $(Q)$(top_srcdir)/scripts/config/mkconfigs > $@
478 depend dep: $(top_builddir)/.depend ;
479 $(top_builddir)/.depend: $(buildtree) scripts/bb_mkdep $(DEP_INCLUDES)
482 $(Q)scripts/bb_mkdep $(MKDEP_ARGS) \
483 -I $(top_srcdir)/include $(top_srcdir) > $@.tmp
486 include/bb_config.h: .config
488 @$(top_builddir)/scripts/config/conf -o $(CONFIG_CONFIG_IN)
490 endif # ifeq ($(strip $(HAVE_DOT_CONFIG)),y)
493 - rm -f docs/busybox.dvi docs/busybox.ps \
494 docs/busybox.pod docs/busybox.net/busybox.html \
495 docs/busybox pod2htm* *.gdb *.elf *~ core .*config.log \
496 docs/BusyBox.txt docs/BusyBox.1 docs/BusyBox.html \
497 docs/busybox.net/BusyBox.html busybox.links \
499 .config.old busybox busybox_unstripped
500 - rm -r -f _install testsuite/links
501 - find . -name .\*.flags -exec rm -f {} \;
502 - find . -name \*.o -exec rm -f {} \;
503 - find . -name \*.om -exec rm -f {} \;
504 - find . -name \*.os -exec rm -f {} \;
505 - find . -name \*.osm -exec rm -f {} \;
506 - find . -name \*.a -exec rm -f {} \;
509 - $(MAKE) -C scripts/config clean
510 - rm -f scripts/bb_mkdep
511 - rm -r -f include/config $(DEP_INCLUDES)
512 - find . -name .depend'*' -exec rm -f {} \;
513 rm -f .config .config.old .config.cmd
515 release: distclean #doc
517 rm -r -f $(PROG)-$(VERSION); \
518 cp -a busybox $(PROG)-$(VERSION); \
520 find $(PROG)-$(VERSION)/ -type d \
523 -exec rm -r -f {} \; ; \
525 find $(PROG)-$(VERSION)/ -type f \
528 -exec rm -f {} \; ; \
530 tar -cvzf $(PROG)-$(VERSION).tar.gz $(PROG)-$(VERSION)/;
535 # keep these in sync with noconfig_targets above!
536 .PHONY: dummy subdirs check test depend dep buildtree \
537 menuconfig config oldconfig randconfig \
538 defconfig allyesconfig allnoconfig allbareconfig \