3 # Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 #--------------------------------------------------------------
21 # You shouldn't need to mess with anything beyond this point...
22 #--------------------------------------------------------------
23 noconfig_targets := menuconfig config oldconfig randconfig \
24 defconfig allyesconfig allnoconfig clean distclean \
34 top_builddir=$(CURDIR)
37 export srctree=$(top_srcdir)
38 vpath %/Config.in $(srctree)
40 include $(top_srcdir)/Rules.mak
42 DIRS:=applets archival archival/libunarchive coreutils console-tools \
43 debianutils editors findutils init miscutils modutils networking \
44 networking/libiproute networking/udhcp procps loginutils shell \
45 sysklogd util-linux e2fsprogs libpwdgrp coreutils/libcoreutils libbb
47 SRC_DIRS:=$(patsubst %,$(top_srcdir)/%,$(DIRS))
49 ifeq ($(strip $(CONFIG_SELINUX)),y)
50 LIBRARIES += -lselinux
53 CONFIG_CONFIG_IN = $(top_srcdir)/sysdeps/$(TARGET_OS)/Config.in
54 CONFIG_DEFCONFIG = $(top_srcdir)/sysdeps/$(TARGET_OS)/defconfig
56 ALL_DIRS:= $(DIRS) scripts/config
57 ALL_MAKEFILES:=$(patsubst %,%/Makefile,$(ALL_DIRS))
62 ifeq ("$(origin O)", "command line")
67 # That's our default target when none is given on the command line
71 ifneq ($(KBUILD_OUTPUT),)
72 # Invoke a second make in the output directory, passing relevant variables
73 # check that the output directory actually exists
74 saved-output := $(KBUILD_OUTPUT)
75 KBUILD_OUTPUT := $(shell cd $(KBUILD_OUTPUT) && /bin/pwd)
76 $(if $(wildcard $(KBUILD_OUTPUT)),, \
77 $(error output directory "$(saved-output)" does not exist))
79 .PHONY: $(MAKECMDGOALS)
81 $(filter-out _all,$(MAKECMDGOALS)) _all: $(KBUILD_OUTPUT)/Rules.mak $(KBUILD_OUTPUT)/Makefile
82 $(MAKE) -C $(KBUILD_OUTPUT) \
83 top_srcdir=$(CURDIR) \
84 top_builddir=$(KBUILD_OUTPUT) \
85 TOPDIR=$(KBUILD_OUTPUT) \
86 KBUILD_SRC=$(CURDIR) \
87 -f $(CURDIR)/Makefile $@
89 $(KBUILD_OUTPUT)/Rules.mak:
91 @echo top_srcdir=$(CURDIR) >> $@
92 @echo top_builddir=$(KBUILD_OUTPUT) >> $@
93 @echo include $(top_srcdir)/Rules.mak >> $@
95 $(KBUILD_OUTPUT)/Makefile:
97 @echo top_srcdir=$(CURDIR) >> $@
98 @echo top_builddir=$(KBUILD_OUTPUT) >> $@
99 @echo KBUILD_SRC='$$(top_srcdir)' >> $@
100 @echo include '$$(KBUILD_SRC)'/Makefile >> $@
102 # Leave processing to above invocation of make
104 endif # ifneq ($(KBUILD_OUTPUT),)
105 endif # ifeq ($(KBUILD_SRC),)
107 ifeq ($(skip-makefile),)
111 ifeq ($(strip $(HAVE_DOT_CONFIG)),y)
113 all: busybox busybox.links doc
115 all_tree: $(ALL_MAKEFILES)
117 $(ALL_MAKEFILES): %/Makefile: $(top_srcdir)/%/Makefile
118 [ -d $(@D) ] || mkdir -p $(@D); cp $< $@
120 # In this section, we need .config
121 -include $(top_builddir)/.config.cmd
122 include $(patsubst %,%/Makefile.in, $(SRC_DIRS))
123 -include $(top_builddir)/.depend
125 busybox: $(ALL_MAKEFILES) .depend include/bb_config.h $(libraries-y)
126 $(CC) $(LDFLAGS) -o $@ -Wl,--start-group $(libraries-y) $(LIBRARIES) -Wl,--end-group
129 busybox.links: $(top_srcdir)/applets/busybox.mkll include/config.h $(top_srcdir)/include/applets.h
132 install: $(top_srcdir)/applets/install.sh busybox busybox.links
133 $(SHELL) $< $(PREFIX)
134 ifeq ($(strip $(CONFIG_FEATURE_SUID)),y)
137 @echo --------------------------------------------------
138 @echo You will probably need to make your busybox binary
139 @echo setuid root to ensure all configured applets will
141 @echo --------------------------------------------------
145 uninstall: busybox.links
146 rm -f $(PREFIX)/bin/busybox
147 for i in `cat busybox.links` ; do rm -f $(PREFIX)$$i; done
149 install-hardlinks: $(top_srcdir)/applets/install.sh busybox busybox.links
150 $(SHELL) $< $(PREFIX) --hardlinks
153 bindir=$(top_builddir) srcdir=$(top_srcdir)/testsuite \
154 $(top_srcdir)/testsuite/runtest
158 $(MAKE) top_srcdir=$(top_srcdir) top_builddir=$(top_builddir) \
159 -f $(top_srcdir)/Makefile STRIPCMD=/bin/true
160 nm --size-sort busybox
162 # Documentation Targets
163 doc: docs/busybox.pod docs/BusyBox.txt docs/BusyBox.1 docs/BusyBox.html
165 docs/busybox.pod : $(top_srcdir)/docs/busybox_header.pod $(top_srcdir)/include/usage.h $(top_srcdir)/docs/busybox_footer.pod
167 - ( cat $(top_srcdir)/docs/busybox_header.pod; \
168 $(top_srcdir)/docs/autodocifier.pl $(top_srcdir)/include/usage.h; \
169 cat $(top_srcdir)/docs/busybox_footer.pod ) > docs/busybox.pod
171 docs/BusyBox.txt: docs/busybox.pod
173 $(SECHO) BusyBox Documentation
178 docs/BusyBox.1: docs/busybox.pod
180 - pod2man --center=BusyBox --release="version $(VERSION)" \
183 docs/BusyBox.html: docs/busybox.net/BusyBox.html
185 -@ rm -f docs/BusyBox.html
186 -@ cp docs/busybox.net/BusyBox.html docs/BusyBox.html
188 docs/busybox.net/BusyBox.html: docs/busybox.pod
189 -@ mkdir -p docs/busybox.net
190 - pod2html --noindex $< > \
191 docs/busybox.net/BusyBox.html
194 # The nifty new buildsystem stuff
195 scripts/mkdep: $(top_srcdir)/scripts/mkdep.c
196 $(HOSTCC) $(HOSTCFLAGS) -o $@ $<
198 scripts/split-include: $(top_srcdir)/scripts/split-include.c
199 $(HOSTCC) $(HOSTCFLAGS) -o $@ $<
202 .depend: scripts/mkdep include/config.h include/bbconfigopts.h
203 rm -f .depend .hdepend;
204 mkdir -p include/config;
205 scripts/mkdep -I include -- \
206 `find $(top_srcdir) -name \*.c -print | sed -e "s,^./,,"` >> .depend;
207 scripts/mkdep -I include -- \
208 `find $(top_srcdir) -name \*.h -print | sed -e "s,^./,,"` >> .hdepend;
210 include/config/MARKER: depend scripts/split-include
211 scripts/split-include include/config.h include/config
212 @ touch include/config/MARKER
214 include/config.h: .config
215 @if [ ! -x $(top_builddir)/scripts/config/conf ] ; then \
216 $(MAKE) -C scripts/config conf; \
218 @$(top_builddir)/scripts/config/conf -o $(CONFIG_CONFIG_IN)
220 include/bb_config.h: include/config.h
221 echo -e "#ifndef BB_CONFIG_H\n#define BB_CONFIG_H" > $@
222 sed -e 's/#undef CONFIG_\(.*\)/#define ENABLE_\1 0/' \
223 -e 's/#define CONFIG_\(.*\)/#define CONFIG_\1\n#define ENABLE_\1/' \
227 include/bbconfigopts.h: .config
228 @[ -d $(@D) ] || mkdir -v $(@D)
229 $(top_srcdir)/scripts/config/mkconfigs >include/bbconfigopts.h
233 $(SECHO) Finished installing...
236 else # ifeq ($(strip $(HAVE_DOT_CONFIG)),y)
241 # ---------------------------------------------------------------------------
243 scripts/config/conf: scripts/config/Makefile $(top_srcdir)/Rules.mak
244 $(MAKE) -C scripts/config conf
245 -@if [ ! -f .config ] ; then \
246 cp $(CONFIG_DEFCONFIG) .config; \
249 scripts/config/mconf: scripts/config/Makefile $(top_srcdir)/Rules.mak
250 $(MAKE) -C scripts/config ncurses conf mconf
251 -@if [ ! -f .config ] ; then \
252 cp $(CONFIG_DEFCONFIG) .config; \
255 menuconfig: scripts/config/mconf
256 @./scripts/config/mconf $(CONFIG_CONFIG_IN)
258 config: scripts/config/conf
259 @./scripts/config/conf $(CONFIG_CONFIG_IN)
261 oldconfig: scripts/config/conf
262 @./scripts/config/conf -o $(CONFIG_CONFIG_IN)
264 randconfig: scripts/config/conf
265 @./scripts/config/conf -r $(CONFIG_CONFIG_IN)
267 allyesconfig: scripts/config/conf
268 @./scripts/config/conf -y $(CONFIG_CONFIG_IN)
269 sed -i -e "s/^CONFIG_DEBUG.*/# CONFIG_DEBUG is not set/" .config
270 sed -i -e "s/^USING_CROSS_COMPILER.*/# USING_CROSS_COMPILER is not set/" .config
271 sed -i -e "s/^CONFIG_STATIC.*/# CONFIG_STATIC is not set/" .config
272 sed -i -e "s/^CONFIG_SELINUX.*/# CONFIG_SELINUX is not set/" .config
273 @./scripts/config/conf -o $(CONFIG_CONFIG_IN)
275 allnoconfig: scripts/config/conf
276 @./scripts/config/conf -n $(CONFIG_CONFIG_IN)
278 defconfig: scripts/config/conf
279 @./scripts/config/conf -d $(CONFIG_CONFIG_IN)
282 - rm -f docs/busybox.dvi docs/busybox.ps \
283 docs/busybox.pod docs/busybox.net/busybox.html \
284 docs/busybox pod2htm* *.gdb *.elf *~ core .*config.log \
285 docs/BusyBox.txt docs/BusyBox.1 docs/BusyBox.html \
286 docs/busybox.net/BusyBox.html busybox.links libbb/loop.h \
287 .config.old .hdepend busybox testsuite/links/*
289 - find . -name .\*.flags -exec rm -f {} \;
290 - find . -name \*.o -exec rm -f {} \;
291 - find . -name \*.a -exec rm -f {} \;
294 - rm -f scripts/split-include scripts/mkdep
295 - rm -rf include/config include/config.h include/bb_config.h include/bbconfigopts.h
296 - find . -name .depend -exec rm -f {} \;
297 rm -f .config .config.old .config.cmd
298 - $(MAKE) -C scripts/config clean
300 release: distclean #doc
302 rm -rf $(PROG)-$(VERSION); \
303 cp -a busybox $(PROG)-$(VERSION); \
305 find $(PROG)-$(VERSION)/ -type d \
308 -exec rm -rf {} \; ; \
310 find $(PROG)-$(VERSION)/ -type f \
313 -exec rm -f {} \; ; \
315 tar -cvzf $(PROG)-$(VERSION).tar.gz $(PROG)-$(VERSION)/;
321 endif # ifeq ($(strip $(HAVE_DOT_CONFIG)),y)
323 endif # ifeq ($(skip-makefile),)
325 .PHONY: dummy subdirs release distclean clean config oldconfig \
326 menuconfig tags check test depend buildtree