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)
38 vpath %/Config.in $(srctree)
40 include $(top_builddir)/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 libpwdgrp coreutils/libcoreutils libbb
47 SRC_DIRS:=$(patsubst %,$(top_srcdir)/%,$(DIRS))
49 ifeq ($(strip $(CONFIG_SELINUX)),y)
50 CFLAGS += -I/usr/include/selinux
54 CONFIG_CONFIG_IN = $(top_srcdir)/sysdeps/$(TARGET_OS)/Config.in
55 CONFIG_DEFCONFIG = $(top_srcdir)/sysdeps/$(TARGET_OS)/defconfig
57 ALL_DIRS:= $(DIRS) scripts/config
58 ALL_MAKEFILES:=$(patsubst %,%/Makefile,$(ALL_DIRS))
63 ifeq ("$(origin O)", "command line")
68 # That's our default target when none is given on the command line
72 ifneq ($(KBUILD_OUTPUT),)
73 # Invoke a second make in the output directory, passing relevant variables
74 # check that the output directory actually exists
75 saved-output := $(KBUILD_OUTPUT)
76 KBUILD_OUTPUT := $(shell cd $(KBUILD_OUTPUT) && /bin/pwd)
77 $(if $(wildcard $(KBUILD_OUTPUT)),, \
78 $(error output directory "$(saved-output)" does not exist))
80 .PHONY: $(MAKECMDGOALS)
82 $(filter-out _all,$(MAKECMDGOALS)) _all: $(KBUILD_OUTPUT)/Rules.mak $(KBUILD_OUTPUT)/Makefile
83 $(MAKE) -C $(KBUILD_OUTPUT) \
84 top_srcdir=$(CURDIR) \
85 top_builddir=$(KBUILD_OUTPUT) \
86 TOPDIR=$(KBUILD_OUTPUT) \
87 KBUILD_SRC=$(CURDIR) \
88 -f $(CURDIR)/Makefile $@
90 $(KBUILD_OUTPUT)/Rules.mak:
92 @echo top_srcdir=$(CURDIR) >> $@
93 @echo top_builddir=$(KBUILD_OUTPUT) >> $@
94 @echo include $(top_srcdir)/Rules.mak >> $@
96 $(KBUILD_OUTPUT)/Makefile:
98 @echo top_srcdir=$(CURDIR) >> $@
99 @echo top_builddir=$(KBUILD_OUTPUT) >> $@
100 @echo KBUILD_SRC='$$(top_srcdir)' >> $@
101 @echo include '$$(KBUILD_SRC)'/Makefile >> $@
103 # Leave processing to above invocation of make
105 endif # ifneq ($(KBUILD_OUTPUT),)
106 endif # ifeq ($(KBUILD_SRC),)
108 ifeq ($(skip-makefile),)
112 ifeq ($(strip $(HAVE_DOT_CONFIG)),y)
114 all: busybox busybox.links doc
116 all_tree: $(ALL_MAKEFILES)
118 $(ALL_MAKEFILES): %/Makefile: $(top_srcdir)/%/Makefile
119 d=`dirname $@`; [ -d "$$d" ] || mkdir -p "$$d"; cp $< $@
121 # In this section, we need .config
122 -include $(top_builddir)/.config.cmd
123 include $(patsubst %,%/Makefile.in, $(SRC_DIRS))
124 -include $(top_builddir)/.depend
126 busybox: $(ALL_MAKEFILES) .depend include/config.h $(libraries-y)
127 $(CC) $(LDFLAGS) -o $@ -Wl,--start-group $(libraries-y) $(LIBRARIES) -Wl,--end-group
130 busybox.links: $(top_srcdir)/applets/busybox.mkll include/config.h $(top_srcdir)/include/applets.h
133 install: $(top_srcdir)/applets/install.sh busybox busybox.links
134 $(SHELL) $< $(PREFIX)
135 ifeq ($(strip $(CONFIG_FEATURE_SUID)),y)
138 @echo --------------------------------------------------
139 @echo You will probably need to make your busybox binary
140 @echo setuid root to ensure all configured applets will
142 @echo --------------------------------------------------
146 uninstall: busybox.links
147 rm -f $(PREFIX)/bin/busybox
148 for i in `cat busybox.links` ; do rm -f $(PREFIX)$$i; done
150 install-hardlinks: applets/install.sh busybox busybox.links
151 $(SHELL) $< $(PREFIX) --hardlinks
154 bindir=$(top_builddir) srcdir=$(top_srcdir)/testsuite \
155 $(top_srcdir)/testsuite/runtest
157 # Documentation Targets
158 doc: docs/busybox.pod docs/BusyBox.txt docs/BusyBox.1 docs/BusyBox.html
160 docs/busybox.pod : $(top_srcdir)/docs/busybox_header.pod $(top_srcdir)/include/usage.h $(top_srcdir)/docs/busybox_footer.pod
162 - ( cat $(top_srcdir)/docs/busybox_header.pod; \
163 $(top_srcdir)/docs/autodocifier.pl $(top_srcdir)/include/usage.h; \
164 cat $(top_srcdir)/docs/busybox_footer.pod ) > docs/busybox.pod
166 docs/BusyBox.txt: docs/busybox.pod
168 @echo BusyBox Documentation
173 docs/BusyBox.1: docs/busybox.pod
175 - pod2man --center=BusyBox --release="version $(VERSION)" \
178 docs/BusyBox.html: docs/busybox.net/BusyBox.html
180 -@ rm -f docs/BusyBox.html
181 -@ cp docs/busybox.net/BusyBox.html docs/BusyBox.html
183 docs/busybox.net/BusyBox.html: docs/busybox.pod
184 -@ mkdir -p docs/busybox.net
185 - pod2html --noindex $< > \
186 docs/busybox.net/BusyBox.html
189 # The nifty new buildsystem stuff
190 scripts/mkdep: $(top_srcdir)/scripts/mkdep.c
191 $(HOSTCC) $(HOSTCFLAGS) -o $@ $<
193 scripts/split-include: $(top_srcdir)/scripts/split-include.c
194 $(HOSTCC) $(HOSTCFLAGS) -o $@ $<
196 .depend: scripts/mkdep
197 rm -f .depend .hdepend;
198 mkdir -p include/config;
199 scripts/mkdep -I include -- \
200 `find $(top_srcdir) -name \*.c -print | sed -e "s,^./,,"` >> .depend;
201 scripts/mkdep -I include -- \
202 `find $(top_srcdir) -name \*.h -print | sed -e "s,^./,,"` >> .hdepend;
204 depend dep: include/config.h .depend
206 include/config/MARKER: depend scripts/split-include
207 scripts/split-include include/config.h include/config
208 @ touch include/config/MARKER
210 include/config.h: .config
211 @if [ ! -x $(top_builddir)/scripts/config/conf ] ; then \
212 $(MAKE) -C scripts/config conf; \
214 @$(top_builddir)/scripts/config/conf -o $(CONFIG_CONFIG_IN)
218 @echo Finished installing...
221 else # ifeq ($(strip $(HAVE_DOT_CONFIG)),y)
226 # ---------------------------------------------------------------------------
228 $(ALL_MAKEFILES): %/Makefile: $(top_srcdir)/%/Makefile
229 d=`dirname $@`; [ -d "$$d" ] || mkdir -p "$$d"; cp $< $@
231 scripts/config/conf: scripts/config/Makefile Rules.mak
232 $(MAKE) -C scripts/config conf
233 -@if [ ! -f .config ] ; then \
234 cp $(CONFIG_DEFCONFIG) .config; \
237 scripts/config/mconf: scripts/config/Makefile Rules.mak
238 $(MAKE) -C scripts/config ncurses conf mconf
239 -@if [ ! -f .config ] ; then \
240 cp $(CONFIG_DEFCONFIG) .config; \
243 menuconfig: scripts/config/mconf
244 @./scripts/config/mconf $(CONFIG_CONFIG_IN)
246 config: scripts/config/conf
247 @./scripts/config/conf $(CONFIG_CONFIG_IN)
249 oldconfig: scripts/config/conf
250 @./scripts/config/conf -o $(CONFIG_CONFIG_IN)
252 randconfig: scripts/config/conf
253 @./scripts/config/conf -r $(CONFIG_CONFIG_IN)
255 allyesconfig: scripts/config/conf
256 @./scripts/config/conf -y $(CONFIG_CONFIG_IN)
257 sed -i -e "s/^CONFIG_DEBUG.*/# CONFIG_DEBUG is not set/" .config
258 sed -i -e "s/^USING_CROSS_COMPILER.*/# USING_CROSS_COMPILER is not set/" .config
259 sed -i -e "s/^CONFIG_STATIC.*/# CONFIG_STATIC is not set/" .config
260 sed -i -e "s/^CONFIG_SELINUX.*/# CONFIG_SELINUX is not set/" .config
261 @./scripts/config/conf -o $(CONFIG_CONFIG_IN)
263 allnoconfig: scripts/config/conf
264 @./scripts/config/conf -n $(CONFIG_CONFIG_IN)
266 defconfig: scripts/config/conf
267 @./scripts/config/conf -d $(CONFIG_CONFIG_IN)
270 - rm -f docs/busybox.dvi docs/busybox.ps \
271 docs/busybox.pod docs/busybox.net/busybox.html \
272 docs/busybox pod2htm* *.gdb *.elf *~ core .*config.log \
273 docs/BusyBox.txt docs/BusyBox.1 docs/BusyBox.html \
274 docs/busybox.net/BusyBox.html busybox.links libbb/loop.h \
275 .config.old .hdepend busybox
277 - find . -name .\*.flags -exec rm -f {} \;
278 - find . -name \*.o -exec rm -f {} \;
279 - find . -name \*.a -exec rm -f {} \;
282 - rm -f scripts/split-include scripts/mkdep
283 - rm -rf include/config include/config.h
284 - find . -name .depend -exec rm -f {} \;
285 rm -f .config .config.old .config.cmd
286 - $(MAKE) -C scripts/config clean
288 release: distclean #doc
290 rm -rf $(PROG)-$(VERSION); \
291 cp -a busybox $(PROG)-$(VERSION); \
293 find $(PROG)-$(VERSION)/ -type d \
296 -exec rm -rf {} \; ; \
298 find $(PROG)-$(VERSION)/ -type f \
301 -exec rm -f {} \; ; \
303 tar -cvzf $(PROG)-$(VERSION).tar.gz $(PROG)-$(VERSION)/;
309 endif # ifeq ($(strip $(HAVE_DOT_CONFIG)),y)
311 endif # ifeq ($(skip-makefile),)
313 .PHONY: dummy subdirs release distclean clean config oldconfig \
314 menuconfig tags check test depend buildtree