807ab50580c75b723bd9b03a57627476711451f1
[oweals/busybox.git] / Makefile
1 # Makefile for busybox
2 #
3 # Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
4 #
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.
9 #
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.
14 #
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
18 #
19
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 \
25         release tags
26
27 ifndef TOPDIR
28 TOPDIR=$(CURDIR)/
29 endif
30 ifndef top_srcdir
31 top_srcdir=$(CURDIR)
32 endif
33 ifndef top_builddir
34 top_builddir=$(CURDIR)
35 endif
36
37 srctree=$(top_srcdir)
38 vpath %/Config.in $(srctree)
39
40 include $(top_builddir)/Rules.mak
41
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
46
47 SRC_DIRS:=$(patsubst %,$(top_srcdir)/%,$(DIRS))
48
49 ifeq ($(strip $(CONFIG_SELINUX)),y)
50 LIBRARIES += -lselinux
51 endif
52
53 CONFIG_CONFIG_IN = $(top_srcdir)/sysdeps/$(TARGET_OS)/Config.in
54 CONFIG_DEFCONFIG = $(top_srcdir)/sysdeps/$(TARGET_OS)/defconfig
55
56 ALL_DIRS:= $(DIRS) scripts/config
57 ALL_MAKEFILES:=$(patsubst %,%/Makefile,$(ALL_DIRS))
58
59 ifeq ($(KBUILD_SRC),)
60
61 ifdef O
62   ifeq ("$(origin O)", "command line")
63     KBUILD_OUTPUT := $(O)
64   endif
65 endif
66
67 # That's our default target when none is given on the command line
68 .PHONY: _all
69 _all:
70
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))
78
79 .PHONY: $(MAKECMDGOALS)
80
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 $@
88
89 $(KBUILD_OUTPUT)/Rules.mak:
90         @echo > $@
91         @echo top_srcdir=$(CURDIR) >> $@
92         @echo top_builddir=$(KBUILD_OUTPUT) >> $@
93         @echo include $(top_srcdir)/Rules.mak >> $@
94
95 $(KBUILD_OUTPUT)/Makefile:
96         @echo > $@
97         @echo top_srcdir=$(CURDIR) >> $@
98         @echo top_builddir=$(KBUILD_OUTPUT) >> $@
99         @echo KBUILD_SRC='$$(top_srcdir)' >> $@
100         @echo include '$$(KBUILD_SRC)'/Makefile >> $@
101
102 # Leave processing to above invocation of make
103 skip-makefile := 1
104 endif # ifneq ($(KBUILD_OUTPUT),)
105 endif # ifeq ($(KBUILD_SRC),)
106
107 ifeq ($(skip-makefile),)
108
109 _all: all
110
111 ifeq ($(strip $(HAVE_DOT_CONFIG)),y)
112
113 all: busybox busybox.links doc
114
115 all_tree:       $(ALL_MAKEFILES)
116
117 $(ALL_MAKEFILES): %/Makefile: $(top_srcdir)/%/Makefile
118         d=`dirname $@`; [ -d "$$d" ] || mkdir -p "$$d"; cp $< $@
119
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
124
125 busybox: $(ALL_MAKEFILES) .depend include/bb_config.h $(libraries-y)
126         $(CC) $(LDFLAGS) -o $@ -Wl,--start-group $(libraries-y) $(LIBRARIES) -Wl,--end-group
127         $(STRIPCMD) $@
128
129 busybox.links: $(top_srcdir)/applets/busybox.mkll include/config.h $(top_srcdir)/include/applets.h
130         - $(SHELL) $^ >$@
131
132 install: $(top_srcdir)/applets/install.sh busybox busybox.links
133         $(SHELL) $< $(PREFIX)
134 ifeq ($(strip $(CONFIG_FEATURE_SUID)),y)
135         @echo
136         @echo
137         @echo --------------------------------------------------
138         @echo You will probably need to make your busybox binary
139         @echo setuid root to ensure all configured applets will
140         @echo work properly.
141         @echo --------------------------------------------------
142         @echo
143 endif
144
145 uninstall: busybox.links
146         rm -f $(PREFIX)/bin/busybox
147         for i in `cat busybox.links` ; do rm -f $(PREFIX)$$i; done
148
149 install-hardlinks: $(top_srcdir)/applets/install.sh busybox busybox.links
150         $(SHELL) $< $(PREFIX) --hardlinks
151
152 check: busybox
153         bindir=$(top_builddir) srcdir=$(top_srcdir)/testsuite \
154         $(top_srcdir)/testsuite/runtest
155
156 # Documentation Targets
157 doc: docs/busybox.pod docs/BusyBox.txt docs/BusyBox.1 docs/BusyBox.html
158
159 docs/busybox.pod : $(top_srcdir)/docs/busybox_header.pod $(top_srcdir)/include/usage.h $(top_srcdir)/docs/busybox_footer.pod
160         -mkdir -p docs
161         - ( cat $(top_srcdir)/docs/busybox_header.pod; \
162             $(top_srcdir)/docs/autodocifier.pl $(top_srcdir)/include/usage.h; \
163             cat $(top_srcdir)/docs/busybox_footer.pod ) > docs/busybox.pod
164
165 docs/BusyBox.txt: docs/busybox.pod
166         @echo
167         @echo BusyBox Documentation
168         @echo
169         -mkdir -p docs
170         -pod2text $< > $@
171
172 docs/BusyBox.1: docs/busybox.pod
173         - mkdir -p docs
174         - pod2man --center=BusyBox --release="version $(VERSION)" \
175                 $< > $@
176
177 docs/BusyBox.html: docs/busybox.net/BusyBox.html
178         - mkdir -p docs
179         -@ rm -f docs/BusyBox.html
180         -@ cp docs/busybox.net/BusyBox.html docs/BusyBox.html
181
182 docs/busybox.net/BusyBox.html: docs/busybox.pod
183         -@ mkdir -p docs/busybox.net
184         -  pod2html --noindex $< > \
185             docs/busybox.net/BusyBox.html
186         -@ rm -f pod2htm*
187
188 # The nifty new buildsystem stuff
189 scripts/mkdep: $(top_srcdir)/scripts/mkdep.c
190         $(HOSTCC) $(HOSTCFLAGS) -o $@ $<
191
192 scripts/split-include: $(top_srcdir)/scripts/split-include.c
193         $(HOSTCC) $(HOSTCFLAGS) -o $@ $<
194
195 .depend: scripts/mkdep include/config.h
196         rm -f .depend .hdepend;
197         mkdir -p include/config;
198         scripts/mkdep -I include -- \
199           `find $(top_srcdir) -name \*.c -print | sed -e "s,^./,,"` >> .depend;
200         scripts/mkdep -I include -- \
201           `find $(top_srcdir) -name \*.h -print | sed -e "s,^./,,"` >> .hdepend;
202
203 depend dep: .depend
204
205 include/config/MARKER: depend scripts/split-include
206         scripts/split-include include/config.h include/config
207         @ touch include/config/MARKER
208
209 include/config.h: .config
210         @if [ ! -x $(top_builddir)/scripts/config/conf ] ; then \
211             $(MAKE) -C scripts/config conf; \
212         fi;
213         @$(top_builddir)/scripts/config/conf -o $(CONFIG_CONFIG_IN)
214
215 include/bb_config.h: include/config.h
216         echo "#ifndef AUTOCONF_INCLUDED" > $@
217         sed -e 's/#undef \(.*\)/static const int \1 = 0;/' < $< >> $@
218         echo "#endif" >> $@
219
220 finished2:
221         @echo
222         @echo Finished installing...
223         @echo
224
225 else # ifeq ($(strip $(HAVE_DOT_CONFIG)),y)
226
227 all: menuconfig
228
229 # configuration
230 # ---------------------------------------------------------------------------
231
232 $(ALL_MAKEFILES): %/Makefile: $(top_srcdir)/%/Makefile
233         d=`dirname $@`; [ -d "$$d" ] || mkdir -p "$$d"; cp $< $@
234
235 scripts/config/conf: scripts/config/Makefile Rules.mak
236         $(MAKE) -C scripts/config conf
237         -@if [ ! -f .config ] ; then \
238                 cp $(CONFIG_DEFCONFIG) .config; \
239         fi
240
241 scripts/config/mconf: scripts/config/Makefile Rules.mak
242         $(MAKE) -C scripts/config ncurses conf mconf
243         -@if [ ! -f .config ] ; then \
244                 cp $(CONFIG_DEFCONFIG) .config; \
245         fi
246
247 menuconfig: scripts/config/mconf
248         @./scripts/config/mconf $(CONFIG_CONFIG_IN)
249
250 config: scripts/config/conf
251         @./scripts/config/conf $(CONFIG_CONFIG_IN)
252
253 oldconfig: scripts/config/conf
254         @./scripts/config/conf -o $(CONFIG_CONFIG_IN)
255
256 randconfig: scripts/config/conf
257         @./scripts/config/conf -r $(CONFIG_CONFIG_IN)
258
259 allyesconfig: scripts/config/conf
260         @./scripts/config/conf -y $(CONFIG_CONFIG_IN)
261         sed -i -e "s/^CONFIG_DEBUG.*/# CONFIG_DEBUG is not set/" .config
262         sed -i -e "s/^USING_CROSS_COMPILER.*/# USING_CROSS_COMPILER is not set/" .config
263         sed -i -e "s/^CONFIG_STATIC.*/# CONFIG_STATIC is not set/" .config
264         sed -i -e "s/^CONFIG_SELINUX.*/# CONFIG_SELINUX is not set/" .config
265         @./scripts/config/conf -o $(CONFIG_CONFIG_IN)
266
267 allnoconfig: scripts/config/conf
268         @./scripts/config/conf -n $(CONFIG_CONFIG_IN)
269
270 defconfig: scripts/config/conf
271         @./scripts/config/conf -d $(CONFIG_CONFIG_IN)
272
273 clean:
274         - rm -f docs/busybox.dvi docs/busybox.ps \
275             docs/busybox.pod docs/busybox.net/busybox.html \
276             docs/busybox pod2htm* *.gdb *.elf *~ core .*config.log \
277             docs/BusyBox.txt docs/BusyBox.1 docs/BusyBox.html \
278             docs/busybox.net/BusyBox.html busybox.links libbb/loop.h \
279             .config.old .hdepend busybox
280         - rm -rf _install
281         - find . -name .\*.flags -exec rm -f {} \;
282         - find . -name \*.o -exec rm -f {} \;
283         - find . -name \*.a -exec rm -f {} \;
284
285 distclean: clean
286         - rm -f scripts/split-include scripts/mkdep
287         - rm -rf include/config include/config.h include/bb_config.h
288         - find . -name .depend -exec rm -f {} \;
289         rm -f .config .config.old .config.cmd
290         - $(MAKE) -C scripts/config clean
291
292 release: distclean #doc
293         cd ..;                                  \
294         rm -rf $(PROG)-$(VERSION);              \
295         cp -a busybox $(PROG)-$(VERSION);       \
296                                                 \
297         find $(PROG)-$(VERSION)/ -type d        \
298                                  -name CVS      \
299                                  -print         \
300                 -exec rm -rf {} \; ;            \
301                                                 \
302         find $(PROG)-$(VERSION)/ -type f        \
303                                  -name .\#*     \
304                                  -print         \
305                 -exec rm -f {} \;  ;            \
306                                                 \
307         tar -cvzf $(PROG)-$(VERSION).tar.gz $(PROG)-$(VERSION)/;
308
309 tags:
310         ctags -R .
311
312
313 endif # ifeq ($(strip $(HAVE_DOT_CONFIG)),y)
314
315 endif # ifeq ($(skip-makefile),)
316
317 .PHONY: dummy subdirs release distclean clean config oldconfig \
318         menuconfig tags check test depend buildtree
319