fleshed out a bit more... just wanted to put the current
[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
19 PROG=busybox
20 VERSION=0.41
21 BUILDTIME=$(shell date "+%Y%m%d-%H%M")
22
23 # Comment out the following to make a debuggable build
24 # Leave this off for production use.
25 DODEBUG=false
26 # If you want a static binary, turn this on.  I can't think
27 # of many situations where anybody would ever want it static, 
28 # but...
29 DOSTATIC=false
30
31 #This will choke on a non-debian system
32 ARCH=`uname -m | sed -e 's/i.86/i386/' | sed -e 's/sparc.*/sparc/'`
33
34 GCCMAJVERSION=$(shell $(CC) --version | sed -n "s/^\([^\.]*\).*/\1/p" )
35 GCCMINVERSION=$(shell $(CC) --version | sed -n "s/^[^\.]*\.\([^\.]*\)[\.].*/\1/p" )
36 GCCEGCS=$(shell $(CC) --version | sed -n "s/.*\(egcs\).*/\1/p" )
37
38 GCCSUPPORTSOPTSIZE=$(shell \
39 if ( test $(GCCMAJVERSION) -eq 2 ) ; then \
40     if ( test $(GCCMINVERSION) -ge 66 ) ; then \
41         echo "true"; \
42     else \
43         echo "false"; \
44     fi; \
45 else \
46     if ( test $(GCCMAJVERSION) -gt 2 ) ; then \
47         echo "true"; \
48     else \
49         echo "false"; \
50     fi; \
51 fi; )
52
53 GCCISEGCS=$(shell \
54 if ( test "x$(GCCEGCS)" == "xegcs" ) ; then \
55                 echo "true"; \
56         else \
57                 echo "false"; \
58         fi; )
59
60 EGCSEXTREMEFLAGS = -m386 -mcpu=i386 -march=i386 -malign-jumps=1 -malign-loops=1 -malign-functions=1
61 GCCEXTREMEFLAGS  = -m386 -malign-jumps=1 -malign-loops=1 -malign-functions=1
62
63 ifeq ($(GCCISEGCS), true)
64         EXTREMEFLAGS = $(EGCSEXTREMEFLAGS)
65 else
66         EXTREMEFLAGS = $(GCCEXTREMEFLAGS)
67 endif
68
69 ifeq ($(GCCSUPPORTSOPTSIZE), true)
70         OPTIMIZATION=-Os $(EXTREMEFLAGS)
71 else
72         OPTIMIZATION=-O2 $(EXTREMEFLAGS)
73 endif
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 -DDEBUG_INIT
78     STRIP=
79     LDFLAGS=
80 else
81     CFLAGS+=-Wall $(OPTIMIZATION) -fomit-frame-pointer -fno-builtin -D_GNU_SOURCE
82     LDFLAGS= -s
83     STRIP= strip --remove-section=.note --remove-section=.comment $(PROG)
84     #Only staticly link when _not_ debugging 
85     ifeq ($(DOSTATIC),true)
86         LDFLAGS+= --static
87     endif
88     
89 endif
90
91 ifndef $(PREFIX)
92     PREFIX=`pwd`/_install
93 endif
94
95 LIBRARIES=
96 OBJECTS=$(shell ./busybox.sh)
97 CFLAGS+= -DBB_VER='"$(VERSION)"'
98 CFLAGS+= -DBB_BT='"$(BUILDTIME)"'
99 ifdef BB_INIT_SCRIPT
100     CFLAGS += -DINIT_SCRIPT=${BB_INIT_SCRIPT}
101 endif
102
103 all: busybox busybox.links
104
105 busybox: $(OBJECTS)
106         $(CC) $(LDFLAGS) -o $(PROG) $(OBJECTS) $(LIBRARIES)
107         $(STRIP)
108
109 busybox.links:
110         - ./busybox.mkll | sort >$@
111
112 clean:
113         - rm -f $(PROG) busybox.links *~ *.o core 
114         - rm -rf _install
115
116 distclean: clean
117         - rm -f $(PROG)
118
119 $(OBJECTS):  busybox.def.h internal.h Makefile
120
121 install: busybox busybox.links
122         ./install.sh $(PREFIX)
123
124 dist: release
125
126 release: distclean
127         (cd .. ; rm -rf busybox-$(VERSION) ; cp -a busybox busybox-$(VERSION); rm -rf busybox-$(VERSION)/CVS busybox-$(VERSION)/scripts/CVS busybox-$(VERSION)/docs/CVS busybox-$(VERSION)/.cvsignore ; tar -cvzf busybox-$(VERSION).tar.gz busybox-$(VERSION)) 
128
129