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 clean distclean \
15 # the toplevel sourcedir
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
38 CONFIG_CONFIG_IN = $(top_srcdir)/sysdeps/$(TARGET_OS)/Config.in
39 CONFIG_DEFCONFIG = $(top_srcdir)/sysdeps/$(TARGET_OS)/defconfig
44 ifeq ("$(origin O)", "command line")
49 # If no alternate output-dir was specified, we build in cwd
50 # We are using KBUILD_OUTPUT nevertheless to make sure that we create
51 # Rules.mak and the toplevel Makefile, in case they don't exist.
52 KBUILD_OUTPUT := $(top_builddir)
55 # All object directories.
57 all_tree := $(patsubst %,$(top_builddir)/%,$(OBJ_DIRS) scripts scripts/config include)
62 ifneq ($(KBUILD_OUTPUT),)
63 # Invoke a second make in the output directory, passing relevant variables
64 # Check that the output directory actually exists
65 saved-output := $(KBUILD_OUTPUT)
66 KBUILD_OUTPUT := $(shell cd $(KBUILD_OUTPUT) && /bin/pwd)
67 $(if $(wildcard $(KBUILD_OUTPUT)),, \
68 $(error output directory "$(saved-output)" does not exist))
70 .PHONY: $(MAKECMDGOALS)
72 $(filter-out _all,$(MAKECMDGOALS)) _all: $(KBUILD_OUTPUT)/Rules.mak $(KBUILD_OUTPUT)/Makefile all_tree
73 $(MAKE) -C $(KBUILD_OUTPUT) \
74 top_srcdir=$(top_srcdir) \
75 top_builddir=$(top_builddir) \
76 KBUILD_SRC=$(top_srcdir) \
79 -f $(CURDIR)/Makefile $@
81 $(KBUILD_OUTPUT)/Rules.mak:
83 @echo top_srcdir=$(top_srcdir) >> $@
84 @echo top_builddir=$(KBUILD_OUTPUT) >> $@
85 @echo include $(top_srcdir)/Rules.mak >> $@
87 $(KBUILD_OUTPUT)/Makefile:
89 @echo top_srcdir=$(top_srcdir) >> $@
90 @echo top_builddir=$(KBUILD_OUTPUT) >> $@
91 @echo KBUILD_SRC='$$(top_srcdir)' >> $@
92 @echo include '$$(KBUILD_SRC)'/Makefile >> $@
94 # Leave processing to above invocation of make
96 endif # ifneq ($(KBUILD_OUTPUT),)
97 endif # ifeq ($(KBUILD_SRC),)
99 ifeq ($(skip-makefile),)
101 # We only need a copy of the Makefile for the config targets and reuse
102 # the rest from the source directory, i.e. we do not cp ALL_MAKEFILES.
103 scripts/config/Makefile: $(top_srcdir)/scripts/config/Makefile
110 @echo ' clean - delete temporary files created by build'
111 @echo ' distclean - delete all non-source files (including .config)'
114 @echo ' all - Executable and documentation'
115 @echo ' busybox - the swiss-army executable'
116 @echo ' doc - docs/BusyBox.{txt,html,1}'
118 @echo 'Configuration:'
119 @echo ' allnoconfig - disable all symbols in .config'
120 @echo ' allyesconfig - enable (almost) all symbols in .config'
121 @echo ' config - text based configurator (of last resort).'
122 @echo ' defconfig - set .config to defaults'
123 @echo ' menuconfig - interactive curses-based configurator'
124 @echo ' oldconfig - resolve any unresolved symbols in .config'
126 @echo 'Installation:'
127 @echo ' install - install busybox and symlinks into $prefix'
128 @echo ' install-hardlinks - install busybox and hardlinks into $prefix'
132 @echo ' check - run the test suite for all applets'
133 @echo ' randconfig - generate a random configuration'
134 @echo ' release - create a distribution tarball'
135 @echo ' sizes - show size of all enabled busybox symbols'
139 include $(top_srcdir)/Rules.mak
141 ifneq ($(strip $(HAVE_DOT_CONFIG)),y)
143 # Default target if none was requested explicitly
146 # warn if no configuration exists and we are asked to build a non-config target
149 @echo "No $(top_builddir)/$@ found!"
150 @echo "Please refer to 'make help', section Configuration."
155 # ---------------------------------------------------------------------------
157 scripts/config/conf: scripts/config/Makefile
158 $(MAKE) -C scripts/config conf
159 -@if [ ! -f .config ] ; then \
160 cp $(CONFIG_DEFCONFIG) .config; \
163 scripts/config/mconf: scripts/config/Makefile
164 $(MAKE) -C scripts/config ncurses conf mconf
165 -@if [ ! -f .config ] ; then \
166 cp $(CONFIG_DEFCONFIG) .config; \
169 menuconfig: scripts/config/mconf
170 @./scripts/config/mconf $(CONFIG_CONFIG_IN)
172 config: scripts/config/conf
173 @./scripts/config/conf $(CONFIG_CONFIG_IN)
175 oldconfig: scripts/config/conf
176 @./scripts/config/conf -o $(CONFIG_CONFIG_IN)
178 randconfig: scripts/config/conf
179 @./scripts/config/conf -r $(CONFIG_CONFIG_IN)
181 allyesconfig: scripts/config/conf
182 @./scripts/config/conf -y $(CONFIG_CONFIG_IN)
183 sed -i -r -e "s/^(CONFIG_DEBUG|USING_CROSS_COMPILER|CONFIG_STATIC|CONFIG_SELINUX).*/# \1 is not set/" .config
184 @./scripts/config/conf -o $(CONFIG_CONFIG_IN)
186 allnoconfig: scripts/config/conf
187 @./scripts/config/conf -n $(CONFIG_CONFIG_IN)
189 defconfig: scripts/config/conf
190 @./scripts/config/conf -d $(CONFIG_CONFIG_IN)
192 else # ifneq ($(strip $(HAVE_DOT_CONFIG)),y)
194 all: busybox busybox.links doc
196 # In this section, we need .config
197 -include $(top_builddir)/.config.cmd
198 include $(patsubst %,%/Makefile.in, $(SRC_DIRS))
199 -include $(top_builddir)/.depend
201 endif # ifneq ($(strip $(HAVE_DOT_CONFIG)),y)
203 busybox: .depend $(libraries-y)
204 $(CC) $(EXTRA_CFLAGS) $(LDFLAGS) -o $@ -Wl,--start-group $(libraries-y) $(LIBRARIES) -Wl,--end-group
207 busybox.links: $(top_srcdir)/applets/busybox.mkll include/config.h $(top_srcdir)/include/applets.h
210 install: $(top_srcdir)/applets/install.sh busybox busybox.links
211 $(SHELL) $< $(PREFIX)
212 ifeq ($(strip $(CONFIG_FEATURE_SUID)),y)
215 @echo --------------------------------------------------
216 @echo You will probably need to make your busybox binary
217 @echo setuid root to ensure all configured applets will
219 @echo --------------------------------------------------
223 uninstall: busybox.links
224 rm -f $(PREFIX)/bin/busybox
225 for i in `cat busybox.links` ; do rm -f $(PREFIX)$$i; done
227 install-hardlinks: $(top_srcdir)/applets/install.sh busybox busybox.links
228 $(SHELL) $< $(PREFIX) --hardlinks
230 # see if we are in verbose mode
233 ifeq ("$(origin V)", "command line")
234 KBUILD_VERBOSE := $(V)
237 ifneq ($(strip $(KBUILD_VERBOSE)),)
241 bindir=$(top_builddir) srcdir=$(top_srcdir)/testsuite \
242 $(top_srcdir)/testsuite/runtest $(CHECK_VERBOSE)
246 $(MAKE) top_srcdir=$(top_srcdir) top_builddir=$(top_builddir) \
247 -f $(top_srcdir)/Makefile STRIPCMD=/bin/true
248 nm --size-sort busybox
250 # Documentation Targets
251 doc: docs/busybox.pod docs/BusyBox.txt docs/BusyBox.1 docs/BusyBox.html
253 docs/busybox.pod : $(top_srcdir)/docs/busybox_header.pod $(top_srcdir)/include/usage.h $(top_srcdir)/docs/busybox_footer.pod
255 - ( cat $(top_srcdir)/docs/busybox_header.pod; \
256 $(top_srcdir)/docs/autodocifier.pl $(top_srcdir)/include/usage.h; \
257 cat $(top_srcdir)/docs/busybox_footer.pod ) > docs/busybox.pod
259 docs/BusyBox.txt: docs/busybox.pod
261 $(SECHO) BusyBox Documentation
266 docs/BusyBox.1: docs/busybox.pod
268 - pod2man --center=BusyBox --release="version $(VERSION)" \
271 docs/BusyBox.html: docs/busybox.net/BusyBox.html
273 -@ rm -f docs/BusyBox.html
274 -@ cp docs/busybox.net/BusyBox.html docs/BusyBox.html
276 docs/busybox.net/BusyBox.html: docs/busybox.pod
277 -@ mkdir -p docs/busybox.net
278 - pod2html --noindex $< > \
279 docs/busybox.net/BusyBox.html
282 # The nifty new buildsystem stuff
283 scripts/bb_mkdep: $(top_srcdir)/scripts/bb_mkdep.c
284 $(HOSTCC) $(HOSTCFLAGS) -o $@ $<
286 DEP_INCLUDES := include/config.h include/bb_config.h
288 ifeq ($(strip $(CONFIG_BBCONFIG)),y)
289 DEP_INCLUDES += include/bbconfigopts.h
291 include/bbconfigopts.h: .config
292 $(top_srcdir)/scripts/config/mkconfigs > $@
295 depend dep $(top_builddir)/.depend: .depend
296 .depend: scripts/bb_mkdep $(DEP_INCLUDES)
298 @mkdir -p include/config
299 scripts/bb_mkdep -c include/config.h -c include/bb_config.h -I $(top_srcdir)/include $(top_srcdir)/ > $@.tmp
302 include/config.h: .config
303 @if [ ! -x $(top_builddir)/scripts/config/conf ] ; then \
304 $(MAKE) -C scripts/config conf; \
306 @$(top_builddir)/scripts/config/conf -o $(CONFIG_CONFIG_IN)
308 include/bb_config.h: include/config.h
309 @echo -e "#ifndef BB_CONFIG_H\n#define BB_CONFIG_H" > $@
310 @sed -e 's/#undef CONFIG_\(.*\)/#define ENABLE_\1 0/' \
311 -e 's/#define CONFIG_\(.*\)/#define CONFIG_\1\n#define ENABLE_\1/' \
316 - $(MAKE) -C scripts/config $@
317 - rm -f docs/busybox.dvi docs/busybox.ps \
318 docs/busybox.pod docs/busybox.net/busybox.html \
319 docs/busybox pod2htm* *.gdb *.elf *~ core .*config.log \
320 docs/BusyBox.txt docs/BusyBox.1 docs/BusyBox.html \
321 docs/busybox.net/BusyBox.html busybox.links libbb/loop.h \
323 - rm -rf _install testsuite/links
324 - find . -name .\*.flags -exec rm -f {} \;
325 - find . -name \*.o -exec rm -f {} \;
326 - find . -name \*.a -exec rm -f {} \;
329 - rm -f scripts/bb_mkdep
330 - rm -rf include/config include/config.h include/bb_config.h include/bbconfigopts.h
331 - find . -name .depend -exec rm -f {} \;
332 rm -f .config .config.old .config.cmd
334 release: distclean #doc
336 rm -rf $(PROG)-$(VERSION); \
337 cp -a busybox $(PROG)-$(VERSION); \
339 find $(PROG)-$(VERSION)/ -type d \
342 -exec rm -rf {} \; ; \
344 find $(PROG)-$(VERSION)/ -type f \
347 -exec rm -f {} \; ; \
349 tar -cvzf $(PROG)-$(VERSION).tar.gz $(PROG)-$(VERSION)/;
355 endif # ifeq ($(skip-makefile),)
357 .PHONY: dummy subdirs release distclean clean config oldconfig \
358 menuconfig tags check test depend buildtree