a6356b70b693da208f051f558142401359a16ef4
[oweals/busybox.git] / Makefile
1 # Makefile for busybox
2 #
3 # Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
4 #
5 # Licensed under GPLv2, see the file LICENSE in this tarball for details.
6 #
7
8 #--------------------------------------------------------------
9 # You shouldn't need to mess with anything beyond this point...
10 #--------------------------------------------------------------
11 noconfig_targets := menuconfig config oldconfig randconfig \
12         defconfig allyesconfig allnoconfig clean distclean \
13         release tags
14
15 ifndef TOPDIR
16 TOPDIR=$(CURDIR)/
17 endif
18 ifndef top_srcdir
19 top_srcdir=$(CURDIR)
20 endif
21 ifndef top_builddir
22 top_builddir=$(CURDIR)
23 endif
24
25 export srctree=$(top_srcdir)
26 vpath %/Config.in $(srctree)
27
28 include $(top_srcdir)/Rules.mak
29
30 DIRS:=applets archival archival/libunarchive coreutils console-tools \
31         debianutils editors findutils init miscutils modutils networking \
32         networking/libiproute networking/udhcp procps loginutils shell \
33         sysklogd util-linux e2fsprogs libpwdgrp coreutils/libcoreutils libbb
34
35 SRC_DIRS:=$(patsubst %,$(top_srcdir)/%,$(DIRS))
36
37 ifeq ($(strip $(CONFIG_SELINUX)),y)
38 LIBRARIES += -lselinux
39 endif
40
41 CONFIG_CONFIG_IN = $(top_srcdir)/sysdeps/$(TARGET_OS)/Config.in
42 CONFIG_DEFCONFIG = $(top_srcdir)/sysdeps/$(TARGET_OS)/defconfig
43
44 ALL_DIRS:= $(DIRS) scripts/config
45 ALL_MAKEFILES:=$(patsubst %,%/Makefile,$(ALL_DIRS))
46
47 ifeq ($(KBUILD_SRC),)
48
49 ifdef O
50   ifeq ("$(origin O)", "command line")
51     KBUILD_OUTPUT := $(O)
52   endif
53 endif
54
55 # That's our default target when none is given on the command line
56 .PHONY: _all
57 _all:
58
59 ifneq ($(KBUILD_OUTPUT),)
60 # Invoke a second make in the output directory, passing relevant variables
61 # check that the output directory actually exists
62 saved-output := $(KBUILD_OUTPUT)
63 KBUILD_OUTPUT := $(shell cd $(KBUILD_OUTPUT) && /bin/pwd)
64 $(if $(wildcard $(KBUILD_OUTPUT)),, \
65      $(error output directory "$(saved-output)" does not exist))
66
67 .PHONY: $(MAKECMDGOALS)
68
69 $(filter-out _all,$(MAKECMDGOALS)) _all: $(KBUILD_OUTPUT)/Rules.mak $(KBUILD_OUTPUT)/Makefile
70         $(MAKE) -C $(KBUILD_OUTPUT) \
71         top_srcdir=$(CURDIR) \
72         top_builddir=$(KBUILD_OUTPUT) \
73         TOPDIR=$(KBUILD_OUTPUT) \
74         KBUILD_SRC=$(CURDIR) \
75         -f $(CURDIR)/Makefile $@
76
77 $(KBUILD_OUTPUT)/Rules.mak:
78         @echo > $@
79         @echo top_srcdir=$(CURDIR) >> $@
80         @echo top_builddir=$(KBUILD_OUTPUT) >> $@
81         @echo include $(top_srcdir)/Rules.mak >> $@
82
83 $(KBUILD_OUTPUT)/Makefile:
84         @echo > $@
85         @echo top_srcdir=$(CURDIR) >> $@
86         @echo top_builddir=$(KBUILD_OUTPUT) >> $@
87         @echo KBUILD_SRC='$$(top_srcdir)' >> $@
88         @echo include '$$(KBUILD_SRC)'/Makefile >> $@
89
90 # Leave processing to above invocation of make
91 skip-makefile := 1
92 endif # ifneq ($(KBUILD_OUTPUT),)
93 endif # ifeq ($(KBUILD_SRC),)
94
95 ifeq ($(skip-makefile),)
96
97 _all: all
98
99 ifeq ($(strip $(HAVE_DOT_CONFIG)),y)
100
101 all: busybox busybox.links doc
102
103 all_tree:       $(ALL_MAKEFILES)
104
105 $(ALL_MAKEFILES): %/Makefile: $(top_srcdir)/%/Makefile
106         [ -d $(@D) ] || mkdir -p $(@D); cp $< $@
107
108 # In this section, we need .config
109 -include $(top_builddir)/.config.cmd
110 include $(patsubst %,%/Makefile.in, $(SRC_DIRS))
111 -include $(top_builddir)/.depend
112
113 busybox: $(ALL_MAKEFILES) .depend include/bb_config.h $(libraries-y)
114         $(CC) $(LDFLAGS) -o $@ -Wl,--start-group $(libraries-y) $(LIBRARIES) -Wl,--end-group
115         $(STRIPCMD) $@
116
117 busybox.links: $(top_srcdir)/applets/busybox.mkll include/config.h $(top_srcdir)/include/applets.h
118         - $(SHELL) $^ >$@
119
120 install: $(top_srcdir)/applets/install.sh busybox busybox.links
121         $(SHELL) $< $(PREFIX)
122 ifeq ($(strip $(CONFIG_FEATURE_SUID)),y)
123         @echo
124         @echo
125         @echo --------------------------------------------------
126         @echo You will probably need to make your busybox binary
127         @echo setuid root to ensure all configured applets will
128         @echo work properly.
129         @echo --------------------------------------------------
130         @echo
131 endif
132
133 uninstall: busybox.links
134         rm -f $(PREFIX)/bin/busybox
135         for i in `cat busybox.links` ; do rm -f $(PREFIX)$$i; done
136
137 install-hardlinks: $(top_srcdir)/applets/install.sh busybox busybox.links
138         $(SHELL) $< $(PREFIX) --hardlinks
139
140 check: busybox
141         bindir=$(top_builddir) srcdir=$(top_srcdir)/testsuite \
142         $(top_srcdir)/testsuite/runtest
143
144 sizes:
145         -rm -f busybox
146         $(MAKE) top_srcdir=$(top_srcdir) top_builddir=$(top_builddir) \
147                 -f $(top_srcdir)/Makefile STRIPCMD=/bin/true
148         nm --size-sort busybox
149
150 # Documentation Targets
151 doc: docs/busybox.pod docs/BusyBox.txt docs/BusyBox.1 docs/BusyBox.html
152
153 docs/busybox.pod : $(top_srcdir)/docs/busybox_header.pod $(top_srcdir)/include/usage.h $(top_srcdir)/docs/busybox_footer.pod
154         -mkdir -p docs
155         - ( cat $(top_srcdir)/docs/busybox_header.pod; \
156             $(top_srcdir)/docs/autodocifier.pl $(top_srcdir)/include/usage.h; \
157             cat $(top_srcdir)/docs/busybox_footer.pod ) > docs/busybox.pod
158
159 docs/BusyBox.txt: docs/busybox.pod
160         $(SECHO)
161         $(SECHO) BusyBox Documentation
162         $(SECHO)
163         -mkdir -p docs
164         -pod2text $< > $@
165
166 docs/BusyBox.1: docs/busybox.pod
167         - mkdir -p docs
168         - pod2man --center=BusyBox --release="version $(VERSION)" \
169                 $< > $@
170
171 docs/BusyBox.html: docs/busybox.net/BusyBox.html
172         - mkdir -p docs
173         -@ rm -f docs/BusyBox.html
174         -@ cp docs/busybox.net/BusyBox.html docs/BusyBox.html
175
176 docs/busybox.net/BusyBox.html: docs/busybox.pod
177         -@ mkdir -p docs/busybox.net
178         -  pod2html --noindex $< > \
179             docs/busybox.net/BusyBox.html
180         -@ rm -f pod2htm*
181
182 # The nifty new buildsystem stuff
183 scripts/mkdep: $(top_srcdir)/scripts/mkdep.c
184         $(HOSTCC) $(HOSTCFLAGS) -o $@ $<
185
186 scripts/split-include: $(top_srcdir)/scripts/split-include.c
187         $(HOSTCC) $(HOSTCFLAGS) -o $@ $<
188
189 depend dep: .depend
190 .depend: scripts/mkdep include/config.h include/bbconfigopts.h
191         rm -f .depend .hdepend;
192         mkdir -p include/config;
193         scripts/mkdep -I include -- \
194           `find $(top_srcdir) -name \*.c -print | sed -e "s,^./,,"` >> .depend;
195         scripts/mkdep -I include -- \
196           `find $(top_srcdir) -name \*.h -print | sed -e "s,^./,,"` >> .hdepend;
197
198 include/config/MARKER: depend scripts/split-include
199         scripts/split-include include/config.h include/config
200         @ touch include/config/MARKER
201
202 include/config.h: .config
203         @if [ ! -x $(top_builddir)/scripts/config/conf ] ; then \
204             $(MAKE) -C scripts/config conf; \
205         fi;
206         @$(top_builddir)/scripts/config/conf -o $(CONFIG_CONFIG_IN)
207
208 include/bb_config.h: include/config.h
209         echo -e "#ifndef BB_CONFIG_H\n#define BB_CONFIG_H" > $@
210         sed -e 's/#undef CONFIG_\(.*\)/#define ENABLE_\1 0/' \
211             -e 's/#define CONFIG_\(.*\)/#define CONFIG_\1\n#define ENABLE_\1/' \
212                 < $< >> $@
213         echo "#endif" >> $@
214
215 include/bbconfigopts.h: .config
216         @[ -d $(@D) ] || mkdir -v $(@D)
217         $(top_srcdir)/scripts/config/mkconfigs >include/bbconfigopts.h
218
219 finished2:
220         $(SECHO)
221         $(SECHO) Finished installing...
222         $(SECHO)
223
224 else # ifeq ($(strip $(HAVE_DOT_CONFIG)),y)
225
226 all: menuconfig
227
228 # configuration
229 # ---------------------------------------------------------------------------
230
231 scripts/config/conf: scripts/config/Makefile $(top_srcdir)/Rules.mak
232         $(MAKE) -C scripts/config conf
233         -@if [ ! -f .config ] ; then \
234                 cp $(CONFIG_DEFCONFIG) .config; \
235         fi
236
237 scripts/config/mconf: scripts/config/Makefile $(top_srcdir)/Rules.mak
238         $(MAKE) -C scripts/config ncurses conf mconf
239         -@if [ ! -f .config ] ; then \
240                 cp $(CONFIG_DEFCONFIG) .config; \
241         fi
242
243 menuconfig: scripts/config/mconf
244         @./scripts/config/mconf $(CONFIG_CONFIG_IN)
245
246 config: scripts/config/conf
247         @./scripts/config/conf $(CONFIG_CONFIG_IN)
248
249 oldconfig: scripts/config/conf
250         @./scripts/config/conf -o $(CONFIG_CONFIG_IN)
251
252 randconfig: scripts/config/conf
253         @./scripts/config/conf -r $(CONFIG_CONFIG_IN)
254
255 allyesconfig: scripts/config/conf
256         @./scripts/config/conf -y $(CONFIG_CONFIG_IN)
257         sed -i -r -e "s/^(CONFIG_DEBUG|USING_CROSS_COMPILER|CONFIG_STATIC|CONFIG_SELINUX).*/# \1 is not set/" .config
258         @./scripts/config/conf -o $(CONFIG_CONFIG_IN)
259
260 allnoconfig: scripts/config/conf
261         @./scripts/config/conf -n $(CONFIG_CONFIG_IN)
262
263 defconfig: scripts/config/conf
264         @./scripts/config/conf -d $(CONFIG_CONFIG_IN)
265
266 clean:
267         - $(MAKE) -C scripts/config $@
268         - rm -f docs/busybox.dvi docs/busybox.ps \
269             docs/busybox.pod docs/busybox.net/busybox.html \
270             docs/busybox pod2htm* *.gdb *.elf *~ core .*config.log \
271             docs/BusyBox.txt docs/BusyBox.1 docs/BusyBox.html \
272             docs/busybox.net/BusyBox.html busybox.links libbb/loop.h \
273             .config.old .hdepend busybox testsuite/links/*
274         - rm -rf _install
275         - find . -name .\*.flags -exec rm -f {} \;
276         - find . -name \*.o -exec rm -f {} \;
277         - find . -name \*.a -exec rm -f {} \;
278
279 distclean: clean
280         - rm -f scripts/split-include scripts/mkdep
281         - rm -rf include/config include/config.h include/bb_config.h include/bbconfigopts.h
282         - find . -name .depend -exec rm -f {} \;
283         rm -f .config .config.old .config.cmd
284
285 release: distclean #doc
286         cd ..; \
287         rm -rf $(PROG)-$(VERSION); \
288         cp -a busybox $(PROG)-$(VERSION); \
289         \
290         find $(PROG)-$(VERSION)/ -type d \
291                 -name .svn \
292                 -print \
293                 -exec rm -rf {} \; ; \
294         \
295         find $(PROG)-$(VERSION)/ -type f \
296                 -name .\#* \
297                 -print \
298                 -exec rm -f {} \; ; \
299         \
300         tar -cvzf $(PROG)-$(VERSION).tar.gz $(PROG)-$(VERSION)/;
301
302 tags:
303         ctags -R .
304
305
306 endif # ifeq ($(strip $(HAVE_DOT_CONFIG)),y)
307
308 endif # ifeq ($(skip-makefile),)
309
310 .PHONY: dummy subdirs release distclean clean config oldconfig \
311         menuconfig tags check test depend buildtree