Apply patch from Felipe Kellermann to simlify logic of sort functions.
[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 ifeq ($(strip $(CONFIG_FEATURE_SUID)),y)
61         @echo
62         @echo
63         @echo --------------------------------------------------
64         @echo You will probably need to make your busybox binary
65         @echo setuid root to ensure all configured applets will
66         @echo work properly.
67         @echo --------------------------------------------------
68         @echo
69 endif
70
71 uninstall: busybox.links
72         rm -f $(PREFIX)/bin/busybox
73         for i in `cat busybox.links` ; do rm -f $(PREFIX)$$i; done
74
75 install-hardlinks: applets/install.sh busybox busybox.links
76         $(SHELL) $< $(PREFIX) --hardlinks
77
78
79 # Documentation Targets
80 doc: docs/busybox.pod docs/BusyBox.txt docs/BusyBox.1 docs/BusyBox.html
81
82 docs/busybox.pod : docs/busybox_header.pod include/usage.h docs/busybox_footer.pod
83         - ( cat docs/busybox_header.pod; \
84             docs/autodocifier.pl include/usage.h; \
85             cat docs/busybox_footer.pod ) > docs/busybox.pod
86
87 docs/BusyBox.txt: docs/busybox.pod
88         @echo
89         @echo BusyBox Documentation
90         @echo
91         -mkdir -p docs
92         -pod2text $< > $@
93
94 docs/BusyBox.1: docs/busybox.pod
95         - mkdir -p docs
96         - pod2man --center=BusyBox --release="version $(VERSION)" \
97                 $< > $@
98
99 docs/BusyBox.html: docs/busybox.net/BusyBox.html
100         - mkdir -p docs
101         -@ rm -f docs/BusyBox.html
102         -@ ln -s busybox.net/BusyBox.html docs/BusyBox.html
103
104 docs/busybox.net/BusyBox.html: docs/busybox.pod
105         -@ mkdir -p docs/busybox.net
106         -  pod2html --noindex $< > \
107             docs/busybox.net/BusyBox.html
108         -@ rm -f pod2htm*
109
110 # The nifty new buildsystem stuff
111 scripts/mkdep: scripts/mkdep.c
112         $(HOSTCC) $(HOSTCFLAGS) -o scripts/mkdep scripts/mkdep.c
113
114 scripts/split-include: scripts/split-include.c
115         $(HOSTCC) $(HOSTCFLAGS) -o scripts/split-include scripts/split-include.c
116
117 .depend: scripts/mkdep
118         rm -f .depend .hdepend;
119         mkdir -p include/config;
120         $(HOSTCC) $(HOSTCFLAGS) -o scripts/mkdep scripts/mkdep.c
121         scripts/mkdep -I include -- \
122                 `find -name \*.c -print | sed -e "s,^./,,"` >> .depend;
123         scripts/mkdep -I include -- \
124                 `find -name \*.h -print | sed -e "s,^./,,"` >> .hdepend;
125
126 depend dep: include/config.h .depend
127
128 include/config/MARKER: depend scripts/split-include
129         scripts/split-include include/config.h include/config
130         @ touch include/config/MARKER
131
132 include/config.h: .config
133         @if [ ! -x ./scripts/config/conf ] ; then \
134             $(MAKE) -C scripts/config conf; \
135         fi;
136         @./scripts/config/conf -o $(CONFIG_CONFIG_IN)
137
138 %.o: %.c
139         $(CC) $(CFLAGS) $(EXTRA_CFLAGS) -c -o $@ $<
140
141 finished2:
142         @echo
143         @echo Finished installing...
144         @echo
145
146 else # ifeq ($(strip $(HAVE_DOT_CONFIG)),y)
147
148 all: menuconfig
149
150 # configuration
151 # ---------------------------------------------------------------------------
152
153 scripts/config/conf:
154         $(MAKE) -C scripts/config conf
155         -@if [ ! -f .config ] ; then \
156                 cp $(CONFIG_DEFCONFIG) .config; \
157         fi
158 scripts/config/mconf:
159         $(MAKE) -C scripts/config ncurses conf mconf
160         -@if [ ! -f .config ] ; then \
161                 cp $(CONFIG_DEFCONFIG) .config; \
162         fi
163
164 menuconfig: scripts/config/mconf
165         @./scripts/config/mconf $(CONFIG_CONFIG_IN)
166
167 config: scripts/config/conf
168         @./scripts/config/conf $(CONFIG_CONFIG_IN)
169
170 oldconfig: scripts/config/conf
171         @./scripts/config/conf -o $(CONFIG_CONFIG_IN)
172
173 randconfig: scripts/config/conf
174         @./scripts/config/conf -r $(CONFIG_CONFIG_IN)
175
176 allyesconfig: scripts/config/conf
177         @./scripts/config/conf -y $(CONFIG_CONFIG_IN)
178         sed -i -e "s/^CONFIG_DEBUG.*/# CONFIG_DEBUG is not set/" .config
179         sed -i -e "s/^USING_CROSS_COMPILER.*/# USING_CROSS_COMPILER is not set/" .config
180         sed -i -e "s/^CONFIG_STATIC.*/# CONFIG_STATIC is not set/" .config
181         sed -i -e "s/^CONFIG_SELINUX.*/# CONFIG_SELINUX is not set/" .config
182         @./scripts/config/conf -o $(CONFIG_CONFIG_IN)
183
184 allnoconfig: scripts/config/conf
185         @./scripts/config/conf -n $(CONFIG_CONFIG_IN)
186
187 defconfig: scripts/config/conf
188         @./scripts/config/conf -d $(CONFIG_CONFIG_IN)
189
190 check: busybox
191         cd testsuite && ./runtest
192
193 clean:
194         - rm -f docs/busybox.dvi docs/busybox.ps \
195             docs/busybox.pod docs/busybox.net/busybox.html \
196             docs/busybox pod2htm* *.gdb *.elf *~ core .*config.log \
197             docs/BusyBox.txt docs/BusyBox.1 docs/BusyBox.html \
198             docs/busybox.net/BusyBox.html busybox.links libbb/loop.h \
199             .config.old .hdepend busybox
200         - rm -rf _install
201         - find . -name .\*.flags -exec rm -f {} \;
202         - find . -name \*.o -exec rm -f {} \;
203         - find . -name \*.a -exec rm -f {} \;
204
205 distclean: clean
206         - rm -f scripts/split-include scripts/mkdep
207         - rm -rf include/config include/config.h
208         - find . -name .depend -exec rm -f {} \;
209         rm -f .config .config.old .config.cmd
210         - $(MAKE) -C scripts/config clean
211
212 release: distclean #doc
213         cd ..;                                  \
214         rm -rf $(PROG)-$(VERSION);              \
215         cp -a busybox $(PROG)-$(VERSION);       \
216                                                 \
217         find $(PROG)-$(VERSION)/ -type d        \
218                                  -name CVS      \
219                                  -print         \
220                 -exec rm -rf {} \; ;            \
221                                                 \
222         find $(PROG)-$(VERSION)/ -type f        \
223                                  -name .\#*     \
224                                  -print         \
225                 -exec rm -f {} \;  ;            \
226                                                 \
227         tar -cvzf $(PROG)-$(VERSION).tar.gz $(PROG)-$(VERSION)/;
228
229 tags:
230         ctags -R .
231
232
233 endif # ifeq ($(strip $(HAVE_DOT_CONFIG)),y)
234
235 .PHONY: dummy subdirs release distclean clean config oldconfig \
236         menuconfig tags check test depend
237
238