fix building with glibc-2.4
[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 allbareconfig \
13         clean distclean \
14         release tags
15
16 # the toplevel sourcedir
17 ifndef top_srcdir
18 # make-3.79.1 didn't support MAKEFILE_LIST
19 # for building out-of-tree, users of make-3.79.1 still have to pass top_srcdir=
20 # to make: make -f /srcs/busybox/Makefile top_srcdir=/srcs/busybox
21 ifdef MAKEFILE_LIST
22 top_srcdir:=$(shell cd $(dir $(firstword $(MAKEFILE_LIST))) && pwd)
23 else
24 top_srcdir:=$(CURDIR)
25 endif
26 endif
27 # toplevel directory of the object-tree
28 ifndef top_builddir
29 top_builddir:=$(CURDIR)
30 endif
31
32 export srctree=$(top_srcdir)
33 vpath %/Config.in $(srctree)
34
35 DIRS:=applets archival archival/libunarchive coreutils console-tools \
36         debianutils editors findutils init miscutils modutils networking \
37         networking/libiproute networking/udhcp procps loginutils shell \
38         sysklogd util-linux e2fsprogs libpwdgrp coreutils/libcoreutils libbb
39
40 SRC_DIRS:=$(patsubst %,$(top_srcdir)/%,$(DIRS))
41
42 # That's our default target when none is given on the command line
43 .PHONY: _all
44
45 _all: all
46
47 # see if we are in verbose mode
48 ifdef VERBOSE
49   CHECK_VERBOSE := -v
50   PACKAGE_BE_VERBOSE := $(VERBOSE)
51 endif
52 ifdef V
53   CHECK_VERBOSE := -v
54   PACKAGE_BE_VERBOSE := $(V)
55 endif
56
57 ifdef O
58   ifeq ("$(origin O)", "command line")
59     PACKAGE_OUTPUTDIR := $(shell cd $(O) && pwd)
60     top_builddir := $(PACKAGE_OUTPUTDIR)
61   endif
62 else
63 # If no alternate output-dir was specified, we build in cwd
64   PACKAGE_OUTPUTDIR := $(top_builddir)
65 endif
66
67 define check_gcc
68 $(if $(2),$(if $(shell $(CC) $(2) -S -o /dev/null -xc /dev/null > /dev/null 2>&1 && echo y),$(2),$(if $(3),$(3))),$(if $(3),$(3)))
69 endef
70
71 define check_ld
72 $(if $(2),$(if $(shell $(LD) $(2) -o /dev/null -b binary /dev/null > /dev/null 2>&1 && echo y),$(shell echo \-Wl,$(2)),$(if $(3),$(3))),$(if $(3),$(3)))
73 endef
74
75 #######################################################################
76 # make-3.79.1 doesn't support order-only prerequisites..
77 ifeq ($(MAKE_VERSION),3.79.1)
78 |: $(^) ;
79 endif
80 #######################################################################
81
82
83
84 # Handle building out of tree
85 ifneq ($(top_builddir),$(top_srcdir))
86 all_tree := $(patsubst %,$(top_builddir)/%,$(DIRS) scripts scripts/config include include/config)
87 $(all_tree):
88         @mkdir -p "$@"
89
90 saved-output := $(PACKAGE_OUTPUTDIR)
91
92 $(if $(wildcard $(PACKAGE_OUTPUTDIR)),, \
93      $(error output directory "$(saved-output)" does not exist))
94
95 .PHONY: $(filter $(noconfig_targets),$(MAKECMDGOALS))
96
97 $(PACKAGE_OUTPUTDIR)/Rules.mak:
98         @echo > $@
99         @echo top_srcdir=$(top_srcdir) >> $@
100         @echo top_builddir=$(PACKAGE_OUTPUTDIR) >> $@
101         @echo include $$\(top_srcdir\)/Rules.mak >> $@
102
103 $(PACKAGE_OUTPUTDIR)/Makefile:
104         @echo > $@
105         @echo top_srcdir=$(top_srcdir) >> $@
106         @echo top_builddir=$(PACKAGE_OUTPUTDIR) >> $@
107         @echo PACKAGE_SOURCEDIR='$$(top_srcdir)' >> $@
108         @echo include '$$(PACKAGE_SOURCEDIR)'/Makefile >> $@
109
110
111 buildtree := $(all_tree) $(PACKAGE_OUTPUTDIR)/Rules.mak $(PACKAGE_OUTPUTDIR)/Makefile
112
113 # We only need a copy of the Makefile for the config targets and reuse
114 # the rest from the source directory, i.e. we do not cp ALL_MAKEFILES.
115 scripts/config/Makefile: $(top_srcdir)/scripts/config/Makefile | $(buildtree)
116         @cp $(top_srcdir)/scripts/config/Makefile $@
117
118 else
119 all_tree := include/config
120 $(all_tree):
121         @mkdir -p "$@"
122 buildtree := $(all_tree)
123 endif # ifneq ($(PACKAGE_OUTPUTDIR),$(top_srcdir))
124
125 help:
126         @echo 'Cleaning:'
127         @echo '  clean                  - delete temporary files created by build'
128         @echo '  distclean              - delete all non-source files (including .config)'
129         @echo
130         @echo 'Build:'
131         @echo '  all                    - Executable and documentation'
132         @echo '  busybox                - the swiss-army executable'
133         @echo '  doc                    - docs/BusyBox.{txt,html,1}'
134         @echo
135         @echo 'Configuration:'
136         @echo '  allnoconfig            - disable all symbols in .config'
137         @echo '  allyesconfig           - enable all symbols in .config (see defconfig)'
138         @echo '  allbareconfig          - enable all applets without any sub-features'
139         @echo '  config         - text based configurator (of last resort)'
140         @echo '  defconfig              - set .config to largest generic configuration'
141         @echo '  menuconfig             - interactive curses-based configurator'
142         @echo '  oldconfig              - resolve any unresolved symbols in .config'
143         @echo
144         @echo 'Installation:'
145         @echo '  install                - install busybox into $prefix'
146         @echo '  uninstall'
147         @echo
148         @echo 'Development:'
149         @echo '  check                  - run the test suite for all applets'
150         @echo '  randconfig             - generate a random configuration'
151         @echo '  release                - create a distribution tarball'
152         @echo '  sizes                  - show size of all enabled busybox symbols'
153         @echo
154         @echo 'Make flags:'
155         @echo '  V=<number>             - print verbose make output (default: unset)'
156         @echo '                           0 print CC invocations'
157         @echo '                           1'
158         @echo '                           2 also print when make enters a directory'
159         @echo '                           3 also verbosely print shell invocations'
160
161 -include $(top_srcdir)/Rules.mak
162
163 ifneq ($(strip $(HAVE_DOT_CONFIG)),y)
164 # Default target if none was requested explicitly
165 all: defconfig menuconfig ;
166
167 ifneq ($(filter-out $(noconfig_targets),$(MAKECMDGOALS)),)
168 # warn if no configuration exists and we are asked to build a non-config target
169 .config:
170         @echo ""
171         @echo "No $(top_builddir)/$@ found!"
172         @echo "Please refer to 'make help', section Configuration."
173         @echo ""
174         @exit 1
175 else
176 # Avoid implicit rule to kick in by using an empty command
177 .config: $(buildtree) ;
178 endif
179 endif # ifneq ($(strip $(HAVE_DOT_CONFIG)),y)
180
181
182 # configuration
183 # ---------------------------------------------------------------------------
184
185 CONFIG_CONFIG_IN = $(top_srcdir)/Config.in
186
187 scripts/config/conf: scripts/config/Makefile
188         $(Q)$(MAKE) -C scripts/config conf
189
190 scripts/config/mconf: scripts/config/Makefile
191         $(Q)$(MAKE) -C scripts/config ncurses conf mconf
192
193 menuconfig: scripts/config/mconf
194         @./scripts/config/mconf $(CONFIG_CONFIG_IN)
195
196 config: scripts/config/conf
197         @./scripts/config/conf $(CONFIG_CONFIG_IN)
198
199 oldconfig: scripts/config/conf
200         @./scripts/config/conf -o $(CONFIG_CONFIG_IN)
201
202 randconfig: scripts/config/conf
203         @./scripts/config/conf -r $(CONFIG_CONFIG_IN)
204
205 allyesconfig: scripts/config/conf
206         @./scripts/config/conf -y $(CONFIG_CONFIG_IN)
207         @$(SED) -i -r -e "s/^(USING_CROSS_COMPILER)=.*/# \1 is not set/" .config
208         @./scripts/config/conf -o $(CONFIG_CONFIG_IN)
209
210 allnoconfig: scripts/config/conf
211         @./scripts/config/conf -n $(CONFIG_CONFIG_IN)
212
213 # defconfig is allyesconfig minus any features that are specialized enough
214 # or cause enough behavior change that the user really should switch them on
215 # manually if that's what they want.  Sort of "maximum sane config".
216
217 defconfig: scripts/config/conf
218         @./scripts/config/conf -y $(CONFIG_CONFIG_IN)
219         @$(SED) -i -r -e "s/^(USING_CROSS_COMPILER|CONFIG_(DEBUG.*|STATIC|SELINUX|BUILD_(AT_ONCE|LIBBUSYBOX)|FEATURE_(DEVFS|FULL_LIBBUSYBOX|SHARED_BUSYBOX|MTAB_SUPPORT|CLEAN_UP|UDHCP_DEBUG)|INSTALL_NO_USR))=.*/# \1 is not set/" .config
220         @./scripts/config/conf -o $(CONFIG_CONFIG_IN)
221
222 allbareconfig: scripts/config/conf
223         @./scripts/config/conf -y $(CONFIG_CONFIG_IN)
224         @$(SED) -i -r -e "s/^(USING_CROSS_COMPILER|CONFIG_(DEBUG|STATIC|SELINUX|DEVFSD|NC_GAPING_SECURITY_HOLE|BUILD_AT_ONCE)).*/# \1 is not set/" .config
225         @$(SED) -i -e "/FEATURE/s/=.*//;/^[^#]/s/.*FEATURE.*/# \0 is not set/;" .config
226         @echo "CONFIG_FEATURE_BUFFERS_GO_ON_STACK=y" >> .config
227         @./scripts/config/conf -o $(CONFIG_CONFIG_IN)
228
229 ifeq ($(strip $(HAVE_DOT_CONFIG)),y)
230
231 # Load all Config.in
232 -include $(top_builddir)/.config.cmd
233
234 endif # ifeq ($(strip $(HAVE_DOT_CONFIG)),y)
235
236 include $(patsubst %,%/Makefile.in,$(SRC_DIRS))
237
238 ifeq ($(strip $(HAVE_DOT_CONFIG)),y)
239 # Finally pull in the dependencies (headers and other includes) of the
240 # individual object files
241 -include $(top_builddir)/.depend
242
243 $(top_builddir)/applets/applets.o: $(top_builddir)/.config
244 # Everything is set.
245
246 all: busybox busybox.links doc ;
247
248 # Two modes of operation: legacy and IMA
249 # Legacy mode builds each object through an individual invocation of CC
250 # IMA compiles all sources at once (aka IPO aka IPA etc.)
251
252 ifeq ($(strip $(CONFIG_BUILD_AT_ONCE)),y)
253 libraries-y:=
254 # Which parts of the internal libs are requested?
255 # Per default we only want what was actually selected.
256 # -a denotes all while -y denotes the selected ones.
257 ifeq ($(strip $(CONFIG_FEATURE_FULL_LIBBUSYBOX)),y)
258 LIBRARY_DEFINE:=$(LIBRARY_DEFINE-a)
259 LIBRARY_SRC   :=$(LIBRARY_SRC-a)
260 else # CONFIG_FEATURE_FULL_LIBBUSYBOX
261 LIBRARY_DEFINE:=$(LIBRARY_DEFINE-y)
262 LIBRARY_SRC   :=$(LIBRARY_SRC-y)
263 endif # CONFIG_FEATURE_FULL_LIBBUSYBOX
264 APPLET_SRC:=$(APPLET_SRC-y)
265 APPLETS_DEFINE:=$(APPLETS_DEFINE-y)
266 else  # CONFIG_BUILD_AT_ONCE
267 # no --combine, build archives out of the individual .o
268 # This was the old way the binary was built.
269 libbusybox-obj:=archival/libunarchive/libunarchive.a \
270         networking/libiproute/libiproute.a \
271         libpwdgrp/libpwdgrp.a coreutils/libcoreutils/libcoreutils.a \
272         libbb/libbb.a
273 libbusybox-obj:=$(patsubst %,$(top_builddir)/%,$(libbusybox-obj))
274 ifeq ($(strip $(CONFIG_FEATURE_SHARED_BUSYBOX)),y)
275 # linking against libbusybox, so don't build the .a already contained in the .so
276 libraries-y:=$(filter-out $(libbusybox-obj),$(libraries-y))
277 endif # CONFIG_FEATURE_SHARED_BUSYBOX
278
279 endif # CONFIG_BUILD_AT_ONCE
280
281 ifeq ($(strip $(CONFIG_BUILD_LIBBUSYBOX)),y)
282 LD_LIBBUSYBOX:=libbusybox.so
283 LIBBUSYBOX_SONAME:=$(LD_LIBBUSYBOX).$(MAJOR_VERSION).$(MINOR_VERSION).$(SUBLEVEL_VERSION)
284 DO_INSTALL_LIBS:=$(LD_LIBBUSYBOX) \
285         $(LD_LIBBUSYBOX).$(MAJOR_VERSION) \
286         $(LD_LIBBUSYBOX).$(MAJOR_VERSION).$(MINOR_VERSION)
287
288 endif # CONFIG_BUILD_LIBBUSYBOX
289
290 ifeq ($(strip $(CONFIG_BUILD_AT_ONCE)),y)
291 ifneq ($(strip $(CONFIG_FEATURE_SHARED_BUSYBOX)),y)
292 # --combine but not linking against libbusybox, so compile lib*.c
293 BUSYBOX_SRC   := $(LIBRARY_SRC)
294 BUSYBOX_DEFINE:= $(LIBRARY_DEFINE)
295 endif # !CONFIG_FEATURE_SHARED_BUSYBOX
296 $(LIBBUSYBOX_SONAME): $(LIBRARY_SRC)
297 else # CONFIG_BUILD_AT_ONCE
298 $(LIBBUSYBOX_SONAME): $(libbusybox-obj)
299 AR_INTRO:=-Wl,--whole-archive
300 AR_EXTRO:=-Wl,--no-whole-archive
301 endif # CONFIG_BUILD_AT_ONCE
302
303
304 ifeq ($(strip $(CONFIG_FEATURE_SHARED_BUSYBOX)),y)
305 LDBUSYBOX:=-L$(top_builddir) -lbusybox
306 endif
307
308 ifeq ($(strip $(CONFIG_BUILD_LIBBUSYBOX)),y)
309 $(LIBBUSYBOX_SONAME):
310 ifndef MAJOR_VERSION
311         $(error MAJOR_VERSION needed for $@ is not defined)
312 endif
313         $(do_link) $(LIB_CFLAGS) $(CFLAGS_COMBINE) \
314         -Wl,-soname=$(LD_LIBBUSYBOX).$(MAJOR_VERSION) \
315         -Wl,-z,combreloc $(LIB_LDFLAGS) \
316         -o $(@) \
317         -Wl,--start-group \
318         $(LIBRARY_DEFINE) $(AR_INTRO) $(^) $(AR_EXTRO) \
319         -Wl,--end-group
320         @rm -f $(DO_INSTALL_LIBS)
321         @for i in $(DO_INSTALL_LIBS); do ln -s $(@) $$i ; done
322         $(do_strip)
323
324 endif # ifeq ($(strip $(CONFIG_BUILD_LIBBUSYBOX)),y)
325
326 busybox_unstripped: $(top_builddir)/.depend $(LIBBUSYBOX_SONAME) $(BUSYBOX_SRC) $(APPLET_SRC) $(libraries-y)
327         $(do_link) $(PROG_CFLAGS) $(PROG_LDFLAGS) $(CFLAGS_COMBINE) \
328         $(foreach f,$(^:.o=.c),$(CFLAGS-$(notdir $(patsubst %/$,%,$(dir $(f))))-$(notdir $(f)))) \
329         $(CFLAGS-$(@)) \
330         -o $@ -Wl,--start-group \
331         $(APPLETS_DEFINE) $(APPLET_SRC) \
332         $(BUSYBOX_DEFINE) $(BUSYBOX_SRC) \
333         $(libraries-y) \
334         $(LDBUSYBOX) $(LIBRARIES) \
335         -Wl,--end-group
336
337 busybox: busybox_unstripped
338         $(Q)cp busybox_unstripped busybox
339         $(do_strip)
340
341 busybox.links: $(top_srcdir)/applets/busybox.mkll include/bb_config.h $(top_srcdir)/include/applets.h
342         $(Q)-$(SHELL) $^ >$@
343
344 install: $(top_srcdir)/applets/install.sh busybox busybox.links
345         $(Q)DO_INSTALL_LIBS="$(strip $(LIBBUSYBOX_SONAME) $(DO_INSTALL_LIBS))" \
346                 $(SHELL) $< $(PREFIX) $(INSTALL_OPTS)
347 ifeq ($(strip $(CONFIG_FEATURE_SUID)),y)
348         @echo
349         @echo
350         @echo --------------------------------------------------
351         @echo You will probably need to make your busybox binary
352         @echo setuid root to ensure all configured applets will
353         @echo work properly.
354         @echo --------------------------------------------------
355         @echo
356 endif
357
358 uninstall: busybox.links
359         rm -f $(PREFIX)/bin/busybox
360         for i in `cat busybox.links` ; do rm -f $(PREFIX)$$i; done
361 ifneq ($(strip $(DO_INSTALL_LIBS)),n)
362         for i in $(LIBBUSYBOX_SONAME) $(DO_INSTALL_LIBS); do \
363                 rm -f $(PREFIX)$$i; \
364         done
365 endif
366
367 check test: busybox
368         bindir=$(top_builddir) srcdir=$(top_srcdir)/testsuite \
369         $(top_srcdir)/testsuite/runtest $(CHECK_VERBOSE)
370
371 sizes: busybox_unstripped
372         $(NM) --size-sort $(<)
373
374 # Documentation Targets
375 doc: docs/busybox.pod docs/BusyBox.txt docs/BusyBox.1 docs/BusyBox.html ;
376
377 docs/busybox.pod : $(top_srcdir)/docs/busybox_header.pod $(top_srcdir)/include/usage.h $(top_srcdir)/docs/busybox_footer.pod $(top_srcdir)/docs/autodocifier.pl
378         $(disp_doc)
379         $(Q)-mkdir -p docs
380         $(Q)-( cat $(top_srcdir)/docs/busybox_header.pod ; \
381             $(top_srcdir)/docs/autodocifier.pl $(top_srcdir)/include/usage.h ; \
382             cat $(top_srcdir)/docs/busybox_footer.pod ; ) > docs/busybox.pod
383
384 docs/BusyBox.txt: docs/busybox.pod
385         $(disp_doc)
386         $(Q)-mkdir -p docs
387         $(Q)-pod2text $< > $@
388
389 docs/BusyBox.1: docs/busybox.pod
390         $(disp_doc)
391         $(Q)-mkdir -p docs
392         $(Q)-pod2man --center=BusyBox --release="version $(VERSION)" \
393                 $< > $@
394
395 docs/BusyBox.html: docs/busybox.net/BusyBox.html
396         $(disp_doc)
397         $(Q)-mkdir -p docs
398         $(Q)-rm -f docs/BusyBox.html
399         $(Q)-cp docs/busybox.net/BusyBox.html docs/BusyBox.html
400
401 docs/busybox.net/BusyBox.html: docs/busybox.pod
402         $(Q)-mkdir -p docs/busybox.net
403         $(Q)-pod2html --noindex $< > \
404             docs/busybox.net/BusyBox.html
405         $(Q)-rm -f pod2htm*
406
407 # The nifty new dependency stuff
408 scripts/bb_mkdep: $(top_srcdir)/scripts/bb_mkdep.c
409         $(do_link.h)
410
411 DEP_INCLUDES := include/bb_config.h
412
413 ifeq ($(strip $(CONFIG_BBCONFIG)),y)
414 DEP_INCLUDES += include/bbconfigopts.h
415
416 include/bbconfigopts.h: .config
417         $(disp_gen)
418         $(Q)$(top_srcdir)/scripts/config/mkconfigs > $@
419 endif
420
421 depend dep: $(top_builddir)/.depend ;
422 $(top_builddir)/.depend: $(buildtree) scripts/bb_mkdep $(DEP_INCLUDES)
423         $(disp_gen)
424         $(Q)rm -f .depend
425         $(Q)scripts/bb_mkdep $(MKDEP_ARGS) \
426                 -I $(top_srcdir)/include $(top_srcdir) > $@.tmp
427         $(Q)mv $@.tmp $@
428
429 include/bb_config.h: .config
430         $(disp_gen)
431         @$(top_builddir)/scripts/config/conf -o $(CONFIG_CONFIG_IN)
432
433 endif # ifeq ($(strip $(HAVE_DOT_CONFIG)),y)
434
435 clean:
436         - rm -f docs/busybox.dvi docs/busybox.ps \
437             docs/busybox.pod docs/busybox.net/busybox.html \
438             docs/busybox pod2htm* *.gdb *.elf *~ core .*config.log \
439             docs/BusyBox.txt docs/BusyBox.1 docs/BusyBox.html \
440             docs/busybox.net/BusyBox.html busybox.links \
441             libbusybox.so* \
442             .config.old busybox busybox_unstripped
443         - rm -r -f _install testsuite/links
444         - find . -name .\*.flags -o -name \*.o  -o -name \*.om \
445             -o -name \*.os -o -name \*.osm -o -name \*.a | xargs rm -f
446
447 distclean: clean
448         - $(MAKE) -C scripts/config clean
449         - rm -f scripts/bb_mkdep
450         - rm -r -f include/config $(DEP_INCLUDES)
451         - find . -name .depend'*' | xargs rm -f 
452         rm -f .config .config.old .config.cmd
453
454 release: distclean #doc
455         cd ..; \
456         rm -r -f $(PROG)-$(VERSION); \
457         cp -a busybox $(PROG)-$(VERSION); \
458         \
459         find $(PROG)-$(VERSION)/ -type d \
460                 -name .svn \
461                 -print \
462                 -exec rm -r -f {} \; ; \
463         \
464         find $(PROG)-$(VERSION)/ -type f \
465                 -name .\#* \
466                 -print \
467                 -exec rm -f {} \; ; \
468         \
469         tar -cvzf $(PROG)-$(VERSION).tar.gz $(PROG)-$(VERSION)/;
470
471 tags:
472         ctags -R .
473
474 # keep these in sync with noconfig_targets above!
475 .PHONY: dummy subdirs check test depend dep buildtree \
476         menuconfig config oldconfig randconfig \
477         defconfig allyesconfig allnoconfig allbareconfig \
478         clean distclean \
479         release tags
480