blob: 2e9aa27e6f0bfa7f7e9a1e155b9e34c15f7bac67 [file] [log] [blame]
Eric Andersen85208e22002-04-12 12:05:57 +00001# Rules.make for busybox
Eric Andersen4bcdd722001-10-24 05:26:42 +00002#
Eric Andersen85208e22002-04-12 12:05:57 +00003# Copyright (C) 2002 Erik Andersen <andersee@debian.org>
4#
5# This program is free software; you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation; either version 2 of the License, or
8# (at your option) any later version.
9#
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13# General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with this program; if not, write to the Free Software
17# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Eric Andersen4bcdd722001-10-24 05:26:42 +000018#
19
Eric Andersen85208e22002-04-12 12:05:57 +000020PROG := busybox
21VERSION := 0.61.pre
22BUILDTIME := $(shell TZ=UTC date -u "+%Y.%m.%d-%H:%M%z")
23HOSTCC := gcc
24HOSTCFLAGS:= -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer
Eric Andersen4bcdd722001-10-24 05:26:42 +000025
26
Eric Andersen85208e22002-04-12 12:05:57 +000027# What OS are you compiling busybox for? This allows you to include
28# OS specific things, syscall overrides, etc.
29TARGET_OS:=linux
Eric Andersen4bcdd722001-10-24 05:26:42 +000030
Eric Andersen85208e22002-04-12 12:05:57 +000031# With a modern GNU make(1) (highly recommended, that's what all the
32# developers use), all of the following configuration values can be
33# overridden at the command line. For example:
34# make CROSS=powerpc-linux- BB_SRC_DIR=$HOME/busybox PREFIX=/mnt/app
Eric Andersen4bcdd722001-10-24 05:26:42 +000035
Eric Andersen85208e22002-04-12 12:05:57 +000036# If you want to add some simple compiler switches (like -march=i686),
37# especially from the command line, use this instead of CFLAGS directly.
38# For optimization overrides, it's better still to set OPTIMIZATION.
39CFLAGS_EXTRA:=
40
41# If you want a static binary, turn this on.
42DOSTATIC:=false
43
44# Set the following to `true' to make a debuggable build.
45# Leave this set to `false' for production use.
46DODEBUG:=false
47
48# This enables compiling with dmalloc ( http://dmalloc.com/ )
49# which is an excellent public domain mem leak and malloc problem
50# detector. To enable dmalloc, before running busybox you will
51# want to first set up your environment.
52# eg: `export DMALLOC_OPTIONS=debug=0x34f47d83,inter=100,log=logfile`
53# The debug= value is generated using the following command
54# dmalloc -p log-stats -p log-non-free -p log-bad-space -p log-elapsed-time \
55# -p check-fence -p check-heap -p check-lists -p check-blank \
56# -p check-funcs -p realloc-copy -p allow-free-null
57# Do not enable this for production builds...
58DODMALLOC:=false
59
60# Electric-fence is another very useful malloc debugging library.
61# Do not enable this for production builds...
62DOEFENCE:=false
63
64# If you want large file summit support, turn this on.
65# This has no effect if you don't have a kernel with lfs
66# support, and a system with libc-2.1.3 or later.
67# Some of the programs that can benefit from lfs support
68# are dd, gzip, mount, tar, and mkfs_minix.
69# LFS allows you to use the above programs for files
70# larger than 2GB!
71DOLFS:=false
72
73# If you have a "pristine" source directory, point BB_SRC_DIR to it.
74# Experimental and incomplete; tell the mailing list
75# <busybox@busybox.net> if you do or don't like it so far.
76BB_SRC_DIR:=
77
78# If you are running a cross compiler, you may want to set CROSS
79# to something more interesting, like "arm-linux-".
80CROSS:=
81CC := $(CROSS)gcc
82AR := $(CROSS)ar
83AS := $(CROSS)as
84LD := $(CROSS)ld
85NM := $(CROSS)nm
86STRIP := $(CROSS)strip
87CPP := $(CC) -E
88MAKEFILES := $(TOPDIR).config
89export VERSION BUILDTIME TOPDIR HOSTCC HOSTCFLAGS CROSS CC AR AS LD NM STRIP CPP
90
91
92# To compile vs uClibc, just use the compiler wrapper built by uClibc...
93# Everything should compile and work as expected these days...
94#CC:=/usr/i386-linux-uclibc/usr/bin/i386-uclibc-gcc
95
96# To compile vs some other alternative libc, you may need to use/adjust
97# the following lines to meet your needs...
98#
99# If you are using Red Hat 6.x with the compatible RPMs (for developing under
100# Red Hat 5.x and glibc 2.0) uncomment the following. Be sure to read about
101# using the compatible RPMs (compat-*) at http://www.redhat.com !
102#LIBCDIR:=/usr/i386-glibc20-linux
103#
104# The following is used for libc5 (if you install altgcc and libc5-altdev
105# on a Debian system).
106#LIBCDIR:=/usr/i486-linuxlibc1
107#
108# For other libraries, you are on your own...
109#LDFLAGS+=-nostdlib
110#LIBRARIES:=$(LIBCDIR)/lib/libc.a -lgcc
111#CROSS_CFLAGS+=-nostdinc -I$(LIBCDIR)/include -I$(GCCINCDIR)
112#GCCINCDIR:=$(shell gcc -print-search-dirs | sed -ne "s/install: \(.*\)/\1include/gp")
113
114# use '-Os' optimization if available, else use -O2
115OPTIMIZATION:=${shell if $(CC) -Os -S -o /dev/null -xc /dev/null \
116 >/dev/null 2>&1; then echo "-Os"; else echo "-O2" ; fi}
117GCC_STACK_BOUNDRY:=${shell if $(CC) -mpreferred-stack-boundary=2 -S -o /dev/null -xc /dev/null \
118 >/dev/null 2>&1; then echo "-mpreferred-stack-boundary=2"; else echo "" ; fi}
119OPTIMIZATIONS:=$(OPTIMIZATION) -fomit-frame-pointer $(GCC_STACK_BOUNDRY) #-fstrict-aliasing -march=i386 -mcpu=i386 -malign-functions=0 -malign-jumps=0
120WARNINGS:=-Wall -Wstrict-prototypes -Wshadow
121CFLAGS:=-I$(TOPDIR)include
122ARFLAGS:=-r
123
124#
125#--------------------------------------------------------
126# If you're going to do a lot of builds with a non-vanilla configuration,
127# it makes sense to adjust parameters above, so you can type "make"
128# by itself, instead of following it by the same half-dozen overrides
129# every time. The stuff below, on the other hand, is probably less
130# prone to casual user adjustment.
131#
132
133ifeq ($(strip $(DOLFS)),true)
134 # For large file summit support
135 CFLAGS+=-D_FILE_OFFSET_BITS=64 -D__USE_FILE_OFFSET64
136endif
137ifeq ($(strip $(DODMALLOC)),true)
138 # For testing mem leaks with dmalloc
139 CFLAGS+=-DDMALLOC
140 LIBRARIES:=-ldmalloc
141 # Force debug=true, since this is useless when not debugging...
142 DODEBUG:=true
143else
144 ifeq ($(strip $(DOEFENCE)),true)
145 LIBRARIES:=-lefence
146 # Force debug=true, since this is useless when not debugging...
147 DODEBUG:=true
148 endif
149endif
150ifeq ($(strip $(DODEBUG)),true)
151 CFLAGS +=$(WARNINGS) -g -D_GNU_SOURCE
152 LDFLAGS +=-Wl,-warn-common
153 STRIPCMD:=/bin/true -Not_stripping_since_we_are_debugging
154else
155 CFLAGS += $(WARNINGS) $(OPTIMIZATIONS) -D_GNU_SOURCE
156 LDFLAGS += -s -Wl,-warn-common
157 STRIPCMD:=$(STRIP) --remove-section=.note --remove-section=.comment
158endif
159ifeq ($(strip $(DOSTATIC)),true)
160 LDFLAGS += --static
161endif
162
163ifndef $(PREFIX)
164 PREFIX:=`pwd`/_install
165endif
166
167# Additional complications due to support for pristine source dir.
168# Include files in the build directory should take precedence over
169# the copy in BB_SRC_DIR, both during the compilation phase and the
170# shell script that finds the list of object files.
171# Work in progress by <ldoolitt@recycle.lbl.gov>.
172#
173ifneq ($(strip $(BB_SRC_DIR)),)
174 VPATH:=$(BB_SRC_DIR)
175endif
176
177CFLAGS += -DBB_VER='"$(VERSION)"'
178CFLAGS += -DBB_BT='"$(BUILDTIME)"'
179OBJECTS:=$(APPLET_SOURCES:.c=.o) busybox.o usage.o applets.o
180CFLAGS += $(CROSS_CFLAGS)
181ifdef BB_INIT_SCRIPT
182 CFLAGS += -DINIT_SCRIPT='"$(BB_INIT_SCRIPT)"'
183endif
184
185# Put user-supplied flags at the end, where they
186# have a chance of winning.
187CFLAGS += $(CFLAGS_EXTRA)
Eric Andersen4bcdd722001-10-24 05:26:42 +0000188
189%.o: %.c
Eric Andersen85208e22002-04-12 12:05:57 +0000190 $(CC) $(CFLAGS) $(EXTRA_CFLAGS) -c -o $@ $<
Eric Andersen4bcdd722001-10-24 05:26:42 +0000191
Eric Andersen85208e22002-04-12 12:05:57 +0000192ifdef _FASTDEP_ALL_SUB_DIRS
Eric Andersen4bcdd722001-10-24 05:26:42 +0000193fastdep: dummy
Eric Andersen85208e22002-04-12 12:05:57 +0000194 $(TOPDIR)scripts/mkdep $(CFLAGS) $(EXTRA_CFLAGS_nostdinc) -- $(wildcard *.[chS]) > .depend
Eric Andersen4bcdd722001-10-24 05:26:42 +0000195ifdef ALL_SUB_DIRS
196 $(MAKE) $(patsubst %,_sfdep_%,$(ALL_SUB_DIRS)) _FASTDEP_ALL_SUB_DIRS="$(ALL_SUB_DIRS)"
197endif
198
Eric Andersen4bcdd722001-10-24 05:26:42 +0000199$(patsubst %,_sfdep_%,$(_FASTDEP_ALL_SUB_DIRS)):
200 $(MAKE) -C $(patsubst _sfdep_%,%,$@) fastdep
201endif
202
Eric Andersen85208e22002-04-12 12:05:57 +0000203.PHONY: dummy
Eric Andersen4bcdd722001-10-24 05:26:42 +0000204
Eric Andersen4bcdd722001-10-24 05:26:42 +0000205
Eric Andersen4bcdd722001-10-24 05:26:42 +0000206
Eric Andersen85208e22002-04-12 12:05:57 +0000207.EXPORT_ALL_VARIABLES:
Eric Andersen4bcdd722001-10-24 05:26:42 +0000208