A few minor updates. ;-)
[oweals/busybox.git] / Makefile
1 # Makefile for busybox
2 #
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
7 #
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 # General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 #
17
18 PROG      := busybox
19 VERSION   := 0.42
20 BUILDTIME := $(shell TZ=GMT date "+%Y%m%d-%H%M")
21
22 # Set the following to `true' to make a debuggable build.
23 # Leave this set to `false' for production use.
24 # eg: `make DODEBUG=true'
25 DODEBUG = false
26
27 # If you want a static binary, turn this on.  I can't think
28 # of many situations where anybody would ever want it static, 
29 # but...
30 DOSTATIC = false
31
32 # This will choke on a non-debian system
33 ARCH =`uname -m | sed -e 's/i.86/i386/' | sed -e 's/sparc.*/sparc/'`
34
35 CC = gcc
36
37 GCCMAJVERSION = $(shell $(CC) --version | sed -n "s/^[^0-9]*\([0-9]\)\.\([0-9].*\)[\.].*/\1/p")
38 GCCMINVERSION = $(shell $(CC) --version | sed -n "s/^[^0-9]*\([0-9]\)\.\([0-9].*\)[\.].*/\2/p")
39
40
41 GCCSUPPORTSOPTSIZE = $(shell                    \
42 if ( test $(GCCMAJVERSION) -eq 2 ) ; then       \
43     if ( test $(GCCMINVERSION) -ge 66 ) ; then  \
44         echo "true";                            \
45     else                                        \
46         echo "false";                           \
47     fi;                                         \
48 else                                            \
49     if ( test $(GCCMAJVERSION) -gt 2 ) ; then   \
50         echo "true";                            \
51     else                                        \
52         echo "false";                           \
53     fi;                                         \
54 fi; )
55
56
57 ifeq ($(GCCSUPPORTSOPTSIZE), true)
58     OPTIMIZATION = -Os
59 else
60     OPTIMIZATION = -O2
61 endif
62
63 # -D_GNU_SOURCE is needed because environ is used in init.c
64 ifeq ($(DODEBUG),true)
65     CFLAGS += -Wall -g -D_GNU_SOURCE -DDEBUG_INIT
66     STRIP   =
67     LDFLAGS =
68 else
69     CFLAGS  += -Wall $(OPTIMIZATION) -fomit-frame-pointer -fno-builtin -D_GNU_SOURCE
70     LDFLAGS  = -s
71     STRIP    = strip --remove-section=.note --remove-section=.comment $(PROG)
72     #Only staticly link when _not_ debugging 
73     ifeq ($(DOSTATIC),true)
74         LDFLAGS += --static
75     endif
76 endif
77
78 ifndef $(PREFIX)
79     PREFIX = `pwd`/_install
80 endif
81
82 LIBRARIES =
83 OBJECTS   = $(shell ./busybox.sh) messages.o utility.o
84 CFLAGS    += -DBB_VER='"$(VERSION)"'
85 CFLAGS    += -DBB_BT='"$(BUILDTIME)"'
86 ifdef BB_INIT_SCRIPT
87     CFLAGS += -DINIT_SCRIPT=${BB_INIT_SCRIPT}
88 endif
89
90 all: busybox busybox.links
91
92 busybox: $(OBJECTS)
93         $(CC) $(LDFLAGS) -o $(PROG) $(OBJECTS) $(LIBRARIES)
94         $(STRIP)
95
96 busybox.links: busybox.def.h
97         - ./busybox.mkll | sort >$@
98
99 clean:
100         - rm -f $(PROG) busybox.links *~ *.o core 
101         - rm -rf _install
102
103 distclean: clean
104         - rm -f $(PROG)
105
106 $(OBJECTS): %.o: %.c busybox.def.h internal.h Makefile messages.c 
107
108 install: busybox busybox.links
109         ./install.sh $(PREFIX)
110
111 dist: release
112
113 release: distclean
114         cd ..;                                  \
115         rm -rf busybox-$(VERSION);              \
116         cp -a busybox busybox-$(VERSION);       \
117                                                 \
118         find busybox-$(VERSION)/ -type d        \
119                                  -name CVS      \
120                                  -print         \
121                 | xargs rm -rf;                 \
122                                                 \
123         find busybox-$(VERSION)/ -type f        \
124                                  -name .cvsignore \
125                                  -print         \
126                 | xargs rm -f;                  \
127                                                 \
128         tar -cvzf busybox-$(VERSION).tar.gz busybox-$(VERSION)/;