Add support for /etc/filesystem when searching for an "auto" filesystem
[oweals/busybox.git] / Makefile
1 # Makefile for busybox
2 #
3 # Copyright (C) 1999-2002 Erik Andersen <andersee@debian.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 TOPDIR:= $(shell /bin/pwd)/
21 include $(TOPDIR).config
22 include $(TOPDIR)Rules.mak
23 SUBDIRS:=applets archival archival/libunarchive console-tools \
24         editors fileutils findutils init miscutils modutils networking \
25         procps loginutils shell shellutils sysklogd \
26         textutils util-linux libbb libpwdgrp
27
28 all:    do-it-all
29
30 #
31 # Make "config" the default target if there is no configuration file or
32 # "depend" the target if there is no top-level dependency information.
33 ifeq (.config,$(wildcard .config))
34 include .config
35 ifeq (.depend,$(wildcard .depend))
36 include .depend 
37 do-it-all:      busybox busybox.links #doc
38 include $(patsubst %,%/Makefile.in, $(SUBDIRS))
39 else
40 CONFIGURATION = depend
41 do-it-all:      depend
42 endif
43 else
44 CONFIGURATION = menuconfig
45 do-it-all:      menuconfig
46 endif
47
48
49 busybox: depend $(libraries-y)
50         $(CC) $(LDFLAGS) -o $@ $(libraries-y) $(LIBRARIES)
51         $(STRIPCMD) $@
52
53 busybox.links: applets/busybox.mkll
54         - $(SHELL) $^ >$@
55
56 install: applets/install.sh busybox busybox.links
57         $(SHELL) $< $(PREFIX)
58
59 uninstall: busybox busybox.links
60         for i in `cat busybox.links` ; do rm -f $$PREFIX$$i; done
61
62 install-hardlinks: applets/install.sh busybox busybox.links
63         $(SHELL) $< $(PREFIX) --hardlinks
64
65
66 # Documentation Targets
67 doc: olddoc
68
69 # Old Docs...
70 olddoc: docs/busybox.pod docs/BusyBox.txt docs/BusyBox.1 docs/BusyBox.html
71
72 docs/busybox.pod : docs/busybox_header.pod include/usage.h docs/busybox_footer.pod
73         - ( cat docs/busybox_header.pod; \
74             docs/autodocifier.pl include/usage.h; \
75             cat docs/busybox_footer.pod ) > docs/busybox.pod
76
77 docs/BusyBox.txt: docs/busybox.pod
78         @echo
79         @echo BusyBox Documentation
80         @echo
81         -mkdir -p docs
82         -pod2text $< > $@
83
84 docs/BusyBox.1: docs/busybox.pod
85         - mkdir -p docs
86         - pod2man --center=BusyBox --release="version $(VERSION)" \
87                 $< > $@
88
89 docs/BusyBox.html: docs/busybox.net/BusyBox.html
90         - mkdir -p docs
91         -@ rm -f docs/BusyBox.html
92         -@ ln -s busybox.net/BusyBox.html docs/BusyBox.html
93
94 docs/busybox.net/BusyBox.html: docs/busybox.pod
95         -@ mkdir -p docs/busybox.net
96         -  pod2html --noindex $< > \
97             docs/busybox.net/BusyBox.html
98         -@ rm -f pod2htm*
99
100
101 # New docs based on DOCBOOK SGML
102 newdoc: docs/busybox.txt docs/busybox.pdf docs/busybox/busyboxdocumentation.html
103
104 docs/busybox.txt: docs/busybox.sgml
105         @echo
106         @echo BusyBox Documentation
107         @echo
108         - mkdir -p docs
109         (cd docs; sgmltools -b txt busybox.sgml)
110
111 docs/busybox.dvi: docs/busybox.sgml
112         - mkdir -p docs
113         (cd docs; sgmltools -b dvi busybox.sgml)
114
115 docs/busybox.ps: docs/busybox.sgml
116         - mkdir -p docs
117         (cd docs; sgmltools -b ps busybox.sgml)
118
119 docs/busybox.pdf: docs/busybox.ps
120         - mkdir -p docs
121         (cd docs; ps2pdf busybox.ps)
122
123 docs/busybox/busyboxdocumentation.html: docs/busybox.sgml
124         - mkdir -p docs
125         (cd docs/busybox.net; sgmltools -b html ../busybox.sgml)
126
127
128
129 # The nifty new buildsystem stuff
130 $(TOPDIR)scripts/mkdep: scripts/mkdep.c
131         $(HOSTCC) $(HOSTCFLAGS) -o scripts/mkdep scripts/mkdep.c
132
133 $(TOPDIR)scripts/split-include: scripts/split-include.c
134         $(HOSTCC) $(HOSTCFLAGS) -o scripts/split-include scripts/split-include.c
135
136 $(TOPDIR).depend: $(TOPDIR)scripts/mkdep
137         rm -f .depend .hdepend;
138         mkdir -p $(TOPDIR)include/config;
139         $(HOSTCC) $(HOSTCFLAGS) -o scripts/mkdep scripts/mkdep.c
140         scripts/mkdep -I $(TOPDIR)include -- \
141                 `find $(TOPDIR) -name \*.c -print` >> .depend;
142         scripts/mkdep -I $(TOPDIR)include -- \
143                 `find $(TOPDIR) -name \*.h -print` >> .hdepend;
144         $(MAKE) $(patsubst %,_sfdep_%,$(SUBDIRS)) _FASTDEP_ALL_SUB_DIRS="$(SUBDIRS)" ;
145         @ echo -e "\n\nNow run 'make' to build BusyBox\n\n"
146
147 depend dep: $(TOPDIR)include/config.h $(TOPDIR).depend
148
149 BB_SHELL := ${shell if [ -x "$$BASH" ]; then echo $$BASH; \
150         else if [ -x /bin/bash ]; then echo /bin/bash; \
151         else echo sh; fi ; fi}
152
153 include/config/MARKER: depend $(TOPDIR)scripts/split-include
154         scripts/split-include include/config.h include/config
155         @ touch include/config/MARKER
156
157 $(TOPDIR)include/config.h:
158         @if [ ! -f $(TOPDIR)include/config.h ] ; then \
159                 make oldconfig; \
160         fi;
161
162 $(TOPDIR).config:
163         @if [ ! -f $(TOPDIR).config ] ; then \
164             cp $(TOPDIR)sysdeps/$(TARGET_OS)/defconfig $(TOPDIR).config; \
165         fi;
166
167 menuconfig: $(TOPDIR).config
168         mkdir -p $(TOPDIR)include/config
169         $(MAKE) -C scripts/lxdialog all
170         $(BB_SHELL) scripts/Menuconfig sysdeps/$(TARGET_OS)/config.in
171
172 config: $(TOPDIR).config
173         mkdir -p $(TOPDIR)include/config
174         $(BB_SHELL) scripts/Configure sysdeps/$(TARGET_OS)/config.in
175
176 oldconfig: $(TOPDIR).config
177         mkdir -p $(TOPDIR)include/config
178         $(BB_SHELL) scripts/Configure -d sysdeps/$(TARGET_OS)/config.in
179
180
181 ifdef CONFIGURATION
182 ..$(CONFIGURATION):
183         @echo
184         @echo "You have a bad or nonexistent" .$(CONFIGURATION) ": running 'make" $(CONFIGURATION)"'"
185         @echo
186         $(MAKE) $(CONFIGURATION)
187         @echo
188         @echo "Successful. Try re-making (ignore the error that follows)"
189         @echo
190         exit 1
191
192 dummy:
193
194 else
195
196 dummy:
197
198 endif
199
200
201 %.o: %.c
202         $(CC) $(CFLAGS) $(EXTRA_CFLAGS) -c -o $@ $<
203
204
205 # Testing...
206 test tests:
207         # old way of doing it
208         #cd tests && $(MAKE) all
209         # new way of doing it
210         cd tests && ./tester.sh
211
212 # Cleanup
213 clean:
214         - $(MAKE) -C tests clean
215         - $(MAKE) -C scripts/lxdialog clean
216         - rm -f docs/BusyBox.txt docs/BusyBox.1 docs/BusyBox.html \
217             docs/busybox.net/BusyBox.html
218         - rm -f docs/busybox.txt docs/busybox.dvi docs/busybox.ps \
219             docs/busybox.pdf docs/busybox.net/busybox.html \
220             docs/busybox _install pod2htm* *.gdb *.elf *~ core
221         - rm -f busybox busybox.links libbb/loop.h .config.old .hdepend
222         - rm -f scripts/split-include scripts/mkdep .*config.log
223         - rm -rf include/config include/config.h
224         - find -name .\*.flags -exec rm -f {} \;   
225         - find -name .depend -exec rm -f {} \;
226         - find -name \*.o -exec rm -f {} \;
227         - find -name \*.a -exec rm -f {} \;
228
229 distclean: clean
230         - rm -f busybox 
231         - cd tests && $(MAKE) distclean
232
233 dist release: distclean doc
234         cd ..;                                  \
235         rm -rf busybox-$(VERSION);              \
236         cp -a busybox busybox-$(VERSION);       \
237                                                 \
238         find busybox-$(VERSION)/ -type d        \
239                                  -name CVS      \
240                                  -print         \
241                 -exec rm -rf {} \; ;            \
242                                                 \
243         find busybox-$(VERSION)/ -type f        \
244                                  -name .\#*     \
245                                  -print         \
246                 -exec rm -f {} \;  ;            \
247                                                 \
248         tar -cvzf busybox-$(VERSION).tar.gz busybox-$(VERSION)/;
249
250
251
252 .PHONY: tags check depend
253
254 tags:
255         ctags -R .
256
257 check: busybox
258         cd testsuite && ./runtest
259