eea01d383b19b7a57230df7d81e4d7d2be220ef9
[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.43
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 # This will choke on a non-debian system
35 ARCH =`uname -m | sed -e 's/i.86/i386/' | sed -e 's/sparc.*/sparc/'`
36
37 CC = gcc
38
39 GCCMAJVERSION = $(shell $(CC) --version | sed -n "s/^[^0-9]*\([0-9]\)\.\([0-9].*\)[\.].*/\1/p")
40 GCCMINVERSION = $(shell $(CC) --version | sed -n "s/^[^0-9]*\([0-9]\)\.\([0-9].*\)[\.].*/\2/p")
41
42
43 GCCSUPPORTSOPTSIZE = $(shell                    \
44 if ( test $(GCCMAJVERSION) -eq 2 ) ; then       \
45     if ( test $(GCCMINVERSION) -ge 66 ) ; then  \
46         echo "true";                            \
47     else                                        \
48         echo "false";                           \
49     fi;                                         \
50 else                                            \
51     if ( test $(GCCMAJVERSION) -gt 2 ) ; then   \
52         echo "true";                            \
53     else                                        \
54         echo "false";                           \
55     fi;                                         \
56 fi; )
57
58
59 ifeq ($(GCCSUPPORTSOPTSIZE), true)
60     OPTIMIZATION = -Os
61 else
62     OPTIMIZATION = -O2
63 endif
64
65 # Allow alternative stripping tools to be used...
66 ifndef $(STRIPTOOL)
67     STRIPTOOL = strip
68 endif
69
70
71 # -D_GNU_SOURCE is needed because environ is used in init.c
72 ifeq ($(DODEBUG),true)
73     CFLAGS += -Wall -g -D_GNU_SOURCE
74     LDFLAGS = 
75     STRIP   =
76 else
77     CFLAGS  += -Wall $(OPTIMIZATION) -fomit-frame-pointer -fno-builtin -D_GNU_SOURCE
78     LDFLAGS  = -s
79     STRIP    = $(STRIPTOOL) --remove-section=.note --remove-section=.comment $(PROG)
80     #Only staticly link when _not_ debugging 
81     ifeq ($(DOSTATIC),true)
82         LDFLAGS += --static
83     endif
84 endif
85
86 ifndef $(PREFIX)
87     PREFIX = `pwd`/_install
88 endif
89
90 LIBRARIES =
91 OBJECTS   = $(shell ./busybox.sh) busybox.o messages.o utility.o
92 CFLAGS    += -DBB_VER='"$(VERSION)"'
93 CFLAGS    += -DBB_BT='"$(BUILDTIME)"'
94 ifdef BB_INIT_SCRIPT
95     CFLAGS += -DINIT_SCRIPT='"$(BB_INIT_SCRIPT)"'
96 endif
97
98 all: busybox busybox.links docs
99
100 busybox: $(OBJECTS)
101         $(CC) $(LDFLAGS) -o $@ $^ $(LIBRARIES)
102         $(STRIP)
103         
104 docs:
105         $(MAKE) -C docs
106
107 busybox.links: busybox.def.h
108         - ./busybox.mkll | sort >$@
109
110 regexp.o nfsmount.o cmdedit.o: %.o: %.h
111 $(OBJECTS): %.o: busybox.def.h internal.h  %.c Makefile
112
113 test tests:
114         cd tests && $(MAKE) all
115
116 clean:
117         - rm -f busybox.links *~ *.o core
118         - rm -rf _install
119         - cd tests && $(MAKE) clean
120
121 distclean: clean
122         - rm -f busybox
123         - cd tests && $(MAKE) distclean
124
125 install: busybox busybox.links
126         ./install.sh $(PREFIX)
127
128 dist release: distclean
129         $(MAKE) -C docs
130         cd ..;                                  \
131         rm -rf busybox-$(VERSION);              \
132         cp -a busybox busybox-$(VERSION);       \
133                                                 \
134         find busybox-$(VERSION)/ -type d        \
135                                  -name CVS      \
136                                  -print         \
137                 | xargs rm -rf;                 \
138                                                 \
139         find busybox-$(VERSION)/ -type f        \
140                                  -name .cvsignore \
141                                  -print         \
142                 | xargs rm -f;                  \
143                                                 \
144         tar -cvzf busybox-$(VERSION).tar.gz busybox-$(VERSION)/;