blob: 6c447264408b03414535256068622e83bb264fa2 [file] [log] [blame]
Eric Andersen85208e22002-04-12 12:05:57 +00001# Rules.make for busybox
Eric Andersen4bcdd722001-10-24 05:26:42 +00002#
Eric Andersenc7bda1c2004-03-15 08:29:22 +00003# Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
Eric Andersen85208e22002-04-12 12:05:57 +00004#
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 Andersenc9f20d92002-12-05 08:41:41 +000020#--------------------------------------------------------
Eric Andersen85208e22002-04-12 12:05:57 +000021PROG := busybox
Bernhard Reutner-Fischer8c7a7e62005-10-13 10:40:18 +000022MAJOR_VERSION :=1
23MINOR_VERSION :=1
24SUBLEVEL_VERSION:=0
25EXTRAVERSION :=-pre1
26VERSION :=$(MAJOR_VERSION).$(MINOR_VERSION).$(SUBLEVEL_VERSION)$(EXTRAVERSION)
Eric Andersen85208e22002-04-12 12:05:57 +000027BUILDTIME := $(shell TZ=UTC date -u "+%Y.%m.%d-%H:%M%z")
Eric Andersen4bcdd722001-10-24 05:26:42 +000028
29
Eric Andersenc9f20d92002-12-05 08:41:41 +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:
Bernhard Reutner-Fischer5c071bc2005-10-05 07:40:46 +000034# make CROSS=powerpc-linux- top_srcdir="$HOME/busybox" PREFIX=/mnt/app
Eric Andersenc9f20d92002-12-05 08:41:41 +000035#--------------------------------------------------------
Eric Andersen4bcdd722001-10-24 05:26:42 +000036
Eric Andersenc9f20d92002-12-05 08:41:41 +000037# If you are running a cross compiler, you will want to set 'CROSS'
38# to something more interesting... Target architecture is determined
39# by asking the CC compiler what arch it compiles things for, so unless
40# your compiler is broken, you should not need to specify TARGET_ARCH
Eric Andersen5912acb2003-11-05 11:34:26 +000041CROSS =$(subst ",, $(strip $(CROSS_COMPILER_PREFIX)))
Eric Andersen5912acb2003-11-05 11:34:26 +000042CC = $(CROSS)gcc
43AR = $(CROSS)ar
44AS = $(CROSS)as
45LD = $(CROSS)ld
46NM = $(CROSS)nm
47STRIP = $(CROSS)strip
48CPP = $(CC) -E
Eric Andersen7daa0762004-10-08 07:46:08 +000049# MAKEFILES = $(top_builddir)/.config
Bernhard Reutner-Fischer8c7a7e62005-10-13 10:40:18 +000050RM = rm
51RM_F = $(RM) -f
52LN = ln
53LN_S = $(LN) -s
54MKDIR = mkdir
55MKDIR_P = $(MKDIR) -p
56MV = mv
57CP = cp
58
Eric Andersen85208e22002-04-12 12:05:57 +000059
Eric Andersenc9f20d92002-12-05 08:41:41 +000060# What OS are you compiling busybox for? This allows you to include
61# OS specific things, syscall overrides, etc.
Eric Andersen5912acb2003-11-05 11:34:26 +000062TARGET_OS=linux
Eric Andersen85208e22002-04-12 12:05:57 +000063
Eric Andersenc9f20d92002-12-05 08:41:41 +000064# Select the compiler needed to build binaries for your development system
Eric Andersen5912acb2003-11-05 11:34:26 +000065HOSTCC = gcc
Robert Griebl53f133a2002-12-16 21:55:39 +000066HOSTCFLAGS= -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer
Eric Andersenc9f20d92002-12-05 08:41:41 +000067
Eric Andersenc7bda1c2004-03-15 08:29:22 +000068# Ensure consistent sort order, 'gcc -print-search-dirs' behavior, etc.
Eric Andersen85d9d802003-01-14 09:12:39 +000069LC_ALL:= C
70
Eric Andersenc9f20d92002-12-05 08:41:41 +000071# If you want to add some simple compiler switches (like -march=i686),
72# especially from the command line, use this instead of CFLAGS directly.
73# For optimization overrides, it's better still to set OPTIMIZATION.
74CFLAGS_EXTRA=$(subst ",, $(strip $(EXTRA_CFLAGS_OPTIONS)))
Eric Andersenc7bda1c2004-03-15 08:29:22 +000075
Eric Andersen85208e22002-04-12 12:05:57 +000076# To compile vs some other alternative libc, you may need to use/adjust
77# the following lines to meet your needs...
78#
79# If you are using Red Hat 6.x with the compatible RPMs (for developing under
80# Red Hat 5.x and glibc 2.0) uncomment the following. Be sure to read about
81# using the compatible RPMs (compat-*) at http://www.redhat.com !
82#LIBCDIR:=/usr/i386-glibc20-linux
83#
Eric Andersen0a14c9f2003-07-22 08:56:01 +000084# For other libraries, you are on your own. But these may (or may not) help...
Eric Andersen85208e22002-04-12 12:05:57 +000085#LDFLAGS+=-nostdlib
86#LIBRARIES:=$(LIBCDIR)/lib/libc.a -lgcc
87#CROSS_CFLAGS+=-nostdinc -I$(LIBCDIR)/include -I$(GCCINCDIR)
88#GCCINCDIR:=$(shell gcc -print-search-dirs | sed -ne "s/install: \(.*\)/\1include/gp")
89
Robert Griebl53f133a2002-12-16 21:55:39 +000090WARNINGS=-Wall -Wstrict-prototypes -Wshadow
Eric Andersen7daa0762004-10-08 07:46:08 +000091CFLAGS=-I$(top_builddir)/include -I$(top_srcdir)/include -I$(srcdir)
Mike Frysinger4d008962005-07-27 01:09:24 +000092ARFLAGS=cru
Eric Andersen85208e22002-04-12 12:05:57 +000093
Eric Andersenc9f20d92002-12-05 08:41:41 +000094#--------------------------------------------------------
Bernhard Reutner-Fischer1c943eb2005-09-26 16:01:43 +000095export VERSION BUILDTIME HOSTCC HOSTCFLAGS CROSS CC AR AS LD NM STRIP CPP
Eric Andersen5912acb2003-11-05 11:34:26 +000096ifeq ($(strip $(TARGET_ARCH)),)
Rob Landley088ee412005-07-28 19:38:52 +000097TARGET_ARCH:=$(shell $(CC) -dumpmachine | sed -e s'/-.*//' \
Eric Andersen5b0f9e42002-06-23 04:50:49 +000098 -e 's/i.86/i386/' \
99 -e 's/sparc.*/sparc/' \
100 -e 's/arm.*/arm/g' \
101 -e 's/m68k.*/m68k/' \
102 -e 's/ppc/powerpc/g' \
103 -e 's/v850.*/v850/g' \
104 -e 's/sh[234]/sh/' \
Eric Andersenc9f20d92002-12-05 08:41:41 +0000105 -e 's/mips-.*/mips/' \
106 -e 's/mipsel-.*/mipsel/' \
107 -e 's/cris.*/cris/' \
108 )
Eric Andersen5912acb2003-11-05 11:34:26 +0000109endif
Eric Andersenc9f20d92002-12-05 08:41:41 +0000110
Glenn L McGrath3bff6662003-08-29 12:23:09 +0000111# Pull in the user's busybox configuration
Eric Andersenc9f20d92002-12-05 08:41:41 +0000112ifeq ($(filter $(noconfig_targets),$(MAKECMDGOALS)),)
Eric Andersen7daa0762004-10-08 07:46:08 +0000113-include $(top_builddir)/.config
Eric Andersenc9f20d92002-12-05 08:41:41 +0000114endif
115
Eric Andersen1b6eb9b2002-10-30 06:55:37 +0000116# A nifty macro to make testing gcc features easier
Mike Frysingerb3b756d2005-07-28 22:26:25 +0000117check_gcc=$(shell \
118 if [ "$(1)" != "" ]; then \
119 if $(CC) $(1) -S -o /dev/null -xc /dev/null > /dev/null 2>&1; \
120 then echo "$(1)"; else echo "$(2)"; fi \
121 fi)
Eric Andersen5b0f9e42002-06-23 04:50:49 +0000122
Mike Frysingerc99e2c52005-07-28 22:14:35 +0000123# Setup some shortcuts so that silent mode is silent like it should be
124ifeq ($(subst s,,$(MAKEFLAGS)),$(MAKEFLAGS))
125export MAKE_IS_SILENT=n
126SECHO=@echo
127else
128export MAKE_IS_SILENT=y
129SECHO=-@false
130endif
131
Eric Andersen5b0f9e42002-06-23 04:50:49 +0000132#--------------------------------------------------------
133# Arch specific compiler optimization stuff should go here.
134# Unless you want to override the defaults, do not set anything
135# for OPTIMIZATION...
136
137# use '-Os' optimization if available, else use -O2
Mike Frysingerb3b756d2005-07-28 22:26:25 +0000138OPTIMIZATION:=$(call check_gcc,-Os,-O2)
Eric Andersen5b0f9e42002-06-23 04:50:49 +0000139
140# Some nice architecture specific optimizations
141ifeq ($(strip $(TARGET_ARCH)),arm)
142 OPTIMIZATION+=-fstrict-aliasing
143endif
144ifeq ($(strip $(TARGET_ARCH)),i386)
Eric Andersen0a14c9f2003-07-22 08:56:01 +0000145 OPTIMIZATION+=$(call check_gcc,-march=i386,)
Eric Andersen1b6eb9b2002-10-30 06:55:37 +0000146 OPTIMIZATION+=$(call check_gcc,-mpreferred-stack-boundary=2,)
147 OPTIMIZATION+=$(call check_gcc,-falign-functions=0 -falign-jumps=0 -falign-loops=0,\
148 -malign-functions=0 -malign-jumps=0 -malign-loops=0)
Eric Andersen5b0f9e42002-06-23 04:50:49 +0000149endif
Mike Frysingerb3b756d2005-07-28 22:26:25 +0000150OPTIMIZATIONS:=$(OPTIMIZATION) -fomit-frame-pointer
Eric Andersen5b0f9e42002-06-23 04:50:49 +0000151
Eric Andersen85208e22002-04-12 12:05:57 +0000152#
153#--------------------------------------------------------
154# If you're going to do a lot of builds with a non-vanilla configuration,
155# it makes sense to adjust parameters above, so you can type "make"
156# by itself, instead of following it by the same half-dozen overrides
157# every time. The stuff below, on the other hand, is probably less
158# prone to casual user adjustment.
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000159#
Eric Andersen85208e22002-04-12 12:05:57 +0000160
Eric Andersene5272072003-07-22 22:15:21 +0000161ifeq ($(strip $(CONFIG_LFS)),y)
Eric Andersen85208e22002-04-12 12:05:57 +0000162 # For large file summit support
Eric Andersenecfa2902002-09-22 12:09:44 +0000163 CFLAGS+=-D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
Eric Andersen85208e22002-04-12 12:05:57 +0000164endif
Eric Andersene5272072003-07-22 22:15:21 +0000165ifeq ($(strip $(CONFIG_DMALLOC)),y)
Eric Andersen85208e22002-04-12 12:05:57 +0000166 # For testing mem leaks with dmalloc
167 CFLAGS+=-DDMALLOC
168 LIBRARIES:=-ldmalloc
Eric Andersen85208e22002-04-12 12:05:57 +0000169else
Eric Andersene5272072003-07-22 22:15:21 +0000170 ifeq ($(strip $(CONFIG_EFENCE)),y)
Eric Andersen85208e22002-04-12 12:05:57 +0000171 LIBRARIES:=-lefence
Eric Andersen85208e22002-04-12 12:05:57 +0000172 endif
173endif
Eric Andersene5272072003-07-22 22:15:21 +0000174ifeq ($(strip $(CONFIG_DEBUG)),y)
Eric Andersen85208e22002-04-12 12:05:57 +0000175 CFLAGS +=$(WARNINGS) -g -D_GNU_SOURCE
176 LDFLAGS +=-Wl,-warn-common
177 STRIPCMD:=/bin/true -Not_stripping_since_we_are_debugging
178else
Eric Andersenbae7c1a2003-03-07 17:27:51 +0000179 CFLAGS+=$(WARNINGS) $(OPTIMIZATIONS) -D_GNU_SOURCE -DNDEBUG
Rob Landleyc7a3e1b2005-07-31 04:25:00 +0000180 LDFLAGS += -Wl,-warn-common
Mike Frysinger1c1655a2005-07-31 22:11:33 +0000181 STRIPCMD:=$(STRIP) -s --remove-section=.note --remove-section=.comment
Eric Andersen85208e22002-04-12 12:05:57 +0000182endif
Eric Andersene5272072003-07-22 22:15:21 +0000183ifeq ($(strip $(CONFIG_STATIC)),y)
Eric Andersen85208e22002-04-12 12:05:57 +0000184 LDFLAGS += --static
185endif
186
Bernhard Reutner-Fischer5c071bc2005-10-05 07:40:46 +0000187ifeq ($(strip $(CONFIG_SELINUX)),y)
188 LIBRARIES += -lselinux
189endif
190
Eric Andersen12f834c2002-10-26 10:17:24 +0000191ifeq ($(strip $(PREFIX)),)
Eric Andersen85208e22002-04-12 12:05:57 +0000192 PREFIX:=`pwd`/_install
193endif
194
195# Additional complications due to support for pristine source dir.
196# Include files in the build directory should take precedence over
Bernhard Reutner-Fischer5c071bc2005-10-05 07:40:46 +0000197# the copy in top_srcdir, both during the compilation phase and the
Eric Andersen85208e22002-04-12 12:05:57 +0000198# shell script that finds the list of object files.
199# Work in progress by <ldoolitt@recycle.lbl.gov>.
Bernhard Reutner-Fischer5c071bc2005-10-05 07:40:46 +0000200
Eric Andersen85208e22002-04-12 12:05:57 +0000201
Eric Andersen85208e22002-04-12 12:05:57 +0000202OBJECTS:=$(APPLET_SOURCES:.c=.o) busybox.o usage.o applets.o
203CFLAGS += $(CROSS_CFLAGS)
204ifdef BB_INIT_SCRIPT
205 CFLAGS += -DINIT_SCRIPT='"$(BB_INIT_SCRIPT)"'
206endif
207
208# Put user-supplied flags at the end, where they
209# have a chance of winning.
210CFLAGS += $(CFLAGS_EXTRA)
Eric Andersen4bcdd722001-10-24 05:26:42 +0000211
Eric Andersen85208e22002-04-12 12:05:57 +0000212.PHONY: dummy