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 \
13 clean distclean help \
16 # the toplevel sourcedir
18 # make-3.79.1 didn't support MAKEFILE_LIST
19 # for building out-of-tree, users of make-3.79.1 still have to pass top_srcdir=
20 # to make: make -f /srcs/busybox/Makefile top_srcdir=/srcs/busybox
22 top_srcdir:=$(shell cd $(dir $(firstword $(MAKEFILE_LIST))) && pwd)
27 # toplevel directory of the object-tree
29 top_builddir:=$(CURDIR)
32 export srctree=$(top_srcdir)
33 vpath %/Config.in $(srctree)
35 DIRS:=applets archival archival/libunarchive coreutils console-tools \
36 debianutils editors findutils init miscutils modutils networking \
37 networking/libiproute networking/udhcp procps loginutils shell \
38 sysklogd util-linux e2fsprogs libpwdgrp coreutils/libcoreutils libbb
40 SRC_DIRS:=$(patsubst %,$(top_srcdir)/%,$(DIRS))
42 # That's our default target when none is given on the command line
47 # see if we are in verbose mode
50 PACKAGE_BE_VERBOSE := $(VERBOSE)
54 PACKAGE_BE_VERBOSE := $(V)
58 ifeq ("$(origin O)", "command line")
59 PACKAGE_OUTPUTDIR := $(shell cd $(O) && pwd)
60 top_builddir := $(PACKAGE_OUTPUTDIR)
63 # If no alternate output-dir was specified, we build in cwd
64 PACKAGE_OUTPUTDIR := $(top_builddir)
68 $(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)))
72 $(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)))
75 #######################################################################
76 # make-3.79.1 doesn't support order-only prerequisites..
77 ifeq ($(MAKE_VERSION),3.79.1)
80 #######################################################################
84 # Handle building out of tree
85 ifneq ($(top_builddir),$(top_srcdir))
86 all_tree := $(patsubst %,$(top_builddir)/%,$(DIRS) scripts scripts/config include include/config)
90 saved-output := $(PACKAGE_OUTPUTDIR)
92 $(if $(wildcard $(PACKAGE_OUTPUTDIR)),, \
93 $(error output directory "$(saved-output)" does not exist))
95 .PHONY: $(filter $(noconfig_targets),$(MAKECMDGOALS))
97 $(PACKAGE_OUTPUTDIR)/Rules.mak:
99 @echo top_srcdir=$(top_srcdir) >> $@
100 @echo top_builddir=$(PACKAGE_OUTPUTDIR) >> $@
101 @echo include $$\(top_srcdir\)/Rules.mak >> $@
103 $(PACKAGE_OUTPUTDIR)/Makefile:
105 @echo top_srcdir=$(top_srcdir) >> $@
106 @echo top_builddir=$(PACKAGE_OUTPUTDIR) >> $@
107 @echo PACKAGE_SOURCEDIR='$$(top_srcdir)' >> $@
108 @echo include '$$(PACKAGE_SOURCEDIR)'/Makefile >> $@
111 buildtree := $(all_tree) $(PACKAGE_OUTPUTDIR)/Rules.mak $(PACKAGE_OUTPUTDIR)/Makefile
113 # We only need a copy of the Makefile for the config targets and reuse
114 # the rest from the source directory, i.e. we do not cp ALL_MAKEFILES.
115 scripts/config/Makefile: $(top_srcdir)/scripts/config/Makefile | $(buildtree)
116 @cp $(top_srcdir)/scripts/config/Makefile $@
119 all_tree := include/config
122 buildtree := $(all_tree)
123 endif # ifneq ($(PACKAGE_OUTPUTDIR),$(top_srcdir))
127 @echo ' clean - delete temporary files created by build'
128 @echo ' distclean - delete all non-source files (including .config)'
131 @echo ' all - Executable and documentation'
132 @echo ' busybox - the swiss-army executable'
133 @echo ' doc - docs/BusyBox.{txt,html,1}'
135 @echo 'Configuration:'
136 @echo ' allnoconfig - disable all symbols in .config'
137 @echo ' allyesconfig - enable all symbols in .config (see defconfig)'
138 @echo ' allbareconfig - enable all applets without any sub-features'
139 @echo ' config - text based configurator (of last resort)'
140 @echo ' defconfig - set .config to largest generic configuration'
141 @echo ' menuconfig - interactive curses-based configurator'
142 @echo ' oldconfig - resolve any unresolved symbols in .config'
144 @echo 'Installation:'
145 @echo ' install - install busybox into $prefix'
149 @echo ' check - run the test suite for all applets'
150 @echo ' randconfig - generate a random configuration'
151 @echo ' release - create a distribution tarball'
152 @echo ' sizes - show size of all enabled busybox symbols'
155 @echo ' V=<number> - print verbose make output (default: unset)'
156 @echo ' 0 print CC invocations'
158 @echo ' 2 also print when make enters a directory'
159 @echo ' 3 also verbosely print shell invocations'
161 -include $(top_srcdir)/Rules.mak
163 ifneq ($(strip $(HAVE_DOT_CONFIG)),y)
164 # Default target if none was requested explicitly
167 ifneq ($(filter-out $(noconfig_targets),$(MAKECMDGOALS)),)
168 # warn if no configuration exists and we are asked to build a non-config target
171 @echo "No $(top_builddir)/$@ found!"
172 @echo "Please refer to 'make help', section Configuration."
176 # Avoid implicit rule to kick in by using an empty command
177 .config: $(buildtree) ;
179 endif # ifneq ($(strip $(HAVE_DOT_CONFIG)),y)
183 # ---------------------------------------------------------------------------
185 CONFIG_CONFIG_IN = $(top_srcdir)/Config.in
187 scripts/config/conf: scripts/config/Makefile
188 $(Q)$(MAKE) -C scripts/config conf
190 scripts/config/mconf: scripts/config/Makefile
191 $(Q)$(MAKE) -C scripts/config ncurses conf mconf
193 menuconfig: scripts/config/mconf
194 @[ -f .config ] || make $(MAKEFLAGS) defconfig
195 @./scripts/config/mconf $(CONFIG_CONFIG_IN)
197 config: scripts/config/conf
198 @./scripts/config/conf $(CONFIG_CONFIG_IN)
200 oldconfig: scripts/config/conf
201 @./scripts/config/conf -o $(CONFIG_CONFIG_IN)
203 randconfig: scripts/config/conf
204 @./scripts/config/conf -r $(CONFIG_CONFIG_IN)
206 allyesconfig: scripts/config/conf
207 @./scripts/config/conf -y $(CONFIG_CONFIG_IN)
208 @$(SED) -i -r -e "s/^(USING_CROSS_COMPILER)=.*/# \1 is not set/" .config
209 @./scripts/config/conf -o $(CONFIG_CONFIG_IN)
211 allnoconfig: scripts/config/conf
212 @./scripts/config/conf -n $(CONFIG_CONFIG_IN)
214 # defconfig is allyesconfig minus any features that are specialized enough
215 # or cause enough behavior change that the user really should switch them on
216 # manually if that's what they want. Sort of "maximum sane config".
218 defconfig: scripts/config/conf
219 @./scripts/config/conf -y $(CONFIG_CONFIG_IN)
220 @$(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
221 @./scripts/config/conf -o $(CONFIG_CONFIG_IN)
223 allbareconfig: scripts/config/conf
224 @./scripts/config/conf -y $(CONFIG_CONFIG_IN)
225 @$(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
226 @$(SED) -i -e "/FEATURE/s/=.*//;/^[^#]/s/.*FEATURE.*/# \0 is not set/;" .config
227 @echo "CONFIG_FEATURE_BUFFERS_GO_ON_STACK=y" >> .config
228 @./scripts/config/conf -o $(CONFIG_CONFIG_IN)
230 ifeq ($(strip $(HAVE_DOT_CONFIG)),y)
233 -include $(top_builddir)/.config.cmd
235 endif # ifeq ($(strip $(HAVE_DOT_CONFIG)),y)
237 include $(patsubst %,%/Makefile.in,$(SRC_DIRS))
239 ifeq ($(strip $(HAVE_DOT_CONFIG)),y)
240 # Finally pull in the dependencies (headers and other includes) of the
241 # individual object files
242 -include $(top_builddir)/.depend
244 $(top_builddir)/applets/applets.o: $(top_builddir)/.config
247 all: busybox busybox.links doc ;
249 # Two modes of operation: legacy and IMA
250 # Legacy mode builds each object through an individual invocation of CC
251 # IMA compiles all sources at once (aka IPO aka IPA etc.)
253 ifeq ($(strip $(CONFIG_BUILD_AT_ONCE)),y)
255 # Which parts of the internal libs are requested?
256 # Per default we only want what was actually selected.
257 # -a denotes all while -y denotes the selected ones.
258 ifeq ($(strip $(CONFIG_FEATURE_FULL_LIBBUSYBOX)),y)
259 LIBRARY_DEFINE:=$(LIBRARY_DEFINE-a)
260 LIBRARY_SRC :=$(LIBRARY_SRC-a)
261 else # CONFIG_FEATURE_FULL_LIBBUSYBOX
262 LIBRARY_DEFINE:=$(LIBRARY_DEFINE-y)
263 LIBRARY_SRC :=$(LIBRARY_SRC-y)
264 endif # CONFIG_FEATURE_FULL_LIBBUSYBOX
265 APPLET_SRC:=$(APPLET_SRC-y)
266 APPLETS_DEFINE:=$(APPLETS_DEFINE-y)
267 else # CONFIG_BUILD_AT_ONCE
268 # no --combine, build archives out of the individual .o
269 # This was the old way the binary was built.
270 libbusybox-obj:=archival/libunarchive/libunarchive.a \
271 networking/libiproute/libiproute.a \
272 libpwdgrp/libpwdgrp.a coreutils/libcoreutils/libcoreutils.a \
274 libbusybox-obj:=$(patsubst %,$(top_builddir)/%,$(libbusybox-obj))
275 ifeq ($(strip $(CONFIG_FEATURE_SHARED_BUSYBOX)),y)
276 # linking against libbusybox, so don't build the .a already contained in the .so
277 libraries-y:=$(filter-out $(libbusybox-obj),$(libraries-y))
278 endif # CONFIG_FEATURE_SHARED_BUSYBOX
280 endif # CONFIG_BUILD_AT_ONCE
282 ifeq ($(strip $(CONFIG_BUILD_LIBBUSYBOX)),y)
283 LD_LIBBUSYBOX:=libbusybox.so
284 LIBBUSYBOX_SONAME:=$(LD_LIBBUSYBOX).$(MAJOR_VERSION).$(MINOR_VERSION).$(SUBLEVEL_VERSION)
285 DO_INSTALL_LIBS:=$(LD_LIBBUSYBOX) \
286 $(LD_LIBBUSYBOX).$(MAJOR_VERSION) \
287 $(LD_LIBBUSYBOX).$(MAJOR_VERSION).$(MINOR_VERSION)
289 endif # CONFIG_BUILD_LIBBUSYBOX
291 ifeq ($(strip $(CONFIG_BUILD_AT_ONCE)),y)
292 ifneq ($(strip $(CONFIG_FEATURE_SHARED_BUSYBOX)),y)
293 # --combine but not linking against libbusybox, so compile lib*.c
294 BUSYBOX_SRC := $(LIBRARY_SRC)
295 BUSYBOX_DEFINE:= $(LIBRARY_DEFINE)
296 endif # !CONFIG_FEATURE_SHARED_BUSYBOX
297 $(LIBBUSYBOX_SONAME): $(LIBRARY_SRC)
298 else # CONFIG_BUILD_AT_ONCE
299 $(LIBBUSYBOX_SONAME): $(libbusybox-obj)
300 AR_INTRO:=-Wl,--whole-archive
301 AR_EXTRO:=-Wl,--no-whole-archive
302 endif # CONFIG_BUILD_AT_ONCE
305 ifeq ($(strip $(CONFIG_FEATURE_SHARED_BUSYBOX)),y)
306 LDBUSYBOX:=-L$(top_builddir) -lbusybox
309 ifeq ($(strip $(CONFIG_BUILD_LIBBUSYBOX)),y)
310 $(LIBBUSYBOX_SONAME):
312 $(error MAJOR_VERSION needed for $@ is not defined)
314 $(do_link) $(LIB_CFLAGS) $(CFLAGS_COMBINE) \
315 -Wl,-soname=$(LD_LIBBUSYBOX).$(MAJOR_VERSION) \
316 -Wl,-z,combreloc $(LIB_LDFLAGS) \
319 $(LIBRARY_DEFINE) $(AR_INTRO) $(^) $(AR_EXTRO) \
321 @rm -f $(DO_INSTALL_LIBS)
322 @for i in $(DO_INSTALL_LIBS); do ln -s $(@) $$i ; done
325 endif # ifeq ($(strip $(CONFIG_BUILD_LIBBUSYBOX)),y)
327 busybox_unstripped: $(top_builddir)/.depend $(LIBBUSYBOX_SONAME) $(BUSYBOX_SRC) $(APPLET_SRC) $(libraries-y)
328 $(do_link) $(PROG_CFLAGS) $(PROG_LDFLAGS) $(CFLAGS_COMBINE) \
329 $(foreach f,$(^:.o=.c),$(CFLAGS-$(notdir $(patsubst %/$,%,$(dir $(f))))-$(notdir $(f)))) \
331 -o $@ -Wl,--start-group \
332 $(APPLETS_DEFINE) $(APPLET_SRC) \
333 $(BUSYBOX_DEFINE) $(BUSYBOX_SRC) \
335 $(LDBUSYBOX) $(LIBRARIES) \
338 busybox: busybox_unstripped
339 $(Q)cp busybox_unstripped busybox
342 busybox.links: $(top_srcdir)/applets/busybox.mkll include/bb_config.h $(top_srcdir)/include/applets.h
345 install: $(top_srcdir)/applets/install.sh busybox busybox.links
346 $(Q)DO_INSTALL_LIBS="$(strip $(LIBBUSYBOX_SONAME) $(DO_INSTALL_LIBS))" \
347 $(SHELL) $< $(PREFIX) $(INSTALL_OPTS)
348 ifeq ($(strip $(CONFIG_FEATURE_SUID)),y)
351 @echo --------------------------------------------------
352 @echo You will probably need to make your busybox binary
353 @echo setuid root to ensure all configured applets will
355 @echo --------------------------------------------------
359 uninstall: busybox.links
360 rm -f $(PREFIX)/bin/busybox
361 for i in `cat busybox.links` ; do rm -f $(PREFIX)$$i; done
362 ifneq ($(strip $(DO_INSTALL_LIBS)),n)
363 for i in $(LIBBUSYBOX_SONAME) $(DO_INSTALL_LIBS); do \
364 rm -f $(PREFIX)$$i; \
369 bindir=$(top_builddir) srcdir=$(top_srcdir)/testsuite \
370 $(top_srcdir)/testsuite/runtest $(CHECK_VERBOSE)
372 sizes: busybox_unstripped
373 $(NM) --size-sort $(<)
375 # Documentation Targets
376 doc: docs/busybox.pod docs/BusyBox.txt docs/BusyBox.1 docs/BusyBox.html ;
378 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
381 $(Q)-( cat $(top_srcdir)/docs/busybox_header.pod ; \
382 $(top_srcdir)/docs/autodocifier.pl $(top_srcdir)/include/usage.h ; \
383 cat $(top_srcdir)/docs/busybox_footer.pod ; ) > docs/busybox.pod
385 docs/BusyBox.txt: docs/busybox.pod
388 $(Q)-pod2text $< > $@
390 docs/BusyBox.1: docs/busybox.pod
393 $(Q)-pod2man --center=BusyBox --release="version $(VERSION)" \
396 docs/BusyBox.html: docs/busybox.net/BusyBox.html
399 $(Q)-rm -f docs/BusyBox.html
400 $(Q)-cp docs/busybox.net/BusyBox.html docs/BusyBox.html
402 docs/busybox.net/BusyBox.html: docs/busybox.pod
403 $(Q)-mkdir -p docs/busybox.net
404 $(Q)-pod2html --noindex $< > \
405 docs/busybox.net/BusyBox.html
408 # The nifty new dependency stuff
409 scripts/bb_mkdep: $(top_srcdir)/scripts/bb_mkdep.c
412 DEP_INCLUDES := include/bb_config.h
414 ifeq ($(strip $(CONFIG_BBCONFIG)),y)
415 DEP_INCLUDES += include/bbconfigopts.h
417 include/bbconfigopts.h: .config
419 $(Q)$(top_srcdir)/scripts/config/mkconfigs > $@
422 depend dep: $(top_builddir)/.depend ;
423 $(top_builddir)/.depend: $(buildtree) scripts/bb_mkdep $(DEP_INCLUDES)
426 $(Q)scripts/bb_mkdep $(MKDEP_ARGS) \
427 -I $(top_srcdir)/include $(top_srcdir) > $@.tmp
430 include/bb_config.h: .config
432 @$(top_builddir)/scripts/config/conf -o $(CONFIG_CONFIG_IN)
434 endif # ifeq ($(strip $(HAVE_DOT_CONFIG)),y)
437 - rm -f docs/busybox.dvi docs/busybox.ps \
438 docs/busybox.pod docs/busybox.net/busybox.html \
439 docs/busybox pod2htm* *.gdb *.elf *~ core .*config.log \
440 docs/BusyBox.txt docs/BusyBox.1 docs/BusyBox.html \
441 docs/busybox.net/BusyBox.html busybox.links \
443 .config.old busybox busybox_unstripped
444 - rm -r -f _install testsuite/links
445 - find . -name .\*.flags -o -name \*.o -o -name \*.om \
446 -o -name \*.os -o -name \*.osm -o -name \*.a | xargs rm -f
449 - $(MAKE) -C scripts/config clean
450 - rm -f scripts/bb_mkdep
451 - rm -r -f include/config $(DEP_INCLUDES)
452 - find . -name .depend'*' | xargs rm -f
453 rm -f .config .config.old .config.cmd
455 release: distclean #doc
457 rm -r -f $(PROG)-$(VERSION); \
458 cp -a busybox $(PROG)-$(VERSION); \
460 find $(PROG)-$(VERSION)/ -type d \
463 -exec rm -r -f {} \; ; \
465 find $(PROG)-$(VERSION)/ -type f \
468 -exec rm -f {} \; ; \
470 tar -cvzf $(PROG)-$(VERSION).tar.gz $(PROG)-$(VERSION)/;
475 # keep these in sync with noconfig_targets above!
476 .PHONY: dummy subdirs check test depend dep buildtree \
477 menuconfig config oldconfig randconfig \
478 defconfig allyesconfig allnoconfig allbareconfig \