f86ebedf7954c229cbcfef055e2d3c3130757066
[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 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         cp $(TOPDIR)sysdeps/$(TARGET_OS)/defconfig $(TOPDIR).config
164         mkdir -p $(TOPDIR)include/config
165         $(MAKE) -C scripts/lxdialog all
166         $(BB_SHELL) scripts/Menuconfig sysdeps/$(TARGET_OS)/config.in
167
168 menuconfig:
169         mkdir -p $(TOPDIR)include/config
170         $(MAKE) -C scripts/lxdialog all
171         $(BB_SHELL) scripts/Menuconfig sysdeps/$(TARGET_OS)/config.in
172
173 config:
174         mkdir -p $(TOPDIR)include/config
175         $(BB_SHELL) scripts/Configure sysdeps/$(TARGET_OS)/config.in
176
177 oldconfig:
178         mkdir -p $(TOPDIR)include/config
179         $(BB_SHELL) scripts/Configure -d sysdeps/$(TARGET_OS)/config.in
180
181
182 ifdef CONFIGURATION
183 ..$(CONFIGURATION):
184         @echo
185         @echo "You have a bad or nonexistent" .$(CONFIGURATION) ": running 'make" $(CONFIGURATION)"'"
186         @echo
187         $(MAKE) $(CONFIGURATION)
188         @echo
189         @echo "Successful. Try re-making (ignore the error that follows)"
190         @echo
191         exit 1
192
193 dummy:
194
195 else
196
197 dummy:
198
199 endif
200
201
202 %.o: %.c
203         $(CC) $(CFLAGS) $(EXTRA_CFLAGS) -c -o $@ $<
204
205
206 # Testing...
207 test tests:
208         # old way of doing it
209         #cd tests && $(MAKE) all
210         # new way of doing it
211         cd tests && ./tester.sh
212
213 # Cleanup
214 clean:
215         - $(MAKE) -C tests clean
216         - $(MAKE) -C scripts/lxdialog clean
217         - rm -f docs/BusyBox.txt docs/BusyBox.1 docs/BusyBox.html \
218             docs/busybox.net/BusyBox.html
219         - rm -f docs/busybox.txt docs/busybox.dvi docs/busybox.ps \
220             docs/busybox.pdf docs/busybox.net/busybox.html \
221             docs/busybox _install pod2htm* *.gdb *.elf *~ core
222         - rm -f busybox busybox.links libbb/loop.h .config.old .hdepend
223         - rm -f scripts/split-include scripts/mkdep .*config.log
224         - rm -rf include/config include/config.h
225         - find -name .\*.flags -exec rm -f {} \;   
226         - find -name .depend -exec rm -f {} \;
227         - find -name \*.o -exec rm -f {} \;
228         - find -name \*.a -exec rm -f {} \;
229
230 distclean: clean
231         - rm -f busybox 
232         - cd tests && $(MAKE) distclean
233
234 dist release: distclean doc
235         cd ..;                                  \
236         rm -rf busybox-$(VERSION);              \
237         cp -a busybox busybox-$(VERSION);       \
238                                                 \
239         find busybox-$(VERSION)/ -type d        \
240                                  -name CVS      \
241                                  -print         \
242                 -exec rm -rf {} \; ;            \
243                                                 \
244         find busybox-$(VERSION)/ -type f        \
245                                  -name .\#*     \
246                                  -print         \
247                 -exec rm -f {} \;  ;            \
248                                                 \
249         tar -cvzf busybox-$(VERSION).tar.gz busybox-$(VERSION)/;
250
251
252
253 .PHONY: tags check depend
254
255 tags:
256         ctags -R .
257
258 check: busybox
259         cd testsuite && ./runtest
260