Update dmalloc options per suggestion from Glenn
[oweals/busybox.git] / Makefile
1 # Makefile for busybox
2 #
3 # Copyright (C) 1999,2000,2001 by Erik Andersen <andersee@debian.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 PROG      := busybox
21 VERSION   := 0.61.pre
22 BUILDTIME := $(shell TZ=UTC date -u "+%Y.%m.%d-%H:%M%z")
23 TOPDIR    := ${shell /bin/pwd}
24 HOSTCC    := gcc
25 HOSTCFLAGS:= -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer
26
27
28 # What OS are you compiling busybox for?  This allows you to include
29 # OS specific things, syscall overrides, etc.
30 TARGET_OS := linux
31
32 # With a modern GNU make(1) (highly recommended, that's what all the
33 # developers use), all of the following configuration values can be
34 # overridden at the command line.  For example:
35 #   make CROSS=powerpc-linux- BB_SRC_DIR=$HOME/busybox PREFIX=/mnt/app
36
37 # If you want to add some simple compiler switches (like -march=i686),
38 # especially from the command line, use this instead of CFLAGS directly.
39 # For optimization overrides, it's better still to set OPTIMIZATION.
40 CFLAGS_EXTRA =
41  
42 # If you want a static binary, turn this on.
43 DOSTATIC = false
44
45 # Set the following to `true' to make a debuggable build.
46 # Leave this set to `false' for production use.
47 DODEBUG = false
48
49 # This enables compiling with dmalloc ( http://dmalloc.com/ )
50 # which is an excellent public domain mem leak and malloc problem
51 # detector.  To enable dmalloc, before running busybox you will
52 # want to first set up your environment.
53 # eg: `export DMALLOC_OPTIONS=debug=0x34f47d83,inter=100,log=logfile`
54 # The debug= value is generated using the following command
55 # dmalloc -p log-stats -p log-non-free -p log-bad-space -p log-elapsed-time \
56 #      -p check-fence -p check-heap -p check-lists -p check-blank \
57 #      -p check-funcs -p realloc-copy -p allow-free-null
58 # Do not enable this for production builds...
59 DODMALLOC = false
60
61 # Electric-fence is another very useful malloc debugging library.
62 # Do not enable this for production builds...
63 DOEFENCE  = false
64
65 # If you want large file summit support, turn this on.
66 # This has no effect if you don't have a kernel with lfs
67 # support, and a system with libc-2.1.3 or later.
68 # Some of the programs that can benefit from lfs support
69 # are dd, gzip, mount, tar, and mkfs_minix.
70 # LFS allows you to use the above programs for files
71 # larger than 2GB!
72 DOLFS = false
73
74 # If you have a "pristine" source directory, point BB_SRC_DIR to it.
75 # Experimental and incomplete; tell the mailing list
76 # <busybox@busybox.net> if you do or don't like it so far.
77 BB_SRC_DIR =
78
79 # If you are running a cross compiler, you may want to set CROSS
80 # to something more interesting, like "arm-linux-".
81 CROSS =
82 CC              = $(CROSS)gcc
83 AR              = $(CROSS)ar
84 AS              = $(CROSS)as
85 LD              = $(CROSS)ld
86 NM              = $(CROSS)nm
87 STRIP           = $(CROSS)strip
88 CPP             = $(CC) -E
89 MAKEFILES       = $(TOPDIR)/.config
90 export VERSION BUILDTIME TOPDIR HOSTCC HOSTCFLAGS CROSS CC AR AS LD NM STRIP CPP
91
92
93 # To compile vs uClibc, just use the compiler wrapper built by uClibc...
94 # Everything should compile and work as expected these days...
95 #CC = /usr/i386-linux-uclibc/usr/bin/i386-uclibc-gcc
96
97 # To compile vs some other alternative libc, you may need to use/adjust
98 # the following lines to meet your needs...
99 #
100 # If you are using Red Hat 6.x with the compatible RPMs (for developing under
101 # Red Hat 5.x and glibc 2.0) uncomment the following.  Be sure to read about
102 # using the compatible RPMs (compat-*) at http://www.redhat.com !
103 #LIBCDIR=/usr/i386-glibc20-linux
104 #
105 # The following is used for libc5 (if you install altgcc and libc5-altdev
106 # on a Debian system).  
107 #LIBCDIR=/usr/i486-linuxlibc1
108 #
109 # For other libraries, you are on your own...
110 #LDFLAGS+=-nostdlib
111 #LIBRARIES = $(LIBCDIR)/lib/libc.a -lgcc
112 #CROSS_CFLAGS+=-nostdinc -I$(LIBCDIR)/include -I$(GCCINCDIR)
113 #GCCINCDIR = $(shell gcc -print-search-dirs | sed -ne "s/install: \(.*\)/\1include/gp")
114
115 # use '-Os' optimization if available, else use -O2
116 OPTIMIZATION := ${shell if $(CC) -Os -S -o /dev/null -xc /dev/null \
117         >/dev/null 2>&1; then echo "-Os"; else echo "-O2" ; fi}
118 GCC_STACK_BOUNDRY := ${shell if $(CC) -mpreferred-stack-boundary=2 -S -o /dev/null -xc /dev/null \
119         >/dev/null 2>&1; then echo "-mpreferred-stack-boundary=2"; else echo "" ; fi}
120 OPTIMIZATIONS=$(OPTIMIZATION) -fomit-frame-pointer $(GCC_STACK_BOUNDRY) #-fstrict-aliasing -march=i386 -mcpu=i386 -malign-functions=0 -malign-jumps=0
121 WARNINGS=-Wall -Wstrict-prototypes -Wshadow
122 CFLAGS = -I$(TOPDIR)/include
123 ARFLAGS = -r
124
125 #
126 #--------------------------------------------------------
127 # If you're going to do a lot of builds with a non-vanilla configuration,
128 # it makes sense to adjust parameters above, so you can type "make"
129 # by itself, instead of following it by the same half-dozen overrides
130 # every time.  The stuff below, on the other hand, is probably less
131 # prone to casual user adjustment.
132
133
134 ifeq ($(strip $(DOLFS)),true)
135     # For large file summit support
136     CFLAGS+=-D_FILE_OFFSET_BITS=64 -D__USE_FILE_OFFSET64
137 endif
138 ifeq ($(strip $(DODMALLOC)),true)
139     # For testing mem leaks with dmalloc
140     CFLAGS+=-DDMALLOC
141     LIBRARIES = -ldmalloc
142     # Force debug=true, since this is useless when not debugging...
143     DODEBUG = true
144 else
145     ifeq ($(strip $(DOEFENCE)),true)
146         LIBRARIES = -lefence
147         # Force debug=true, since this is useless when not debugging...
148         DODEBUG = true
149     endif
150 endif
151 ifeq ($(strip $(DODEBUG)),true)
152     CFLAGS  += $(WARNINGS) -g -D_GNU_SOURCE
153     LDFLAGS += -Wl,-warn-common
154     STRIPCMD = /bin/true -Not_stripping_since_we_are_debugging
155 else
156     CFLAGS  += $(WARNINGS) $(OPTIMIZATIONS) -D_GNU_SOURCE
157     LDFLAGS += -s -Wl,-warn-common
158     STRIPCMD    = $(STRIP) --remove-section=.note --remove-section=.comment
159 endif
160 ifeq ($(strip $(DOSTATIC)),true)
161     LDFLAGS += --static
162 endif
163
164 ifndef $(PREFIX)
165     PREFIX = `pwd`/_install
166 endif
167
168 # Additional complications due to support for pristine source dir.
169 # Include files in the build directory should take precedence over
170 # the copy in BB_SRC_DIR, both during the compilation phase and the
171 # shell script that finds the list of object files.
172 # Work in progress by <ldoolitt@recycle.lbl.gov>.
173 #
174 ifneq ($(strip $(BB_SRC_DIR)),)
175     VPATH = $(BB_SRC_DIR)
176 endif
177
178 OBJECTS   = $(APPLET_SOURCES:.c=.o) busybox.o usage.o applets.o
179 CFLAGS    += $(CROSS_CFLAGS)
180 ifdef BB_INIT_SCRIPT
181     CFLAGS += -DINIT_SCRIPT='"$(BB_INIT_SCRIPT)"'
182 endif
183
184 # Put user-supplied flags at the end, where they
185 # have a chance of winning.
186 CFLAGS += $(CFLAGS_EXTRA)
187
188 .EXPORT_ALL_VARIABLES:
189
190 all:    do-it-all
191
192 #
193 # Make "config" the default target if there is no configuration file or
194 # "depend" the target if there is no top-level dependency information.
195 ifeq (.config,$(wildcard .config))
196 include .config
197 ifeq (.depend,$(wildcard .depend))
198 include .depend 
199 do-it-all:      busybox busybox.links doc
200 else
201 CONFIGURATION = depend
202 do-it-all:      depend
203 endif
204 else
205 CONFIGURATION = menuconfig
206 do-it-all:      menuconfig
207 endif
208
209
210 SUBDIRS =applets archival archival/libunarchive console-tools editors \
211         fileutils findutils init miscutils modutils networking procps \
212         pwd_grp shell shellutils sysklogd textutils util-linux libbb
213
214 bbsubdirs: $(patsubst %, _dir_%, $(SUBDIRS))
215
216 $(patsubst %, _dir_%, $(SUBDIRS)) : dummy include/config/MARKER
217         $(MAKE) CFLAGS="$(CFLAGS)" -C $(patsubst _dir_%, %, $@)
218
219 busybox: config.h dep-files bbsubdirs
220         $(CC) $(LDFLAGS) -o $@ applets/busybox.o $(shell find $(SUBDIRS) -name \*.a) $(LIBRARIES)
221         $(STRIPCMD) $(PROG)
222
223 busybox.links: applets/busybox.mkll
224         - $(SHELL) $^ >$@
225
226 install: applets/install.sh busybox busybox.links
227         $(SHELL) $< $(PREFIX)
228
229 install-hardlinks: applets/install.sh busybox busybox.links
230         $(SHELL) $< $(PREFIX) --hardlinks
231
232
233 # Documentation Targets
234 doc: olddoc
235
236 # Old Docs...
237 olddoc: docs/busybox.pod docs/BusyBox.txt docs/BusyBox.1 docs/BusyBox.html
238
239 docs/busybox.pod : docs/busybox_header.pod include/usage.h docs/busybox_footer.pod
240         - ( cat docs/busybox_header.pod; \
241             docs/autodocifier.pl include/usage.h; \
242             cat docs/busybox_footer.pod ) > docs/busybox.pod
243
244 docs/BusyBox.txt: docs/busybox.pod
245         @echo
246         @echo BusyBox Documentation
247         @echo
248         -mkdir -p docs
249         -pod2text $< > $@
250
251 docs/BusyBox.1: docs/busybox.pod
252         - mkdir -p docs
253         - pod2man --center=BusyBox --release="version $(VERSION)" \
254                 $< > $@
255
256 docs/BusyBox.html: docs/busybox.net/BusyBox.html
257         - mkdir -p docs
258         -@ rm -f docs/BusyBox.html
259         -@ ln -s busybox.net/BusyBox.html docs/BusyBox.html
260
261 docs/busybox.net/BusyBox.html: docs/busybox.pod
262         -@ mkdir -p docs/busybox.net
263         -  pod2html --noindex $< > \
264             docs/busybox.net/BusyBox.html
265         -@ rm -f pod2htm*
266
267
268 # New docs based on DOCBOOK SGML
269 newdoc: docs/busybox.txt docs/busybox.pdf docs/busybox/busyboxdocumentation.html
270
271 docs/busybox.txt: docs/busybox.sgml
272         @echo
273         @echo BusyBox Documentation
274         @echo
275         - mkdir -p docs
276         (cd docs; sgmltools -b txt busybox.sgml)
277
278 docs/busybox.dvi: docs/busybox.sgml
279         - mkdir -p docs
280         (cd docs; sgmltools -b dvi busybox.sgml)
281
282 docs/busybox.ps: docs/busybox.sgml
283         - mkdir -p docs
284         (cd docs; sgmltools -b ps busybox.sgml)
285
286 docs/busybox.pdf: docs/busybox.ps
287         - mkdir -p docs
288         (cd docs; ps2pdf busybox.ps)
289
290 docs/busybox/busyboxdocumentation.html: docs/busybox.sgml
291         - mkdir -p docs
292         (cd docs/busybox.net; sgmltools -b html ../busybox.sgml)
293
294 # The nifty new buildsystem stuff
295 scripts/mkdep: scripts/mkdep.c
296         $(HOSTCC) $(HOSTCFLAGS) -o scripts/mkdep scripts/mkdep.c
297
298 scripts/split-include: scripts/split-include.c
299         $(HOSTCC) $(HOSTCFLAGS) -o scripts/split-include scripts/split-include.c
300
301 dep-files: scripts/mkdep
302         @if [ ! -f .depend ] ; then \
303                 rm -f .depend .hdepend; \
304                 mkdir -p $(TOPDIR)/include/config; \
305                 scripts/mkdep -I $(TOPDIR)/include -- \
306                         `find $(TOPDIR) -name \*.c -print` >> .depend; \
307                 scripts/mkdep -I $(TOPDIR)/include -- \
308                         `find $(TOPDIR) -name \*.h -print` >> .hdepend; \
309                 $(MAKE) $(patsubst %,_sfdep_%,$(SUBDIRS)) _FASTDEP_ALL_SUB_DIRS="$(SUBDIRS)" ; \
310         fi;
311
312
313 depend dep: config.h dep-files
314         @ echo -e "\n\nNow run 'make' to build BusyBox\n\n"
315
316 BB_SHELL := ${shell if [ -x "$$BASH" ]; then echo $$BASH; \
317         else if [ -x /bin/bash ]; then echo /bin/bash; \
318         else echo sh; fi ; fi}
319
320 include/config/MARKER: scripts/split-include include/config.h
321         scripts/split-include include/config.h include/config
322         @ touch include/config/MARKER
323
324 config.h:
325         @if [ ! -f include/config.h ] ; then \
326                 make oldconfig; \
327         fi;
328
329 menuconfig:
330         mkdir -p $(TOPDIR)/include/config
331         $(MAKE) -C scripts/lxdialog all
332         $(BB_SHELL) scripts/Menuconfig sysdeps/$(TARGET_OS)/config.in
333
334 config:
335         mkdir -p $(TOPDIR)/include/config
336         $(BB_SHELL) scripts/Configure sysdeps/$(TARGET_OS)/config.in
337
338 oldconfig:
339         mkdir -p $(TOPDIR)/include/config
340         $(BB_SHELL) scripts/Configure -d sysdeps/$(TARGET_OS)/config.in
341
342
343 ifdef CONFIGURATION
344 ..$(CONFIGURATION):
345         @echo
346         @echo "You have a bad or nonexistent" .$(CONFIGURATION) ": running 'make" $(CONFIGURATION)"'"
347         @echo
348         $(MAKE) $(CONFIGURATION)
349         @echo
350         @echo "Successful. Try re-making (ignore the error that follows)"
351         @echo
352         exit 1
353
354 dummy:
355
356 else
357
358 dummy:
359
360 endif
361
362 include Rules.mak
363
364 # Testing...
365 test tests:
366         # old way of doing it
367         #cd tests && $(MAKE) all
368         # new way of doing it
369         cd tests && ./tester.sh
370
371 # Cleanup
372 clean:
373         - $(MAKE) -C tests clean
374         - $(MAKE) -C scripts/lxdialog clean
375         - rm -f docs/BusyBox.txt docs/BusyBox.1 docs/BusyBox.html \
376             docs/busybox.net/BusyBox.html
377         - rm -f docs/busybox.txt docs/busybox.dvi docs/busybox.ps \
378             docs/busybox.pdf docs/busybox.net/busybox.html \
379             docs/busybox _install pod2htm* *.gdb *.elf *~ core
380         - rm -f busybox busybox.links libbb/loop.h .config.old .hdepend
381         - rm -f scripts/split-include scripts/mkdep .*config.log
382         - rm -rf include/config include/config.h
383         - find -name .\*.flags -o -name .depend -exec rm -f {} \;
384         - find -name \*.o -exec rm -f {} \;
385         - find -name \*.a -exec rm -f {} \;
386
387 distclean: clean
388         - rm -f busybox 
389         - cd tests && $(MAKE) distclean
390
391 dist release: distclean doc
392         cd ..;                                  \
393         rm -rf busybox-$(VERSION);              \
394         cp -a busybox busybox-$(VERSION);       \
395                                                 \
396         find busybox-$(VERSION)/ -type d        \
397                                  -name CVS      \
398                                  -print         \
399                 -exec rm -rf {} \; ;            \
400                                                 \
401         find busybox-$(VERSION)/ -type f        \
402                                  -name .\#*     \
403                                  -print         \
404                 -exec rm -f {} \;  ;            \
405                                                 \
406         tar -cvzf busybox-$(VERSION).tar.gz busybox-$(VERSION)/;
407
408
409
410 .PHONY: tags check
411 tags:
412         ctags -R .
413
414 check: busybox
415         cd testsuite && ./runtest