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