blob: bc37b4a001e4a176e605a466a4240acdd450b5ad [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")
John Beppucbd66282000-04-13 22:57:45 +000024export VERSION
Eric Andersencc8ed391999-10-05 16:24:54 +000025
Erik Andersenfac10d72000-02-07 05:29:42 +000026# Set the following to `true' to make a debuggable build.
27# Leave this set to `false' for production use.
Erik Andersen9ffdaa62000-02-11 21:55:04 +000028# eg: `make DODEBUG=true tests'
Erik Andersen9cf3bfa2000-04-13 18:49:43 +000029DODEBUG = true
Eric Andersen21943ce1999-10-13 18:04:51 +000030
Erik Andersenf3b3d172000-04-09 18:24:05 +000031# If you want a static binary, turn this on.
Erik Andersenc0dac182000-04-06 07:24:45 +000032DOSTATIC = false
Eric Andersencc8ed391999-10-05 16:24:54 +000033
Erik Andersenfac10d72000-02-07 05:29:42 +000034# This will choke on a non-debian system
35ARCH =`uname -m | sed -e 's/i.86/i386/' | sed -e 's/sparc.*/sparc/'`
Eric Andersencc8ed391999-10-05 16:24:54 +000036
Erik Andersenfac10d72000-02-07 05:29:42 +000037CC = gcc
Eric Andersend80e8511999-11-16 00:46:00 +000038
Erik Andersenfac10d72000-02-07 05:29:42 +000039GCCMAJVERSION = $(shell $(CC) --version | sed -n "s/^[^0-9]*\([0-9]\)\.\([0-9].*\)[\.].*/\1/p")
40GCCMINVERSION = $(shell $(CC) --version | sed -n "s/^[^0-9]*\([0-9]\)\.\([0-9].*\)[\.].*/\2/p")
41
42
43GCCSUPPORTSOPTSIZE = $(shell \
44if ( test $(GCCMAJVERSION) -eq 2 ) ; then \
45 if ( test $(GCCMINVERSION) -ge 66 ) ; then \
46 echo "true"; \
47 else \
48 echo "false"; \
49 fi; \
50else \
51 if ( test $(GCCMAJVERSION) -gt 2 ) ; then \
52 echo "true"; \
53 else \
54 echo "false"; \
55 fi; \
Eric Andersend80e8511999-11-16 00:46:00 +000056fi; )
57
58
59ifeq ($(GCCSUPPORTSOPTSIZE), true)
Erik Andersenfac10d72000-02-07 05:29:42 +000060 OPTIMIZATION = -Os
Eric Andersend80e8511999-11-16 00:46:00 +000061else
Erik Andersenfac10d72000-02-07 05:29:42 +000062 OPTIMIZATION = -O2
Eric Andersend80e8511999-11-16 00:46:00 +000063endif
Eric Andersencc8ed391999-10-05 16:24:54 +000064
Erik Andersen9ffdaa62000-02-11 21:55:04 +000065# Allow alternative stripping tools to be used...
66ifndef $(STRIPTOOL)
67 STRIPTOOL = strip
68endif
69
70
Eric Andersencc8ed391999-10-05 16:24:54 +000071# -D_GNU_SOURCE is needed because environ is used in init.c
Eric Andersen17d49ef1999-10-06 20:25:32 +000072ifeq ($(DODEBUG),true)
Erik Andersene132f4b2000-02-09 04:16:43 +000073 CFLAGS += -Wall -g -D_GNU_SOURCE
Erik Andersen0817d132000-04-09 15:17:40 +000074 LDFLAGS =
Erik Andersen9ffdaa62000-02-11 21:55:04 +000075 STRIP =
Eric Andersen17d49ef1999-10-06 20:25:32 +000076else
Erik Andersenfac10d72000-02-07 05:29:42 +000077 CFLAGS += -Wall $(OPTIMIZATION) -fomit-frame-pointer -fno-builtin -D_GNU_SOURCE
78 LDFLAGS = -s
Erik Andersen7c4b2f32000-02-29 21:49:22 +000079 STRIP = $(STRIPTOOL) --remove-section=.note --remove-section=.comment $(PROG)
Eric Andersena7093171999-10-23 05:42:08 +000080 #Only staticly link when _not_ debugging
81 ifeq ($(DOSTATIC),true)
Erik Andersenfac10d72000-02-07 05:29:42 +000082 LDFLAGS += --static
Eric Andersena7093171999-10-23 05:42:08 +000083 endif
Eric Andersen17d49ef1999-10-06 20:25:32 +000084endif
85
Eric Anderseneded54b1999-11-12 08:03:23 +000086ifndef $(PREFIX)
Erik Andersenfac10d72000-02-07 05:29:42 +000087 PREFIX = `pwd`/_install
Eric Andersen17d49ef1999-10-06 20:25:32 +000088endif
Eric Andersen17d49ef1999-10-06 20:25:32 +000089
Erik Andersenfac10d72000-02-07 05:29:42 +000090LIBRARIES =
Erik Andersene2729152000-02-18 21:34:17 +000091OBJECTS = $(shell ./busybox.sh) busybox.o messages.o utility.o
Erik Andersenfac10d72000-02-07 05:29:42 +000092CFLAGS += -DBB_VER='"$(VERSION)"'
93CFLAGS += -DBB_BT='"$(BUILDTIME)"'
Erik Andersend387d011999-12-21 02:55:11 +000094ifdef BB_INIT_SCRIPT
Erik Andersen9ffdaa62000-02-11 21:55:04 +000095 CFLAGS += -DINIT_SCRIPT='"$(BB_INIT_SCRIPT)"'
Erik Andersend387d011999-12-21 02:55:11 +000096endif
97
Erik Andersen9cf3bfa2000-04-13 18:49:43 +000098all: busybox busybox.links docs
Erik Andersen9ffdaa62000-02-11 21:55:04 +000099.PHONY: all
Eric Andersencc8ed391999-10-05 16:24:54 +0000100
101busybox: $(OBJECTS)
Erik Andersen9ffdaa62000-02-11 21:55:04 +0000102 $(CC) $(LDFLAGS) -o $@ $^ $(LIBRARIES)
Erik Andersen7c4b2f32000-02-29 21:49:22 +0000103 $(STRIP)
Eric Andersencc8ed391999-10-05 16:24:54 +0000104
Erik Andersenfac10d72000-02-07 05:29:42 +0000105busybox.links: busybox.def.h
Eric Andersen96bcfd31999-11-12 01:30:18 +0000106 - ./busybox.mkll | sort >$@
Eric Andersen1667fb41999-11-27 20:34:28 +0000107
Erik Andersen9cf3bfa2000-04-13 18:49:43 +0000108docs: docs/busybox.pod
109 cd docs && $(MAKE) clean all
110
Erik Andersen9ffdaa62000-02-11 21:55:04 +0000111regexp.o nfsmount.o: %.o: %.h
112$(OBJECTS): %.o: busybox.def.h internal.h %.c
113
114.PHONY: test tests
115test tests:
116 cd tests && $(MAKE) all
117
118.PHONY: clean
Eric Andersencc8ed391999-10-05 16:24:54 +0000119clean:
Erik Andersen9ffdaa62000-02-11 21:55:04 +0000120 - rm -f busybox.links *~ *.o core
Eric Andersend00c2621999-12-07 08:37:31 +0000121 - rm -rf _install
Erik Andersen9ffdaa62000-02-11 21:55:04 +0000122 - cd tests && $(MAKE) clean
Eric Andersencc8ed391999-10-05 16:24:54 +0000123
Erik Andersen9ffdaa62000-02-11 21:55:04 +0000124.PHONY: distclean
Eric Andersencc8ed391999-10-05 16:24:54 +0000125distclean: clean
Erik Andersen9ffdaa62000-02-11 21:55:04 +0000126 - rm -f busybox
127 - cd tests && $(MAKE) distclean
Eric Andersencc8ed391999-10-05 16:24:54 +0000128
Erik Andersen9ffdaa62000-02-11 21:55:04 +0000129.PHONY: install
Eric Andersen07274581999-11-21 21:50:07 +0000130install: busybox busybox.links
Eric Andersen80974fa1999-11-13 04:51:47 +0000131 ./install.sh $(PREFIX)
Eric Andersen17d49ef1999-10-06 20:25:32 +0000132
Erik Andersen9ffdaa62000-02-11 21:55:04 +0000133.PHONY: dist release
134dist release: distclean
John Beppucbd66282000-04-13 22:57:45 +0000135 $(MAKE) -C docs clean all
Erik Andersenfac10d72000-02-07 05:29:42 +0000136 cd ..; \
137 rm -rf busybox-$(VERSION); \
138 cp -a busybox busybox-$(VERSION); \
139 \
140 find busybox-$(VERSION)/ -type d \
141 -name CVS \
142 -print \
143 | xargs rm -rf; \
144 \
145 find busybox-$(VERSION)/ -type f \
146 -name .cvsignore \
147 -print \
148 | xargs rm -f; \
149 \
150 tar -cvzf busybox-$(VERSION).tar.gz busybox-$(VERSION)/;