blob: fc0396eec8f86d62ffff607c2c489aa750ea78a5 [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 Andersene90f4042000-04-21 21:53:58 +000022VERSION := 0.44
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 Andersen3fe7f9f2000-04-19 03:59:10 +000029DODEBUG = false
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 Andersene90f4042000-04-21 21:53:58 +000034# Figure out what arch we are on (not used at the moment)
35ARCH := $(shell uname -m | sed -e 's/i.86/i386/' | sed -e 's/sparc.*/sparc/')
36
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 Andersen4f3f7572000-04-28 00:18:56 +000040GCCMAJVERSION = $(shell $(CC) --version | cut -f1 -d'.')
41GCCMINVERSION = $(shell $(CC) --version | cut -f2 -d'.')
Erik Andersenfac10d72000-02-07 05:29:42 +000042
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
Erik Andersen03ccce62000-05-02 05:31:00 +000071# TODO: Try compiling vs other libcs.
72# See what -nostdinc and -nostdlib do for them.
Erik Andersen5afc8642000-05-02 00:07:56 +000073# also try --prefix=/usr/my-libc-stuff
Erik Andersen9ffdaa62000-02-11 21:55:04 +000074
Eric Andersencc8ed391999-10-05 16:24:54 +000075# -D_GNU_SOURCE is needed because environ is used in init.c
Eric Andersen17d49ef1999-10-06 20:25:32 +000076ifeq ($(DODEBUG),true)
Erik Andersene132f4b2000-02-09 04:16:43 +000077 CFLAGS += -Wall -g -D_GNU_SOURCE
Erik Andersen0817d132000-04-09 15:17:40 +000078 LDFLAGS =
Erik Andersen9ffdaa62000-02-11 21:55:04 +000079 STRIP =
Eric Andersen17d49ef1999-10-06 20:25:32 +000080else
Erik Andersenfac10d72000-02-07 05:29:42 +000081 CFLAGS += -Wall $(OPTIMIZATION) -fomit-frame-pointer -fno-builtin -D_GNU_SOURCE
82 LDFLAGS = -s
Erik Andersen7c4b2f32000-02-29 21:49:22 +000083 STRIP = $(STRIPTOOL) --remove-section=.note --remove-section=.comment $(PROG)
Eric Andersena7093171999-10-23 05:42:08 +000084 #Only staticly link when _not_ debugging
85 ifeq ($(DOSTATIC),true)
Erik Andersenfac10d72000-02-07 05:29:42 +000086 LDFLAGS += --static
Eric Andersena7093171999-10-23 05:42:08 +000087 endif
Eric Andersen17d49ef1999-10-06 20:25:32 +000088endif
89
Eric Anderseneded54b1999-11-12 08:03:23 +000090ifndef $(PREFIX)
Erik Andersenfac10d72000-02-07 05:29:42 +000091 PREFIX = `pwd`/_install
Eric Andersen17d49ef1999-10-06 20:25:32 +000092endif
Eric Andersen17d49ef1999-10-06 20:25:32 +000093
Erik Andersenfac10d72000-02-07 05:29:42 +000094LIBRARIES =
Erik Andersene2729152000-02-18 21:34:17 +000095OBJECTS = $(shell ./busybox.sh) busybox.o messages.o utility.o
Erik Andersenfac10d72000-02-07 05:29:42 +000096CFLAGS += -DBB_VER='"$(VERSION)"'
97CFLAGS += -DBB_BT='"$(BUILDTIME)"'
Erik Andersend387d011999-12-21 02:55:11 +000098ifdef BB_INIT_SCRIPT
Erik Andersen9ffdaa62000-02-11 21:55:04 +000099 CFLAGS += -DINIT_SCRIPT='"$(BB_INIT_SCRIPT)"'
Erik Andersend387d011999-12-21 02:55:11 +0000100endif
101
Erik Andersen03ccce62000-05-02 05:31:00 +0000102all: busybox busybox.links
Eric Andersencc8ed391999-10-05 16:24:54 +0000103
104busybox: $(OBJECTS)
Erik Andersen9ffdaa62000-02-11 21:55:04 +0000105 $(CC) $(LDFLAGS) -o $@ $^ $(LIBRARIES)
Erik Andersen7c4b2f32000-02-29 21:49:22 +0000106 $(STRIP)
Erik Andersen03ccce62000-05-02 05:31:00 +0000107 ( cd docs ; $(MAKE) )
Erik Andersen1d1d9502000-04-21 01:26:49 +0000108
Erik Andersenfac10d72000-02-07 05:29:42 +0000109busybox.links: busybox.def.h
Eric Andersen96bcfd31999-11-12 01:30:18 +0000110 - ./busybox.mkll | sort >$@
Eric Andersen1667fb41999-11-27 20:34:28 +0000111
Erik Andersen1d1d9502000-04-21 01:26:49 +0000112regexp.o nfsmount.o cmdedit.o: %.o: %.h
Erik Andersena3e57ca2000-04-19 03:38:01 +0000113$(OBJECTS): %.o: busybox.def.h internal.h %.c Makefile
Erik Andersen9ffdaa62000-02-11 21:55:04 +0000114
Erik Andersen9ffdaa62000-02-11 21:55:04 +0000115test tests:
116 cd tests && $(MAKE) all
117
Eric Andersencc8ed391999-10-05 16:24:54 +0000118clean:
Erik Andersen9ffdaa62000-02-11 21:55:04 +0000119 - rm -f busybox.links *~ *.o core
Eric Andersend00c2621999-12-07 08:37:31 +0000120 - rm -rf _install
Erik Andersen9ffdaa62000-02-11 21:55:04 +0000121 - cd tests && $(MAKE) clean
Eric Andersencc8ed391999-10-05 16:24:54 +0000122
123distclean: 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
Eric Andersen07274581999-11-21 21:50:07 +0000127install: busybox busybox.links
Eric Andersen80974fa1999-11-13 04:51:47 +0000128 ./install.sh $(PREFIX)
Eric Andersen17d49ef1999-10-06 20:25:32 +0000129
Erik Andersen9ffdaa62000-02-11 21:55:04 +0000130dist release: distclean
Erik Andersen03ccce62000-05-02 05:31:00 +0000131 ( cd docs ; $(MAKE) )
Erik Andersenfac10d72000-02-07 05:29:42 +0000132 cd ..; \
133 rm -rf busybox-$(VERSION); \
134 cp -a busybox busybox-$(VERSION); \
135 \
136 find busybox-$(VERSION)/ -type d \
137 -name CVS \
138 -print \
139 | xargs rm -rf; \
140 \
141 find busybox-$(VERSION)/ -type f \
142 -name .cvsignore \
143 -print \
144 | xargs rm -f; \
145 \
146 tar -cvzf busybox-$(VERSION).tar.gz busybox-$(VERSION)/;