Apply Vladimir's latest cleanup patch.
[platform/upstream/busybox.git] / Makefile
1 # Makefile for busybox
2 #
3 # Copyright (C) 1999,2000,2001 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.51
22 BUILDTIME := $(shell TZ=UTC date --utc "+%Y.%m.%d-%H:%M%z")
23 export VERSION
24
25 # With a modern GNU make(1) (highly recommended, that's what all the
26 # developers use), all of the following configuration values can be
27 # overridden at the command line.  For example:
28 #   make CROSS=powerpc-linux- BB_SRC_DIR=$HOME/busybox PREFIX=/mnt/app
29
30 # If you want to add some simple compiler switches (like -march=i686),
31 # especially from the command line, use this instead of CFLAGS directly.
32 # For optimization overrides, it's better still to set OPTIMIZATION.
33 CFLAGS_EXTRA =
34  
35 # If you want a static binary, turn this on.
36 DOSTATIC = false
37
38 # Set the following to `true' to make a debuggable build.
39 # Leave this set to `false' for production use.
40 # eg: `make DODEBUG=true tests'
41 # Do not enable this for production builds...
42 DODEBUG = false
43
44 # Setting this to `true' will cause busybox to directly use the system's
45 # password and group functions.  Assuming you use GNU libc, when this is
46 # `true', you will need to install the /etc/nsswitch.conf configuration file
47 # and the required libnss_* libraries. This generally makes your embedded
48 # system quite a bit larger... If you leave this off, busybox will directly
49 # use the /etc/password, /etc/group files (and your system will be smaller, and
50 # I will get fewer emails asking about how glibc NSS works).  Enabling this adds
51 # just 1.4k to the binary size (which is a _lot_ less then glibc NSS costs),
52 # Most people will want to leave this set to false.
53 USE_SYSTEM_PWD_GRP = true
54
55 # This enables compiling with dmalloc ( http://dmalloc.com/ )
56 # which is an excellent public domain mem leak and malloc problem
57 # detector.  To enable dmalloc, before running busybox you will
58 # want to first set up your environment.
59 # eg: `export DMALLOC_OPTIONS=debug=0x14f47d83,inter=100,log=logfile`
60 # Do not enable this for production builds...
61 DODMALLOC = false
62
63 # Electric-fence is another very useful malloc debugging library.
64 # Do not enable this for production builds...
65 DOEFENCE  = false
66
67 # If you want large file summit support, turn this on.
68 # This has no effect if you don't have a kernel with lfs
69 # support, and a system with libc-2.1.3 or later.
70 # Some of the programs that can benefit from lfs support
71 # are dd, gzip, mount, tar, and mkfs_minix.
72 # LFS allows you to use the above programs for files
73 # larger than 2GB!
74 DOLFS = false
75
76 # If you have a "pristine" source directory, point BB_SRC_DIR to it.
77 # Experimental and incomplete; tell the mailing list
78 # <busybox@opensource.lineo.com> if you do or don't like it so far.
79 BB_SRC_DIR =
80
81 # If you are running a cross compiler, you may want to set this
82 # to something more interesting, like "powerpc-linux-".
83 CROSS =
84 CC = $(CROSS)gcc
85 AR = $(CROSS)ar
86 STRIPTOOL = $(CROSS)strip
87
88 # To compile vs uClibc, just use the compiler wrapper built by uClibc...
89 # This make things very easy?  Everything should compile and work as
90 # expected these days...
91 #CC = ../uClibc/extra/gcc-uClibc/gcc-uClibc-i386
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 >/dev/null 2>&1; \
113     then echo "-Os"; else echo "-O2" ; fi)
114
115 WARNINGS = -Wall -Wshadow
116
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
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     STRIP    =
149 else
150     CFLAGS  += $(WARNINGS) $(OPTIMIZATION) -fomit-frame-pointer -D_GNU_SOURCE
151     LDFLAGS += -s -Wl,-warn-common
152     STRIP    = $(STRIPTOOL) --remove-section=.note --remove-section=.comment $(PROG)
153 endif
154 ifeq ($(strip $(DOSTATIC)),true)
155     LDFLAGS += --static
156     #
157     #use '-ffunction-sections -fdata-sections' and '--gc-sections' (if they 
158     # work) to try and strip out any unused junk.  Doesn't do much for me, 
159     # but you may want to give it a shot...
160     #
161     #ifeq ($(shell $(CC) -ffunction-sections -fdata-sections -S \
162     #   -o /dev/null -xc /dev/null 2>/dev/null && $(LD) \
163     #                   --gc-sections -v >/dev/null && echo 1),1)
164     #   CFLAGS += -ffunction-sections -fdata-sections
165     #   LDFLAGS += --gc-sections
166     #endif
167 endif
168
169 ifndef $(PREFIX)
170     PREFIX = `pwd`/_install
171 endif
172
173 # Additional complications due to support for pristine source dir.
174 # Include files in the build directory should take precedence over
175 # the copy in BB_SRC_DIR, both during the compilation phase and the
176 # shell script that finds the list of object files.
177 # Work in progress by <ldoolitt@recycle.lbl.gov>.
178 #
179 ifneq ($(strip $(BB_SRC_DIR)),)
180     VPATH = $(BB_SRC_DIR)
181 endif
182 #ifneq ($(strip $(VPATH)),)
183 #    CFLAGS += -I- -I. $(patsubst %,-I%,$(subst :, ,$(VPATH)))
184 #endif
185
186 # We need to set APPLET_SOURCES to something like
187 #   $(shell busybox.sh Config.h)
188 # but in a manner that works with VPATH and BB_SRC_DIR.
189 # Possible ways to approach this:
190 #
191 #   1. Explicitly search through .:$(VPATH) for busybox.sh and config.h,
192 #      then $(shell $(BUSYBOX_SH) $(CONFIG_H) $(BB_SRC_DIR))
193 #
194 #   2. Explicity search through .:$(VPATH) for slist.mk,
195 #      then $(shell $(MAKE) -f $(SLIST_MK) VPATH=$(VPATH) BB_SRC_DIR=$(BB_SRC_DIR))
196 #
197 #   3. Create slist.mk in this directory, with commands embedded in
198 #      a $(shell ...) command, and $(MAKE) it immediately.
199 #
200 #   4. Use a real rule within this makefile to create a file that sets 
201 #      APPLET_SOURCE_LIST, then include that file.  Has complications
202 #      with the first trip through the makefile (before processing the
203 #      include) trying to do too much, and a spurious warning the first
204 #      time make is run.
205 #
206 # This is option 3:
207 #
208 #APPLET_SOURCES = $(shell \
209 #   echo -e 'all: busybox.sh Config.h\n\t@ $$(SHELL) $$^ $$(BB_SRC_DIR)' >slist.mk; \
210 #   make -f slist.mk VPATH=$(VPATH) BB_SRC_DIR=$(BB_SRC_DIR) \
211 #)
212 # And option 4:
213 -include applet_source_list
214
215 OBJECTS   = $(APPLET_SOURCES:.c=.o) busybox.o messages.o usage.o applets.o
216 CFLAGS    += $(CROSS_CFLAGS)
217 CFLAGS    += -DBB_VER='"$(VERSION)"'
218 CFLAGS    += -DBB_BT='"$(BUILDTIME)"'
219 ifdef BB_INIT_SCRIPT
220     CFLAGS += -DINIT_SCRIPT='"$(BB_INIT_SCRIPT)"'
221 endif
222
223 ifneq ($(strip $(USE_SYSTEM_PWD_GRP)),true)
224     PWD_GRP     = pwd_grp
225     PWD_GRP_DIR = $(BB_SRC_DIR:=/)$(PWD_GRP)
226     PWD_LIB     = libpwd.a
227     PWD_CSRC=__getpwent.c pwent.c getpwnam.c getpwuid.c putpwent.c getpw.c \
228             fgetpwent.c __getgrent.c grent.c getgrnam.c getgrgid.c fgetgrent.c \
229             initgroups.c setgroups.c
230     PWD_OBJS=$(patsubst %.c,$(PWD_GRP)/%.o, $(PWD_CSRC))
231     PWD_CFLAGS = -I$(PWD_GRP_DIR)
232 else
233     CFLAGS    += -DUSE_SYSTEM_PWD_GRP
234 endif
235     
236 LIBBB     = libbb
237 LIBBB_LIB = libbb.a
238 LIBBB_CSRC= ask_confirmation.c check_wildcard_match.c chomp.c copy_file.c \
239 copy_file_chunk.c create_path.c daemon.c device_open.c error_msg.c \
240 find_mount_point.c find_pid_by_name.c find_root_device.c full_read.c \
241 full_write.c get_console.c get_last_path_component.c get_line_from_file.c \
242 human_readable.c inode_hash.c isdirectory.c kernel_version.c loop.c \
243 mode_string.c parse_mode.c parse_number.c print_file.c process_escape_sequence.c \
244 my_getgrgid.c my_getpwnamegid.c my_getpwuid.c my_getgrnam.c my_getpwnam.c \
245 recursive_action.c safe_read.c safe_strncpy.c syscalls.c module_syscalls.c \
246 syslog_msg_with_name.c time_string.c trim.c vdprintf.c wfopen.c xfuncs.c \
247 xregcomp.c error_msg_and_die.c perror_msg.c perror_msg_and_die.c \
248 verror_msg.c vperror_msg.c mtab.c mtab_file.c xgetcwd.c concat_path_file.c
249
250 LIBBB_OBJS=$(patsubst %.c,$(LIBBB)/%.o, $(LIBBB_CSRC))
251 LIBBB_CFLAGS = -I$(LIBBB)
252 ifneq ($(strip $(BB_SRC_DIR)),)
253     LIBBB_CFLAGS += -I$(BB_SRC_DIR)/$(LIBBB)
254 endif
255
256
257 # Put user-supplied flags at the end, where they
258 # have a chance of winning.
259 CFLAGS += $(CFLAGS_EXTRA)
260
261 .EXPORT_ALL_VARIABLES:
262
263 all: applet_source_list busybox busybox.links doc
264
265 applet_source_list: busybox.sh Config.h
266         (echo -n "APPLET_SOURCES := "; $(SHELL) $^ $(BB_SRC_DIR)) > $@
267
268 doc: olddoc
269
270 # Old Docs...
271 olddoc: docs/busybox.pod docs/BusyBox.txt docs/BusyBox.1 docs/BusyBox.html
272
273 docs/busybox.pod : docs/busybox_header.pod usage.h docs/busybox_footer.pod
274         - ( cat docs/busybox_header.pod; \
275             docs/autodocifier.pl usage.h; \
276             cat docs/busybox_footer.pod ) > docs/busybox.pod
277
278 docs/BusyBox.txt: docs/busybox.pod
279         @echo
280         @echo BusyBox Documentation
281         @echo
282         -mkdir -p docs
283         -pod2text $< > $@
284
285 docs/BusyBox.1: docs/busybox.pod
286         - mkdir -p docs
287         - pod2man --center=BusyBox --release="version $(VERSION)" \
288                 $< > $@
289
290 docs/BusyBox.html: docs/busybox.lineo.com/BusyBox.html
291         - mkdir -p docs
292         -@ rm -f docs/BusyBox.html
293         -@ ln -s busybox.lineo.com/BusyBox.html docs/BusyBox.html
294
295 docs/busybox.lineo.com/BusyBox.html: docs/busybox.pod
296         -@ mkdir -p docs/busybox.lineo.com
297         -  pod2html --noindex $< > \
298             docs/busybox.lineo.com/BusyBox.html
299         -@ rm -f pod2html*
300
301
302 # New docs based on DOCBOOK SGML
303 newdoc: docs/busybox.txt docs/busybox.pdf docs/busybox/busyboxdocumentation.html
304
305 docs/busybox.txt: docs/busybox.sgml
306         @echo
307         @echo BusyBox Documentation
308         @echo
309         - mkdir -p docs
310         (cd docs; sgmltools -b txt busybox.sgml)
311
312 docs/busybox.dvi: docs/busybox.sgml
313         - mkdir -p docs
314         (cd docs; sgmltools -b dvi busybox.sgml)
315
316 docs/busybox.ps: docs/busybox.sgml
317         - mkdir -p docs
318         (cd docs; sgmltools -b ps busybox.sgml)
319
320 docs/busybox.pdf: docs/busybox.ps
321         - mkdir -p docs
322         (cd docs; ps2pdf busybox.ps)
323
324 docs/busybox/busyboxdocumentation.html: docs/busybox.sgml
325         - mkdir -p docs
326         (cd docs/busybox.lineo.com; sgmltools -b html ../busybox.sgml)
327
328
329 busybox: $(PWD_LIB) $(LIBBB_LIB) $(OBJECTS) 
330         $(CC) $(LDFLAGS) -o $@ $(OBJECTS) $(PWD_LIB) $(LIBBB_LIB) $(LIBRARIES)
331         $(STRIP)
332
333 # Without VPATH, rule expands to "/bin/sh busybox.mkll Config.h applets.h"
334 # but with VPATH, some or all of those file names are resolved to the
335 # directories in which they live.
336 busybox.links: busybox.mkll Config.h applets.h
337         - $(SHELL) $^ >$@
338
339 nfsmount.o cmdedit.o: %.o: %.h
340 sh.o: cmdedit.h
341 $(OBJECTS): %.o: %.c Config.h busybox.h applets.h Makefile
342         $(CC) -I- $(CFLAGS) -I. $(patsubst %,-I%,$(subst :, ,$(BB_SRC_DIR))) -c $< -o $*.o
343
344 $(PWD_OBJS): %.o: %.c Config.h busybox.h applets.h Makefile
345         - mkdir -p $(PWD_GRP)
346         $(CC) $(CFLAGS) $(PWD_CFLAGS) -c $< -o $*.o
347
348 $(LIBBB_OBJS): %.o: %.c Config.h busybox.h applets.h Makefile libbb/libbb.h
349         - mkdir -p $(LIBBB)
350         $(CC) $(CFLAGS) $(LIBBB_CFLAGS) -c $< -o $*.o
351
352 libpwd.a: $(PWD_OBJS)
353         $(AR) $(ARFLAGS) $@ $^
354
355 libbb.a: $(LIBBB_OBJS)
356         $(AR) $(ARFLAGS) $@ $^
357
358 usage.o: usage.h
359
360 libbb/loop.o: libbb/loop.h
361
362 libbb/loop.h: mk_loop_h.sh
363         @ $(SHELL) $< > $@
364
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 clean:
372         - cd tests && $(MAKE) clean
373         - rm -f docs/BusyBox.txt docs/BusyBox.1 docs/BusyBox.html \
374             docs/busybox.lineo.com/BusyBox.html
375         - rm -f docs/busybox.txt docs/busybox.dvi docs/busybox.ps \
376             docs/busybox.pdf docs/busybox.lineo.com/busybox.html
377         - rm -f multibuild.log Config.h.orig
378         - rm -rf docs/busybox _install libpwd.a libbb.a
379         - rm -f busybox.links libbb/loop.h *~ slist.mk core applet_source_list
380         - find -name \*.o -exec rm -f {} \;
381
382 distclean: clean
383         - rm -f busybox
384         - cd tests && $(MAKE) distclean
385
386 install: install.sh busybox busybox.links
387         $(SHELL) $< $(PREFIX)
388
389 install-hardlinks: install.sh busybox busybox.links
390         $(SHELL) $< $(PREFIX) --hardlinks
391
392 debug_pristine:
393         @ echo VPATH=\"$(VPATH)\"
394         @ echo OBJECTS=\"$(OBJECTS)\"
395
396 dist release: distclean doc
397         cd ..;                                  \
398         rm -rf busybox-$(VERSION);              \
399         cp -a busybox busybox-$(VERSION);       \
400                                                 \
401         find busybox-$(VERSION)/ -type d        \
402                                  -name CVS      \
403                                  -print         \
404                 -exec rm -rf {} \; ;            \
405                                                 \
406         find busybox-$(VERSION)/ -type f        \
407                                  -name .cvsignore \
408                                  -print         \
409                 -exec rm -f {}  \; ;            \
410                                                 \
411         find busybox-$(VERSION)/ -type f        \
412                                  -name .\#*     \
413                                  -print         \
414                 -exec rm -f {} \;  ;            \
415                                                 \
416         tar -cvzf busybox-$(VERSION).tar.gz busybox-$(VERSION)/;
417
418 .PHONY: tags
419 tags:
420         ctags -R .