blob: 6471e34905c6e143d250c0a65a2e1057c9349a42 [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 Andersen330fd2b2000-05-19 05:35:19 +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 Andersen499f65f2000-05-16 20:07:38 +000034# To compile vs an alternative libc, you may need to use/adjust
35# the following lines to meet your needs. This is how I did it...
36#CFLAGS+=-nostdinc -I/home/andersen/CVS/uC-libc/include -I/usr/include/linux
37#LDFLAGS+=-nostdlib -L/home/andersen/CVS/libc.a
38
39
Erik Andersenfac10d72000-02-07 05:29:42 +000040CC = gcc
Eric Andersend80e8511999-11-16 00:46:00 +000041
Erik Andersen3d427ac2000-05-12 19:38:40 +000042# use '-Os' optimization if available, else use -O2
43OPTIMIZATION = $(shell if $(CC) -Os -S -o /dev/null -xc /dev/null >/dev/null 2>&1; \
44 then echo "-Os"; else echo "-O2" ; fi)
Erik Andersenfac10d72000-02-07 05:29:42 +000045
46
Erik Andersen9ffdaa62000-02-11 21:55:04 +000047# Allow alternative stripping tools to be used...
48ifndef $(STRIPTOOL)
49 STRIPTOOL = strip
50endif
51
Eric Andersencc8ed391999-10-05 16:24:54 +000052# -D_GNU_SOURCE is needed because environ is used in init.c
Eric Andersen17d49ef1999-10-06 20:25:32 +000053ifeq ($(DODEBUG),true)
Erik Andersene132f4b2000-02-09 04:16:43 +000054 CFLAGS += -Wall -g -D_GNU_SOURCE
Erik Andersen0817d132000-04-09 15:17:40 +000055 LDFLAGS =
Erik Andersen9ffdaa62000-02-11 21:55:04 +000056 STRIP =
Eric Andersen17d49ef1999-10-06 20:25:32 +000057else
Erik Andersenfac10d72000-02-07 05:29:42 +000058 CFLAGS += -Wall $(OPTIMIZATION) -fomit-frame-pointer -fno-builtin -D_GNU_SOURCE
59 LDFLAGS = -s
Erik Andersen7c4b2f32000-02-29 21:49:22 +000060 STRIP = $(STRIPTOOL) --remove-section=.note --remove-section=.comment $(PROG)
Eric Andersena7093171999-10-23 05:42:08 +000061 #Only staticly link when _not_ debugging
62 ifeq ($(DOSTATIC),true)
Erik Andersenfac10d72000-02-07 05:29:42 +000063 LDFLAGS += --static
Erik Andersen23dea9b2000-05-13 00:28:25 +000064 #
65 #use '-ffunction-sections -fdata-sections' and '--gc-sections' if they work
66 #to try and strip out any unused junk. Doesn't do much for me, but you may
67 #want to give it a shot...
68 #
69 #ifeq ($(shell $(CC) -ffunction-sections -fdata-sections -S \
Erik Andersen499f65f2000-05-16 20:07:38 +000070 # -o /dev/null -xc /dev/null 2>/dev/null && $(LD) --gc-sections -v >/dev/null && echo 1),1)
71 # CFLAGS += -ffunction-sections -fdata-sections
72 # LDFLAGS += --gc-sections
Erik Andersen23dea9b2000-05-13 00:28:25 +000073 #endif
Eric Andersena7093171999-10-23 05:42:08 +000074 endif
Eric Andersen17d49ef1999-10-06 20:25:32 +000075endif
76
Eric Anderseneded54b1999-11-12 08:03:23 +000077ifndef $(PREFIX)
Erik Andersenfac10d72000-02-07 05:29:42 +000078 PREFIX = `pwd`/_install
Eric Andersen17d49ef1999-10-06 20:25:32 +000079endif
Eric Andersen17d49ef1999-10-06 20:25:32 +000080
Erik Andersen499f65f2000-05-16 20:07:38 +000081
Erik Andersenfac10d72000-02-07 05:29:42 +000082LIBRARIES =
Erik Andersene2729152000-02-18 21:34:17 +000083OBJECTS = $(shell ./busybox.sh) busybox.o messages.o utility.o
Erik Andersenfac10d72000-02-07 05:29:42 +000084CFLAGS += -DBB_VER='"$(VERSION)"'
85CFLAGS += -DBB_BT='"$(BUILDTIME)"'
Erik Andersend387d011999-12-21 02:55:11 +000086ifdef BB_INIT_SCRIPT
Erik Andersen9ffdaa62000-02-11 21:55:04 +000087 CFLAGS += -DINIT_SCRIPT='"$(BB_INIT_SCRIPT)"'
Erik Andersend387d011999-12-21 02:55:11 +000088endif
89
Erik Andersen0a704e82000-05-03 03:19:06 +000090all: busybox busybox.links doc
91
Erik Andersena59d7092000-05-03 03:24:21 +000092doc: docs/BusyBox.txt docs/BusyBox.1 docs/BusyBox.html
Erik Andersen0a704e82000-05-03 03:19:06 +000093
Erik Andersena59d7092000-05-03 03:24:21 +000094docs/BusyBox.txt: docs/busybox.pod
Erik Andersen0a704e82000-05-03 03:19:06 +000095 @echo
96 @echo BusyBox Documentation
97 @echo
Erik Andersena59d7092000-05-03 03:24:21 +000098 pod2text docs/busybox.pod > docs/BusyBox.txt
Erik Andersen0a704e82000-05-03 03:19:06 +000099
Erik Andersena59d7092000-05-03 03:24:21 +0000100docs/BusyBox.1: docs/busybox.pod
101 pod2man --center=BusyBox --release="version $(VERSION)" docs/busybox.pod > docs/BusyBox.1
Erik Andersen0a704e82000-05-03 03:19:06 +0000102
Erik Andersena59d7092000-05-03 03:24:21 +0000103docs/BusyBox.html: docs/busybox.pod
Eric Andersen77bd2db2000-06-02 03:21:32 +0000104 pod2html docs/busybox.pod > docs/busybox.lineo.com/BusyBox.html
Eric Andersen86ab8a32000-06-02 03:21:42 +0000105 - rm -f docs/BusyBox.html
106 - ln -s busybox.lineo.com/BusyBox.html docs/BusyBox.html
Erik Andersen0a704e82000-05-03 03:19:06 +0000107 - rm -f pod2html*
108
Eric Andersencc8ed391999-10-05 16:24:54 +0000109busybox: $(OBJECTS)
Erik Andersen9ffdaa62000-02-11 21:55:04 +0000110 $(CC) $(LDFLAGS) -o $@ $^ $(LIBRARIES)
Erik Andersen7c4b2f32000-02-29 21:49:22 +0000111 $(STRIP)
Erik Andersen1d1d9502000-04-21 01:26:49 +0000112
Erik Andersenfac10d72000-02-07 05:29:42 +0000113busybox.links: busybox.def.h
Eric Andersen96bcfd31999-11-12 01:30:18 +0000114 - ./busybox.mkll | sort >$@
Eric Andersen1667fb41999-11-27 20:34:28 +0000115
Erik Andersen1d1d9502000-04-21 01:26:49 +0000116regexp.o nfsmount.o cmdedit.o: %.o: %.h
Erik Andersena3e57ca2000-04-19 03:38:01 +0000117$(OBJECTS): %.o: busybox.def.h internal.h %.c Makefile
Erik Andersen9ffdaa62000-02-11 21:55:04 +0000118
Erik Andersen9ffdaa62000-02-11 21:55:04 +0000119test tests:
120 cd tests && $(MAKE) all
121
Eric Andersencc8ed391999-10-05 16:24:54 +0000122clean:
Erik Andersen9ffdaa62000-02-11 21:55:04 +0000123 - rm -f busybox.links *~ *.o core
Eric Andersend00c2621999-12-07 08:37:31 +0000124 - rm -rf _install
Erik Andersen9ffdaa62000-02-11 21:55:04 +0000125 - cd tests && $(MAKE) clean
Eric Andersen77bd2db2000-06-02 03:21:32 +0000126 - rm -f docs/BusyBox.html docs/busybox.lineo.com/BusyBox.html \
127 docs/BusyBox.1 docs/BusyBox.txt pod2html*
Eric Andersencc8ed391999-10-05 16:24:54 +0000128
129distclean: clean
Erik Andersen9ffdaa62000-02-11 21:55:04 +0000130 - rm -f busybox
131 - cd tests && $(MAKE) distclean
Eric Andersencc8ed391999-10-05 16:24:54 +0000132
Eric Andersen07274581999-11-21 21:50:07 +0000133install: busybox busybox.links
Eric Andersen80974fa1999-11-13 04:51:47 +0000134 ./install.sh $(PREFIX)
Eric Andersen17d49ef1999-10-06 20:25:32 +0000135
Erik Andersen0a704e82000-05-03 03:19:06 +0000136dist release: distclean doc
Erik Andersenfac10d72000-02-07 05:29:42 +0000137 cd ..; \
138 rm -rf busybox-$(VERSION); \
139 cp -a busybox busybox-$(VERSION); \
140 \
141 find busybox-$(VERSION)/ -type d \
142 -name CVS \
143 -print \
144 | xargs rm -rf; \
145 \
146 find busybox-$(VERSION)/ -type f \
147 -name .cvsignore \
148 -print \
149 | xargs rm -f; \
150 \
151 tar -cvzf busybox-$(VERSION).tar.gz busybox-$(VERSION)/;