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 nocheck_targets := clean distclean help release tags
22 # the toplevel sourcedir
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
44 CONFIG_CONFIG_IN = $(top_srcdir)/Config.in
48 ifeq ("$(origin O)", "command line")
53 # If no alternate output-dir was specified, we build in cwd
54 # We are using BUILD_OUTPUT nevertheless to make sure that we create
55 # Rules.mak and the toplevel Makefile, in case they don't exist.
56 BUILD_OUTPUT := $(top_builddir)
59 # see if we are in verbose mode
62 ifeq ("$(origin V)", "command line")
67 ifeq ("$(origin VERBOSE)", "command line")
68 BUILD_VERBOSE := $(VERBOSE)
72 ifneq ($(strip $(BUILD_VERBOSE)),)
78 ifneq ($(strip $(HAVE_DOT_CONFIG)),y)
79 # pull in settings early
80 -include $(top_srcdir)/Rules.mak
83 # All object directories.
85 all_tree := $(patsubst %,$(top_builddir)/%,$(OBJ_DIRS) scripts scripts/config include)
90 ifneq ($(BUILD_OUTPUT),)
91 # Invoke a second make in the output directory, passing relevant variables
92 # Check that the output directory actually exists
93 saved-output := $(BUILD_OUTPUT)
94 BUILD_OUTPUT := $(shell cd $(BUILD_OUTPUT) && /bin/pwd)
95 $(if $(wildcard $(BUILD_OUTPUT)),, \
96 $(error output directory "$(saved-output)" does not exist))
98 .PHONY: $(MAKECMDGOALS)
100 $(filter-out _all,$(MAKECMDGOALS)) _all: $(BUILD_OUTPUT)/Rules.mak $(BUILD_OUTPUT)/Makefile all_tree
101 $(Q)$(MAKE) -C $(BUILD_OUTPUT) \
102 top_srcdir=$(top_srcdir) \
103 top_builddir=$(top_builddir) \
104 BUILD_SRC=$(top_srcdir) \
105 -f $(CURDIR)/Makefile $@
107 $(BUILD_OUTPUT)/Rules.mak:
109 @echo top_srcdir=$(top_srcdir) >> $@
110 @echo top_builddir=$(BUILD_OUTPUT) >> $@
111 @echo include $(top_srcdir)/Rules.mak >> $@
113 $(BUILD_OUTPUT)/Makefile:
115 @echo top_srcdir=$(top_srcdir) >> $@
116 @echo top_builddir=$(BUILD_OUTPUT) >> $@
117 @echo BUILD_SRC='$$(top_srcdir)' >> $@
118 @echo include '$$(BUILD_SRC)'/Makefile >> $@
120 # Leave processing to above invocation of make
122 endif # ifneq ($(BUILD_OUTPUT),)
123 endif # ifeq ($(BUILD_SRC),)
125 ifeq ($(skip-makefile),)
127 # We only need a copy of the Makefile for the config targets and reuse
128 # the rest from the source directory, i.e. we do not cp ALL_MAKEFILES.
129 scripts/config/Makefile: $(top_srcdir)/scripts/config/Makefile
136 @echo ' clean - delete temporary files created by build'
137 @echo ' distclean - delete all non-source files (including .config)'
140 @echo ' all - Executable and documentation'
141 @echo ' busybox - the swiss-army executable'
142 @echo ' doc - docs/BusyBox.{txt,html,1}'
144 @echo 'Configuration:'
145 @echo ' allnoconfig - disable all symbols in .config'
146 @echo ' allyesconfig - enable all symbols in .config (see defconfig)'
147 @echo ' allbareconfig - enable all applets without any sub-features'
148 @echo ' config - text based configurator (of last resort)'
149 @echo ' defconfig - set .config to largest generic configuration'
150 @echo ' menuconfig - interactive curses-based configurator'
151 @echo ' oldconfig - resolve any unresolved symbols in .config'
152 @echo ' hosttools - build sed for the host.'
153 @echo ' You can use these commands if the commands on the host'
154 @echo ' is unusable. Afterwards use it like:'
155 @echo ' make SED="$(top_builddir)/sed"'
157 @echo 'Installation:'
158 @echo ' install - install busybox into $(PREFIX)'
162 @echo ' baseline - create busybox_old for bloatcheck.'
163 @echo ' bloatcheck - show size difference between old and new versions'
164 @echo ' check - run the test suite for all applets'
165 @echo ' checkhelp - check for missing help-entries in Config.in'
166 @echo ' randconfig - generate a random configuration'
167 @echo ' release - create a distribution tarball'
168 @echo ' sizes - show size of all enabled busybox symbols'
169 @echo ' objsizes - show size of each .o object built'
173 include $(top_srcdir)/Rules.mak
175 ifneq ($(strip $(HAVE_DOT_CONFIG)),y)
177 # Default target if none was requested explicitly
180 # warn if no configuration exists and we are asked to build a non-config target
183 @echo "No $(top_builddir)/$@ found!"
184 @echo "Please refer to 'make help', section Configuration."
189 # ---------------------------------------------------------------------------
191 scripts/config/conf: scripts/config/Makefile
192 $(Q)$(MAKE) -C scripts/config conf
193 -@if [ ! -f .config ] ; then \
197 scripts/config/mconf: scripts/config/Makefile
198 $(Q)$(MAKE) -C scripts/config ncurses conf mconf
199 -@if [ ! -f .config ] ; then \
203 menuconfig: scripts/config/mconf
204 @[ -f .config ] || $(MAKE) $(MAKEFLAGS) defconfig
205 @./scripts/config/mconf $(CONFIG_CONFIG_IN)
207 config: scripts/config/conf
208 @./scripts/config/conf $(CONFIG_CONFIG_IN)
210 oldconfig: scripts/config/conf
211 @./scripts/config/conf -o $(CONFIG_CONFIG_IN)
213 randconfig: scripts/config/conf
214 @./scripts/config/conf -r $(CONFIG_CONFIG_IN)
216 allyesconfig: scripts/config/conf
217 @./scripts/config/conf -y $(CONFIG_CONFIG_IN) > /dev/null
218 @$(SED) -i -r -e "s/^(USING_CROSS_COMPILER)=.*/# \1 is not set/" .config
219 @./scripts/config/conf -o $(CONFIG_CONFIG_IN) > /dev/null
221 allnoconfig: scripts/config/conf
222 @./scripts/config/conf -n $(CONFIG_CONFIG_IN) > /dev/null
224 # defconfig is allyesconfig minus any features that are specialized enough
225 # or cause enough behavior change that the user really should switch them on
226 # manually if that's what they want. Sort of "maximum sane config".
228 defconfig: scripts/config/conf
229 @./scripts/config/conf -y $(CONFIG_CONFIG_IN) > /dev/null
230 @$(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
231 @./scripts/config/conf -o $(CONFIG_CONFIG_IN) > /dev/null
234 allbareconfig: scripts/config/conf
235 @./scripts/config/conf -y $(CONFIG_CONFIG_IN) > /dev/null
236 @$(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
237 @$(SED) -i -e "/FEATURE/s/=.*//;/^[^#]/s/.*FEATURE.*/# \0 is not set/;" .config
238 @echo "CONFIG_FEATURE_BUFFERS_GO_ON_STACK=y" >> .config
239 @yes n | ./scripts/config/conf -o $(CONFIG_CONFIG_IN) > /dev/null
242 $(Q)cp .config .config.bak || noold=yea
243 $(Q)$(MAKE) CC="$(HOSTCC)" CFLAGS="$(HOSTCFLAGS) $(INCS)" allnoconfig
244 $(Q)mv .config .config.in
245 $(Q)(grep -v CONFIG_SED .config.in ; \
246 echo "CONFIG_SED=y" ; ) > .config
247 $(Q)$(MAKE) CC="$(HOSTCC)" CFLAGS="$(HOSTCFLAGS) $(INCS)" oldconfig include/bb_config.h
248 $(Q)$(MAKE) CC="$(HOSTCC)" CFLAGS="$(HOSTCFLAGS) $(INCS)" busybox
249 $(Q)[ -f .config.bak ] && mv .config.bak .config || rm .config
251 @echo "Now do: $(MAKE) SED=$(top_builddir)/sed <target>"
253 else # ifneq ($(strip $(HAVE_DOT_CONFIG)),y)
255 all: busybox busybox.links doc
257 # In this section, we need .config
258 -include $(top_builddir)/.config.cmd
259 include $(patsubst %,%/Makefile.in, $(SRC_DIRS))
261 endif # ifneq ($(strip $(HAVE_DOT_CONFIG)),y)
263 -include $(top_builddir)/.config
264 -include $(top_builddir)/.depend
267 ifeq ($(strip $(CONFIG_BUILD_AT_ONCE)),y)
269 # Which parts of the internal libs are requested?
270 # Per default we only want what was actually selected.
271 # -a denotes all while -y denotes the selected ones.
272 ifeq ($(strip $(CONFIG_FEATURE_FULL_LIBBUSYBOX)),y)
273 LIBRARY_DEFINE:=$(LIBRARY_DEFINE-a)
274 LIBRARY_SRC :=$(LIBRARY_SRC-a)
275 else # CONFIG_FEATURE_FULL_LIBBUSYBOX
276 LIBRARY_DEFINE:=$(LIBRARY_DEFINE-y)
277 LIBRARY_SRC :=$(LIBRARY_SRC-y)
278 endif # CONFIG_FEATURE_FULL_LIBBUSYBOX
279 APPLET_SRC:=$(APPLET_SRC-y)
280 APPLETS_DEFINE:=$(APPLETS_DEFINE-y)
281 else # CONFIG_BUILD_AT_ONCE
282 # no --combine, build archives out of the individual .o
283 # This was the old way the binary was built.
284 libbusybox-obj:=archival/libunarchive/libunarchive.a \
285 networking/libiproute/libiproute.a \
286 libpwdgrp/libpwdgrp.a \
287 coreutils/libcoreutils/libcoreutils.a \
289 libbusybox-obj:=$(patsubst %,$(top_builddir)/%,$(libbusybox-obj))
291 ifeq ($(strip $(CONFIG_FEATURE_SHARED_BUSYBOX)),y)
292 # linking against libbusybox, so don't build the .a already contained in the .so
293 libraries-y:=$(filter-out $(libbusybox-obj),$(libraries-y))
294 endif # CONFIG_FEATURE_SHARED_BUSYBOX
295 endif # CONFIG_BUILD_AT_ONCE
298 ifeq ($(strip $(CONFIG_BUILD_LIBBUSYBOX)),y)
299 LD_LIBBUSYBOX:=libbusybox.so
300 LIBBUSYBOX_SONAME:=$(LD_LIBBUSYBOX).$(MAJOR_VERSION).$(MINOR_VERSION).$(SUBLEVEL_VERSION)
301 DO_INSTALL_LIBS:=$(LD_LIBBUSYBOX) \
302 $(LD_LIBBUSYBOX).$(MAJOR_VERSION) \
303 $(LD_LIBBUSYBOX).$(MAJOR_VERSION).$(MINOR_VERSION)
304 endif # CONFIG_BUILD_LIBBUSYBOX
306 ifeq ($(strip $(CONFIG_BUILD_AT_ONCE)),y)
307 ifneq ($(strip $(CONFIG_FEATURE_SHARED_BUSYBOX)),y)
308 # --combine but not linking against libbusybox, so compile all
309 BUSYBOX_SRC := $(LIBRARY_SRC)
310 BUSYBOX_DEFINE:= $(LIBRARY_DEFINE)
311 endif # !CONFIG_FEATURE_SHARED_BUSYBOX
312 $(LIBBUSYBOX_SONAME): $(LIBRARY_SRC)
313 else # CONFIG_BUILD_AT_ONCE
314 $(LIBBUSYBOX_SONAME): $(libbusybox-obj)
315 endif # CONFIG_BUILD_AT_ONCE
317 ifeq ($(strip $(CONFIG_FEATURE_SHARED_BUSYBOX)),y)
318 LDBUSYBOX:=-L$(top_builddir) -lbusybox
321 ifeq ($(strip $(CONFIG_BUILD_LIBBUSYBOX)),y)
322 $(LIBBUSYBOX_SONAME):
324 $(error MAJOR_VERSION needed for $@ is not defined)
327 -Wl,-soname=$(LD_LIBBUSYBOX).$(MAJOR_VERSION) \
329 @rm -f $(DO_INSTALL_LIBS)
330 @for i in $(DO_INSTALL_LIBS); do ln -s $(@) $$i ; done
333 endif # ifeq ($(strip $(CONFIG_BUILD_LIBBUSYBOX)),y)
335 busybox_unstripped: .depend $(LIBBUSYBOX_SONAME) $(BUSYBOX_SRC) $(APPLET_SRC) $(libraries-y)
338 busybox: busybox_unstripped
339 $(Q)cp busybox_unstripped busybox
345 busybox.links: $(top_srcdir)/applets/busybox.mkll include/bb_config.h $(top_srcdir)/include/applets.h
348 install: $(top_srcdir)/applets/install.sh busybox busybox.links
349 $(Q)DO_INSTALL_LIBS="$(strip $(LIBBUSYBOX_SONAME) $(DO_INSTALL_LIBS))" \
350 $(SHELL) $< $(PREFIX) $(INSTALL_OPTS)
351 ifeq ($(strip $(CONFIG_FEATURE_SUID)),y)
354 @echo --------------------------------------------------
355 @echo You will probably need to make your busybox binary
356 @echo setuid root to ensure all configured applets will
358 @echo --------------------------------------------------
362 uninstall: busybox.links
363 rm -f $(PREFIX)/bin/busybox
364 for i in `cat busybox.links` ; do rm -f $(PREFIX)$$i; done
365 ifneq ($(strip $(DO_INSTALL_LIBS)),n)
366 for i in $(LIBBUSYBOX_SONAME) $(DO_INSTALL_LIBS); do \
367 rm -f $(PREFIX)$$i; \
372 bindir=$(top_builddir) srcdir=$(top_srcdir)/testsuite SED="$(SED)" \
373 $(SHELL) $(top_srcdir)/testsuite/runtest $(CHECK_VERBOSE)
376 $(Q)$(top_srcdir)/scripts/checkhelp.awk \
377 $(wildcard $(patsubst %,%/Config.in,$(SRC_DIRS) ./))
379 sizes: busybox_unstripped
380 $(NM) --size-sort $(<)
382 bloatcheck: busybox_old busybox_unstripped
383 @$(top_srcdir)/scripts/bloat-o-meter busybox_old busybox_unstripped
385 baseline: busybox_unstripped
386 @mv busybox_unstripped busybox_old
388 objsizes: busybox_unstripped
389 $(SHELL) $(top_srcdir)/scripts/objsizes
391 # Documentation Targets
392 doc: docs/busybox.pod docs/BusyBox.txt docs/BusyBox.1 docs/BusyBox.html
394 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
397 $(Q)-( cat $(top_srcdir)/docs/busybox_header.pod ; \
398 $(top_srcdir)/docs/autodocifier.pl $(top_srcdir)/include/usage.h ; \
399 cat $(top_srcdir)/docs/busybox_footer.pod ; ) > docs/busybox.pod
401 docs/BusyBox.txt: docs/busybox.pod
404 $(Q)-pod2text $< > $@
406 docs/BusyBox.1: docs/busybox.pod
409 $(Q)-pod2man --center=BusyBox --release="version $(VERSION)" \
412 docs/BusyBox.html: docs/busybox.net/BusyBox.html
415 $(Q)-rm -f docs/BusyBox.html
416 $(Q)-cp docs/busybox.net/BusyBox.html docs/BusyBox.html
418 docs/busybox.net/BusyBox.html: docs/busybox.pod
419 $(Q)-mkdir -p docs/busybox.net
420 $(Q)-pod2html --noindex $< > \
421 docs/busybox.net/BusyBox.html
424 # The nifty new dependency stuff
425 scripts/bb_mkdep: $(top_srcdir)/scripts/bb_mkdep.c
428 DEP_INCLUDES := include/bb_config.h
430 ifeq ($(strip $(CONFIG_BBCONFIG)),y)
431 DEP_INCLUDES += include/bbconfigopts.h
433 include/bbconfigopts.h: .config
435 $(Q)$(top_srcdir)/scripts/config/mkconfigs > $@
438 ifeq ($(strip $(CONFIG_FEATURE_COMPRESS_USAGE)),y)
439 USAGE_BIN:=scripts/usage
440 $(USAGE_BIN): $(top_srcdir)/scripts/usage.c .config
443 DEP_INCLUDES += include/usage_compressed.h
445 include/usage_compressed.h: .config $(USAGE_BIN)
446 $(Q)SED="$(SED)" $(SHELL) $(top_srcdir)/scripts/usage_compressed "$(top_builddir)/scripts" > $@
447 endif # CONFIG_FEATURE_COMPRESS_USAGE
449 # workaround alleged bug in make-3.80, make-3.81
450 .NOTPARALLEL: .depend
453 .depend: scripts/bb_mkdep $(USAGE_BIN) $(DEP_INCLUDES)
456 $(Q)mkdir -p include/config
457 $(Q)scripts/bb_mkdep -I $(top_srcdir)/include $(top_srcdir) > $@.tmp
460 include/bb_config.h: .config
461 @if [ ! -x $(top_builddir)/scripts/config/conf ] ; then \
462 $(MAKE) -C scripts/config conf; \
464 @$(top_builddir)/scripts/config/conf -o $(CONFIG_CONFIG_IN)
467 - $(MAKE) -C scripts/config $@
468 - rm -f docs/busybox.dvi docs/busybox.ps \
469 docs/busybox.pod docs/busybox.net/busybox.html \
470 docs/busybox pod2htm* *.gdb *.elf *~ core .*config.log \
471 docs/BusyBox.txt docs/BusyBox.1 docs/BusyBox.html \
472 docs/busybox.net/BusyBox.html busybox.links \
474 .config.old busybox busybox_unstripped
475 - rm -r -f _install testsuite/links
476 - find . -name .\*.flags -o -name \*.o -o -name \*.om \
477 -o -name \*.os -o -name \*.osm -o -name \*.a | xargs rm -f
480 rm -f scripts/bb_mkdep scripts/usage
481 rm -r -f include/config include/config.h $(DEP_INCLUDES)
482 find . -name .depend'*' -print0 | xargs -0 rm -f
484 rm -f .config .config.old .config.cmd
486 release: distclean #doc
488 rm -r -f $(PROG)-$(VERSION); \
489 cp -a busybox $(PROG)-$(VERSION); \
491 find $(PROG)-$(VERSION)/ -type d \
494 -exec rm -r -f {} \; ; \
496 find $(PROG)-$(VERSION)/ -type f \
499 -exec rm -f {} \; ; \
501 tar -cvzf $(PROG)-$(VERSION).tar.gz $(PROG)-$(VERSION)/;
507 endif # ifeq ($(skip-makefile),)