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 \
22 top_builddir=$(CURDIR)
25 export srctree=$(top_srcdir)
26 vpath %/Config.in $(srctree)
28 include $(top_srcdir)/Rules.mak
30 DIRS:=applets archival archival/libunarchive coreutils console-tools \
31 debianutils editors findutils init miscutils modutils networking \
32 networking/libiproute networking/udhcp procps loginutils shell \
33 sysklogd util-linux e2fsprogs libpwdgrp coreutils/libcoreutils libbb
35 SRC_DIRS:=$(patsubst %,$(top_srcdir)/%,$(DIRS))
37 ifeq ($(strip $(CONFIG_SELINUX)),y)
38 LIBRARIES += -lselinux
41 CONFIG_CONFIG_IN = $(top_srcdir)/sysdeps/$(TARGET_OS)/Config.in
42 CONFIG_DEFCONFIG = $(top_srcdir)/sysdeps/$(TARGET_OS)/defconfig
44 ALL_DIRS:= $(DIRS) scripts/config
45 ALL_MAKEFILES:=$(patsubst %,%/Makefile,$(ALL_DIRS))
50 ifeq ("$(origin O)", "command line")
55 # That's our default target when none is given on the command line
59 ifneq ($(KBUILD_OUTPUT),)
60 # Invoke a second make in the output directory, passing relevant variables
61 # check that the output directory actually exists
62 saved-output := $(KBUILD_OUTPUT)
63 KBUILD_OUTPUT := $(shell cd $(KBUILD_OUTPUT) && /bin/pwd)
64 $(if $(wildcard $(KBUILD_OUTPUT)),, \
65 $(error output directory "$(saved-output)" does not exist))
67 .PHONY: $(MAKECMDGOALS)
69 $(filter-out _all,$(MAKECMDGOALS)) _all: $(KBUILD_OUTPUT)/Rules.mak $(KBUILD_OUTPUT)/Makefile
70 $(MAKE) -C $(KBUILD_OUTPUT) \
71 top_srcdir=$(CURDIR) \
72 top_builddir=$(KBUILD_OUTPUT) \
73 TOPDIR=$(KBUILD_OUTPUT) \
74 KBUILD_SRC=$(CURDIR) \
75 -f $(CURDIR)/Makefile $@
77 $(KBUILD_OUTPUT)/Rules.mak:
79 @echo top_srcdir=$(CURDIR) >> $@
80 @echo top_builddir=$(KBUILD_OUTPUT) >> $@
81 @echo include $(top_srcdir)/Rules.mak >> $@
83 $(KBUILD_OUTPUT)/Makefile:
85 @echo top_srcdir=$(CURDIR) >> $@
86 @echo top_builddir=$(KBUILD_OUTPUT) >> $@
87 @echo KBUILD_SRC='$$(top_srcdir)' >> $@
88 @echo include '$$(KBUILD_SRC)'/Makefile >> $@
90 # Leave processing to above invocation of make
92 endif # ifneq ($(KBUILD_OUTPUT),)
93 endif # ifeq ($(KBUILD_SRC),)
95 ifeq ($(skip-makefile),)
101 @echo ' clean - delete temporary files created by build'
102 @echo ' distclean - delete all non-source files (including .config)'
105 @echo ' all - Executable and documentation'
106 @echo ' busybox - the swiss-army executable'
107 @echo ' doc - docs/BusyBox.{txt,html,1}'
109 @echo 'Configuration:'
110 @echo ' allnoconfig - disable all symbols in .config'
111 @echo ' allyesconfig - enable (almost) all symbols in .config'
112 @echo ' config - text based configurator (of last resort).'
113 @echo ' defconfig - set .config to defaults'
114 @echo ' menuconfig - interactive curses-based configurator'
115 @echo ' oldconfig - resolve any unresolved symbols in .config'
117 @echo 'Installation:'
118 @echo ' install - install busybox and symlinks into $prefix'
119 @echo ' install-hardlinks - install busybox and hardlinks into $prefix'
123 @echo ' check - run the test suite for all applets'
124 @echo ' randconfig - generate a random configuration'
125 @echo ' release - create a distribution tarball'
126 @echo ' sizes - show size of all enabled busybox symbols'
129 ifeq ($(strip $(HAVE_DOT_CONFIG)),y)
131 all: busybox busybox.links doc
133 all_tree: $(ALL_MAKEFILES)
135 $(ALL_MAKEFILES): %/Makefile: $(top_srcdir)/%/Makefile
136 [ -d $(@D) ] || mkdir -p $(@D); cp $< $@
138 # In this section, we need .config
139 -include $(top_builddir)/.config.cmd
140 include $(patsubst %,%/Makefile.in, $(SRC_DIRS))
141 -include $(top_builddir)/.depend
143 busybox: $(ALL_MAKEFILES) .depend $(libraries-y)
144 $(CC) $(LDFLAGS) -o $@ -Wl,--start-group $(libraries-y) $(LIBRARIES) -Wl,--end-group
147 busybox.links: $(top_srcdir)/applets/busybox.mkll include/config.h $(top_srcdir)/include/applets.h
150 install: $(top_srcdir)/applets/install.sh busybox busybox.links
151 $(SHELL) $< $(PREFIX)
152 ifeq ($(strip $(CONFIG_FEATURE_SUID)),y)
155 @echo --------------------------------------------------
156 @echo You will probably need to make your busybox binary
157 @echo setuid root to ensure all configured applets will
159 @echo --------------------------------------------------
163 uninstall: busybox.links
164 rm -f $(PREFIX)/bin/busybox
165 for i in `cat busybox.links` ; do rm -f $(PREFIX)$$i; done
167 install-hardlinks: $(top_srcdir)/applets/install.sh busybox busybox.links
168 $(SHELL) $< $(PREFIX) --hardlinks
171 bindir=$(top_builddir) srcdir=$(top_srcdir)/testsuite \
172 $(top_srcdir)/testsuite/runtest
176 $(MAKE) top_srcdir=$(top_srcdir) top_builddir=$(top_builddir) \
177 -f $(top_srcdir)/Makefile STRIPCMD=/bin/true
178 nm --size-sort busybox
180 # Documentation Targets
181 doc: docs/busybox.pod docs/BusyBox.txt docs/BusyBox.1 docs/BusyBox.html
183 docs/busybox.pod : $(top_srcdir)/docs/busybox_header.pod $(top_srcdir)/include/usage.h $(top_srcdir)/docs/busybox_footer.pod
185 - ( cat $(top_srcdir)/docs/busybox_header.pod; \
186 $(top_srcdir)/docs/autodocifier.pl $(top_srcdir)/include/usage.h; \
187 cat $(top_srcdir)/docs/busybox_footer.pod ) > docs/busybox.pod
189 docs/BusyBox.txt: docs/busybox.pod
191 $(SECHO) BusyBox Documentation
196 docs/BusyBox.1: docs/busybox.pod
198 - pod2man --center=BusyBox --release="version $(VERSION)" \
201 docs/BusyBox.html: docs/busybox.net/BusyBox.html
203 -@ rm -f docs/BusyBox.html
204 -@ cp docs/busybox.net/BusyBox.html docs/BusyBox.html
206 docs/busybox.net/BusyBox.html: docs/busybox.pod
207 -@ mkdir -p docs/busybox.net
208 - pod2html --noindex $< > \
209 docs/busybox.net/BusyBox.html
212 # The nifty new buildsystem stuff
213 scripts/bb_mkdep: $(top_srcdir)/scripts/bb_mkdep.c
214 $(HOSTCC) $(HOSTCFLAGS) -o $@ $<
216 DEP_INCLUDES := include/config.h include/bb_config.h
218 ifeq ($(strip $(CONFIG_BBCONFIG)),y)
219 DEP_INCLUDES += include/bbconfigopts.h
221 include/bbconfigopts.h: .config
222 scripts/config/mkconfigs > $@
225 depend dep $(top_builddir)/.depend: .depend
226 .depend: scripts/bb_mkdep $(DEP_INCLUDES)
228 @mkdir -p include/config
229 scripts/bb_mkdep -c include/config.h -c include/bb_config.h > $@.tmp
232 include/config.h: .config
233 @if [ ! -x $(top_builddir)/scripts/config/conf ] ; then \
234 $(MAKE) -C scripts/config conf; \
236 @$(top_builddir)/scripts/config/conf -o $(CONFIG_CONFIG_IN)
238 include/bb_config.h: include/config.h
239 @echo -e "#ifndef BB_CONFIG_H\n#define BB_CONFIG_H" > $@
240 @sed -e 's/#undef CONFIG_\(.*\)/#define ENABLE_\1 0/' \
241 -e 's/#define CONFIG_\(.*\)/#define CONFIG_\1\n#define ENABLE_\1/' \
247 $(SECHO) Finished installing...
250 else # ifeq ($(strip $(HAVE_DOT_CONFIG)),y)
255 # ---------------------------------------------------------------------------
257 scripts/config/conf: scripts/config/Makefile $(top_srcdir)/Rules.mak
258 $(MAKE) -C scripts/config conf
259 -@if [ ! -f .config ] ; then \
260 cp $(CONFIG_DEFCONFIG) .config; \
263 scripts/config/mconf: scripts/config/Makefile $(top_srcdir)/Rules.mak
264 $(MAKE) -C scripts/config ncurses conf mconf
265 -@if [ ! -f .config ] ; then \
266 cp $(CONFIG_DEFCONFIG) .config; \
269 menuconfig: scripts/config/mconf
270 @./scripts/config/mconf $(CONFIG_CONFIG_IN)
272 config: scripts/config/conf
273 @./scripts/config/conf $(CONFIG_CONFIG_IN)
275 oldconfig: scripts/config/conf
276 @./scripts/config/conf -o $(CONFIG_CONFIG_IN)
278 randconfig: scripts/config/conf
279 @./scripts/config/conf -r $(CONFIG_CONFIG_IN)
281 allyesconfig: scripts/config/conf
282 @./scripts/config/conf -y $(CONFIG_CONFIG_IN)
283 sed -i -r -e "s/^(CONFIG_DEBUG|USING_CROSS_COMPILER|CONFIG_STATIC|CONFIG_SELINUX).*/# \1 is not set/" .config
284 @./scripts/config/conf -o $(CONFIG_CONFIG_IN)
286 allnoconfig: scripts/config/conf
287 @./scripts/config/conf -n $(CONFIG_CONFIG_IN)
289 defconfig: scripts/config/conf
290 @./scripts/config/conf -d $(CONFIG_CONFIG_IN)
293 - $(MAKE) -C scripts/config $@
294 - rm -f docs/busybox.dvi docs/busybox.ps \
295 docs/busybox.pod docs/busybox.net/busybox.html \
296 docs/busybox pod2htm* *.gdb *.elf *~ core .*config.log \
297 docs/BusyBox.txt docs/BusyBox.1 docs/BusyBox.html \
298 docs/busybox.net/BusyBox.html busybox.links libbb/loop.h \
300 - rm -rf _install testsuite/links
301 - find . -name .\*.flags -exec rm -f {} \;
302 - find . -name \*.o -exec rm -f {} \;
303 - find . -name \*.a -exec rm -f {} \;
306 - rm -f scripts/bb_mkdep
307 - rm -rf include/config include/config.h include/bb_config.h include/bbconfigopts.h
308 - find . -name .depend -exec rm -f {} \;
309 rm -f .config .config.old .config.cmd
311 release: distclean #doc
313 rm -rf $(PROG)-$(VERSION); \
314 cp -a busybox $(PROG)-$(VERSION); \
316 find $(PROG)-$(VERSION)/ -type d \
319 -exec rm -rf {} \; ; \
321 find $(PROG)-$(VERSION)/ -type f \
324 -exec rm -f {} \; ; \
326 tar -cvzf $(PROG)-$(VERSION).tar.gz $(PROG)-$(VERSION)/;
332 endif # ifeq ($(strip $(HAVE_DOT_CONFIG)),y)
334 endif # ifeq ($(skip-makefile),)
336 .PHONY: dummy subdirs release distclean clean config oldconfig \
337 menuconfig tags check test depend buildtree