blob: fc6ed96a2a7f6cabe1db5e7cc4f7fe264f5fab0e [file] [log] [blame]
Eric Andersenc4996011999-10-20 22:08:37 +00001# Makefile for busybox
2#
Erik Andersen9ffdaa62000-02-11 21:55:04 +00003# Copyright (C) 1999-2000 Erik Andersen <andersee@debian.org>
4# Copyright (C) 2000 Karl M. Hegbloom <karlheg@debian.org>
5#
Eric Andersenc4996011999-10-20 22:08:37 +00006# 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
Erik Andersen7c4b2f32000-02-29 21:49:22 +000021PROG := busybox
Erik Andersene2729152000-02-18 21:34:17 +000022VERSION := 0.43
Erik Andersen1ad302a2000-03-24 00:54:46 +000023BUILDTIME := $(shell TZ=UTC date --utc "+%Y.%m.%d-%H:%M%z")
Eric Andersencc8ed391999-10-05 16:24:54 +000024
Erik Andersenfac10d72000-02-07 05:29:42 +000025# Set the following to `true' to make a debuggable build.
26# Leave this set to `false' for production use.
Erik Andersen9ffdaa62000-02-11 21:55:04 +000027# eg: `make DODEBUG=true tests'
Erik Andersen9c5c29d2000-03-06 18:34:48 +000028DODEBUG = false
Eric Andersen21943ce1999-10-13 18:04:51 +000029
Eric Andersena7093171999-10-23 05:42:08 +000030# 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...
Erik Andersenc0dac182000-04-06 07:24:45 +000033DOSTATIC = false
Eric Andersencc8ed391999-10-05 16:24:54 +000034
Erik Andersenfac10d72000-02-07 05:29:42 +000035# This will choke on a non-debian system
36ARCH =`uname -m | sed -e 's/i.86/i386/' | sed -e 's/sparc.*/sparc/'`
Eric Andersencc8ed391999-10-05 16:24:54 +000037
Erik Andersenfac10d72000-02-07 05:29:42 +000038CC = gcc
Eric Andersend80e8511999-11-16 00:46:00 +000039
Erik Andersenfac10d72000-02-07 05:29:42 +000040GCCMAJVERSION = $(shell $(CC) --version | sed -n "s/^[^0-9]*\([0-9]\)\.\([0-9].*\)[\.].*/\1/p")
41GCCMINVERSION = $(shell $(CC) --version | sed -n "s/^[^0-9]*\([0-9]\)\.\([0-9].*\)[\.].*/\2/p")
42
43
44GCCSUPPORTSOPTSIZE = $(shell \
45if ( test $(GCCMAJVERSION) -eq 2 ) ; then \
46 if ( test $(GCCMINVERSION) -ge 66 ) ; then \
47 echo "true"; \
48 else \
49 echo "false"; \
50 fi; \
51else \
52 if ( test $(GCCMAJVERSION) -gt 2 ) ; then \
53 echo "true"; \
54 else \
55 echo "false"; \
56 fi; \
Eric Andersend80e8511999-11-16 00:46:00 +000057fi; )
58
59
60ifeq ($(GCCSUPPORTSOPTSIZE), true)
Erik Andersenfac10d72000-02-07 05:29:42 +000061 OPTIMIZATION = -Os
Eric Andersend80e8511999-11-16 00:46:00 +000062else
Erik Andersenfac10d72000-02-07 05:29:42 +000063 OPTIMIZATION = -O2
Eric Andersend80e8511999-11-16 00:46:00 +000064endif
Eric Andersencc8ed391999-10-05 16:24:54 +000065
Erik Andersen9ffdaa62000-02-11 21:55:04 +000066# Allow alternative stripping tools to be used...
67ifndef $(STRIPTOOL)
68 STRIPTOOL = strip
69endif
70
71
Eric Andersencc8ed391999-10-05 16:24:54 +000072# -D_GNU_SOURCE is needed because environ is used in init.c
Eric Andersen17d49ef1999-10-06 20:25:32 +000073ifeq ($(DODEBUG),true)
Erik Andersene132f4b2000-02-09 04:16:43 +000074 CFLAGS += -Wall -g -D_GNU_SOURCE
Erik Andersenfac10d72000-02-07 05:29:42 +000075 LDFLAGS =
Erik Andersen9ffdaa62000-02-11 21:55:04 +000076 STRIP =
Eric Andersen17d49ef1999-10-06 20:25:32 +000077else
Erik Andersenfac10d72000-02-07 05:29:42 +000078 CFLAGS += -Wall $(OPTIMIZATION) -fomit-frame-pointer -fno-builtin -D_GNU_SOURCE
79 LDFLAGS = -s
Erik Andersen7c4b2f32000-02-29 21:49:22 +000080 STRIP = $(STRIPTOOL) --remove-section=.note --remove-section=.comment $(PROG)
Eric Andersena7093171999-10-23 05:42:08 +000081 #Only staticly link when _not_ debugging
82 ifeq ($(DOSTATIC),true)
Erik Andersenfac10d72000-02-07 05:29:42 +000083 LDFLAGS += --static
Eric Andersena7093171999-10-23 05:42:08 +000084 endif
Eric Andersen17d49ef1999-10-06 20:25:32 +000085endif
86
Eric Anderseneded54b1999-11-12 08:03:23 +000087ifndef $(PREFIX)
Erik Andersenfac10d72000-02-07 05:29:42 +000088 PREFIX = `pwd`/_install
Eric Andersen17d49ef1999-10-06 20:25:32 +000089endif
Eric Andersen17d49ef1999-10-06 20:25:32 +000090
Erik Andersenfac10d72000-02-07 05:29:42 +000091LIBRARIES =
Erik Andersene2729152000-02-18 21:34:17 +000092OBJECTS = $(shell ./busybox.sh) busybox.o messages.o utility.o
Erik Andersenfac10d72000-02-07 05:29:42 +000093CFLAGS += -DBB_VER='"$(VERSION)"'
94CFLAGS += -DBB_BT='"$(BUILDTIME)"'
Erik Andersend387d011999-12-21 02:55:11 +000095ifdef BB_INIT_SCRIPT
Erik Andersen9ffdaa62000-02-11 21:55:04 +000096 CFLAGS += -DINIT_SCRIPT='"$(BB_INIT_SCRIPT)"'
Erik Andersend387d011999-12-21 02:55:11 +000097endif
98
Eric Andersen96bcfd31999-11-12 01:30:18 +000099all: busybox busybox.links
Erik Andersen9ffdaa62000-02-11 21:55:04 +0000100.PHONY: all
Eric Andersencc8ed391999-10-05 16:24:54 +0000101
102busybox: $(OBJECTS)
Erik Andersen9ffdaa62000-02-11 21:55:04 +0000103 $(CC) $(LDFLAGS) -o $@ $^ $(LIBRARIES)
Erik Andersen7c4b2f32000-02-29 21:49:22 +0000104 $(STRIP)
Eric Andersencc8ed391999-10-05 16:24:54 +0000105
Erik Andersenfac10d72000-02-07 05:29:42 +0000106busybox.links: busybox.def.h
Eric Andersen96bcfd31999-11-12 01:30:18 +0000107 - ./busybox.mkll | sort >$@
Eric Andersen1667fb41999-11-27 20:34:28 +0000108
Erik Andersen9ffdaa62000-02-11 21:55:04 +0000109regexp.o nfsmount.o: %.o: %.h
110$(OBJECTS): %.o: busybox.def.h internal.h %.c
111
112.PHONY: test tests
113test tests:
114 cd tests && $(MAKE) all
115
116.PHONY: clean
Eric Andersencc8ed391999-10-05 16:24:54 +0000117clean:
Erik Andersen9ffdaa62000-02-11 21:55:04 +0000118 - rm -f busybox.links *~ *.o core
Eric Andersend00c2621999-12-07 08:37:31 +0000119 - rm -rf _install
Erik Andersen9ffdaa62000-02-11 21:55:04 +0000120 - cd tests && $(MAKE) clean
Eric Andersencc8ed391999-10-05 16:24:54 +0000121
Erik Andersen9ffdaa62000-02-11 21:55:04 +0000122.PHONY: distclean
Eric Andersencc8ed391999-10-05 16:24:54 +0000123distclean: clean
Erik Andersen9ffdaa62000-02-11 21:55:04 +0000124 - rm -f busybox
125 - cd tests && $(MAKE) distclean
Eric Andersencc8ed391999-10-05 16:24:54 +0000126
Erik Andersen9ffdaa62000-02-11 21:55:04 +0000127.PHONY: install
Eric Andersen07274581999-11-21 21:50:07 +0000128install: busybox busybox.links
Eric Andersen80974fa1999-11-13 04:51:47 +0000129 ./install.sh $(PREFIX)
Eric Andersen17d49ef1999-10-06 20:25:32 +0000130
Erik Andersen9ffdaa62000-02-11 21:55:04 +0000131.PHONY: dist release
132dist release: distclean
Erik Andersenfac10d72000-02-07 05:29:42 +0000133 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)/;