Fix it so build dependancies actually work and do something useful
[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 TOPDIR=./
27 include Rules.mak
28
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 libpwdgrp coreutils/libcoreutils libbb
33
34 ifeq ($(strip $(CONFIG_SELINUX)),y)
35 CFLAGS += -I/usr/include/selinux
36 LIBRARIES += -lsecure
37 endif
38
39 CONFIG_CONFIG_IN = sysdeps/$(TARGET_OS)/Config.in
40 CONFIG_DEFCONFIG = sysdeps/$(TARGET_OS)/defconfig
41
42 ifeq ($(strip $(HAVE_DOT_CONFIG)),y)
43
44 all: busybox busybox.links doc
45
46 # In this section, we need .config
47 -include .config.cmd
48 include $(patsubst %,%/Makefile.in, $(DIRS))
49 -include $(TOPDIR).depend
50
51 busybox: .depend include/config.h $(libraries-y)
52         $(CC) $(LDFLAGS) -o $@ -Wl,--start-group $(libraries-y) $(LIBRARIES) -Wl,--end-group
53         $(STRIPCMD) $@
54
55 busybox.links: applets/busybox.mkll include/config.h
56         - $(SHELL) $^ >$@
57
58 install: applets/install.sh busybox busybox.links
59         $(SHELL) $< $(PREFIX)
60
61 uninstall: busybox.links
62         rm -f $(PREFIX)/bin/busybox
63         for i in `cat busybox.links` ; do rm -f $(PREFIX)$$i; done
64
65 install-hardlinks: applets/install.sh busybox busybox.links
66         $(SHELL) $< $(PREFIX) --hardlinks
67
68
69 # Documentation Targets
70 doc: olddoc
71
72 # Old Docs...
73 olddoc: docs/busybox.pod docs/BusyBox.txt docs/BusyBox.1 docs/BusyBox.html
74
75 docs/busybox.pod : docs/busybox_header.pod include/usage.h docs/busybox_footer.pod
76         - ( cat docs/busybox_header.pod; \
77             docs/autodocifier.pl include/usage.h; \
78             cat docs/busybox_footer.pod ) > docs/busybox.pod
79
80 docs/BusyBox.txt: docs/busybox.pod
81         @echo
82         @echo BusyBox Documentation
83         @echo
84         -mkdir -p docs
85         -pod2text $< > $@
86
87 docs/BusyBox.1: docs/busybox.pod
88         - mkdir -p docs
89         - pod2man --center=BusyBox --release="version $(VERSION)" \
90                 $< > $@
91
92 docs/BusyBox.html: docs/busybox.net/BusyBox.html
93         - mkdir -p docs
94         -@ rm -f docs/BusyBox.html
95         -@ ln -s busybox.net/BusyBox.html docs/BusyBox.html
96
97 docs/busybox.net/BusyBox.html: docs/busybox.pod
98         -@ mkdir -p docs/busybox.net
99         -  pod2html --noindex $< > \
100             docs/busybox.net/BusyBox.html
101         -@ rm -f pod2htm*
102
103
104 # New docs based on DOCBOOK SGML
105 newdoc: docs/busybox.txt docs/busybox.pdf docs/busybox/busyboxdocumentation.html
106
107 docs/busybox.txt: docs/busybox.sgml
108         @echo
109         @echo BusyBox Documentation
110         @echo
111         - mkdir -p docs
112         (cd docs; sgmltools -b txt busybox.sgml)
113
114 docs/busybox.dvi: docs/busybox.sgml
115         - mkdir -p docs
116         (cd docs; sgmltools -b dvi busybox.sgml)
117
118 docs/busybox.ps: docs/busybox.sgml
119         - mkdir -p docs
120         (cd docs; sgmltools -b ps busybox.sgml)
121
122 docs/busybox.pdf: docs/busybox.ps
123         - mkdir -p docs
124         (cd docs; ps2pdf busybox.ps)
125
126 docs/busybox/busyboxdocumentation.html: docs/busybox.sgml
127         - mkdir -p docs
128         (cd docs/busybox.net; sgmltools -b html ../busybox.sgml)
129
130 # The nifty new buildsystem stuff
131 scripts/mkdep: scripts/mkdep.c
132         $(HOSTCC) $(HOSTCFLAGS) -o scripts/mkdep scripts/mkdep.c
133
134 scripts/split-include: scripts/split-include.c
135         $(HOSTCC) $(HOSTCFLAGS) -o scripts/split-include scripts/split-include.c
136
137 .depend: scripts/mkdep
138         rm -f .depend .hdepend;
139         mkdir -p include/config;
140         $(HOSTCC) $(HOSTCFLAGS) -o scripts/mkdep scripts/mkdep.c
141         scripts/mkdep -I include -- \
142                 `find -name \*.c -print | sed -e "s,^./,,"` >> .depend;
143         scripts/mkdep -I include -- \
144                 `find -name \*.h -print | sed -e "s,^./,,"` >> .hdepend;
145
146 depend dep: include/config.h .depend
147
148 include/config/MARKER: depend scripts/split-include
149         scripts/split-include include/config.h include/config
150         @ touch include/config/MARKER
151
152 include/config.h: .config
153         @if [ ! -x ./scripts/config/conf ] ; then \
154             $(MAKE) -C scripts/config conf; \
155         fi;
156         @./scripts/config/conf -o $(CONFIG_CONFIG_IN)
157
158 %.o: %.c
159         $(CC) $(CFLAGS) $(EXTRA_CFLAGS) -c -o $@ $<
160
161 finished2:
162         @echo
163         @echo Finished installing...
164         @echo
165
166 else # ifeq ($(strip $(HAVE_DOT_CONFIG)),y)
167
168 all: menuconfig
169
170 # configuration
171 # ---------------------------------------------------------------------------
172
173 scripts/config/conf:
174         $(MAKE) -C scripts/config conf
175         -@if [ ! -f .config ] ; then \
176                 cp $(CONFIG_DEFCONFIG) .config; \
177         fi
178 scripts/config/mconf:
179         $(MAKE) -C scripts/config ncurses conf mconf
180         -@if [ ! -f .config ] ; then \
181                 cp $(CONFIG_DEFCONFIG) .config; \
182         fi
183
184 menuconfig: scripts/config/mconf
185         @./scripts/config/mconf $(CONFIG_CONFIG_IN)
186
187 config: scripts/config/conf
188         @./scripts/config/conf $(CONFIG_CONFIG_IN)
189
190 oldconfig: scripts/config/conf
191         @./scripts/config/conf -o $(CONFIG_CONFIG_IN)
192
193 randconfig: scripts/config/conf
194         @./scripts/config/conf -r $(CONFIG_CONFIG_IN)
195
196 allyesconfig: scripts/config/conf
197         @./scripts/config/conf -y $(CONFIG_CONFIG_IN)
198         sed -i -e "s/^CONFIG_DEBUG.*/# CONFIG_DEBUG is not set/" .config
199         sed -i -e "s/^USING_CROSS_COMPILER.*/# USING_CROSS_COMPILER is not set/" .config
200         sed -i -e "s/^CONFIG_STATIC.*/# CONFIG_STATIC is not set/" .config
201         sed -i -e "s/^CONFIG_SELINUX.*/# CONFIG_SELINUX is not set/" .config
202         @./scripts/config/conf -o $(CONFIG_CONFIG_IN)
203
204 allnoconfig: scripts/config/conf
205         @./scripts/config/conf -n $(CONFIG_CONFIG_IN)
206
207 defconfig: scripts/config/conf
208         @./scripts/config/conf -d $(CONFIG_CONFIG_IN)
209
210 test tests: busybox
211         # Note that 'tests' is depricated.  Use 'make check' instead
212         # To use the nice new testsuite....
213         cd tests && ./tester.sh
214
215 check: busybox
216         cd testsuite && ./runtest
217
218 clean:
219         - $(MAKE) -C tests clean
220         - rm -f docs/busybox.txt docs/busybox.dvi docs/busybox.ps \
221             docs/busybox.pdf docs/busybox.pod docs/busybox.net/busybox.html \
222             docs/busybox pod2htm* *.gdb *.elf *~ core .*config.log \
223             docs/BusyBox.txt docs/BusyBox.1 docs/BusyBox.html \
224             docs/busybox.net/BusyBox.html busybox.links libbb/loop.h \
225             .config.old .hdepend busybox
226         - rm -rf _install
227         - find . -name .\*.flags -exec rm -f {} \;
228         - find . -name \*.o -exec rm -f {} \;
229         - find . -name \*.a -exec rm -f {} \;
230
231 distclean: clean
232         - rm -f scripts/split-include scripts/mkdep
233         - rm -rf include/config include/config.h
234         - find . -name .depend -exec rm -f {} \;
235         rm -f .config .config.old .config.cmd
236         - $(MAKE) -C scripts/config clean
237
238 release: distclean #doc
239         cd ..;                                  \
240         rm -rf $(PROG)-$(VERSION);              \
241         cp -a busybox $(PROG)-$(VERSION);       \
242                                                 \
243         find $(PROG)-$(VERSION)/ -type d        \
244                                  -name CVS      \
245                                  -print         \
246                 -exec rm -rf {} \; ;            \
247                                                 \
248         find $(PROG)-$(VERSION)/ -type f        \
249                                  -name .\#*     \
250                                  -print         \
251                 -exec rm -f {} \;  ;            \
252                                                 \
253         tar -cvzf $(PROG)-$(VERSION).tar.gz $(PROG)-$(VERSION)/;
254
255 tags:
256         ctags -R .
257
258
259 endif # ifeq ($(strip $(HAVE_DOT_CONFIG)),y)
260
261 .PHONY: dummy subdirs release distclean clean config oldconfig \
262         menuconfig tags check test tests depend
263
264