424218cfa682d91ffb5ee23e786f186b0ff1b52b
[oweals/busybox.git] / Makefile
1 # Makefile for busybox
2 #
3 # Copyright (C) 1999-2000 Erik Andersen <andersee@debian.org>
4 # Copyright (C) 2000 Karl M. Hegbloom <karlheg@debian.org>
5 #
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #
20
21 PROG      := busybox
22 VERSION   := 0.44
23 BUILDTIME := $(shell TZ=UTC date --utc "+%Y.%m.%d-%H:%M%z")
24 export VERSION
25
26 # Set the following to `true' to make a debuggable build.
27 # Leave this set to `false' for production use.
28 # eg: `make DODEBUG=true tests'
29 DODEBUG = false
30
31 # If you want a static binary, turn this on.
32 DOSTATIC = false
33
34 # Figure out what arch we are on (not used at the moment)
35 ARCH := $(shell uname -m | sed -e 's/i.86/i386/' | sed -e 's/sparc.*/sparc/')
36
37
38 CC = gcc
39
40 GCCMAJVERSION = $(shell $(CC) --version | cut -f1 -d'.')
41 GCCMINVERSION = $(shell $(CC) --version | cut -f2 -d'.')
42
43
44 GCCSUPPORTSOPTSIZE = $(shell                    \
45 if ( test $(GCCMAJVERSION) -eq 2 ) ; then       \
46     if ( test $(GCCMINVERSION) -ge 66 ) ; then  \
47         echo "true";                            \
48     else                                        \
49         echo "false";                           \
50     fi;                                         \
51 else                                            \
52     if ( test $(GCCMAJVERSION) -gt 2 ) ; then   \
53         echo "true";                            \
54     else                                        \
55         echo "false";                           \
56     fi;                                         \
57 fi; )
58
59
60 ifeq ($(GCCSUPPORTSOPTSIZE), true)
61     OPTIMIZATION = -Os
62 else
63     OPTIMIZATION = -O2
64 endif
65
66 # Allow alternative stripping tools to be used...
67 ifndef $(STRIPTOOL)
68     STRIPTOOL = strip
69 endif
70
71 # TODO: Try compiling vs other libcs.  
72 # See what -nostdinc and -nostdlib do for them.
73 # also try --prefix=/usr/my-libc-stuff
74
75 # -D_GNU_SOURCE is needed because environ is used in init.c
76 ifeq ($(DODEBUG),true)
77     CFLAGS += -Wall -g -D_GNU_SOURCE
78     LDFLAGS = 
79     STRIP   =
80 else
81     CFLAGS  += -Wall $(OPTIMIZATION) -fomit-frame-pointer -fno-builtin -D_GNU_SOURCE
82     LDFLAGS  = -s
83     STRIP    = $(STRIPTOOL) --remove-section=.note --remove-section=.comment $(PROG)
84     #Only staticly link when _not_ debugging 
85     ifeq ($(DOSTATIC),true)
86         LDFLAGS += --static
87     endif
88 endif
89
90 ifndef $(PREFIX)
91     PREFIX = `pwd`/_install
92 endif
93
94 LIBRARIES =
95 OBJECTS   = $(shell ./busybox.sh) busybox.o messages.o utility.o
96 CFLAGS    += -DBB_VER='"$(VERSION)"'
97 CFLAGS    += -DBB_BT='"$(BUILDTIME)"'
98 ifdef BB_INIT_SCRIPT
99     CFLAGS += -DINIT_SCRIPT='"$(BB_INIT_SCRIPT)"'
100 endif
101
102 all: busybox busybox.links doc
103
104 doc: BusyBox.txt BusyBox.1 BusyBox.html
105
106 BusyBox.txt: docs/busybox.pod
107         @echo
108         @echo BusyBox Documentation
109         @echo
110         pod2text docs/busybox.pod > BusyBox.txt
111
112 BusyBox.1: docs/busybox.pod
113         pod2man --center=BusyBox --release="version $(VERSION)" docs/busybox.pod > BusyBox.1
114
115 BusyBox.html: docs/busybox.pod
116         pod2html docs/busybox.pod > BusyBox.html
117         - rm -f pod2html*
118
119 clean:
120
121 busybox: $(OBJECTS)
122         $(CC) $(LDFLAGS) -o $@ $^ $(LIBRARIES)
123         $(STRIP)
124
125 busybox.links: busybox.def.h
126         - ./busybox.mkll | sort >$@
127
128 regexp.o nfsmount.o cmdedit.o: %.o: %.h
129 $(OBJECTS): %.o: busybox.def.h internal.h  %.c Makefile
130
131 test tests:
132         cd tests && $(MAKE) all
133
134 clean:
135         - rm -f busybox.links *~ *.o core
136         - rm -rf _install
137         - cd tests && $(MAKE) clean
138         - rm -f BusyBox.html BusyBox.1 BusyBox.txt pod2html*
139
140 distclean: clean
141         - rm -f busybox
142         - cd tests && $(MAKE) distclean
143
144 install: busybox busybox.links
145         ./install.sh $(PREFIX)
146
147 dist release: distclean doc
148         cd ..;                                  \
149         rm -rf busybox-$(VERSION);              \
150         cp -a busybox busybox-$(VERSION);       \
151                                                 \
152         find busybox-$(VERSION)/ -type d        \
153                                  -name CVS      \
154                                  -print         \
155                 | xargs rm -rf;                 \
156                                                 \
157         find busybox-$(VERSION)/ -type f        \
158                                  -name .cvsignore \
159                                  -print         \
160                 | xargs rm -f;                  \
161                                                 \
162         tar -cvzf busybox-$(VERSION).tar.gz busybox-$(VERSION)/;