This commit was manufactured by cvs2svn to create tag 'busybox_1_00'.
[oweals/busybox.git] / busybox / 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 libpwdgrp coreutils/libcoreutils libbb
46
47 SRC_DIRS:=$(patsubst %,$(top_srcdir)/%,$(DIRS))
48
49 ifeq ($(strip $(CONFIG_SELINUX)),y)
50 CFLAGS += -I/usr/include/selinux
51 LIBRARIES += -lsecure
52 endif
53
54 CONFIG_CONFIG_IN = $(top_srcdir)/sysdeps/$(TARGET_OS)/Config.in
55 CONFIG_DEFCONFIG = $(top_srcdir)/sysdeps/$(TARGET_OS)/defconfig
56
57 ALL_DIRS:= $(DIRS) scripts/config
58 ALL_MAKEFILES:=$(patsubst %,%/Makefile,$(ALL_DIRS))
59
60 ifeq ($(KBUILD_SRC),)
61
62 ifdef O
63   ifeq ("$(origin O)", "command line")
64     KBUILD_OUTPUT := $(O)
65   endif
66 endif
67
68 # That's our default target when none is given on the command line
69 .PHONY: _all
70 _all:
71
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))
79
80 .PHONY: $(MAKECMDGOALS)
81
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 $@
89
90 $(KBUILD_OUTPUT)/Rules.mak:
91         @echo > $@
92         @echo top_srcdir=$(CURDIR) >> $@
93         @echo top_builddir=$(KBUILD_OUTPUT) >> $@
94         @echo include $(top_srcdir)/Rules.mak >> $@
95
96 $(KBUILD_OUTPUT)/Makefile:
97         @echo > $@
98         @echo top_srcdir=$(CURDIR) >> $@
99         @echo top_builddir=$(KBUILD_OUTPUT) >> $@
100         @echo KBUILD_SRC='$$(top_srcdir)' >> $@
101         @echo include '$$(KBUILD_SRC)'/Makefile >> $@
102
103 # Leave processing to above invocation of make
104 skip-makefile := 1
105 endif # ifneq ($(KBUILD_OUTPUT),)
106 endif # ifeq ($(KBUILD_SRC),)
107
108 ifeq ($(skip-makefile),)
109
110 _all: all
111
112 ifeq ($(strip $(HAVE_DOT_CONFIG)),y)
113
114 all: busybox busybox.links doc
115
116 all_tree:       $(ALL_MAKEFILES)
117
118 $(ALL_MAKEFILES): %/Makefile: $(top_srcdir)/%/Makefile
119         d=`dirname $@`; [ -d "$$d" ] || mkdir -p "$$d"; cp $< $@
120
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
125
126 busybox: $(ALL_MAKEFILES) .depend include/config.h $(libraries-y)
127         $(CC) $(LDFLAGS) -o $@ -Wl,--start-group $(libraries-y) $(LIBRARIES) -Wl,--end-group
128         $(STRIPCMD) $@
129
130 busybox.links: $(top_srcdir)/applets/busybox.mkll include/config.h $(top_srcdir)/include/applets.h
131         - $(SHELL) $^ >$@
132
133 install: applets/install.sh busybox busybox.links
134         $(SHELL) $< $(PREFIX)
135 ifeq ($(strip $(CONFIG_FEATURE_SUID)),y)
136         @echo
137         @echo
138         @echo --------------------------------------------------
139         @echo You will probably need to make your busybox binary
140         @echo setuid root to ensure all configured applets will
141         @echo work properly.
142         @echo --------------------------------------------------
143         @echo
144 endif
145
146 uninstall: busybox.links
147         rm -f $(PREFIX)/bin/busybox
148         for i in `cat busybox.links` ; do rm -f $(PREFIX)$$i; done
149
150 install-hardlinks: applets/install.sh busybox busybox.links
151         $(SHELL) $< $(PREFIX) --hardlinks
152
153 check: busybox
154         bindir=$(top_builddir) srcdir=$(top_srcdir)/testsuite \
155         $(top_srcdir)/testsuite/runtest
156
157 # Documentation Targets
158 doc: docs/busybox.pod docs/BusyBox.txt docs/BusyBox.1 docs/BusyBox.html
159
160 docs/busybox.pod : $(top_srcdir)/docs/busybox_header.pod $(top_srcdir)/include/usage.h $(top_srcdir)/docs/busybox_footer.pod
161         -mkdir -p docs
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
165
166 docs/BusyBox.txt: docs/busybox.pod
167         @echo
168         @echo BusyBox Documentation
169         @echo
170         -mkdir -p docs
171         -pod2text $< > $@
172
173 docs/BusyBox.1: docs/busybox.pod
174         - mkdir -p docs
175         - pod2man --center=BusyBox --release="version $(VERSION)" \
176                 $< > $@
177
178 docs/BusyBox.html: docs/busybox.net/BusyBox.html
179         - mkdir -p docs
180         -@ rm -f docs/BusyBox.html
181         -@ cp docs/busybox.net/BusyBox.html docs/BusyBox.html
182
183 docs/busybox.net/BusyBox.html: docs/busybox.pod
184         -@ mkdir -p docs/busybox.net
185         -  pod2html --noindex $< > \
186             docs/busybox.net/BusyBox.html
187         -@ rm -f pod2htm*
188
189 # The nifty new buildsystem stuff
190 scripts/mkdep: $(top_srcdir)/scripts/mkdep.c
191         $(HOSTCC) $(HOSTCFLAGS) -o $@ $<
192
193 scripts/split-include: $(top_srcdir)/scripts/split-include.c
194         $(HOSTCC) $(HOSTCFLAGS) -o $@ $<
195
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;
203
204 depend dep: include/config.h .depend
205
206 include/config/MARKER: depend scripts/split-include
207         scripts/split-include include/config.h include/config
208         @ touch include/config/MARKER
209
210 include/config.h: .config
211         @if [ ! -x $(top_builddir)/scripts/config/conf ] ; then \
212             $(MAKE) -C scripts/config conf; \
213         fi;
214         @$(top_builddir)/scripts/config/conf -o $(CONFIG_CONFIG_IN)
215
216 finished2:
217         @echo
218         @echo Finished installing...
219         @echo
220
221 else # ifeq ($(strip $(HAVE_DOT_CONFIG)),y)
222
223 all: menuconfig
224
225 # configuration
226 # ---------------------------------------------------------------------------
227
228 $(ALL_MAKEFILES): %/Makefile: $(top_srcdir)/%/Makefile
229         d=`dirname $@`; [ -d "$$d" ] || mkdir -p "$$d"; cp $< $@
230
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; \
235         fi
236
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; \
241         fi
242
243 menuconfig: scripts/config/mconf
244         @./scripts/config/mconf $(CONFIG_CONFIG_IN)
245
246 config: scripts/config/conf
247         @./scripts/config/conf $(CONFIG_CONFIG_IN)
248
249 oldconfig: scripts/config/conf
250         @./scripts/config/conf -o $(CONFIG_CONFIG_IN)
251
252 randconfig: scripts/config/conf
253         @./scripts/config/conf -r $(CONFIG_CONFIG_IN)
254
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)
262
263 allnoconfig: scripts/config/conf
264         @./scripts/config/conf -n $(CONFIG_CONFIG_IN)
265
266 defconfig: scripts/config/conf
267         @./scripts/config/conf -d $(CONFIG_CONFIG_IN)
268
269 clean:
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
276         - rm -rf _install
277         - find . -name .\*.flags -exec rm -f {} \;
278         - find . -name \*.o -exec rm -f {} \;
279         - find . -name \*.a -exec rm -f {} \;
280
281 distclean: clean
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
287
288 release: distclean #doc
289         cd ..;                                  \
290         rm -rf $(PROG)-$(VERSION);              \
291         cp -a busybox $(PROG)-$(VERSION);       \
292                                                 \
293         find $(PROG)-$(VERSION)/ -type d        \
294                                  -name CVS      \
295                                  -print         \
296                 -exec rm -rf {} \; ;            \
297                                                 \
298         find $(PROG)-$(VERSION)/ -type f        \
299                                  -name .\#*     \
300                                  -print         \
301                 -exec rm -f {} \;  ;            \
302                                                 \
303         tar -cvzf $(PROG)-$(VERSION).tar.gz $(PROG)-$(VERSION)/;
304
305 tags:
306         ctags -R .
307
308
309 endif # ifeq ($(strip $(HAVE_DOT_CONFIG)),y)
310
311 endif # ifeq ($(skip-makefile),)
312
313 .PHONY: dummy subdirs release distclean clean config oldconfig \
314         menuconfig tags check test depend buildtree
315