Move messages.c to libbb. Make each string in messages.c be its own .o file.
[oweals/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 -u "+%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/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 >/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 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 \
239 concat_path_file.c copy_file.c copy_file_chunk.c create_path.c \
240 daemon.c deb_extract.c device_open.c error_msg.c error_msg_and_die.c \
241 find_mount_point.c find_pid_by_name.c find_root_device.c full_read.c \
242 full_write.c get_ar_headers.c get_console.c get_last_path_component.c \
243 get_line_from_file.c gz_open.c human_readable.c inode_hash.c isdirectory.c \
244 kernel_version.c loop.c mode_string.c module_syscalls.c mtab.c mtab_file.c \
245 my_getgrnam.c my_getgrgid.c my_getpwnam.c my_getpwnamegid.c my_getpwuid.c \
246 parse_mode.c parse_number.c perror_msg.c perror_msg_and_die.c print_file.c \
247 process_escape_sequence.c read_package_field.c read_text_file_to_buffer.c \
248 recursive_action.c safe_read.c safe_strncpy.c seek_ared_file.c syscalls.c \
249 syslog_msg_with_name.c time_string.c trim.c untar.c unzip.c vdprintf.c \
250 verror_msg.c vperror_msg.c wfopen.c xfuncs.c xgetcwd.c xregcomp.c interface.c \
251 remove_file.c
252 LIBBB_OBJS=$(patsubst %.c,$(LIBBB)/%.o, $(LIBBB_CSRC))
253 LIBBB_CFLAGS = -I$(LIBBB)
254 ifneq ($(strip $(BB_SRC_DIR)),)
255     LIBBB_CFLAGS += -I$(BB_SRC_DIR)/$(LIBBB)
256 endif
257
258 LIBBB_MSRC=libbb/messages.c
259 LIBBB_MESSAGES= full_version name_too_long omitting_directory not_a_directory \
260 memory_exhausted invalid_date invalid_option io_error dash_dash_help \
261 write_error too_few_args name_longer_than_foo
262 LIBBB_MOBJ=$(patsubst %,$(LIBBB)/%.o, $(LIBBB_MESSAGES))
263
264
265 # Put user-supplied flags at the end, where they
266 # have a chance of winning.
267 CFLAGS += $(CFLAGS_EXTRA)
268
269 .EXPORT_ALL_VARIABLES:
270
271 all: applet_source_list busybox busybox.links doc
272
273 applet_source_list: busybox.sh Config.h
274         (echo -n "APPLET_SOURCES := "; $(SHELL) $^ $(BB_SRC_DIR)) > $@
275
276 doc: olddoc
277
278 # Old Docs...
279 olddoc: docs/busybox.pod docs/BusyBox.txt docs/BusyBox.1 docs/BusyBox.html
280
281 docs/busybox.pod : docs/busybox_header.pod usage.h docs/busybox_footer.pod
282         - ( cat docs/busybox_header.pod; \
283             docs/autodocifier.pl usage.h; \
284             cat docs/busybox_footer.pod ) > docs/busybox.pod
285
286 docs/BusyBox.txt: docs/busybox.pod
287         @echo
288         @echo BusyBox Documentation
289         @echo
290         -mkdir -p docs
291         -pod2text $< > $@
292
293 docs/BusyBox.1: docs/busybox.pod
294         - mkdir -p docs
295         - pod2man --center=BusyBox --release="version $(VERSION)" \
296                 $< > $@
297
298 docs/BusyBox.html: docs/busybox.lineo.com/BusyBox.html
299         - mkdir -p docs
300         -@ rm -f docs/BusyBox.html
301         -@ ln -s busybox.lineo.com/BusyBox.html docs/BusyBox.html
302
303 docs/busybox.lineo.com/BusyBox.html: docs/busybox.pod
304         -@ mkdir -p docs/busybox.lineo.com
305         -  pod2html --noindex $< > \
306             docs/busybox.lineo.com/BusyBox.html
307         -@ rm -f pod2htm*
308
309
310 # New docs based on DOCBOOK SGML
311 newdoc: docs/busybox.txt docs/busybox.pdf docs/busybox/busyboxdocumentation.html
312
313 docs/busybox.txt: docs/busybox.sgml
314         @echo
315         @echo BusyBox Documentation
316         @echo
317         - mkdir -p docs
318         (cd docs; sgmltools -b txt busybox.sgml)
319
320 docs/busybox.dvi: docs/busybox.sgml
321         - mkdir -p docs
322         (cd docs; sgmltools -b dvi busybox.sgml)
323
324 docs/busybox.ps: docs/busybox.sgml
325         - mkdir -p docs
326         (cd docs; sgmltools -b ps busybox.sgml)
327
328 docs/busybox.pdf: docs/busybox.ps
329         - mkdir -p docs
330         (cd docs; ps2pdf busybox.ps)
331
332 docs/busybox/busyboxdocumentation.html: docs/busybox.sgml
333         - mkdir -p docs
334         (cd docs/busybox.lineo.com; sgmltools -b html ../busybox.sgml)
335
336
337 busybox: $(PWD_LIB) $(LIBBB_LIB) $(OBJECTS) 
338         $(CC) $(LDFLAGS) -o $@ $(OBJECTS) $(LIBBB_LIB) $(PWD_LIB) $(LIBRARIES)
339         $(STRIP)
340
341 # Without VPATH, rule expands to "/bin/sh busybox.mkll Config.h applets.h"
342 # but with VPATH, some or all of those file names are resolved to the
343 # directories in which they live.
344 busybox.links: busybox.mkll Config.h applets.h
345         - $(SHELL) $^ >$@
346
347 nfsmount.o cmdedit.o: %.o: %.h
348 sh.o: cmdedit.h
349 $(OBJECTS): %.o: %.c Config.h busybox.h applets.h Makefile
350         $(CC) -I- $(CFLAGS) -I. $(patsubst %,-I%,$(subst :, ,$(BB_SRC_DIR))) -c $< -o $*.o
351
352 $(PWD_OBJS): %.o: %.c Config.h busybox.h applets.h Makefile
353         - mkdir -p $(PWD_GRP)
354         $(CC) $(CFLAGS) $(PWD_CFLAGS) -c $< -o $*.o
355
356 $(LIBBB_OBJS): %.o: %.c Config.h busybox.h applets.h Makefile libbb/libbb.h
357         - mkdir -p $(LIBBB)
358         $(CC) $(CFLAGS) $(LIBBB_CFLAGS) -c $< -o $*.o
359
360 $(LIBBB_MOBJ): $(LIBBB_MSRC)
361         $(CC) $(CFLAGS) $(LIBBB_CFLAGS) -DL_$(patsubst libbb/%,%,$*) -c $< -o $*.o
362
363 libpwd.a: $(PWD_OBJS)
364         $(AR) $(ARFLAGS) $@ $^
365
366 libbb.a:  $(LIBBB_MOBJ) $(LIBBB_OBJS)
367         $(AR) $(ARFLAGS) $@ $^
368
369 usage.o: usage.h
370
371 libbb/loop.o: libbb/loop.h
372
373 libbb/loop.h: mk_loop_h.sh
374         @ $(SHELL) $< > $@
375
376 test tests:
377         # old way of doing it
378         #cd tests && $(MAKE) all
379         # new way of doing it
380         cd tests && ./tester.sh
381
382 clean:
383         - cd tests && $(MAKE) clean
384         - rm -f docs/BusyBox.txt docs/BusyBox.1 docs/BusyBox.html \
385             docs/busybox.lineo.com/BusyBox.html
386         - rm -f docs/busybox.txt docs/busybox.dvi docs/busybox.ps \
387             docs/busybox.pdf docs/busybox.lineo.com/busybox.html
388         - rm -f multibuild.log Config.h.orig
389         - rm -rf docs/busybox _install libpwd.a libbb.a pod2htm*
390         - rm -f busybox.links libbb/loop.h *~ slist.mk core applet_source_list
391         - find -name \*.o -exec rm -f {} \;
392
393 distclean: clean
394         - rm -f busybox
395         - cd tests && $(MAKE) distclean
396
397 install: install.sh busybox busybox.links
398         $(SHELL) $< $(PREFIX)
399
400 install-hardlinks: install.sh busybox busybox.links
401         $(SHELL) $< $(PREFIX) --hardlinks
402
403 debug_pristine:
404         @ echo VPATH=\"$(VPATH)\"
405         @ echo OBJECTS=\"$(OBJECTS)\"
406
407 dist release: distclean doc
408         cd ..;                                  \
409         rm -rf busybox-$(VERSION);              \
410         cp -a busybox busybox-$(VERSION);       \
411                                                 \
412         find busybox-$(VERSION)/ -type d        \
413                                  -name CVS      \
414                                  -print         \
415                 -exec rm -rf {} \; ;            \
416                                                 \
417         find busybox-$(VERSION)/ -type f        \
418                                  -name .cvsignore \
419                                  -print         \
420                 -exec rm -f {}  \; ;            \
421                                                 \
422         find busybox-$(VERSION)/ -type f        \
423                                  -name .\#*     \
424                                  -print         \
425                 -exec rm -f {} \;  ;            \
426                                                 \
427         tar -cvzf busybox-$(VERSION).tar.gz busybox-$(VERSION)/;
428
429 .PHONY: tags
430 tags:
431         ctags -R .