don't out \r to syslog
[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 # the toplevel sourcedir
16 ifndef top_srcdir
17 top_srcdir=$(CURDIR)
18 endif
19 # toplevel directory of the object-tree
20 ifndef top_builddir
21 top_builddir=$(CURDIR)
22 endif
23
24 export srctree=$(top_srcdir)
25 vpath %/Config.in $(srctree)
26
27 include $(top_srcdir)/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 e2fsprogs libpwdgrp coreutils/libcoreutils libbb
33
34 SRC_DIRS:=$(patsubst %,$(top_srcdir)/%,$(DIRS))
35
36 ifeq ($(strip $(CONFIG_SELINUX)),y)
37 LIBRARIES += -lselinux
38 endif
39
40 CONFIG_CONFIG_IN = $(top_srcdir)/sysdeps/$(TARGET_OS)/Config.in
41 CONFIG_DEFCONFIG = $(top_srcdir)/sysdeps/$(TARGET_OS)/defconfig
42
43 ALL_DIRS:= $(DIRS) scripts/config
44 ALL_MAKEFILES:=$(patsubst %,%/Makefile,$(ALL_DIRS))
45
46 ifeq ($(KBUILD_SRC),)
47
48 ifdef O
49   ifeq ("$(origin O)", "command line")
50     KBUILD_OUTPUT := $(O)
51   endif
52 endif
53
54 # That's our default target when none is given on the command line
55 .PHONY: _all
56 _all:
57
58 ifneq ($(KBUILD_OUTPUT),)
59 # Invoke a second make in the output directory, passing relevant variables
60 # check that the output directory actually exists
61 saved-output := $(KBUILD_OUTPUT)
62 KBUILD_OUTPUT := $(shell cd $(KBUILD_OUTPUT) && /bin/pwd)
63 $(if $(wildcard $(KBUILD_OUTPUT)),, \
64      $(error output directory "$(saved-output)" does not exist))
65
66 .PHONY: $(MAKECMDGOALS)
67
68 $(filter-out _all,$(MAKECMDGOALS)) _all: $(KBUILD_OUTPUT)/Rules.mak $(KBUILD_OUTPUT)/Makefile
69         $(MAKE) -C $(KBUILD_OUTPUT) \
70         top_srcdir=$(CURDIR) \
71         top_builddir=$(KBUILD_OUTPUT) \
72         KBUILD_SRC=$(CURDIR) \
73         -f $(CURDIR)/Makefile $@
74
75 $(KBUILD_OUTPUT)/Rules.mak:
76         @echo > $@
77         @echo top_srcdir=$(CURDIR) >> $@
78         @echo top_builddir=$(KBUILD_OUTPUT) >> $@
79         @echo include $(top_srcdir)/Rules.mak >> $@
80
81 $(KBUILD_OUTPUT)/Makefile:
82         @echo > $@
83         @echo top_srcdir=$(CURDIR) >> $@
84         @echo top_builddir=$(KBUILD_OUTPUT) >> $@
85         @echo KBUILD_SRC='$$(top_srcdir)' >> $@
86         @echo include '$$(KBUILD_SRC)'/Makefile >> $@
87
88 # Leave processing to above invocation of make
89 skip-makefile := 1
90 endif # ifneq ($(KBUILD_OUTPUT),)
91 endif # ifeq ($(KBUILD_SRC),)
92
93 ifeq ($(skip-makefile),)
94
95 _all: all
96
97 help:
98         @echo 'Cleaning:'
99         @echo '  clean                  - delete temporary files created by build'
100         @echo '  distclean              - delete all non-source files (including .config)'
101         @echo
102         @echo 'Build:'
103         @echo '  all                    - Executable and documentation'
104         @echo '  busybox                - the swiss-army executable'
105         @echo '  doc                    - docs/BusyBox.{txt,html,1}'
106         @echo
107         @echo 'Configuration:'
108         @echo '  allnoconfig            - disable all symbols in .config'
109         @echo '  allyesconfig           - enable (almost) all symbols in .config'
110         @echo '  config         - text based configurator (of last resort).'
111         @echo '  defconfig              - set .config to defaults'
112         @echo '  menuconfig             - interactive curses-based configurator'
113         @echo '  oldconfig              - resolve any unresolved symbols in .config'
114         @echo
115         @echo 'Installation:'
116         @echo '  install                - install busybox and symlinks into $prefix'
117         @echo '  install-hardlinks      - install busybox and hardlinks into $prefix'
118         @echo '  uninstall'
119         @echo
120         @echo 'Development:'
121         @echo '  check                  - run the test suite for all applets'
122         @echo '  randconfig             - generate a random configuration'
123         @echo '  release                - create a distribution tarball'
124         @echo '  sizes                  - show size of all enabled busybox symbols'
125         @echo
126
127 ifeq ($(strip $(HAVE_DOT_CONFIG)),y)
128
129 all: busybox busybox.links doc
130
131 all_tree:       $(ALL_MAKEFILES)
132
133 $(ALL_MAKEFILES): %/Makefile: $(top_srcdir)/%/Makefile
134         [ -d $(@D) ] || mkdir -p $(@D); cp $< $@
135
136 # In this section, we need .config
137 -include $(top_builddir)/.config.cmd
138 include $(patsubst %,%/Makefile.in, $(SRC_DIRS))
139 -include $(top_builddir)/.depend
140
141 busybox: $(ALL_MAKEFILES) .depend $(libraries-y)
142         $(CC) $(EXTRA_CFLAGS) $(LDFLAGS) -o $@ -Wl,--start-group $(libraries-y) $(LIBRARIES) -Wl,--end-group
143         $(STRIPCMD) $@
144
145 busybox.links: $(top_srcdir)/applets/busybox.mkll include/config.h $(top_srcdir)/include/applets.h
146         - $(SHELL) $^ >$@
147
148 install: $(top_srcdir)/applets/install.sh busybox busybox.links
149         $(SHELL) $< $(PREFIX)
150 ifeq ($(strip $(CONFIG_FEATURE_SUID)),y)
151         @echo
152         @echo
153         @echo --------------------------------------------------
154         @echo You will probably need to make your busybox binary
155         @echo setuid root to ensure all configured applets will
156         @echo work properly.
157         @echo --------------------------------------------------
158         @echo
159 endif
160
161 uninstall: busybox.links
162         rm -f $(PREFIX)/bin/busybox
163         for i in `cat busybox.links` ; do rm -f $(PREFIX)$$i; done
164
165 install-hardlinks: $(top_srcdir)/applets/install.sh busybox busybox.links
166         $(SHELL) $< $(PREFIX) --hardlinks
167
168 check test: busybox
169         bindir=$(top_builddir) srcdir=$(top_srcdir)/testsuite \
170         $(top_srcdir)/testsuite/runtest
171
172 sizes:
173         -rm -f busybox
174         $(MAKE) top_srcdir=$(top_srcdir) top_builddir=$(top_builddir) \
175                 -f $(top_srcdir)/Makefile STRIPCMD=/bin/true
176         nm --size-sort busybox
177
178 # Documentation Targets
179 doc: docs/busybox.pod docs/BusyBox.txt docs/BusyBox.1 docs/BusyBox.html
180
181 docs/busybox.pod : $(top_srcdir)/docs/busybox_header.pod $(top_srcdir)/include/usage.h $(top_srcdir)/docs/busybox_footer.pod
182         -mkdir -p docs
183         - ( cat $(top_srcdir)/docs/busybox_header.pod; \
184             $(top_srcdir)/docs/autodocifier.pl $(top_srcdir)/include/usage.h; \
185             cat $(top_srcdir)/docs/busybox_footer.pod ) > docs/busybox.pod
186
187 docs/BusyBox.txt: docs/busybox.pod
188         $(SECHO)
189         $(SECHO) BusyBox Documentation
190         $(SECHO)
191         -mkdir -p docs
192         -pod2text $< > $@
193
194 docs/BusyBox.1: docs/busybox.pod
195         - mkdir -p docs
196         - pod2man --center=BusyBox --release="version $(VERSION)" \
197                 $< > $@
198
199 docs/BusyBox.html: docs/busybox.net/BusyBox.html
200         - mkdir -p docs
201         -@ rm -f docs/BusyBox.html
202         -@ cp docs/busybox.net/BusyBox.html docs/BusyBox.html
203
204 docs/busybox.net/BusyBox.html: docs/busybox.pod
205         -@ mkdir -p docs/busybox.net
206         -  pod2html --noindex $< > \
207             docs/busybox.net/BusyBox.html
208         -@ rm -f pod2htm*
209
210 # The nifty new buildsystem stuff
211 scripts/bb_mkdep: $(top_srcdir)/scripts/bb_mkdep.c
212         $(HOSTCC) $(HOSTCFLAGS) -o $@ $<
213
214 DEP_INCLUDES := include/config.h include/bb_config.h
215
216 ifeq ($(strip $(CONFIG_BBCONFIG)),y)
217 DEP_INCLUDES += include/bbconfigopts.h
218
219 include/bbconfigopts.h: .config
220         scripts/config/mkconfigs > $@
221 endif
222
223 depend dep $(top_builddir)/.depend: .depend
224 .depend: scripts/bb_mkdep $(DEP_INCLUDES)
225         @rm -f .depend
226         @mkdir -p include/config
227         scripts/bb_mkdep -c include/config.h -c include/bb_config.h > $@.tmp
228         mv $@.tmp $@
229
230 include/config.h: .config
231         @if [ ! -x $(top_builddir)/scripts/config/conf ] ; then \
232             $(MAKE) -C scripts/config conf; \
233         fi;
234         @$(top_builddir)/scripts/config/conf -o $(CONFIG_CONFIG_IN)
235
236 include/bb_config.h: include/config.h
237         @echo -e "#ifndef BB_CONFIG_H\n#define BB_CONFIG_H" > $@
238         @sed -e 's/#undef CONFIG_\(.*\)/#define ENABLE_\1 0/' \
239             -e 's/#define CONFIG_\(.*\)/#define CONFIG_\1\n#define ENABLE_\1/' \
240                 < $< >> $@
241         @echo "#endif" >> $@
242
243 finished2:
244         $(SECHO)
245         $(SECHO) Finished installing...
246         $(SECHO)
247
248 else # ifeq ($(strip $(HAVE_DOT_CONFIG)),y)
249
250 all: menuconfig
251
252 # configuration
253 # ---------------------------------------------------------------------------
254
255 scripts/config/conf: scripts/config/Makefile $(top_srcdir)/Rules.mak
256         $(MAKE) -C scripts/config conf
257         -@if [ ! -f .config ] ; then \
258                 cp $(CONFIG_DEFCONFIG) .config; \
259         fi
260
261 scripts/config/mconf: scripts/config/Makefile $(top_srcdir)/Rules.mak
262         $(MAKE) -C scripts/config ncurses conf mconf
263         -@if [ ! -f .config ] ; then \
264                 cp $(CONFIG_DEFCONFIG) .config; \
265         fi
266
267 menuconfig: scripts/config/mconf
268         @./scripts/config/mconf $(CONFIG_CONFIG_IN)
269
270 config: scripts/config/conf
271         @./scripts/config/conf $(CONFIG_CONFIG_IN)
272
273 oldconfig: scripts/config/conf
274         @./scripts/config/conf -o $(CONFIG_CONFIG_IN)
275
276 randconfig: scripts/config/conf
277         @./scripts/config/conf -r $(CONFIG_CONFIG_IN)
278
279 allyesconfig: scripts/config/conf
280         @./scripts/config/conf -y $(CONFIG_CONFIG_IN)
281         sed -i -r -e "s/^(CONFIG_DEBUG|USING_CROSS_COMPILER|CONFIG_STATIC|CONFIG_SELINUX).*/# \1 is not set/" .config
282         @./scripts/config/conf -o $(CONFIG_CONFIG_IN)
283
284 allnoconfig: scripts/config/conf
285         @./scripts/config/conf -n $(CONFIG_CONFIG_IN)
286
287 defconfig: scripts/config/conf
288         @./scripts/config/conf -d $(CONFIG_CONFIG_IN)
289
290 clean:
291         - $(MAKE) -C scripts/config $@
292         - rm -f docs/busybox.dvi docs/busybox.ps \
293             docs/busybox.pod docs/busybox.net/busybox.html \
294             docs/busybox pod2htm* *.gdb *.elf *~ core .*config.log \
295             docs/BusyBox.txt docs/BusyBox.1 docs/BusyBox.html \
296             docs/busybox.net/BusyBox.html busybox.links libbb/loop.h \
297             .config.old busybox
298         - rm -rf _install testsuite/links
299         - find . -name .\*.flags -exec rm -f {} \;
300         - find . -name \*.o -exec rm -f {} \;
301         - find . -name \*.a -exec rm -f {} \;
302
303 distclean: clean
304         - rm -f scripts/bb_mkdep
305         - rm -rf include/config include/config.h include/bb_config.h include/bbconfigopts.h
306         - find . -name .depend -exec rm -f {} \;
307         rm -f .config .config.old .config.cmd
308
309 release: distclean #doc
310         cd ..; \
311         rm -rf $(PROG)-$(VERSION); \
312         cp -a busybox $(PROG)-$(VERSION); \
313         \
314         find $(PROG)-$(VERSION)/ -type d \
315                 -name .svn \
316                 -print \
317                 -exec rm -rf {} \; ; \
318         \
319         find $(PROG)-$(VERSION)/ -type f \
320                 -name .\#* \
321                 -print \
322                 -exec rm -f {} \; ; \
323         \
324         tar -cvzf $(PROG)-$(VERSION).tar.gz $(PROG)-$(VERSION)/;
325
326 tags:
327         ctags -R .
328
329
330 endif # ifeq ($(strip $(HAVE_DOT_CONFIG)),y)
331
332 endif # ifeq ($(skip-makefile),)
333
334 .PHONY: dummy subdirs release distclean clean config oldconfig \
335         menuconfig tags check test depend buildtree