Completely rework the config system so that it no longer annoys me to work on
[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 pwd_grp pwd_grp/libpwd_grp shell shellutils sysklogd \
26         textutils util-linux libbb
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) $(libraries-y) $(LIBRARIES) -o $@
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 install-hardlinks: applets/install.sh busybox busybox.links
60         $(SHELL) $< $(PREFIX) --hardlinks
61
62
63 # Documentation Targets
64 doc: olddoc
65
66 # Old Docs...
67 olddoc: docs/busybox.pod docs/BusyBox.txt docs/BusyBox.1 docs/BusyBox.html
68
69 docs/busybox.pod : docs/busybox_header.pod include/usage.h docs/busybox_footer.pod
70         - ( cat docs/busybox_header.pod; \
71             docs/autodocifier.pl include/usage.h; \
72             cat docs/busybox_footer.pod ) > docs/busybox.pod
73
74 docs/BusyBox.txt: docs/busybox.pod
75         @echo
76         @echo BusyBox Documentation
77         @echo
78         -mkdir -p docs
79         -pod2text $< > $@
80
81 docs/BusyBox.1: docs/busybox.pod
82         - mkdir -p docs
83         - pod2man --center=BusyBox --release="version $(VERSION)" \
84                 $< > $@
85
86 docs/BusyBox.html: docs/busybox.net/BusyBox.html
87         - mkdir -p docs
88         -@ rm -f docs/BusyBox.html
89         -@ ln -s busybox.net/BusyBox.html docs/BusyBox.html
90
91 docs/busybox.net/BusyBox.html: docs/busybox.pod
92         -@ mkdir -p docs/busybox.net
93         -  pod2html --noindex $< > \
94             docs/busybox.net/BusyBox.html
95         -@ rm -f pod2htm*
96
97
98 # New docs based on DOCBOOK SGML
99 newdoc: docs/busybox.txt docs/busybox.pdf docs/busybox/busyboxdocumentation.html
100
101 docs/busybox.txt: docs/busybox.sgml
102         @echo
103         @echo BusyBox Documentation
104         @echo
105         - mkdir -p docs
106         (cd docs; sgmltools -b txt busybox.sgml)
107
108 docs/busybox.dvi: docs/busybox.sgml
109         - mkdir -p docs
110         (cd docs; sgmltools -b dvi busybox.sgml)
111
112 docs/busybox.ps: docs/busybox.sgml
113         - mkdir -p docs
114         (cd docs; sgmltools -b ps busybox.sgml)
115
116 docs/busybox.pdf: docs/busybox.ps
117         - mkdir -p docs
118         (cd docs; ps2pdf busybox.ps)
119
120 docs/busybox/busyboxdocumentation.html: docs/busybox.sgml
121         - mkdir -p docs
122         (cd docs/busybox.net; sgmltools -b html ../busybox.sgml)
123
124
125
126 # The nifty new buildsystem stuff
127 $(TOPDIR)scripts/mkdep: scripts/mkdep.c
128         $(HOSTCC) $(HOSTCFLAGS) -o scripts/mkdep scripts/mkdep.c
129
130 $(TOPDIR)scripts/split-include: scripts/split-include.c
131         $(HOSTCC) $(HOSTCFLAGS) -o scripts/split-include scripts/split-include.c
132
133 $(TOPDIR).depend: $(TOPDIR)scripts/mkdep
134         rm -f .depend .hdepend;
135         mkdir -p $(TOPDIR)include/config;
136         $(HOSTCC) $(HOSTCFLAGS) -o scripts/mkdep scripts/mkdep.c
137         scripts/mkdep -I $(TOPDIR)include -- \
138                 `find $(TOPDIR) -name \*.c -print` >> .depend;
139         scripts/mkdep -I $(TOPDIR)include -- \
140                 `find $(TOPDIR) -name \*.h -print` >> .hdepend;
141         $(MAKE) $(patsubst %,_sfdep_%,$(SUBDIRS)) _FASTDEP_ALL_SUB_DIRS="$(SUBDIRS)" ;
142         @ echo -e "\n\nNow run 'make' to build BusyBox\n\n"
143
144 depend dep: $(TOPDIR)include/config.h $(TOPDIR).depend
145
146 BB_SHELL := ${shell if [ -x "$$BASH" ]; then echo $$BASH; \
147         else if [ -x /bin/bash ]; then echo /bin/bash; \
148         else echo sh; fi ; fi}
149
150 include/config/MARKER: depend $(TOPDIR)scripts/split-include
151         scripts/split-include include/config.h include/config
152         @ touch include/config/MARKER
153
154 $(TOPDIR)include/config.h:
155         @if [ ! -f $(TOPDIR)include/config.h ] ; then \
156                 make oldconfig; \
157         fi;
158
159 menuconfig:
160         mkdir -p $(TOPDIR)include/config
161         $(MAKE) -C scripts/lxdialog all
162         $(BB_SHELL) scripts/Menuconfig sysdeps/$(TARGET_OS)/config.in
163
164 config:
165         mkdir -p $(TOPDIR)include/config
166         $(BB_SHELL) scripts/Configure sysdeps/$(TARGET_OS)/config.in
167
168 oldconfig:
169         mkdir -p $(TOPDIR)include/config
170         $(BB_SHELL) scripts/Configure -d sysdeps/$(TARGET_OS)/config.in
171
172
173 ifdef CONFIGURATION
174 ..$(CONFIGURATION):
175         @echo
176         @echo "You have a bad or nonexistent" .$(CONFIGURATION) ": running 'make" $(CONFIGURATION)"'"
177         @echo
178         $(MAKE) $(CONFIGURATION)
179         @echo
180         @echo "Successful. Try re-making (ignore the error that follows)"
181         @echo
182         exit 1
183
184 dummy:
185
186 else
187
188 dummy:
189
190 endif
191
192
193 %.o: %.c
194         $(CC) $(CFLAGS) $(EXTRA_CFLAGS) -c -o $@ $<
195
196
197 # Testing...
198 test tests:
199         # old way of doing it
200         #cd tests && $(MAKE) all
201         # new way of doing it
202         cd tests && ./tester.sh
203
204 # Cleanup
205 clean:
206         - $(MAKE) -C tests clean
207         - $(MAKE) -C scripts/lxdialog clean
208         - rm -f docs/BusyBox.txt docs/BusyBox.1 docs/BusyBox.html \
209             docs/busybox.net/BusyBox.html
210         - rm -f docs/busybox.txt docs/busybox.dvi docs/busybox.ps \
211             docs/busybox.pdf docs/busybox.net/busybox.html \
212             docs/busybox _install pod2htm* *.gdb *.elf *~ core
213         - rm -f busybox busybox.links libbb/loop.h .config.old .hdepend
214         - rm -f scripts/split-include scripts/mkdep .*config.log
215         - rm -rf include/config include/config.h
216         - find -name .\*.flags -o -name .depend -exec rm -f {} \;
217         - find -name \*.o -exec rm -f {} \;
218         - find -name \*.a -exec rm -f {} \;
219
220 distclean: clean
221         - rm -f busybox 
222         - cd tests && $(MAKE) distclean
223
224 dist release: distclean doc
225         cd ..;                                  \
226         rm -rf busybox-$(VERSION);              \
227         cp -a busybox busybox-$(VERSION);       \
228                                                 \
229         find busybox-$(VERSION)/ -type d        \
230                                  -name CVS      \
231                                  -print         \
232                 -exec rm -rf {} \; ;            \
233                                                 \
234         find busybox-$(VERSION)/ -type f        \
235                                  -name .\#*     \
236                                  -print         \
237                 -exec rm -f {} \;  ;            \
238                                                 \
239         tar -cvzf busybox-$(VERSION).tar.gz busybox-$(VERSION)/;
240
241
242
243 .PHONY: tags check depend
244
245 tags:
246         ctags -R .
247
248 check: busybox
249         cd testsuite && ./runtest
250