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 et al
247 $(foreach d,$(DIRS_UPPER),$(eval $(notdir $(d))-y:=))
249 include $(patsubst %,%/Makefile.in,$(SRC_DIRS))
251 # Then we need the dependencies for ..._OBJ
254 # write patterns for both .os and .o
255 $(if $($(1)_OBJ.os),$($(1)_OBJ.os:.os=.o): $(top_builddir)/$(2)/%.o: $(top_srcdir)/$(2)/%.c)
257 $(if $($(1)_OBJ$(os)),$($(1)_OBJ$(os)): $(top_builddir)/$(2)/%$(os): $(top_srcdir)/$(2)/%.c)
258 $(if $($(1)_OBJ),$($(1)_OBJ): $(top_builddir)/$(2)/%.o: $(top_srcdir)/$(2)/%.c)
260 lib-obj-y+=$($(1)_OBJ) $($(1)_OBJ.o) $($(1)_OBJ.os)
261 lib-mobj-y+=$($(1)_MOBJ.o) $($(1)_MOBJ.os)
262 bin-obj-y+=$($(1)_OBJ:.os=.o) $($(1)_OBJ.o:.os=.o) $($(1)_OBJ.os:.os=.o)
263 bin-mobj-y+=$($(1)_MOBJ.o:.osm=.om) $($(1)_MOBJ.os:.osm=.om)
265 # The actual directory patterns for .o*
266 $(foreach d,$(DIRS),$(eval $(call dir_pattern.o,$(subst /,_,$(d)),$(d))))
268 ifeq ($(strip $(HAVE_DOT_CONFIG)),y)
269 # Finally pull in the dependencies (headers and other includes) of the
270 # individual object files
271 -include $(top_builddir)/.depend
273 $(top_builddir)/applets/applets.o: $(top_builddir)/.config
276 all: busybox busybox.links doc ;
278 # Two modes of operation: legacy and IMA
279 # Legacy mode builds each object through an individual invocation of CC
280 # IMA compiles all sources at once (aka IPO aka IPA etc.)
282 ifeq ($(strip $(CONFIG_BUILD_AT_ONCE)),y)
283 # We are not building .o
286 # Which parts of the internal libs are requested?
287 # Per default we only want what was actually selected.
288 # -a denotes all while -y denotes the selected ones.
289 ifeq ($(strip $(CONFIG_FEATURE_FULL_LIBBUSYBOX)),y)
290 LIBRARY_DEFINE:=$(LIBRARY_DEFINE-a)
291 LIBRARY_SRC :=$(LIBRARY_SRC-a)
292 else # CONFIG_FEATURE_FULL_LIBBUSYBOX
293 LIBRARY_DEFINE:=$(LIBRARY_DEFINE-y)
294 LIBRARY_SRC :=$(LIBRARY_SRC-y)
295 endif # CONFIG_FEATURE_FULL_LIBBUSYBOX
296 APPLET_SRC:=$(APPLET_SRC-y)
297 APPLETS_DEFINE:=$(APPLETS_DEFINE-y)
298 else # CONFIG_BUILD_AT_ONCE
299 # no --combine, build archives out of the individual .o
300 # This was the old way the binary was built.
301 libbusybox-obj:=$(archival_libunarchive_OBJ$(os)) \
302 $(networking_libiproute_OBJ$(os)) \
303 $(libpwdgrp_MOBJ$(os)) \
304 $(coreutils_libcoreutils_OBJ$(os)) \
305 $(libbb_OBJ$(os)) $(libbb_MOBJ$(os))
307 ifeq ($(strip $(CONFIG_FEATURE_SHARED_BUSYBOX)),y)
308 # linking against libbusybox, so don't build the .o already contained in the .so
309 bin-obj-y:=$(filter-out $(libbusybox-obj) $(libbusybox-obj:.os=.o),$(bin-obj-y))
310 bin-mobj-y:=$(filter-out $(libbusybox-obj) $(libbusybox-obj:.osm=.om),$(bin-mobj-y))
311 endif # CONFIG_FEATURE_SHARED_BUSYBOX
312 endif # CONFIG_BUILD_AT_ONCE
314 # build an .a to keep .hash et al small
315 ifneq ($(bin-obj-y)$(bin-mobj-y),)
316 applets.a:=$(bin-obj-y) $(bin-mobj-y)
319 applets.a: $(applets.a)
326 ifeq ($(strip $(CONFIG_BUILD_LIBBUSYBOX)),y)
327 LD_LIBBUSYBOX:=libbusybox.so
328 LIBBUSYBOX_SONAME:=$(LD_LIBBUSYBOX).$(MAJOR_VERSION).$(MINOR_VERSION).$(SUBLEVEL_VERSION)
329 DO_INSTALL_LIBS:=$(LD_LIBBUSYBOX) \
330 $(LD_LIBBUSYBOX).$(MAJOR_VERSION) \
331 $(LD_LIBBUSYBOX).$(MAJOR_VERSION).$(MINOR_VERSION)
333 endif # CONFIG_BUILD_LIBBUSYBOX
335 ifeq ($(strip $(CONFIG_BUILD_AT_ONCE)),y)
336 ifneq ($(strip $(CONFIG_FEATURE_SHARED_BUSYBOX)),y)
337 # --combine but not linking against libbusybox, so compile lib*.c
338 BUSYBOX_SRC := $(LIBRARY_SRC)
339 BUSYBOX_DEFINE:= $(LIBRARY_DEFINE)
340 endif # !CONFIG_FEATURE_SHARED_BUSYBOX
341 $(LIBBUSYBOX_SONAME): $(LIBRARY_SRC)
342 else # CONFIG_BUILD_AT_ONCE
343 $(LIBBUSYBOX_SONAME): $(libbusybox-obj)
344 endif # CONFIG_BUILD_AT_ONCE
347 ifeq ($(strip $(CONFIG_FEATURE_SHARED_BUSYBOX)),y)
348 LDBUSYBOX:=-L$(top_builddir) -lbusybox
351 ifeq ($(strip $(CONFIG_BUILD_LIBBUSYBOX)),y)
352 $(LIBBUSYBOX_SONAME):
354 $(error MAJOR_VERSION needed for $@ is not defined)
356 $(do_link) $(LIB_CFLAGS) $(LIB_LDFLAGS) $(CFLAGS_COMBINE) \
357 -Wl,-soname=$(LD_LIBBUSYBOX).$(MAJOR_VERSION) \
358 -Wl,-z,combreloc $(LIB_LDFLAGS) \
361 $(LIBRARY_DEFINE) $(^) \
363 @rm -f $(DO_INSTALL_LIBS)
364 @for i in $(DO_INSTALL_LIBS); do ln -s $(@) $$i ; done
367 endif # ifeq ($(strip $(CONFIG_BUILD_LIBBUSYBOX)),y)
369 busybox_unstripped: $(top_builddir)/.depend $(LIBBUSYBOX_SONAME) $(BUSYBOX_SRC) $(APPLET_SRC) $(bin-obj.a)
370 $(do_link) $(PROG_CFLAGS) $(PROG_LDFLAGS) $(CFLAGS_COMBINE) \
371 $(foreach f,$(^:.o=.c),$(CFLAGS-$(notdir $(patsubst %/$,%,$(dir $(f))))-$(notdir $(f)))) \
373 -o $@ -Wl,--start-group \
374 $(APPLETS_DEFINE) $(APPLET_SRC) \
375 $(BUSYBOX_DEFINE) $(BUSYBOX_SRC) \
377 $(LDBUSYBOX) $(LIBRARIES) \
380 busybox: busybox_unstripped
381 $(Q)cp busybox_unstripped busybox
384 busybox.links: $(top_srcdir)/applets/busybox.mkll include/bb_config.h $(top_srcdir)/include/applets.h
387 install: $(top_srcdir)/applets/install.sh busybox busybox.links
388 $(Q)DO_INSTALL_LIBS="$(strip $(LIBBUSYBOX_SONAME) $(DO_INSTALL_LIBS))" \
389 $(SHELL) $< $(PREFIX) $(INSTALL_OPTS)
390 ifeq ($(strip $(CONFIG_FEATURE_SUID)),y)
393 @echo --------------------------------------------------
394 @echo You will probably need to make your busybox binary
395 @echo setuid root to ensure all configured applets will
397 @echo --------------------------------------------------
401 uninstall: busybox.links
402 rm -f $(PREFIX)/bin/busybox
403 for i in `cat busybox.links` ; do rm -f $(PREFIX)$$i; done
404 ifneq ($(strip $(DO_INSTALL_LIBS)),n)
405 for i in $(LIBBUSYBOX_SONAME) $(DO_INSTALL_LIBS); do \
406 rm -f $(PREFIX)$$i; \
411 bindir=$(top_builddir) srcdir=$(top_srcdir)/testsuite \
412 $(top_srcdir)/testsuite/runtest $(CHECK_VERBOSE)
414 sizes: busybox_unstripped
415 $(NM) --size-sort $(<)
417 # Documentation Targets
418 doc: docs/busybox.pod docs/BusyBox.txt docs/BusyBox.1 docs/BusyBox.html ;
420 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
423 $(Q)-( cat $(top_srcdir)/docs/busybox_header.pod ; \
424 $(top_srcdir)/docs/autodocifier.pl $(top_srcdir)/include/usage.h ; \
425 cat $(top_srcdir)/docs/busybox_footer.pod ; ) > docs/busybox.pod
427 docs/BusyBox.txt: docs/busybox.pod
430 $(Q)-pod2text $< > $@
432 docs/BusyBox.1: docs/busybox.pod
435 $(Q)-pod2man --center=BusyBox --release="version $(VERSION)" \
438 docs/BusyBox.html: docs/busybox.net/BusyBox.html
441 $(Q)-rm -f docs/BusyBox.html
442 $(Q)-cp docs/busybox.net/BusyBox.html docs/BusyBox.html
444 docs/busybox.net/BusyBox.html: docs/busybox.pod
445 $(Q)-mkdir -p docs/busybox.net
446 $(Q)-pod2html --noindex $< > \
447 docs/busybox.net/BusyBox.html
450 # The nifty new dependency stuff
451 scripts/bb_mkdep: $(top_srcdir)/scripts/bb_mkdep.c
454 DEP_INCLUDES := include/bb_config.h
456 ifeq ($(strip $(CONFIG_BBCONFIG)),y)
457 DEP_INCLUDES += include/bbconfigopts.h
459 include/bbconfigopts.h: .config
461 $(Q)$(top_srcdir)/scripts/config/mkconfigs > $@
464 depend dep: $(top_builddir)/.depend ;
465 $(top_builddir)/.depend: $(buildtree) scripts/bb_mkdep $(DEP_INCLUDES)
468 $(Q)scripts/bb_mkdep $(MKDEP_ARGS) \
469 -I $(top_srcdir)/include $(top_srcdir) > $@.tmp
472 include/bb_config.h: .config
474 @$(top_builddir)/scripts/config/conf -o $(CONFIG_CONFIG_IN)
476 endif # ifeq ($(strip $(HAVE_DOT_CONFIG)),y)
479 - rm -f docs/busybox.dvi docs/busybox.ps \
480 docs/busybox.pod docs/busybox.net/busybox.html \
481 docs/busybox pod2htm* *.gdb *.elf *~ core .*config.log \
482 docs/BusyBox.txt docs/BusyBox.1 docs/BusyBox.html \
483 docs/busybox.net/BusyBox.html busybox.links \
484 $(DO_INSTALL_LIBS) $(LIBBUSYBOX_SONAME) \
485 .config.old busybox busybox_unstripped
486 - rm -r -f _install testsuite/links
487 - find . -name .\*.flags -exec rm -f {} \;
488 - find . -name \*.o -exec rm -f {} \;
489 - find . -name \*.om -exec rm -f {} \;
490 - find . -name \*.os -exec rm -f {} \;
491 - find . -name \*.a -exec rm -f {} \;
494 - $(MAKE) -C scripts/config clean
495 - rm -f scripts/bb_mkdep
496 - rm -r -f include/config $(DEP_INCLUDES)
497 - find . -name .depend'*' -exec rm -f {} \;
498 rm -f .config .config.old .config.cmd
500 release: distclean #doc
502 rm -r -f $(PROG)-$(VERSION); \
503 cp -a busybox $(PROG)-$(VERSION); \
505 find $(PROG)-$(VERSION)/ -type d \
508 -exec rm -r -f {} \; ; \
510 find $(PROG)-$(VERSION)/ -type f \
513 -exec rm -f {} \; ; \
515 tar -cvzf $(PROG)-$(VERSION).tar.gz $(PROG)-$(VERSION)/;
520 # keep these in sync with noconfig_targets above!
521 .PHONY: dummy subdirs check test depend dep buildtree \
522 menuconfig config oldconfig randconfig \
523 defconfig allyesconfig allnoconfig allbareconfig \