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