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 # You shouldn't have to edit anything in this file for configuration
9 # purposes, try "make help" or read http://busybox.net/FAQ.html.
11 .PHONY: dummy subdirs release distclean clean config oldconfig menuconfig \
12 tags check test depend dep buildtree hosttools _all checkhelp \
13 sizes bloatcheck baseline objsizes
15 noconfig_targets := menuconfig config oldconfig randconfig hosttools \
16 defconfig allyesconfig allnoconfig allbareconfig \
17 clean distclean help \
20 # the toplevel sourcedir
24 # toplevel directory of the object-tree
26 top_builddir=$(CURDIR)
29 export srctree=$(top_srcdir)
30 vpath %/Config.in $(srctree)
32 DIRS:=applets archival archival/libunarchive coreutils console-tools \
33 debianutils editors findutils init miscutils modutils networking \
34 networking/libiproute networking/udhcp procps loginutils shell \
35 sysklogd util-linux e2fsprogs libpwdgrp coreutils/libcoreutils libbb
37 SRC_DIRS:=$(patsubst %,$(top_srcdir)/%,$(DIRS))
39 # That's our default target when none is given on the command line
42 CONFIG_CONFIG_IN = $(top_srcdir)/Config.in
47 ifeq ("$(origin O)", "command line")
52 # If no alternate output-dir was specified, we build in cwd
53 # We are using KBUILD_OUTPUT nevertheless to make sure that we create
54 # Rules.mak and the toplevel Makefile, in case they don't exist.
55 KBUILD_OUTPUT := $(top_builddir)
58 ifneq ($(strip $(HAVE_DOT_CONFIG)),y)
59 # pull in OS specific commands like cp, mkdir, etc. early
60 -include $(top_srcdir)/Rules.mak
63 # All object directories.
65 all_tree := $(patsubst %,$(top_builddir)/%,$(OBJ_DIRS) scripts scripts/config include)
70 ifneq ($(KBUILD_OUTPUT),)
71 # Invoke a second make in the output directory, passing relevant variables
72 # Check that the output directory actually exists
73 saved-output := $(KBUILD_OUTPUT)
74 KBUILD_OUTPUT := $(shell cd $(KBUILD_OUTPUT) && /bin/pwd)
75 $(if $(wildcard $(KBUILD_OUTPUT)),, \
76 $(error output directory "$(saved-output)" does not exist))
78 .PHONY: $(MAKECMDGOALS)
80 $(filter-out _all,$(MAKECMDGOALS)) _all: $(KBUILD_OUTPUT)/Rules.mak $(KBUILD_OUTPUT)/Makefile all_tree
81 $(Q)$(MAKE) -C $(KBUILD_OUTPUT) \
82 top_srcdir=$(top_srcdir) \
83 top_builddir=$(top_builddir) \
84 KBUILD_SRC=$(top_srcdir) \
85 -f $(CURDIR)/Makefile $@
87 $(KBUILD_OUTPUT)/Rules.mak:
89 @echo top_srcdir=$(top_srcdir) >> $@
90 @echo top_builddir=$(KBUILD_OUTPUT) >> $@
91 @echo include $(top_srcdir)/Rules.mak >> $@
93 $(KBUILD_OUTPUT)/Makefile:
95 @echo top_srcdir=$(top_srcdir) >> $@
96 @echo top_builddir=$(KBUILD_OUTPUT) >> $@
97 @echo KBUILD_SRC='$$(top_srcdir)' >> $@
98 @echo include '$$(KBUILD_SRC)'/Makefile >> $@
100 # Leave processing to above invocation of make
102 endif # ifneq ($(KBUILD_OUTPUT),)
103 endif # ifeq ($(KBUILD_SRC),)
105 ifeq ($(skip-makefile),)
107 # We only need a copy of the Makefile for the config targets and reuse
108 # the rest from the source directory, i.e. we do not cp ALL_MAKEFILES.
109 scripts/config/Makefile: $(top_srcdir)/scripts/config/Makefile
116 @echo ' clean - delete temporary files created by build'
117 @echo ' distclean - delete all non-source files (including .config)'
120 @echo ' all - Executable and documentation'
121 @echo ' busybox - the swiss-army executable'
122 @echo ' doc - docs/BusyBox.{txt,html,1}'
124 @echo 'Configuration:'
125 @echo ' allnoconfig - disable all symbols in .config'
126 @echo ' allyesconfig - enable all symbols in .config (see defconfig)'
127 @echo ' allbareconfig - enable all applets without any sub-features'
128 @echo ' config - text based configurator (of last resort)'
129 @echo ' defconfig - set .config to largest generic configuration'
130 @echo ' menuconfig - interactive curses-based configurator'
131 @echo ' oldconfig - resolve any unresolved symbols in .config'
132 @echo ' hosttools - build sed for the host.'
133 @echo ' You can use these commands if the commands on the host'
134 @echo ' is unusable. Afterwards use it like:'
135 @echo ' make SED="$(top_builddir)/sed"'
137 @echo 'Installation:'
138 @echo ' install - install busybox into $(PREFIX)'
142 @echo ' baseline - create busybox_old for bloatcheck.'
143 @echo ' bloatcheck - show size difference between old and new versions'
144 @echo ' check - run the test suite for all applets'
145 @echo ' checkhelp - check for missing help-entries in Config.in'
146 @echo ' randconfig - generate a random configuration'
147 @echo ' release - create a distribution tarball'
148 @echo ' sizes - show size of all enabled busybox symbols'
149 @echo ' objsizes - show size of each .o object built'
153 include $(top_srcdir)/Rules.mak
155 ifneq ($(strip $(HAVE_DOT_CONFIG)),y)
157 # Default target if none was requested explicitly
160 # warn if no configuration exists and we are asked to build a non-config target
163 @echo "No $(top_builddir)/$@ found!"
164 @echo "Please refer to 'make help', section Configuration."
169 # ---------------------------------------------------------------------------
171 scripts/config/conf: scripts/config/Makefile
172 $(Q)$(MAKE) -C scripts/config conf
173 -@if [ ! -f .config ] ; then \
177 scripts/config/mconf: scripts/config/Makefile
178 $(Q)$(MAKE) -C scripts/config ncurses conf mconf
179 -@if [ ! -f .config ] ; then \
183 menuconfig: scripts/config/mconf
184 @[ -f .config ] || $(MAKE) $(MAKEFLAGS) defconfig
185 @./scripts/config/mconf $(CONFIG_CONFIG_IN)
187 config: scripts/config/conf
188 @./scripts/config/conf $(CONFIG_CONFIG_IN)
190 oldconfig: scripts/config/conf
191 @./scripts/config/conf -o $(CONFIG_CONFIG_IN)
193 randconfig: scripts/config/conf
194 @./scripts/config/conf -r $(CONFIG_CONFIG_IN)
196 allyesconfig: scripts/config/conf
197 @./scripts/config/conf -y $(CONFIG_CONFIG_IN) > /dev/null
198 @$(SED) -i -r -e "s/^(USING_CROSS_COMPILER)=.*/# \1 is not set/" .config
199 @./scripts/config/conf -o $(CONFIG_CONFIG_IN) > /dev/null
201 allnoconfig: scripts/config/conf
202 @./scripts/config/conf -n $(CONFIG_CONFIG_IN) > /dev/null
204 # defconfig is allyesconfig minus any features that are specialized enough
205 # or cause enough behavior change that the user really should switch them on
206 # manually if that's what they want. Sort of "maximum sane config".
208 defconfig: scripts/config/conf
209 @./scripts/config/conf -y $(CONFIG_CONFIG_IN) > /dev/null
210 @$(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
211 @./scripts/config/conf -o $(CONFIG_CONFIG_IN) > /dev/null
214 allbareconfig: scripts/config/conf
215 @./scripts/config/conf -y $(CONFIG_CONFIG_IN) > /dev/null
216 @$(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
217 @$(SED) -i -e "/FEATURE/s/=.*//;/^[^#]/s/.*FEATURE.*/# \0 is not set/;" .config
218 @echo "CONFIG_FEATURE_BUFFERS_GO_ON_STACK=y" >> .config
219 @yes n | ./scripts/config/conf -o $(CONFIG_CONFIG_IN) > /dev/null
222 $(Q)cp .config .config.bak || noold=yea
223 $(Q)$(MAKE) CC="$(HOSTCC)" CFLAGS="$(HOSTCFLAGS) $(INCS)" allnoconfig
224 $(Q)mv .config .config.in
225 $(Q)(grep -v CONFIG_SED .config.in ; \
226 echo "CONFIG_SED=y" ; ) > .config
227 $(Q)$(MAKE) CC="$(HOSTCC)" CFLAGS="$(HOSTCFLAGS) $(INCS)" oldconfig include/bb_config.h
228 $(Q)$(MAKE) CC="$(HOSTCC)" CFLAGS="$(HOSTCFLAGS) $(INCS)" busybox
229 $(Q)[ -f .config.bak ] && mv .config.bak .config || rm .config
231 @echo "Now do: $(MAKE) SED=$(top_builddir)/sed <target>"
233 else # ifneq ($(strip $(HAVE_DOT_CONFIG)),y)
235 all: busybox busybox.links doc
237 # In this section, we need .config
238 -include $(top_builddir)/.config.cmd
239 include $(patsubst %,%/Makefile.in, $(SRC_DIRS))
241 endif # ifneq ($(strip $(HAVE_DOT_CONFIG)),y)
243 -include $(top_builddir)/.config
244 -include $(top_builddir)/.depend
247 ifeq ($(strip $(CONFIG_BUILD_AT_ONCE)),y)
249 # Which parts of the internal libs are requested?
250 # Per default we only want what was actually selected.
251 # -a denotes all while -y denotes the selected ones.
252 ifeq ($(strip $(CONFIG_FEATURE_FULL_LIBBUSYBOX)),y)
253 LIBRARY_DEFINE:=$(LIBRARY_DEFINE-a)
254 LIBRARY_SRC :=$(LIBRARY_SRC-a)
255 else # CONFIG_FEATURE_FULL_LIBBUSYBOX
256 LIBRARY_DEFINE:=$(LIBRARY_DEFINE-y)
257 LIBRARY_SRC :=$(LIBRARY_SRC-y)
258 endif # CONFIG_FEATURE_FULL_LIBBUSYBOX
259 APPLET_SRC:=$(APPLET_SRC-y)
260 APPLETS_DEFINE:=$(APPLETS_DEFINE-y)
261 else # CONFIG_BUILD_AT_ONCE
262 # no --combine, build archives out of the individual .o
263 # This was the old way the binary was built.
264 libbusybox-obj:=archival/libunarchive/libunarchive.a \
265 networking/libiproute/libiproute.a \
266 libpwdgrp/libpwdgrp.a \
267 coreutils/libcoreutils/libcoreutils.a \
269 libbusybox-obj:=$(patsubst %,$(top_builddir)/%,$(libbusybox-obj))
271 ifeq ($(strip $(CONFIG_FEATURE_SHARED_BUSYBOX)),y)
272 # linking against libbusybox, so don't build the .a already contained in the .so
273 libraries-y:=$(filter-out $(libbusybox-obj),$(libraries-y))
274 endif # CONFIG_FEATURE_SHARED_BUSYBOX
275 endif # CONFIG_BUILD_AT_ONCE
278 ifeq ($(strip $(CONFIG_BUILD_LIBBUSYBOX)),y)
279 LD_LIBBUSYBOX:=libbusybox.so
280 LIBBUSYBOX_SONAME:=$(LD_LIBBUSYBOX).$(MAJOR_VERSION).$(MINOR_VERSION).$(SUBLEVEL_VERSION)
281 DO_INSTALL_LIBS:=$(LD_LIBBUSYBOX) \
282 $(LD_LIBBUSYBOX).$(MAJOR_VERSION) \
283 $(LD_LIBBUSYBOX).$(MAJOR_VERSION).$(MINOR_VERSION)
284 endif # CONFIG_BUILD_LIBBUSYBOX
286 ifeq ($(strip $(CONFIG_BUILD_AT_ONCE)),y)
287 ifneq ($(strip $(CONFIG_FEATURE_SHARED_BUSYBOX)),y)
288 # --combine but not linking against libbusybox, so compile all
289 BUSYBOX_SRC := $(LIBRARY_SRC)
290 BUSYBOX_DEFINE:= $(LIBRARY_DEFINE)
291 endif # !CONFIG_FEATURE_SHARED_BUSYBOX
292 $(LIBBUSYBOX_SONAME): $(LIBRARY_SRC)
293 else # CONFIG_BUILD_AT_ONCE
294 $(LIBBUSYBOX_SONAME): $(libbusybox-obj)
295 endif # CONFIG_BUILD_AT_ONCE
297 ifeq ($(strip $(CONFIG_FEATURE_SHARED_BUSYBOX)),y)
298 LDBUSYBOX:=-L$(top_builddir) -lbusybox
301 ifeq ($(strip $(CONFIG_BUILD_LIBBUSYBOX)),y)
302 $(LIBBUSYBOX_SONAME):
304 $(error MAJOR_VERSION needed for $@ is not defined)
306 $(do_link) $(LIB_CFLAGS) $(CFLAGS_COMBINE) \
307 -Wl,-soname=$(LD_LIBBUSYBOX).$(MAJOR_VERSION) \
308 -Wl,-z,combreloc $(LIB_LDFLAGS) \
310 $(LD_START_GROUP) $(LD_WHOLE_ARCHIVE) \
311 $(LIBRARY_DEFINE) $(^) \
312 $(LD_NO_WHOLE_ARCHIVE) $(LD_END_GROUP)
313 @rm -f $(DO_INSTALL_LIBS)
314 @for i in $(DO_INSTALL_LIBS); do ln -s $(@) $$i ; done
317 endif # ifeq ($(strip $(CONFIG_BUILD_LIBBUSYBOX)),y)
319 busybox_unstripped: .depend $(LIBBUSYBOX_SONAME) $(BUSYBOX_SRC) $(APPLET_SRC) $(libraries-y)
320 $(do_link) $(PROG_CFLAGS) $(PROG_LDFLAGS) $(CFLAGS_COMBINE) \
321 -o $@ $(LD_START_GROUP) \
322 $(APPLETS_DEFINE) $(APPLET_SRC) \
323 $(BUSYBOX_DEFINE) $(BUSYBOX_SRC) $(libraries-y) \
324 $(LDBUSYBOX) $(LIBRARIES) \
327 busybox: busybox_unstripped
328 $(Q)cp busybox_unstripped busybox
334 busybox.links: $(top_srcdir)/applets/busybox.mkll include/bb_config.h $(top_srcdir)/include/applets.h
337 install: $(top_srcdir)/applets/install.sh busybox busybox.links
338 $(Q)DO_INSTALL_LIBS="$(strip $(LIBBUSYBOX_SONAME) $(DO_INSTALL_LIBS))" \
339 $(SHELL) $< $(PREFIX) $(INSTALL_OPTS)
340 ifeq ($(strip $(CONFIG_FEATURE_SUID)),y)
343 @echo --------------------------------------------------
344 @echo You will probably need to make your busybox binary
345 @echo setuid root to ensure all configured applets will
347 @echo --------------------------------------------------
351 uninstall: busybox.links
352 rm -f $(PREFIX)/bin/busybox
353 for i in `cat busybox.links` ; do rm -f $(PREFIX)$$i; done
354 ifneq ($(strip $(DO_INSTALL_LIBS)),n)
355 for i in $(LIBBUSYBOX_SONAME) $(DO_INSTALL_LIBS); do \
356 rm -f $(PREFIX)$$i; \
360 # see if we are in verbose mode
363 ifeq ("$(origin V)", "command line")
364 KBUILD_VERBOSE := $(V)
367 ifneq ($(strip $(KBUILD_VERBOSE)),)
373 bindir=$(top_builddir) srcdir=$(top_srcdir)/testsuite SED="$(SED)" \
374 $(SHELL) $(top_srcdir)/testsuite/runtest $(CHECK_VERBOSE)
377 $(Q)$(top_srcdir)/scripts/checkhelp.awk \
378 $(wildcard $(patsubst %,%/Config.in,$(SRC_DIRS) ./))
380 sizes: busybox_unstripped
381 $(NM) --size-sort $(<)
383 bloatcheck: busybox_old busybox_unstripped
384 @$(top_srcdir)/scripts/bloat-o-meter busybox_old busybox_unstripped
386 baseline: busybox_unstripped
387 @mv busybox_unstripped busybox_old
389 objsizes: busybox_unstripped
390 $(SHELL) $(top_srcdir)/scripts/objsizes
392 # Documentation Targets
393 doc: docs/busybox.pod docs/BusyBox.txt docs/BusyBox.1 docs/BusyBox.html
395 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
398 $(Q)-( cat $(top_srcdir)/docs/busybox_header.pod ; \
399 $(top_srcdir)/docs/autodocifier.pl $(top_srcdir)/include/usage.h ; \
400 cat $(top_srcdir)/docs/busybox_footer.pod ; ) > docs/busybox.pod
402 docs/BusyBox.txt: docs/busybox.pod
405 $(Q)-pod2text $< > $@
407 docs/BusyBox.1: docs/busybox.pod
410 $(Q)-pod2man --center=BusyBox --release="version $(VERSION)" \
413 docs/BusyBox.html: docs/busybox.net/BusyBox.html
416 $(Q)-rm -f docs/BusyBox.html
417 $(Q)-cp docs/busybox.net/BusyBox.html docs/BusyBox.html
419 docs/busybox.net/BusyBox.html: docs/busybox.pod
420 $(Q)-mkdir -p docs/busybox.net
421 $(Q)-pod2html --noindex $< > \
422 docs/busybox.net/BusyBox.html
425 # The nifty new dependency stuff
426 scripts/bb_mkdep: $(top_srcdir)/scripts/bb_mkdep.c
429 DEP_INCLUDES := include/bb_config.h
431 ifeq ($(strip $(CONFIG_BBCONFIG)),y)
432 DEP_INCLUDES += include/bbconfigopts.h
434 include/bbconfigopts.h: .config
436 $(Q)$(top_srcdir)/scripts/config/mkconfigs > $@
439 ifeq ($(strip $(CONFIG_FEATURE_COMPRESS_USAGE)),y)
440 USAGE_BIN:=scripts/usage
441 $(USAGE_BIN): $(top_srcdir)/scripts/usage.c
444 DEP_INCLUDES += include/usage_compressed.h
446 include/usage_compressed.h: .config $(USAGE_BIN)
447 $(Q)SED="$(SED)" $(SHELL) $(top_srcdir)/scripts/usage_compressed "$(top_builddir)/scripts" > $@
448 endif # CONFIG_FEATURE_COMPRESS_USAGE
450 # workaround alleged bug in make-3.80, make-3.81
451 .NOTPARALLEL: .depend
454 .depend: scripts/bb_mkdep $(USAGE_BIN) $(DEP_INCLUDES)
457 $(Q)mkdir -p include/config
458 $(Q)scripts/bb_mkdep -I $(top_srcdir)/include $(top_srcdir) > $@.tmp
461 include/bb_config.h: .config
462 @if [ ! -x $(top_builddir)/scripts/config/conf ] ; then \
463 $(MAKE) -C scripts/config conf; \
465 @$(top_builddir)/scripts/config/conf -o $(CONFIG_CONFIG_IN)
468 - $(MAKE) -C scripts/config $@
469 - rm -f docs/busybox.dvi docs/busybox.ps \
470 docs/busybox.pod docs/busybox.net/busybox.html \
471 docs/busybox pod2htm* *.gdb *.elf *~ core .*config.log \
472 docs/BusyBox.txt docs/BusyBox.1 docs/BusyBox.html \
473 docs/busybox.net/BusyBox.html busybox.links \
475 .config.old busybox busybox_unstripped
476 - rm -r -f _install testsuite/links
477 - find . -name .\*.flags -o -name \*.o -o -name \*.om \
478 -o -name \*.os -o -name \*.osm -o -name \*.a | xargs rm -f
481 rm -f scripts/bb_mkdep scripts/usage
482 rm -r -f include/config include/config.h $(DEP_INCLUDES)
483 find . -name .depend'*' -print0 | xargs -0 rm -f
485 rm -f .config .config.old .config.cmd
487 release: distclean #doc
489 rm -r -f $(PROG)-$(VERSION); \
490 cp -a busybox $(PROG)-$(VERSION); \
492 find $(PROG)-$(VERSION)/ -type d \
495 -exec rm -r -f {} \; ; \
497 find $(PROG)-$(VERSION)/ -type f \
500 -exec rm -f {} \; ; \
502 tar -cvzf $(PROG)-$(VERSION).tar.gz $(PROG)-$(VERSION)/;
508 endif # ifeq ($(skip-makefile),)