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 include $(top_srcdir)/Rules.mak
29 DIRS:=applets archival archival/libunarchive coreutils console-tools \
30 debianutils editors findutils init miscutils modutils networking \
31 networking/libiproute networking/udhcp procps loginutils shell \
32 sysklogd util-linux e2fsprogs libpwdgrp coreutils/libcoreutils libbb
34 SRC_DIRS:=$(patsubst %,$(top_srcdir)/%,$(DIRS))
36 ifeq ($(strip $(CONFIG_SELINUX)),y)
37 LIBRARIES += -lselinux
40 CONFIG_CONFIG_IN = $(top_srcdir)/sysdeps/$(TARGET_OS)/Config.in
41 CONFIG_DEFCONFIG = $(top_srcdir)/sysdeps/$(TARGET_OS)/defconfig
43 ALL_DIRS:= $(DIRS) scripts/config
44 ALL_MAKEFILES:=$(patsubst %,%/Makefile,$(ALL_DIRS))
49 ifeq ("$(origin O)", "command line")
54 # That's our default target when none is given on the command line
58 ifneq ($(KBUILD_OUTPUT),)
59 # Invoke a second make in the output directory, passing relevant variables
60 # check that the output directory actually exists
61 saved-output := $(KBUILD_OUTPUT)
62 KBUILD_OUTPUT := $(shell cd $(KBUILD_OUTPUT) && /bin/pwd)
63 $(if $(wildcard $(KBUILD_OUTPUT)),, \
64 $(error output directory "$(saved-output)" does not exist))
66 .PHONY: $(MAKECMDGOALS)
68 $(filter-out _all,$(MAKECMDGOALS)) _all: $(KBUILD_OUTPUT)/Rules.mak $(KBUILD_OUTPUT)/Makefile
69 $(MAKE) -C $(KBUILD_OUTPUT) \
70 top_srcdir=$(CURDIR) \
71 top_builddir=$(KBUILD_OUTPUT) \
72 KBUILD_SRC=$(CURDIR) \
73 -f $(CURDIR)/Makefile $@
75 $(KBUILD_OUTPUT)/Rules.mak:
77 @echo top_srcdir=$(CURDIR) >> $@
78 @echo top_builddir=$(KBUILD_OUTPUT) >> $@
79 @echo include $(top_srcdir)/Rules.mak >> $@
81 $(KBUILD_OUTPUT)/Makefile:
83 @echo top_srcdir=$(CURDIR) >> $@
84 @echo top_builddir=$(KBUILD_OUTPUT) >> $@
85 @echo KBUILD_SRC='$$(top_srcdir)' >> $@
86 @echo include '$$(KBUILD_SRC)'/Makefile >> $@
88 # Leave processing to above invocation of make
90 endif # ifneq ($(KBUILD_OUTPUT),)
91 endif # ifeq ($(KBUILD_SRC),)
93 ifeq ($(skip-makefile),)
99 @echo ' clean - delete temporary files created by build'
100 @echo ' distclean - delete all non-source files (including .config)'
103 @echo ' all - Executable and documentation'
104 @echo ' busybox - the swiss-army executable'
105 @echo ' doc - docs/BusyBox.{txt,html,1}'
107 @echo 'Configuration:'
108 @echo ' allnoconfig - disable all symbols in .config'
109 @echo ' allyesconfig - enable (almost) all symbols in .config'
110 @echo ' config - text based configurator (of last resort).'
111 @echo ' defconfig - set .config to defaults'
112 @echo ' menuconfig - interactive curses-based configurator'
113 @echo ' oldconfig - resolve any unresolved symbols in .config'
115 @echo 'Installation:'
116 @echo ' install - install busybox and symlinks into $prefix'
117 @echo ' install-hardlinks - install busybox and hardlinks into $prefix'
121 @echo ' check - run the test suite for all applets'
122 @echo ' randconfig - generate a random configuration'
123 @echo ' release - create a distribution tarball'
124 @echo ' sizes - show size of all enabled busybox symbols'
127 ifeq ($(strip $(HAVE_DOT_CONFIG)),y)
129 all: busybox busybox.links doc
131 all_tree: $(ALL_MAKEFILES)
133 $(ALL_MAKEFILES): %/Makefile: $(top_srcdir)/%/Makefile
134 [ -d $(@D) ] || mkdir -p $(@D); cp $< $@
136 # In this section, we need .config
137 -include $(top_builddir)/.config.cmd
138 include $(patsubst %,%/Makefile.in, $(SRC_DIRS))
139 -include $(top_builddir)/.depend
141 busybox: $(ALL_MAKEFILES) .depend $(libraries-y)
142 $(CC) $(EXTRA_CFLAGS) $(LDFLAGS) -o $@ -Wl,--start-group $(libraries-y) $(LIBRARIES) -Wl,--end-group
145 busybox.links: $(top_srcdir)/applets/busybox.mkll include/config.h $(top_srcdir)/include/applets.h
148 install: $(top_srcdir)/applets/install.sh busybox busybox.links
149 $(SHELL) $< $(PREFIX)
150 ifeq ($(strip $(CONFIG_FEATURE_SUID)),y)
153 @echo --------------------------------------------------
154 @echo You will probably need to make your busybox binary
155 @echo setuid root to ensure all configured applets will
157 @echo --------------------------------------------------
161 uninstall: busybox.links
162 rm -f $(PREFIX)/bin/busybox
163 for i in `cat busybox.links` ; do rm -f $(PREFIX)$$i; done
165 install-hardlinks: $(top_srcdir)/applets/install.sh busybox busybox.links
166 $(SHELL) $< $(PREFIX) --hardlinks
169 bindir=$(top_builddir) srcdir=$(top_srcdir)/testsuite \
170 $(top_srcdir)/testsuite/runtest
174 $(MAKE) top_srcdir=$(top_srcdir) top_builddir=$(top_builddir) \
175 -f $(top_srcdir)/Makefile STRIPCMD=/bin/true
176 nm --size-sort busybox
178 # Documentation Targets
179 doc: docs/busybox.pod docs/BusyBox.txt docs/BusyBox.1 docs/BusyBox.html
181 docs/busybox.pod : $(top_srcdir)/docs/busybox_header.pod $(top_srcdir)/include/usage.h $(top_srcdir)/docs/busybox_footer.pod
183 - ( cat $(top_srcdir)/docs/busybox_header.pod; \
184 $(top_srcdir)/docs/autodocifier.pl $(top_srcdir)/include/usage.h; \
185 cat $(top_srcdir)/docs/busybox_footer.pod ) > docs/busybox.pod
187 docs/BusyBox.txt: docs/busybox.pod
189 $(SECHO) BusyBox Documentation
194 docs/BusyBox.1: docs/busybox.pod
196 - pod2man --center=BusyBox --release="version $(VERSION)" \
199 docs/BusyBox.html: docs/busybox.net/BusyBox.html
201 -@ rm -f docs/BusyBox.html
202 -@ cp docs/busybox.net/BusyBox.html docs/BusyBox.html
204 docs/busybox.net/BusyBox.html: docs/busybox.pod
205 -@ mkdir -p docs/busybox.net
206 - pod2html --noindex $< > \
207 docs/busybox.net/BusyBox.html
210 # The nifty new buildsystem stuff
211 scripts/bb_mkdep: $(top_srcdir)/scripts/bb_mkdep.c
212 $(HOSTCC) $(HOSTCFLAGS) -o $@ $<
214 DEP_INCLUDES := include/config.h include/bb_config.h
216 ifeq ($(strip $(CONFIG_BBCONFIG)),y)
217 DEP_INCLUDES += include/bbconfigopts.h
219 include/bbconfigopts.h: .config
220 scripts/config/mkconfigs > $@
223 depend dep $(top_builddir)/.depend: .depend
224 .depend: scripts/bb_mkdep $(DEP_INCLUDES)
226 @mkdir -p include/config
227 scripts/bb_mkdep -c include/config.h -c include/bb_config.h > $@.tmp
230 include/config.h: .config
231 @if [ ! -x $(top_builddir)/scripts/config/conf ] ; then \
232 $(MAKE) -C scripts/config conf; \
234 @$(top_builddir)/scripts/config/conf -o $(CONFIG_CONFIG_IN)
236 include/bb_config.h: include/config.h
237 @echo -e "#ifndef BB_CONFIG_H\n#define BB_CONFIG_H" > $@
238 @sed -e 's/#undef CONFIG_\(.*\)/#define ENABLE_\1 0/' \
239 -e 's/#define CONFIG_\(.*\)/#define CONFIG_\1\n#define ENABLE_\1/' \
245 $(SECHO) Finished installing...
248 else # ifeq ($(strip $(HAVE_DOT_CONFIG)),y)
253 # ---------------------------------------------------------------------------
255 scripts/config/conf: scripts/config/Makefile $(top_srcdir)/Rules.mak
256 $(MAKE) -C scripts/config conf
257 -@if [ ! -f .config ] ; then \
258 cp $(CONFIG_DEFCONFIG) .config; \
261 scripts/config/mconf: scripts/config/Makefile $(top_srcdir)/Rules.mak
262 $(MAKE) -C scripts/config ncurses conf mconf
263 -@if [ ! -f .config ] ; then \
264 cp $(CONFIG_DEFCONFIG) .config; \
267 menuconfig: scripts/config/mconf
268 @./scripts/config/mconf $(CONFIG_CONFIG_IN)
270 config: scripts/config/conf
271 @./scripts/config/conf $(CONFIG_CONFIG_IN)
273 oldconfig: scripts/config/conf
274 @./scripts/config/conf -o $(CONFIG_CONFIG_IN)
276 randconfig: scripts/config/conf
277 @./scripts/config/conf -r $(CONFIG_CONFIG_IN)
279 allyesconfig: scripts/config/conf
280 @./scripts/config/conf -y $(CONFIG_CONFIG_IN)
281 sed -i -r -e "s/^(CONFIG_DEBUG|USING_CROSS_COMPILER|CONFIG_STATIC|CONFIG_SELINUX).*/# \1 is not set/" .config
282 @./scripts/config/conf -o $(CONFIG_CONFIG_IN)
284 allnoconfig: scripts/config/conf
285 @./scripts/config/conf -n $(CONFIG_CONFIG_IN)
287 defconfig: scripts/config/conf
288 @./scripts/config/conf -d $(CONFIG_CONFIG_IN)
291 - $(MAKE) -C scripts/config $@
292 - rm -f docs/busybox.dvi docs/busybox.ps \
293 docs/busybox.pod docs/busybox.net/busybox.html \
294 docs/busybox pod2htm* *.gdb *.elf *~ core .*config.log \
295 docs/BusyBox.txt docs/BusyBox.1 docs/BusyBox.html \
296 docs/busybox.net/BusyBox.html busybox.links libbb/loop.h \
298 - rm -rf _install testsuite/links
299 - find . -name .\*.flags -exec rm -f {} \;
300 - find . -name \*.o -exec rm -f {} \;
301 - find . -name \*.a -exec rm -f {} \;
304 - rm -f scripts/bb_mkdep
305 - rm -rf include/config include/config.h include/bb_config.h include/bbconfigopts.h
306 - find . -name .depend -exec rm -f {} \;
307 rm -f .config .config.old .config.cmd
309 release: distclean #doc
311 rm -rf $(PROG)-$(VERSION); \
312 cp -a busybox $(PROG)-$(VERSION); \
314 find $(PROG)-$(VERSION)/ -type d \
317 -exec rm -rf {} \; ; \
319 find $(PROG)-$(VERSION)/ -type f \
322 -exec rm -f {} \; ; \
324 tar -cvzf $(PROG)-$(VERSION).tar.gz $(PROG)-$(VERSION)/;
330 endif # ifeq ($(strip $(HAVE_DOT_CONFIG)),y)
332 endif # ifeq ($(skip-makefile),)
334 .PHONY: dummy subdirs release distclean clean config oldconfig \
335 menuconfig tags check test depend buildtree