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