10b76ee43ebc430709eb0510c16ebd2392630dd1
[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.42
23 BUILDTIME := $(shell TZ=GMT date "+%Y%m%d-%H%M")
24
25 # Set the following to `true' to make a debuggable build.
26 # Leave this set to `false' for production use.
27 # eg: `make DODEBUG=true tests'
28 DODEBUG = false
29
30 # If you want a static binary, turn this on.  I can't think
31 # of many situations where anybody would ever want it static, 
32 # but...
33 DOSTATIC = false
34
35 # This will choke on a non-debian system
36 ARCH =`uname -m | sed -e 's/i.86/i386/' | sed -e 's/sparc.*/sparc/'`
37
38 CC = gcc
39
40 GCCMAJVERSION = $(shell $(CC) --version | sed -n "s/^[^0-9]*\([0-9]\)\.\([0-9].*\)[\.].*/\1/p")
41 GCCMINVERSION = $(shell $(CC) --version | sed -n "s/^[^0-9]*\([0-9]\)\.\([0-9].*\)[\.].*/\2/p")
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
72 # -D_GNU_SOURCE is needed because environ is used in init.c
73 ifeq ($(DODEBUG),true)
74     CFLAGS += -Wall -g -D_GNU_SOURCE
75     LDFLAGS =
76     STRIP   =
77 else
78     CFLAGS  += -Wall $(OPTIMIZATION) -fomit-frame-pointer -fno-builtin -D_GNU_SOURCE
79     LDFLAGS  = -s
80     STRIP    = $(STRIPTOOL) --remove-section=.note --remove-section=.comment
81     #Only staticly link when _not_ debugging 
82     ifeq ($(DOSTATIC),true)
83         LDFLAGS += --static
84     endif
85 endif
86
87 ifndef $(PREFIX)
88     PREFIX = `pwd`/_install
89 endif
90
91 LIBRARIES =
92 OBJECTS   = $(shell ./busybox.sh) messages.o utility.o
93 CFLAGS    += -DBB_VER='"$(VERSION)"'
94 CFLAGS    += -DBB_BT='"$(BUILDTIME)"'
95 ifdef BB_INIT_SCRIPT
96     CFLAGS += -DINIT_SCRIPT='"$(BB_INIT_SCRIPT)"'
97 endif
98
99 all: busybox busybox.links
100 .PHONY: all
101
102 busybox: $(OBJECTS)
103         $(CC) $(LDFLAGS) -o $@ $^ $(LIBRARIES)
104         $(STRIP) $@
105
106 busybox.links: busybox.def.h
107         - ./busybox.mkll | sort >$@
108
109 regexp.o nfsmount.o: %.o: %.h
110 $(OBJECTS): %.o: busybox.def.h internal.h  %.c
111
112 .PHONY: test tests
113 test tests:
114         cd tests && $(MAKE) all
115
116 .PHONY: clean
117 clean:
118         - rm -f busybox.links *~ *.o core
119         - rm -rf _install
120         - cd tests && $(MAKE) clean
121
122 .PHONY: distclean
123 distclean: clean
124         - rm -f busybox
125         - cd tests && $(MAKE) distclean
126
127 .PHONY: install
128 install: busybox busybox.links
129         ./install.sh $(PREFIX)
130
131 .PHONY: dist release
132 dist release: distclean
133         cd ..;                                  \
134         rm -rf busybox-$(VERSION);              \
135         cp -a busybox busybox-$(VERSION);       \
136                                                 \
137         find busybox-$(VERSION)/ -type d        \
138                                  -name CVS      \
139                                  -print         \
140                 | xargs rm -rf;                 \
141                                                 \
142         find busybox-$(VERSION)/ -type f        \
143                                  -name .cvsignore \
144                                  -print         \
145                 | xargs rm -f;                  \
146                                                 \
147         tar -cvzf busybox-$(VERSION).tar.gz busybox-$(VERSION)/;