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 | # |
Mike Frysinger | 5a5d0fa | 2005-11-29 02:53:52 +0000 | [diff] [blame] | 3 | # Copyright (C) 1999-2005 by Erik Andersen <andersen@codepoet.org> |
Eric Andersen | 85208e2 | 2002-04-12 12:05:57 +0000 | [diff] [blame] | 4 | # |
Mike Frysinger | 5a5d0fa | 2005-11-29 02:53:52 +0000 | [diff] [blame] | 5 | # Licensed under GPLv2, see the file LICENSE in this tarball for details. |
Eric Andersen | 4bcdd72 | 2001-10-24 05:26:42 +0000 | [diff] [blame] | 6 | # |
| 7 | |
Mike Frysinger | 004ad11 | 2005-11-29 02:52:25 +0000 | [diff] [blame] | 8 | # Pull in the user's busybox configuration |
| 9 | ifeq ($(filter $(noconfig_targets),$(MAKECMDGOALS)),) |
| 10 | -include $(top_builddir)/.config |
| 11 | endif |
| 12 | |
Bernhard Reutner-Fischer | 5d26126 | 2006-03-01 22:54:48 +0000 | [diff] [blame] | 13 | ifeq ($(MAKELEVEL),0) |
| 14 | ifeq ($(HAVE_DOT_CONFIG),y) |
| 15 | rules-mak-rules:=0 |
| 16 | endif |
| 17 | endif |
| 18 | |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 19 | #-------------------------------------------------------- |
Eric Andersen | 85208e2 | 2002-04-12 12:05:57 +0000 | [diff] [blame] | 20 | PROG := busybox |
Bernhard Reutner-Fischer | 8c7a7e6 | 2005-10-13 10:40:18 +0000 | [diff] [blame] | 21 | MAJOR_VERSION :=1 |
| 22 | MINOR_VERSION :=1 |
Bernhard Reutner-Fischer | b565a12 | 2006-01-19 09:22:39 +0000 | [diff] [blame] | 23 | SUBLEVEL_VERSION:=1 |
| 24 | EXTRAVERSION :=-pre0 |
Bernhard Reutner-Fischer | 8c7a7e6 | 2005-10-13 10:40:18 +0000 | [diff] [blame] | 25 | VERSION :=$(MAJOR_VERSION).$(MINOR_VERSION).$(SUBLEVEL_VERSION)$(EXTRAVERSION) |
Eric Andersen | 85208e2 | 2002-04-12 12:05:57 +0000 | [diff] [blame] | 26 | BUILDTIME := $(shell TZ=UTC date -u "+%Y.%m.%d-%H:%M%z") |
Eric Andersen | 4bcdd72 | 2001-10-24 05:26:42 +0000 | [diff] [blame] | 27 | |
| 28 | |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 29 | #-------------------------------------------------------- |
Eric Andersen | 85208e2 | 2002-04-12 12:05:57 +0000 | [diff] [blame] | 30 | # With a modern GNU make(1) (highly recommended, that's what all the |
| 31 | # developers use), all of the following configuration values can be |
| 32 | # overridden at the command line. For example: |
Bernhard Reutner-Fischer | 5c071bc | 2005-10-05 07:40:46 +0000 | [diff] [blame] | 33 | # make CROSS=powerpc-linux- top_srcdir="$HOME/busybox" PREFIX=/mnt/app |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 34 | #-------------------------------------------------------- |
Eric Andersen | 4bcdd72 | 2001-10-24 05:26:42 +0000 | [diff] [blame] | 35 | |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 36 | # If you are running a cross compiler, you will want to set 'CROSS' |
| 37 | # to something more interesting... Target architecture is determined |
| 38 | # by asking the CC compiler what arch it compiles things for, so unless |
Bernhard Reutner-Fischer | 5d26126 | 2006-03-01 22:54:48 +0000 | [diff] [blame] | 39 | # your compiler is broken, you should not need to specify __TARGET_ARCH |
Eric Andersen | 5912acb | 2003-11-05 11:34:26 +0000 | [diff] [blame] | 40 | CROSS =$(subst ",, $(strip $(CROSS_COMPILER_PREFIX))) |
Bernhard Reutner-Fischer | 5d26126 | 2006-03-01 22:54:48 +0000 | [diff] [blame] | 41 | #") |
Eric Andersen | 5912acb | 2003-11-05 11:34:26 +0000 | [diff] [blame] | 42 | CC = $(CROSS)gcc |
| 43 | AR = $(CROSS)ar |
| 44 | AS = $(CROSS)as |
| 45 | LD = $(CROSS)ld |
| 46 | NM = $(CROSS)nm |
| 47 | STRIP = $(CROSS)strip |
| 48 | CPP = $(CC) -E |
Bernhard Reutner-Fischer | 5d26126 | 2006-03-01 22:54:48 +0000 | [diff] [blame] | 49 | SED ?= sed |
| 50 | AWK ?= awk |
Bernhard Reutner-Fischer | 8c7a7e6 | 2005-10-13 10:40:18 +0000 | [diff] [blame] | 51 | |
Eric Andersen | 85208e2 | 2002-04-12 12:05:57 +0000 | [diff] [blame] | 52 | |
Bernhard Reutner-Fischer | 5d26126 | 2006-03-01 22:54:48 +0000 | [diff] [blame] | 53 | ifdef PACKAGE_BE_VERBOSE |
| 54 | PACKAGE_BE_VERBOSE := $(shell echo $(PACKAGE_BE_VERBOSE) | $(SED) "s/[[:alpha:]]*//g") |
| 55 | endif |
| 56 | |
| 57 | # for make V=3 and above make $(shell) invocations verbose |
| 58 | ifeq ($(if $(strip $(PACKAGE_BE_VERBOSE)),$(shell test $(PACKAGE_BE_VERBOSE) -gt 2 ; echo $$?),1),0) |
| 59 | SHELL+=-x |
| 60 | MKDEP_ARGS:=-w |
| 61 | endif |
| 62 | |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 63 | # What OS are you compiling busybox for? This allows you to include |
| 64 | # OS specific things, syscall overrides, etc. |
Eric Andersen | 5912acb | 2003-11-05 11:34:26 +0000 | [diff] [blame] | 65 | TARGET_OS=linux |
Eric Andersen | 85208e2 | 2002-04-12 12:05:57 +0000 | [diff] [blame] | 66 | |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 67 | # Select the compiler needed to build binaries for your development system |
Eric Andersen | 5912acb | 2003-11-05 11:34:26 +0000 | [diff] [blame] | 68 | HOSTCC = gcc |
Robert Griebl | 53f133a | 2002-12-16 21:55:39 +0000 | [diff] [blame] | 69 | HOSTCFLAGS= -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 70 | |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 71 | # Ensure consistent sort order, 'gcc -print-search-dirs' behavior, etc. |
Eric Andersen | 85d9d80 | 2003-01-14 09:12:39 +0000 | [diff] [blame] | 72 | LC_ALL:= C |
| 73 | |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 74 | # If you want to add some simple compiler switches (like -march=i686), |
| 75 | # especially from the command line, use this instead of CFLAGS directly. |
Bernhard Reutner-Fischer | 5d26126 | 2006-03-01 22:54:48 +0000 | [diff] [blame] | 76 | # For optimization overrides, it's better still to set OPTIMIZATIONS. |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 77 | CFLAGS_EXTRA=$(subst ",, $(strip $(EXTRA_CFLAGS_OPTIONS))) |
Bernhard Reutner-Fischer | 5d26126 | 2006-03-01 22:54:48 +0000 | [diff] [blame] | 78 | #") |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 79 | |
Eric Andersen | 85208e2 | 2002-04-12 12:05:57 +0000 | [diff] [blame] | 80 | # To compile vs some other alternative libc, you may need to use/adjust |
| 81 | # the following lines to meet your needs... |
| 82 | # |
| 83 | # If you are using Red Hat 6.x with the compatible RPMs (for developing under |
| 84 | # Red Hat 5.x and glibc 2.0) uncomment the following. Be sure to read about |
| 85 | # using the compatible RPMs (compat-*) at http://www.redhat.com ! |
| 86 | #LIBCDIR:=/usr/i386-glibc20-linux |
| 87 | # |
Eric Andersen | 0a14c9f | 2003-07-22 08:56:01 +0000 | [diff] [blame] | 88 | # For other libraries, you are on your own. But these may (or may not) help... |
Eric Andersen | 85208e2 | 2002-04-12 12:05:57 +0000 | [diff] [blame] | 89 | #LDFLAGS+=-nostdlib |
| 90 | #LIBRARIES:=$(LIBCDIR)/lib/libc.a -lgcc |
Rob Landley | 4a070d1 | 2005-12-01 17:01:43 +0000 | [diff] [blame] | 91 | #CROSS_CFLAGS+=-nostdinc -I$(LIBCDIR)/include -I$(GCCINCDIR) -funsigned-char |
Eric Andersen | 85208e2 | 2002-04-12 12:05:57 +0000 | [diff] [blame] | 92 | #GCCINCDIR:=$(shell gcc -print-search-dirs | sed -ne "s/install: \(.*\)/\1include/gp") |
| 93 | |
Robert Griebl | 53f133a | 2002-12-16 21:55:39 +0000 | [diff] [blame] | 94 | WARNINGS=-Wall -Wstrict-prototypes -Wshadow |
Bernhard Reutner-Fischer | 5d26126 | 2006-03-01 22:54:48 +0000 | [diff] [blame] | 95 | CFLAGS+=-I$(top_builddir)/include -I$(top_srcdir)/include |
Bernhard Reutner-Fischer | 7ca61b6 | 2006-01-15 14:04:57 +0000 | [diff] [blame] | 96 | |
Bernhard Reutner-Fischer | c8e278f | 2006-03-02 18:13:05 +0000 | [diff] [blame] | 97 | ARFLAGS=cruP |
Eric Andersen | 85208e2 | 2002-04-12 12:05:57 +0000 | [diff] [blame] | 98 | |
Bernhard Reutner-Fischer | e0b8778 | 2005-12-13 11:52:46 +0000 | [diff] [blame] | 99 | |
Bernhard Reutner-Fischer | 5d26126 | 2006-03-01 22:54:48 +0000 | [diff] [blame] | 100 | |
| 101 | # Get the CC MAJOR/MINOR version |
Bernhard Reutner-Fischer | e0b8778 | 2005-12-13 11:52:46 +0000 | [diff] [blame] | 102 | # gcc centric. Perhaps fiddle with findstring gcc,$(CC) for the rest |
Bernhard Reutner-Fischer | e0b8778 | 2005-12-13 11:52:46 +0000 | [diff] [blame] | 103 | CC_MAJOR:=$(shell printf "%02d" $(shell echo __GNUC__ | $(CC) -E -xc - | tail -n 1)) |
| 104 | CC_MINOR:=$(shell printf "%02d" $(shell echo __GNUC_MINOR__ | $(CC) -E -xc - | tail -n 1)) |
| 105 | |
Bernhard Reutner-Fischer | 5d26126 | 2006-03-01 22:54:48 +0000 | [diff] [blame] | 106 | # Note: spaces are significant here! |
| 107 | # Check if CC version is equal to given MAJOR,MINOR. Returns empty if false. |
| 108 | define cc_eq |
| 109 | $(shell [ $(CC_MAJOR) -eq $(1) -a $(CC_MINOR) -eq $(2) ] && echo y) |
| 110 | endef |
| 111 | # Check if CC version is greater or equal than given MAJOR,MINOR |
| 112 | define cc_ge |
| 113 | $(shell [ $(CC_MAJOR) -ge $(1) -a $(CC_MINOR) -ge $(2) ] && echo y) |
| 114 | endef |
| 115 | # Check if CC version is less or equal than given MAJOR,MINOR |
| 116 | define cc_le |
| 117 | $(shell [ $(CC_MAJOR) -le $(1) -a $(CC_MINOR) -le $(2) ] && echo y) |
| 118 | endef |
| 119 | |
| 120 | # Workaround bugs in make-3.80 for eval in conditionals |
| 121 | define is_eq |
| 122 | $(shell [ $(1) = $(2) ] 2> /dev/null && echo y) |
| 123 | endef |
| 124 | define is_neq |
| 125 | $(shell [ $(1) != $(2) ] 2> /dev/null && echo y) |
| 126 | endef |
| 127 | |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 128 | #-------------------------------------------------------- |
Bernhard Reutner-Fischer | 1c943eb | 2005-09-26 16:01:43 +0000 | [diff] [blame] | 129 | export VERSION BUILDTIME HOSTCC HOSTCFLAGS CROSS CC AR AS LD NM STRIP CPP |
Bernhard Reutner-Fischer | 5d26126 | 2006-03-01 22:54:48 +0000 | [diff] [blame] | 130 | |
| 131 | # TARGET_ARCH and TARGET_MACH will be passed verbatim to CC with recent |
| 132 | # versions of make, so we use __TARGET_ARCH here. |
| 133 | # Current builtin rules looks like that: |
| 134 | # COMPILE.s = $(AS) $(ASFLAGS) $(TARGET_MACH) |
| 135 | # COMPILE.c = $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c |
| 136 | |
| 137 | ifeq ($(strip $(__TARGET_ARCH)),) |
| 138 | __TARGET_ARCH:=$(shell $(CC) -dumpmachine | sed -e s'/-.*//' \ |
Eric Andersen | 5b0f9e4 | 2002-06-23 04:50:49 +0000 | [diff] [blame] | 139 | -e 's/i.86/i386/' \ |
| 140 | -e 's/sparc.*/sparc/' \ |
| 141 | -e 's/arm.*/arm/g' \ |
| 142 | -e 's/m68k.*/m68k/' \ |
| 143 | -e 's/ppc/powerpc/g' \ |
| 144 | -e 's/v850.*/v850/g' \ |
| 145 | -e 's/sh[234]/sh/' \ |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 146 | -e 's/mips-.*/mips/' \ |
| 147 | -e 's/mipsel-.*/mipsel/' \ |
| 148 | -e 's/cris.*/cris/' \ |
| 149 | ) |
Eric Andersen | 5912acb | 2003-11-05 11:34:26 +0000 | [diff] [blame] | 150 | endif |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 151 | |
Bernhard Reutner-Fischer | 5d26126 | 2006-03-01 22:54:48 +0000 | [diff] [blame] | 152 | $(call check_gcc,CFLAGS,-funsigned-char,) |
| 153 | $(call check_gcc,CFLAGS,-mmax-stack-frame=256,) |
Bernhard Reutner-Fischer | 7ca61b6 | 2006-01-15 14:04:57 +0000 | [diff] [blame] | 154 | |
Eric Andersen | 5b0f9e4 | 2002-06-23 04:50:49 +0000 | [diff] [blame] | 155 | #-------------------------------------------------------- |
| 156 | # Arch specific compiler optimization stuff should go here. |
| 157 | # Unless you want to override the defaults, do not set anything |
Bernhard Reutner-Fischer | 5d26126 | 2006-03-01 22:54:48 +0000 | [diff] [blame] | 158 | # for OPTIMIZATIONS... |
Eric Andersen | 5b0f9e4 | 2002-06-23 04:50:49 +0000 | [diff] [blame] | 159 | |
| 160 | # use '-Os' optimization if available, else use -O2 |
Bernhard Reutner-Fischer | 5d26126 | 2006-03-01 22:54:48 +0000 | [diff] [blame] | 161 | $(call check_gcc,OPTIMIZATIONS,-Os,-O2) |
Eric Andersen | 5b0f9e4 | 2002-06-23 04:50:49 +0000 | [diff] [blame] | 162 | |
Bernhard Reutner-Fischer | 7ca61b6 | 2006-01-15 14:04:57 +0000 | [diff] [blame] | 163 | # gcc 2.95 exits with 0 for "unrecognized option" |
Bernhard Reutner-Fischer | 5d26126 | 2006-03-01 22:54:48 +0000 | [diff] [blame] | 164 | $(if $(call is_eq,$(CONFIG_BUILD_AT_ONCE),y),\ |
| 165 | $(if $(call cc_ge,3,0),\ |
| 166 | $(call check_gcc,CFLAGS_COMBINE,--combine,))) |
Bernhard Reutner-Fischer | 7ca61b6 | 2006-01-15 14:04:57 +0000 | [diff] [blame] | 167 | |
Bernhard Reutner-Fischer | 5d26126 | 2006-03-01 22:54:48 +0000 | [diff] [blame] | 168 | $(if $(call is_eq,$(CONFIG_BUILD_AT_ONCE),y),\ |
| 169 | $(call check_gcc,OPTIMIZATIONS,-funit-at-a-time,)) |
Bernhard Reutner-Fischer | 08a1b50 | 2006-01-27 15:45:56 +0000 | [diff] [blame] | 170 | |
Bernhard Reutner-Fischer | 5d26126 | 2006-03-01 22:54:48 +0000 | [diff] [blame] | 171 | # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25795 |
| 172 | #$(if $(call is_eq,$(CONFIG_BUILD_AT_ONCE),y),\ |
| 173 | # $(call check_gcc,PROG_CFLAGS,-fwhole-program,)) |
| 174 | |
| 175 | $(call check_ld,LIB_LDFLAGS,--enable-new-dtags,) |
| 176 | #$(call check_ld,LIB_LDFLAGS,--reduce-memory-overheads,) |
| 177 | #$(call check_ld,LIB_LDFLAGS,--as-needed,) |
| 178 | #$(call check_ld,LIB_LDFLAGS,--warn-shared-textrel,) |
| 179 | |
| 180 | $(call check_ld,PROG_LDFLAGS,--gc-sections,) |
Bernhard Reutner-Fischer | 08a1b50 | 2006-01-27 15:45:56 +0000 | [diff] [blame] | 181 | |
Eric Andersen | 5b0f9e4 | 2002-06-23 04:50:49 +0000 | [diff] [blame] | 182 | # Some nice architecture specific optimizations |
Bernhard Reutner-Fischer | 5d26126 | 2006-03-01 22:54:48 +0000 | [diff] [blame] | 183 | ifeq ($(__TARGET_ARCH),arm) |
| 184 | OPTIMIZATIONS+=-fstrict-aliasing |
| 185 | endif # arm |
| 186 | |
| 187 | $(if $(call is_eq,$(__TARGET_ARCH),i386),\ |
| 188 | $(call check_gcc,OPTIMIZATIONS,-march=i386,)) |
| 189 | |
Bernhard Reutner-Fischer | d9969ea | 2006-03-03 20:31:33 +0000 | [diff] [blame] | 190 | # gcc-4.0 and older seem to benefit from these |
Bernhard Reutner-Fischer | 5d26126 | 2006-03-01 22:54:48 +0000 | [diff] [blame] | 191 | $(if $(call cc_le,4,0),\ |
| 192 | $(call check_gcc,OPTIMIZATIONS,-mpreferred-stack-boundary=2,)\ |
Rob Landley | c05dda4 | 2006-03-03 17:57:50 +0000 | [diff] [blame] | 193 | $(call check_gcc,OPTIMIZATIONS,-falign-functions=1 -falign-jumps=1 -falign-loops=1,\ |
Bernhard Reutner-Fischer | 5d26126 | 2006-03-01 22:54:48 +0000 | [diff] [blame] | 194 | -malign-functions=0 -malign-jumps=0 -malign-loops=0)) |
Bernhard Reutner-Fischer | 7ca61b6 | 2006-01-15 14:04:57 +0000 | [diff] [blame] | 195 | |
| 196 | # gcc-4.1 and beyond seem to benefit from these |
Bernhard Reutner-Fischer | 5d26126 | 2006-03-01 22:54:48 +0000 | [diff] [blame] | 197 | # turn off flags which hurt -Os |
| 198 | $(if $(call cc_ge,4,1),\ |
| 199 | $(call check_gcc,OPTIMIZATIONS,-fno-tree-loop-optimize,)\ |
| 200 | $(call check_gcc,OPTIMIZATIONS,-fno-tree-dominator-opts,)\ |
| 201 | $(call check_gcc,OPTIMIZATIONS,-fno-strength-reduce,)\ |
| 202 | \ |
| 203 | $(call check_gcc,OPTIMIZATIONS,-fno-branch-count-reg,)) |
Bernhard Reutner-Fischer | 7ca61b6 | 2006-01-15 14:04:57 +0000 | [diff] [blame] | 204 | |
Bernhard Reutner-Fischer | 5d26126 | 2006-03-01 22:54:48 +0000 | [diff] [blame] | 205 | $(call check_gcc,OPTIMIZATIONS,-fomit-frame-pointer,) |
Eric Andersen | 5b0f9e4 | 2002-06-23 04:50:49 +0000 | [diff] [blame] | 206 | |
Eric Andersen | 85208e2 | 2002-04-12 12:05:57 +0000 | [diff] [blame] | 207 | # |
| 208 | #-------------------------------------------------------- |
| 209 | # If you're going to do a lot of builds with a non-vanilla configuration, |
| 210 | # it makes sense to adjust parameters above, so you can type "make" |
| 211 | # by itself, instead of following it by the same half-dozen overrides |
| 212 | # every time. The stuff below, on the other hand, is probably less |
| 213 | # prone to casual user adjustment. |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 214 | # |
Eric Andersen | 85208e2 | 2002-04-12 12:05:57 +0000 | [diff] [blame] | 215 | |
Bernhard Reutner-Fischer | 5d26126 | 2006-03-01 22:54:48 +0000 | [diff] [blame] | 216 | ifeq ($(CONFIG_LFS),y) |
Eric Andersen | 85208e2 | 2002-04-12 12:05:57 +0000 | [diff] [blame] | 217 | # For large file summit support |
Eric Andersen | ecfa290 | 2002-09-22 12:09:44 +0000 | [diff] [blame] | 218 | CFLAGS+=-D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 |
Eric Andersen | 85208e2 | 2002-04-12 12:05:57 +0000 | [diff] [blame] | 219 | endif |
Bernhard Reutner-Fischer | 5d26126 | 2006-03-01 22:54:48 +0000 | [diff] [blame] | 220 | ifeq ($(CONFIG_DMALLOC),y) |
Eric Andersen | 85208e2 | 2002-04-12 12:05:57 +0000 | [diff] [blame] | 221 | # For testing mem leaks with dmalloc |
| 222 | CFLAGS+=-DDMALLOC |
| 223 | LIBRARIES:=-ldmalloc |
Eric Andersen | 85208e2 | 2002-04-12 12:05:57 +0000 | [diff] [blame] | 224 | else |
Bernhard Reutner-Fischer | 5d26126 | 2006-03-01 22:54:48 +0000 | [diff] [blame] | 225 | ifeq ($(CONFIG_EFENCE),y) |
Eric Andersen | 85208e2 | 2002-04-12 12:05:57 +0000 | [diff] [blame] | 226 | LIBRARIES:=-lefence |
Eric Andersen | 85208e2 | 2002-04-12 12:05:57 +0000 | [diff] [blame] | 227 | endif |
| 228 | endif |
Bernhard Reutner-Fischer | 5d26126 | 2006-03-01 22:54:48 +0000 | [diff] [blame] | 229 | |
| 230 | $(if $(call is_eq,$(CONFIG_DEBUG),y),\ |
| 231 | $(call check_ld,LDFLAGS,--warn-common,),\ |
| 232 | $(call check_ld,LDFLAGS,--warn-common,)$(call check_ld,LDFLAGS,--sort-common,)) |
| 233 | ifeq ($(CONFIG_DEBUG),y) |
Eric Andersen | 85208e2 | 2002-04-12 12:05:57 +0000 | [diff] [blame] | 234 | CFLAGS +=$(WARNINGS) -g -D_GNU_SOURCE |
Eric Andersen | 85208e2 | 2002-04-12 12:05:57 +0000 | [diff] [blame] | 235 | STRIPCMD:=/bin/true -Not_stripping_since_we_are_debugging |
| 236 | else |
Eric Andersen | bae7c1a | 2003-03-07 17:27:51 +0000 | [diff] [blame] | 237 | CFLAGS+=$(WARNINGS) $(OPTIMIZATIONS) -D_GNU_SOURCE -DNDEBUG |
Mike Frysinger | 1c1655a | 2005-07-31 22:11:33 +0000 | [diff] [blame] | 238 | STRIPCMD:=$(STRIP) -s --remove-section=.note --remove-section=.comment |
Eric Andersen | 85208e2 | 2002-04-12 12:05:57 +0000 | [diff] [blame] | 239 | endif |
Bernhard Reutner-Fischer | 5d26126 | 2006-03-01 22:54:48 +0000 | [diff] [blame] | 240 | $(if $(call is_eq,$(CONFIG_STATIC),y),\ |
| 241 | $(call check_gcc,PROG_CFLAGS,-static,)) |
| 242 | |
| 243 | $(call check_gcc,CFLAGS_SHARED,-shared,) |
Bernhard Reutner-Fischer | 81b9496 | 2006-01-31 11:29:22 +0000 | [diff] [blame] | 244 | LIB_CFLAGS+=$(CFLAGS_SHARED) |
Bernhard Reutner-Fischer | 7ca61b6 | 2006-01-15 14:04:57 +0000 | [diff] [blame] | 245 | |
Bernhard Reutner-Fischer | 5d26126 | 2006-03-01 22:54:48 +0000 | [diff] [blame] | 246 | $(if $(call is_eq,$(CONFIG_BUILD_LIBBUSYBOX),y),\ |
| 247 | $(call check_gcc,CFLAGS_PIC,-fPIC,)) |
Eric Andersen | 85208e2 | 2002-04-12 12:05:57 +0000 | [diff] [blame] | 248 | |
Bernhard Reutner-Fischer | 5d26126 | 2006-03-01 22:54:48 +0000 | [diff] [blame] | 249 | ifeq ($(CONFIG_SELINUX),y) |
Bernhard Reutner-Fischer | 5c071bc | 2005-10-05 07:40:46 +0000 | [diff] [blame] | 250 | LIBRARIES += -lselinux |
| 251 | endif |
| 252 | |
Eric Andersen | 12f834c | 2002-10-26 10:17:24 +0000 | [diff] [blame] | 253 | ifeq ($(strip $(PREFIX)),) |
Eric Andersen | 85208e2 | 2002-04-12 12:05:57 +0000 | [diff] [blame] | 254 | PREFIX:=`pwd`/_install |
| 255 | endif |
| 256 | |
Eric Andersen | 85208e2 | 2002-04-12 12:05:57 +0000 | [diff] [blame] | 257 | CFLAGS += $(CROSS_CFLAGS) |
| 258 | ifdef BB_INIT_SCRIPT |
| 259 | CFLAGS += -DINIT_SCRIPT='"$(BB_INIT_SCRIPT)"' |
| 260 | endif |
| 261 | |
| 262 | # Put user-supplied flags at the end, where they |
| 263 | # have a chance of winning. |
| 264 | CFLAGS += $(CFLAGS_EXTRA) |
Eric Andersen | 4bcdd72 | 2001-10-24 05:26:42 +0000 | [diff] [blame] | 265 | |
Rob Landley | e0c418e | 2005-12-15 07:25:54 +0000 | [diff] [blame] | 266 | #------------------------------------------------------------ |
| 267 | # Installation options |
| 268 | ifeq ($(strip $(CONFIG_INSTALL_APPLET_HARDLINKS)),y) |
| 269 | INSTALL_OPTS=--hardlinks |
| 270 | endif |
| 271 | ifeq ($(strip $(CONFIG_INSTALL_APPLET_SYMLINKS)),y) |
| 272 | INSTALL_OPTS=--symlinks |
| 273 | endif |
| 274 | ifeq ($(strip $(CONFIG_INSTALL_APPLET_DONT)),y) |
| 275 | INSTALL_OPTS= |
| 276 | endif |
| 277 | |
Bernhard Reutner-Fischer | 5d26126 | 2006-03-01 22:54:48 +0000 | [diff] [blame] | 278 | |
| 279 | #------------------------------------------------------------ |
| 280 | # object extensions |
| 281 | |
| 282 | # object potentially used in shared object |
| 283 | ifeq ($(strip $(CONFIG_BUILD_LIBBUSYBOX)),y) |
| 284 | # single-object extension |
| 285 | os:=.os |
| 286 | # multi-object extension |
| 287 | om:=.osm |
| 288 | else |
| 289 | os:=.o |
| 290 | om:=.om |
| 291 | endif |
| 292 | |
Mike Frysinger | b38673f | 2006-02-02 01:41:53 +0000 | [diff] [blame] | 293 | #------------------------------------------------------------ |
| 294 | # Make the output nice and tight |
Bernhard Reutner-Fischer | 5d26126 | 2006-03-01 22:54:48 +0000 | [diff] [blame] | 295 | |
| 296 | # for make V=2 and above, do print directory |
| 297 | ifneq ($(shell test -n "$(strip $(PACKAGE_BE_VERBOSE))" && test $(PACKAGE_BE_VERBOSE) -gt 1 ; echo $$?),0) |
| 298 | MAKEFLAGS += --no-print-directory |
| 299 | endif |
| 300 | |
| 301 | export MAKEOVERRIDES |
Mike Frysinger | b38673f | 2006-02-02 01:41:53 +0000 | [diff] [blame] | 302 | export MAKE_IS_SILENT=n |
| 303 | ifneq ($(findstring s,$(MAKEFLAGS)),) |
| 304 | export MAKE_IS_SILENT=y |
Mike Frysinger | b38673f | 2006-02-02 01:41:53 +0000 | [diff] [blame] | 305 | DISP := sil |
| 306 | Q := @ |
| 307 | else |
| 308 | ifneq ($(V)$(VERBOSE),) |
Mike Frysinger | b38673f | 2006-02-02 01:41:53 +0000 | [diff] [blame] | 309 | DISP := ver |
| 310 | Q := |
| 311 | else |
Mike Frysinger | b38673f | 2006-02-02 01:41:53 +0000 | [diff] [blame] | 312 | DISP := pur |
| 313 | Q := @ |
| 314 | endif |
| 315 | endif |
| 316 | |
Bernhard Reutner-Fischer | 5d26126 | 2006-03-01 22:54:48 +0000 | [diff] [blame] | 317 | define show_objs |
| 318 | $(subst $(top_builddir)/,,$(subst ../,,$@)) |
| 319 | endef |
| 320 | pur_disp_compile.c = @echo " "CC $(show_objs) ; |
| 321 | pur_disp_compile.h = @echo " "HOSTCC $(show_objs) ; |
| 322 | pur_disp_strip = @echo " "STRIP $(show_objs) ; |
| 323 | pur_disp_link = @echo " "LINK $(show_objs) ; |
| 324 | pur_disp_link.h = @echo " "HOSTLINK $(show_objs) ; |
| 325 | pur_disp_ar = @echo " "AR $(ARFLAGS) $(show_objs) ; |
| 326 | pur_disp_gen = @echo " "GEN $@ ; |
| 327 | pur_disp_doc = @echo " "DOC $(subst docs/,,$@) ; |
| 328 | pur_disp_bin = @echo " "BIN $(show_objs) ; |
| 329 | sil_disp_compile.c = @ |
| 330 | sil_disp_compile.h = @ |
| 331 | sil_disp_strip = @ |
| 332 | sil_disp_link = @ |
| 333 | sil_disp_link.h = @ |
| 334 | sil_disp_ar = @ |
| 335 | sil_disp_gen = @ |
| 336 | sil_disp_doc = @ |
| 337 | sil_disp_bin = @ |
| 338 | ver_disp_compile.c = |
| 339 | ver_disp_compile.h = |
| 340 | ver_disp_strip = |
| 341 | ver_disp_link = |
| 342 | ver_disp_link.h = |
| 343 | ver_disp_ar = |
| 344 | ver_disp_gen = |
| 345 | ver_disp_doc = |
| 346 | ver_disp_bin = |
Mike Frysinger | b38673f | 2006-02-02 01:41:53 +0000 | [diff] [blame] | 347 | disp_compile.c = $($(DISP)_disp_compile.c) |
| 348 | disp_compile.h = $($(DISP)_disp_compile.h) |
| 349 | disp_strip = $($(DISP)_disp_strip) |
| 350 | disp_link = $($(DISP)_disp_link) |
Bernhard Reutner-Fischer | 5d26126 | 2006-03-01 22:54:48 +0000 | [diff] [blame] | 351 | disp_link.h = $($(DISP)_disp_link.h) |
Mike Frysinger | b38673f | 2006-02-02 01:41:53 +0000 | [diff] [blame] | 352 | disp_ar = $($(DISP)_disp_ar) |
Bernhard Reutner-Fischer | 5d26126 | 2006-03-01 22:54:48 +0000 | [diff] [blame] | 353 | disp_gen = $($(DISP)_disp_gen) |
| 354 | disp_doc = $($(DISP)_disp_doc) |
| 355 | disp_bin = $($(DISP)_disp_bin) |
| 356 | # CFLAGS-dir == $(CFLAGS-$(notdir $(@D))) |
| 357 | # CFLAGS-dir-file.o == $(CFLAGS-$(notdir $(@D))-$(notdir $(@F))) |
| 358 | # CFLAGS-dir-file.c == $(CFLAGS-$(notdir $(<D))-$(notdir $(<F))) |
| 359 | # all prerequesites == $(foreach fil,$^,$(CFLAGS-$(notdir $(patsubst %/$,%,$(dir $(fil))))-$(notdir $(fil)))) |
| 360 | cmd_compile.c = $(CC) $(CFLAGS) $(EXTRA_CFLAGS) -I$(srcdir) -c -o $@ $< \ |
| 361 | $(foreach f,$^,$(CFLAGS-$(notdir $(patsubst %/$,%,$(dir $(f))))-$(notdir $(f)))) \ |
| 362 | $(CFLAGS-$(notdir $(@D))-$(notdir $(@F))) \ |
| 363 | $(CFLAGS-$(notdir $(@D))) |
| 364 | cmd_compile.m = $(cmd_compile.c) -DL_$(patsubst %$(suffix $(notdir $@)),%,$(notdir $@)) |
Mike Frysinger | b38673f | 2006-02-02 01:41:53 +0000 | [diff] [blame] | 365 | cmd_compile.h = $(HOSTCC) $(HOSTCFLAGS) -c -o $@ $< |
| 366 | cmd_strip = $(STRIPCMD) $@ |
Bernhard Reutner-Fischer | 5d26126 | 2006-03-01 22:54:48 +0000 | [diff] [blame] | 367 | cmd_link = $(CC) $(CFLAGS) $(EXTRA_CFLAGS) -I$(srcdir) $(LDFLAGS) |
| 368 | cmd_link.h = $(HOSTCC) $(HOSTCFLAGS) $(HOST_LDFLAGS) $^ -o $@ |
Mike Frysinger | b38673f | 2006-02-02 01:41:53 +0000 | [diff] [blame] | 369 | cmd_ar = $(AR) $(ARFLAGS) $@ $^ |
Bernhard Reutner-Fischer | 5d26126 | 2006-03-01 22:54:48 +0000 | [diff] [blame] | 370 | compile.c = $(disp_compile.c) $(cmd_compile.c) |
| 371 | compile.m = $(disp_compile.c) $(cmd_compile.m) |
| 372 | compile.h = $(disp_compile.h) $(cmd_compile.h) |
| 373 | do_strip = $(disp_strip) $(cmd_strip) |
| 374 | do_link = $(disp_link) $(cmd_link) |
| 375 | do_link.h = $(disp_link.h) $(cmd_link.h) |
| 376 | do_ar = $(disp_ar) $(cmd_ar) |
| 377 | |
| 378 | ifdef rules-mak-rules |
| 379 | .SUFFIXES: .c .S .o .os .om .osm .oS .so .a .s .i .E |
| 380 | |
| 381 | # generic rules |
| 382 | %.o: %.c ; $(compile.c) |
| 383 | %.os: %.c ; $(compile.c) $(CFLAGS_PIC) |
| 384 | %.o: ; $(compile.c) |
| 385 | %.os: ; $(compile.c) $(CFLAGS_PIC) |
| 386 | %.om: ; $(compile.m) |
| 387 | %.osm: ; $(compile.m) $(CFLAGS_PIC) |
| 388 | |
| 389 | endif # rules-mak-rules |
Mike Frysinger | b38673f | 2006-02-02 01:41:53 +0000 | [diff] [blame] | 390 | |
Eric Andersen | 85208e2 | 2002-04-12 12:05:57 +0000 | [diff] [blame] | 391 | .PHONY: dummy |
Bernhard Reutner-Fischer | 5d26126 | 2006-03-01 22:54:48 +0000 | [diff] [blame] | 392 | |