Eric Andersen | 85208e2 | 2002-04-12 12:05:57 +0000 | [diff] [blame] | 1 | # Rules.make for busybox |
Eric Andersen | 4bcdd72 | 2001-10-24 05:26:42 +0000 | [diff] [blame] | 2 | # |
Eric Andersen | 85208e2 | 2002-04-12 12:05:57 +0000 | [diff] [blame] | 3 | # 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 Andersen | 4bcdd72 | 2001-10-24 05:26:42 +0000 | [diff] [blame] | 18 | # |
| 19 | |
Eric Andersen | 85208e2 | 2002-04-12 12:05:57 +0000 | [diff] [blame] | 20 | PROG := busybox |
| 21 | VERSION := 0.61.pre |
| 22 | BUILDTIME := $(shell TZ=UTC date -u "+%Y.%m.%d-%H:%M%z") |
| 23 | HOSTCC := gcc |
| 24 | HOSTCFLAGS:= -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer |
Eric Andersen | 4bcdd72 | 2001-10-24 05:26:42 +0000 | [diff] [blame] | 25 | |
| 26 | |
Eric Andersen | 85208e2 | 2002-04-12 12:05:57 +0000 | [diff] [blame] | 27 | # What OS are you compiling busybox for? This allows you to include |
| 28 | # OS specific things, syscall overrides, etc. |
| 29 | TARGET_OS:=linux |
Eric Andersen | 4bcdd72 | 2001-10-24 05:26:42 +0000 | [diff] [blame] | 30 | |
Eric Andersen | 85208e2 | 2002-04-12 12:05:57 +0000 | [diff] [blame] | 31 | # 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 Andersen | 4bcdd72 | 2001-10-24 05:26:42 +0000 | [diff] [blame] | 35 | |
Eric Andersen | 85208e2 | 2002-04-12 12:05:57 +0000 | [diff] [blame] | 36 | # 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. |
| 39 | CFLAGS_EXTRA:= |
| 40 | |
| 41 | # If you want a static binary, turn this on. |
| 42 | DOSTATIC:=false |
| 43 | |
| 44 | # Set the following to `true' to make a debuggable build. |
| 45 | # Leave this set to `false' for production use. |
| 46 | DODEBUG:=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... |
| 58 | DODMALLOC:=false |
| 59 | |
| 60 | # Electric-fence is another very useful malloc debugging library. |
| 61 | # Do not enable this for production builds... |
| 62 | DOEFENCE:=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! |
| 71 | DOLFS:=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. |
| 76 | BB_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-". |
| 80 | CROSS:= |
| 81 | CC := $(CROSS)gcc |
| 82 | AR := $(CROSS)ar |
| 83 | AS := $(CROSS)as |
| 84 | LD := $(CROSS)ld |
| 85 | NM := $(CROSS)nm |
| 86 | STRIP := $(CROSS)strip |
| 87 | CPP := $(CC) -E |
| 88 | MAKEFILES := $(TOPDIR).config |
| 89 | export 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... |
Eric Andersen | 887ca79 | 2002-07-03 23:19:26 +0000 | [diff] [blame] | 94 | #CC:=/usr/i386-linux-uclibc/bin/i386-uclibc-gcc |
Eric Andersen | 85208e2 | 2002-04-12 12:05:57 +0000 | [diff] [blame] | 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 | |
Eric Andersen | 85208e2 | 2002-04-12 12:05:57 +0000 | [diff] [blame] | 114 | WARNINGS:=-Wall -Wstrict-prototypes -Wshadow |
| 115 | CFLAGS:=-I$(TOPDIR)include |
| 116 | ARFLAGS:=-r |
| 117 | |
Eric Andersen | 5b0f9e4 | 2002-06-23 04:50:49 +0000 | [diff] [blame] | 118 | TARGET_ARCH:=${shell $(CC) -dumpmachine | sed -e s'/-.*//' \ |
| 119 | -e 's/i.86/i386/' \ |
| 120 | -e 's/sparc.*/sparc/' \ |
| 121 | -e 's/arm.*/arm/g' \ |
| 122 | -e 's/m68k.*/m68k/' \ |
| 123 | -e 's/ppc/powerpc/g' \ |
| 124 | -e 's/v850.*/v850/g' \ |
| 125 | -e 's/sh[234]/sh/' \ |
| 126 | -e 's/mips.*/mips/' \ |
| 127 | } |
| 128 | |
| 129 | #-------------------------------------------------------- |
| 130 | # Arch specific compiler optimization stuff should go here. |
| 131 | # Unless you want to override the defaults, do not set anything |
| 132 | # for OPTIMIZATION... |
| 133 | |
| 134 | # use '-Os' optimization if available, else use -O2 |
| 135 | OPTIMIZATION := ${shell if $(CC) -Os -S -o /dev/null -xc /dev/null >/dev/null 2>&1; \ |
| 136 | then echo "-Os"; else echo "-O2" ; fi} |
| 137 | |
| 138 | # Some nice architecture specific optimizations |
| 139 | ifeq ($(strip $(TARGET_ARCH)),arm) |
| 140 | OPTIMIZATION+=-fstrict-aliasing |
| 141 | endif |
| 142 | ifeq ($(strip $(TARGET_ARCH)),i386) |
| 143 | OPTIMIZATION+=-march=i386 |
| 144 | OPTIMIZATION+=${shell if $(CC) -mpreferred-stack-boundary=2 -S -o /dev/null -xc \ |
| 145 | /dev/null >/dev/null 2>&1; then echo "-mpreferred-stack-boundary=2"; fi} |
| 146 | OPTIMIZATION+=${shell if $(CC) -falign-functions=1 -falign-jumps=0 -falign-loops=0 \ |
| 147 | -S -o /dev/null -xc /dev/null >/dev/null 2>&1; then echo \ |
| 148 | "-falign-functions=1 -falign-jumps=0 -falign-loops=0"; else \ |
| 149 | if $(CC) -malign-functions=0 -malign-jumps=0 -S -o /dev/null -xc \ |
| 150 | /dev/null >/dev/null 2>&1; then echo "-malign-functions=0 -malign-jumps=0"; fi; fi} |
| 151 | endif |
| 152 | OPTIMIZATIONS:=$(OPTIMIZATION) -fomit-frame-pointer |
| 153 | |
Eric Andersen | 85208e2 | 2002-04-12 12:05:57 +0000 | [diff] [blame] | 154 | # |
| 155 | #-------------------------------------------------------- |
| 156 | # If you're going to do a lot of builds with a non-vanilla configuration, |
| 157 | # it makes sense to adjust parameters above, so you can type "make" |
| 158 | # by itself, instead of following it by the same half-dozen overrides |
| 159 | # every time. The stuff below, on the other hand, is probably less |
| 160 | # prone to casual user adjustment. |
| 161 | # |
| 162 | |
| 163 | ifeq ($(strip $(DOLFS)),true) |
| 164 | # For large file summit support |
| 165 | CFLAGS+=-D_FILE_OFFSET_BITS=64 -D__USE_FILE_OFFSET64 |
| 166 | endif |
| 167 | ifeq ($(strip $(DODMALLOC)),true) |
| 168 | # For testing mem leaks with dmalloc |
| 169 | CFLAGS+=-DDMALLOC |
| 170 | LIBRARIES:=-ldmalloc |
| 171 | # Force debug=true, since this is useless when not debugging... |
| 172 | DODEBUG:=true |
| 173 | else |
| 174 | ifeq ($(strip $(DOEFENCE)),true) |
| 175 | LIBRARIES:=-lefence |
| 176 | # Force debug=true, since this is useless when not debugging... |
| 177 | DODEBUG:=true |
| 178 | endif |
| 179 | endif |
| 180 | ifeq ($(strip $(DODEBUG)),true) |
| 181 | CFLAGS +=$(WARNINGS) -g -D_GNU_SOURCE |
| 182 | LDFLAGS +=-Wl,-warn-common |
| 183 | STRIPCMD:=/bin/true -Not_stripping_since_we_are_debugging |
| 184 | else |
| 185 | CFLAGS += $(WARNINGS) $(OPTIMIZATIONS) -D_GNU_SOURCE |
| 186 | LDFLAGS += -s -Wl,-warn-common |
| 187 | STRIPCMD:=$(STRIP) --remove-section=.note --remove-section=.comment |
| 188 | endif |
| 189 | ifeq ($(strip $(DOSTATIC)),true) |
| 190 | LDFLAGS += --static |
| 191 | endif |
| 192 | |
| 193 | ifndef $(PREFIX) |
| 194 | PREFIX:=`pwd`/_install |
| 195 | endif |
| 196 | |
| 197 | # Additional complications due to support for pristine source dir. |
| 198 | # Include files in the build directory should take precedence over |
| 199 | # the copy in BB_SRC_DIR, both during the compilation phase and the |
| 200 | # shell script that finds the list of object files. |
| 201 | # Work in progress by <ldoolitt@recycle.lbl.gov>. |
| 202 | # |
| 203 | ifneq ($(strip $(BB_SRC_DIR)),) |
| 204 | VPATH:=$(BB_SRC_DIR) |
| 205 | endif |
| 206 | |
| 207 | CFLAGS += -DBB_VER='"$(VERSION)"' |
| 208 | CFLAGS += -DBB_BT='"$(BUILDTIME)"' |
| 209 | OBJECTS:=$(APPLET_SOURCES:.c=.o) busybox.o usage.o applets.o |
| 210 | CFLAGS += $(CROSS_CFLAGS) |
| 211 | ifdef BB_INIT_SCRIPT |
| 212 | CFLAGS += -DINIT_SCRIPT='"$(BB_INIT_SCRIPT)"' |
| 213 | endif |
| 214 | |
| 215 | # Put user-supplied flags at the end, where they |
| 216 | # have a chance of winning. |
| 217 | CFLAGS += $(CFLAGS_EXTRA) |
Eric Andersen | 4bcdd72 | 2001-10-24 05:26:42 +0000 | [diff] [blame] | 218 | |
| 219 | %.o: %.c |
Eric Andersen | 85208e2 | 2002-04-12 12:05:57 +0000 | [diff] [blame] | 220 | $(CC) $(CFLAGS) $(EXTRA_CFLAGS) -c -o $@ $< |
Eric Andersen | 4bcdd72 | 2001-10-24 05:26:42 +0000 | [diff] [blame] | 221 | |
Eric Andersen | 85208e2 | 2002-04-12 12:05:57 +0000 | [diff] [blame] | 222 | ifdef _FASTDEP_ALL_SUB_DIRS |
Eric Andersen | 4bcdd72 | 2001-10-24 05:26:42 +0000 | [diff] [blame] | 223 | fastdep: dummy |
Eric Andersen | 85208e2 | 2002-04-12 12:05:57 +0000 | [diff] [blame] | 224 | $(TOPDIR)scripts/mkdep $(CFLAGS) $(EXTRA_CFLAGS_nostdinc) -- $(wildcard *.[chS]) > .depend |
Eric Andersen | 4bcdd72 | 2001-10-24 05:26:42 +0000 | [diff] [blame] | 225 | ifdef ALL_SUB_DIRS |
| 226 | $(MAKE) $(patsubst %,_sfdep_%,$(ALL_SUB_DIRS)) _FASTDEP_ALL_SUB_DIRS="$(ALL_SUB_DIRS)" |
| 227 | endif |
| 228 | |
Eric Andersen | 4bcdd72 | 2001-10-24 05:26:42 +0000 | [diff] [blame] | 229 | $(patsubst %,_sfdep_%,$(_FASTDEP_ALL_SUB_DIRS)): |
| 230 | $(MAKE) -C $(patsubst _sfdep_%,%,$@) fastdep |
| 231 | endif |
| 232 | |
Eric Andersen | 85208e2 | 2002-04-12 12:05:57 +0000 | [diff] [blame] | 233 | .PHONY: dummy |
Eric Andersen | 4bcdd72 | 2001-10-24 05:26:42 +0000 | [diff] [blame] | 234 | |
Eric Andersen | 4bcdd72 | 2001-10-24 05:26:42 +0000 | [diff] [blame] | 235 | |
Eric Andersen | 4bcdd72 | 2001-10-24 05:26:42 +0000 | [diff] [blame] | 236 | |
Eric Andersen | 85208e2 | 2002-04-12 12:05:57 +0000 | [diff] [blame] | 237 | .EXPORT_ALL_VARIABLES: |
Eric Andersen | 4bcdd72 | 2001-10-24 05:26:42 +0000 | [diff] [blame] | 238 | |