Robin Farine writes:
[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: 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 # The nifty new buildsystem stuff
101 scripts/mkdep: scripts/mkdep.c
102         $(HOSTCC) $(HOSTCFLAGS) -o scripts/mkdep scripts/mkdep.c
103
104 scripts/split-include: scripts/split-include.c
105         $(HOSTCC) $(HOSTCFLAGS) -o scripts/split-include scripts/split-include.c
106
107 .depend: scripts/mkdep
108         rm -f .depend .hdepend;
109         mkdir -p include/config;
110         $(HOSTCC) $(HOSTCFLAGS) -o scripts/mkdep scripts/mkdep.c
111         scripts/mkdep -I include -- \
112                 `find -name \*.c -print | sed -e "s,^./,,"` >> .depend;
113         scripts/mkdep -I include -- \
114                 `find -name \*.h -print | sed -e "s,^./,,"` >> .hdepend;
115
116 depend dep: include/config.h .depend
117
118 include/config/MARKER: depend scripts/split-include
119         scripts/split-include include/config.h include/config
120         @ touch include/config/MARKER
121
122 include/config.h: .config
123         @if [ ! -x ./scripts/config/conf ] ; then \
124             $(MAKE) -C scripts/config conf; \
125         fi;
126         @./scripts/config/conf -o $(CONFIG_CONFIG_IN)
127
128 %.o: %.c
129         $(CC) $(CFLAGS) $(EXTRA_CFLAGS) -c -o $@ $<
130
131 finished2:
132         @echo
133         @echo Finished installing...
134         @echo
135
136 else # ifeq ($(strip $(HAVE_DOT_CONFIG)),y)
137
138 all: menuconfig
139
140 # configuration
141 # ---------------------------------------------------------------------------
142
143 scripts/config/conf:
144         $(MAKE) -C scripts/config conf
145         -@if [ ! -f .config ] ; then \
146                 cp $(CONFIG_DEFCONFIG) .config; \
147         fi
148 scripts/config/mconf:
149         $(MAKE) -C scripts/config ncurses conf mconf
150         -@if [ ! -f .config ] ; then \
151                 cp $(CONFIG_DEFCONFIG) .config; \
152         fi
153
154 menuconfig: scripts/config/mconf
155         @./scripts/config/mconf $(CONFIG_CONFIG_IN)
156
157 config: scripts/config/conf
158         @./scripts/config/conf $(CONFIG_CONFIG_IN)
159
160 oldconfig: scripts/config/conf
161         @./scripts/config/conf -o $(CONFIG_CONFIG_IN)
162
163 randconfig: scripts/config/conf
164         @./scripts/config/conf -r $(CONFIG_CONFIG_IN)
165
166 allyesconfig: scripts/config/conf
167         @./scripts/config/conf -y $(CONFIG_CONFIG_IN)
168         sed -i -e "s/^CONFIG_DEBUG.*/# CONFIG_DEBUG is not set/" .config
169         sed -i -e "s/^USING_CROSS_COMPILER.*/# USING_CROSS_COMPILER is not set/" .config
170         sed -i -e "s/^CONFIG_STATIC.*/# CONFIG_STATIC is not set/" .config
171         sed -i -e "s/^CONFIG_SELINUX.*/# CONFIG_SELINUX is not set/" .config
172         @./scripts/config/conf -o $(CONFIG_CONFIG_IN)
173
174 allnoconfig: scripts/config/conf
175         @./scripts/config/conf -n $(CONFIG_CONFIG_IN)
176
177 defconfig: scripts/config/conf
178         @./scripts/config/conf -d $(CONFIG_CONFIG_IN)
179
180 test tests: busybox
181         # Note that 'tests' is depricated.  Use 'make check' instead
182         # To use the nice new testsuite....
183         cd tests && ./tester.sh
184
185 check: busybox
186         cd testsuite && ./runtest
187
188 clean:
189         - $(MAKE) -C tests clean
190         - rm -f docs/busybox.dvi docs/busybox.ps \
191             docs/busybox.pod docs/busybox.net/busybox.html \
192             docs/busybox pod2htm* *.gdb *.elf *~ core .*config.log \
193             docs/BusyBox.txt docs/BusyBox.1 docs/BusyBox.html \
194             docs/busybox.net/BusyBox.html busybox.links libbb/loop.h \
195             .config.old .hdepend busybox
196         - rm -rf _install
197         - find . -name .\*.flags -exec rm -f {} \;
198         - find . -name \*.o -exec rm -f {} \;
199         - find . -name \*.a -exec rm -f {} \;
200
201 distclean: clean
202         - rm -f scripts/split-include scripts/mkdep
203         - rm -rf include/config include/config.h
204         - find . -name .depend -exec rm -f {} \;
205         rm -f .config .config.old .config.cmd
206         - $(MAKE) -C scripts/config clean
207
208 release: distclean #doc
209         cd ..;                                  \
210         rm -rf $(PROG)-$(VERSION);              \
211         cp -a busybox $(PROG)-$(VERSION);       \
212                                                 \
213         find $(PROG)-$(VERSION)/ -type d        \
214                                  -name CVS      \
215                                  -print         \
216                 -exec rm -rf {} \; ;            \
217                                                 \
218         find $(PROG)-$(VERSION)/ -type f        \
219                                  -name .\#*     \
220                                  -print         \
221                 -exec rm -f {} \;  ;            \
222                                                 \
223         tar -cvzf $(PROG)-$(VERSION).tar.gz $(PROG)-$(VERSION)/;
224
225 tags:
226         ctags -R .
227
228
229 endif # ifeq ($(strip $(HAVE_DOT_CONFIG)),y)
230
231 .PHONY: dummy subdirs release distclean clean config oldconfig \
232         menuconfig tags check test tests depend
233
234