Fix cp and mv so 'cp foo/README bar' where foo and bar are directories,
[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.40
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=true
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
37 GCCSUPPORTSOPTSIZE=$(shell \
38 if ( test $(GCCMAJVERSION) -eq 2 ) ; then \
39     if ( test $(GCCMINVERSION) -ge 91 ) ; then \
40         echo "true"; \
41     else \
42         echo "false"; \
43     fi; \
44 else \
45     if ( test $(GCCMAJVERSION) -gt 2 ) ; then \
46         echo "true"; \
47     else \
48         echo "false"; \
49     fi; \
50 fi; )
51
52
53 ifeq ($(GCCSUPPORTSOPTSIZE), true)
54     OPTIMIZATION=-Os
55 else
56     OPTIMIZATION=-O2
57 endif
58
59 # -D_GNU_SOURCE is needed because environ is used in init.c
60 ifeq ($(DODEBUG),true)
61     CFLAGS+=-Wall -g -D_GNU_SOURCE -DDEBUG_INIT
62     STRIP=
63     LDFLAGS=
64 else
65     CFLAGS+=-Wall $(OPTIMIZATION) -fomit-frame-pointer -fno-builtin -D_GNU_SOURCE
66     LDFLAGS= -s
67     STRIP= strip --remove-section=.note --remove-section=.comment $(PROG)
68     #Only staticly link when _not_ debugging 
69     ifeq ($(DOSTATIC),true)
70         LDFLAGS+= --static
71     endif
72     
73 endif
74
75 ifndef $(PREFIX)
76     PREFIX=`pwd`/_install
77 endif
78
79 LIBRARIES=
80 OBJECTS=$(shell ./busybox.sh)
81 CFLAGS+= -DBB_VER='"$(VERSION)"'
82 CFLAGS+= -DBB_BT='"$(BUILDTIME)"'
83 ifdef BB_INIT_SCRIPT
84     CFLAGS += -DINIT_SCRIPT=${BB_INIT_SCRIPT}
85 endif
86
87 all: busybox busybox.links
88
89 busybox: $(OBJECTS)
90         $(CC) $(LDFLAGS) -o $(PROG) $(OBJECTS) $(LIBRARIES)
91         $(STRIP)
92
93 busybox.links:
94         - ./busybox.mkll | sort >$@
95
96 clean:
97         - rm -f $(PROG) busybox.links *~ *.o core 
98         - rm -rf _install
99
100 distclean: clean
101         - rm -f $(PROG)
102
103 $(OBJECTS):  busybox.def.h internal.h Makefile
104
105 install: busybox busybox.links
106         ./install.sh $(PREFIX)
107
108 dist: release
109
110 release: distclean
111         (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)) 
112
113