3 # it uses Makerules.env for build env vars and optional branding.inc
5 # Copyright (C) 1999-2011, Broadcom Corporation
7 # Unless you and Broadcom execute a separate written software license
8 # agreement governing use of this software, this software is licensed to you
9 # under the terms of the GNU General Public License version 2 (the "GPL"),
10 # available at http://www.broadcom.com/licenses/GPLv2.php, with the
11 # following added to such license:
13 # As a special exception, the copyright holders of this software give you
14 # permission to link this software with independent modules, and to copy and
15 # distribute the resulting executable under terms of your choice, provided that
16 # you also meet, for each linked independent module, the terms and conditions of
17 # the license of that module. An independent module is a module which is not
18 # derived from this software. The special exception does not apply to any
19 # modifications of the software.
21 # Notwithstanding the above, under no circumstances may you combine this
22 # software in any way with any other Broadcom software provided under a license
23 # other than the GPL, without Broadcom's express prior written consent.
25 # $Id: Makerules,v 2.78.42.1 2010-05-11 17:55:55 $
27 # This is the TOP level makefile rules, which is used by many makefiles.
28 # Please be cautious on changes, especially compatibilities.
29 # e.g. new gcc compile option should be protected with version check
30 # or "check_gcc" trick
32 # first rule (default)
35 # SRCBASE should be set by the Makefile that includes this.
40 # Set up the build environment variables
41 include ${SRCBASE}/Makerules.env
43 # Define space to be a single space character. Using " " gets the quotes
44 # as well, which we don't want.
46 space := $(empty) $(empty)
48 ifeq ($(HOSTOS), Windows_NT)
50 # force use of bash, otherwise you will get the broken sh.exe.
56 # Setup make variables depending on target
59 ifeq ($(TARGETOS), unix)
61 # The environment for native unix builds
65 GCINCS = -I$(SRCBASE)/include
66 GCDEFS = -DTARGETENV_$(TARGETENV) -DTARGETOS_$(TARGETOS) -DTARGETARCH_$(TARGETARCH)
68 ifeq ($(TARGETARCH), x86_mmx)
69 GCDEFS := $(GCDEFS) -D_X86_ -D_MMX_
71 ifeq ($(TARGETARCH), x86)
72 GCDEFS := $(GCDEFS) -D_X86_
74 ifeq ($(TARGETARCH), mips)
75 GCDEFS := $(GCDEFS) -D_MIPS_
77 ifeq ($(TARGETARCH), mips_be)
78 GCDEFS := $(GCDEFS) -D_MIPS_ -DIL_BIGENDIAN
80 ifeq ($(TARGETARCH), arm)
81 GCDEFS := $(GCDEFS) -D_ARM_ -DIL_BIGENDIAN
83 ifeq ($(TARGETARCH), arm_le)
84 GCDEFS := $(GCDEFS) -D_ARM_
86 ifeq ($(TARGETARCH), arm_android)
87 GCDEFS := $(GCDEFS) -D_ARM_
90 ifeq ($(TARGETENV), freebsd)
91 GCINCS := $(GCINCS) -I/usr/local/include
93 ifeq ($(TARGETENV), sun4)
94 GCDEFS := $(GCDEFS) -D_SPARC_
96 ifeq ($(TARGETENV), macos)
97 MACOS_VER := $(shell sw_vers -productVersion)
99 ifneq (,$(findstring 10.5,$(MACOS_VER)))
100 SDK=/Developer/SDKs/MacOSX10.5.sdk
102 ifneq (,$(findstring 10.6,$(MACOS_VER)))
103 SDK=/Developer/SDKs/MacOSX10.6.sdk
105 SDK=/Developer/SDKs/MacOSX10.4u.sdk
109 GCDEFS := $(GCDEFS) -DMACOSX
110 GCDEFS := $(GCDEFS) -pipe -fpascal-strings -fasm-blocks -fmessage-length=0
111 GCDEFS := $(GCDEFS) -fvisibility=hidden -isysroot $(SDK)
113 ifeq ($(TARGETARCH), PPC)
114 GCDEFS := $(GCDEFS) -arch ppc -mtune=G4
115 GLDFLAGS = -arch ppc -Wl,-syslibroot,$(SDK)
117 ifeq ($(TARGETARCH), x86)
118 GCDEFS := $(GCDEFS) -arch i386
119 GLDFLAGS = -arch i386 -Wl,-syslibroot,$(SDK)
129 ifeq ($(TARGETENV), linuxmips)
130 TARGET_PREFIX = mipsel-linux-
132 ifeq ($(TARGETENV), linuxmips_be)
133 TARGET_PREFIX = mips-linux-
135 ifeq ($(TARGETENV), linuxarm)
136 TARGET_PREFIX = armeb-linux-
138 ifeq ($(TARGETENV), linuxarm_le)
139 TARGET_PREFIX = arm-linux-
141 ifeq ($(TARGETENV), android)
142 TARGET_PREFIX = arm-eabi-
144 GCFLAGS += -I/projects/hnd/tools/linux/hndtools-arm-eabi-4.2.1/android-ndk-r3/build/platforms/android-3/arch-arm/usr/include
145 # GCFLAGS += -I/projects/hnd/tools/linux/hndtools-arm-eabi-4.2.1/arm-eabi/include/bionic/libc/include
146 # GCFLAGS += -I/projects/hnd/tools/linux/hndtools-arm-eabi-4.2.1/arm-eabi/include/bionic/libc/arch-arm/include/
147 GCFLAGS += -I/tools/linux/src/linux-2.6.25-01843-gfea26b0/include/
156 CC = $(TARGET_PREFIX)gcc
157 AS = $(TARGET_PREFIX)as
158 LD = $(TARGET_PREFIX)ld
159 AR = $(TARGET_PREFIX)ar
165 ifeq ($(TARGETENV), freebsd)
168 ifeq ($(TARGETENV), linuxarm)
171 ifeq ($(TARGETENV), linuxarm_le)
174 ifeq ($(TARGETENV), android)
180 endif # $(TARGETOS) == unix
182 ifeq ($(TARGETOS), Windows_NT)
184 # The environment for windows builds
188 ifeq ($(TARGETENV), win32)
189 # standard win32 using MS compiler
191 GCINCS = /I$(SRCBASE)/include
192 GCDEFS = /DTARGETENV_$(TARGETENV) /DTARGETOS_$(TARGETOS) \
193 /DTARGETARCH_$(TARGETARCH) /D_X86_
194 ifeq ($(TARGETARCH), x86_mmx)
198 GCFLAGS = /GM /W3 /Z7
208 GLDFLAGS = /nologo /link /nologo /INCREMENTAL:NO
212 # cygwin32 based environment
214 GCINCS = -I$(SRCBASE)/include
215 GCDEFS = -DTARGETENV_$(TARGETENV) -DTARGETOS_$(TARGETOS) \
216 -DTARGETARCH_$(TARGETARCH) -D_X86_
217 ifeq ($(TARGETARCH), x86_mmx)
234 GLDLIBS = -liberty -lgcc
237 # Tools common to cygwin/win32
242 # RELEASE_TARGET is a the directory under RELEASE_DIR where
243 # target dependant files go. It is composed of the OS and
244 # the CPU, some examples are: winnt40/i386, win98 ...
246 # NEEDSWORK: For now only NT 4.0 stuff uses it.
247 ifneq ($(findstring $(TARGETPLATFORM), "Wdm wdm"), )
248 RELEASE_TARGET = wdm/i386
250 RELEASE_TARGET = winnt40/i386
253 # RELEASE_TOOLS_DIR is a the directory under RELEASE_DIR where
255 # For compatability with previous installs &test scripts, old
256 # tools still go in "yosemite".
257 RELEASE_YOS_DIR = yosemite
258 RELEASE_TOOLS_DIR = tools
260 endif # $(TARGETOS) == Windows_NT
262 ifeq ($(TARGETOS), vxWorks)
265 ifeq ($(HOSTOS), unix)
266 WIND_BASE = /dfs/tools/vxWorks
268 WIND_BASE = z:/tools/vxWorks
271 include $(WIND_BASE)/target/h/make/defs.default
273 ifeq ($(HOSTENV), Windows_NT)
274 WIND_HOST_TYPE = x86-win32
276 ifeq ($(HOSTENV), sun4)
277 WIND_HOST_TYPE = sun4-solaris2
279 WIND_HOST_TYPE = i386-freebsd
283 ifeq ($(TARGETENV), vxsim)
284 CPU = SIMSPARCSOLARIS
286 ifeq ($(TARGETENV), vx386)
290 VXFLAGS = -DCPU_VAR=$(CPU)
294 include $(WIND_BASE)/target/h/make/make.$(CPU)$(TOOL)
295 include $(WIND_BASE)/target/h/make/defs.$(WIND_HOST_TYPE)
297 GCINCS = -I$(WIND_BASE)/target/h -I$(SRCBASE)/include
298 GCDEFS = $(DEFINE_CC) -DCPU=$(CPU) -DTARGETENV_$(TARGETENV) -DTARGETOS_$(TARGETOS) -DTARGETARCH_$(TARGETARCH)
300 GCFLAGS = -Wall $(CC_ARCH_SPEC)
301 LDFLAGS = $(GLDFLAGS) $(LLDFLAGS)
304 WIND_BIN = $(WIND_BASE)/host/$(WIND_HOST_TYPE)/bin
306 AR := $(WIND_BIN)/$(AR)
307 AS := $(WIND_BIN)/$(AS)
308 BINHEX := $(WIND_BIN)/$(BINHEX)
309 CC := $(WIND_BIN)/$(CC)
310 CF := $(WIND_BIN)/$(CF)
312 NM := $(WIND_BIN)/$(NM)
313 RANLIB := $(WIND_BIN)/$(RANLIB)
314 BINXSYM_NAME := $(WIND_BIN)/$(BINXSYM)
316 endif # $(TARGETOS) == vxWorks
318 ifeq ($(TARGETENV), nucleusarm)
320 # The environment for nucleus builds
321 ifeq ($(BSP_BASE_DIR),)
322 BSP_BASE_DIR := $(SRCBASE)/../bsp
325 ifeq ($(NUCLEUS_INC_DIR),)
326 NUCLEUS_INC_DIR := $(BSP_BASE_DIR)/rtos/nucleus/inc
331 GCINCS := -I$(SRCBASE)/include -I$(NUCLEUS_INC_DIR)
332 GCDEFS := -DTARGETENV_$(TARGETENV) -DTARGETOS_$(TARGETOS) -DTARGETARCH_$(TARGETARCH)
336 OBJDIR := $(TARGETENV)/
339 # --md: This option compiles the source and writes make file dependency lines
340 # to a file. The output file is suitable for use by a make utility.
341 # -c: Compiles but does not perform the link phase.
342 # -O2: High optimization.
343 # ---memaccess -UL41: This option tells the compiler that the memory in the
344 # target system has slightly restricted or expanded capabilities.
345 # Disables unaligned mode for code that uses pre-ARMv6 unaligned
347 # "/adsabi" is added to "--apcs /interwork/$(SWST)" so that objects created
348 # under ADS 1.2 can be linked with objects compiled under RVCT 2.2.
349 # --diag_suppress 2084,1658 = blocks the diagnostic warning "Warning: C2084W: support for --apcs /adsabi is deprecated"
350 # 1293: Suppress "Assignment in condition" warning.
355 --apcs /adsabi/interwork/NOSWST \
356 --diag_suppress 2084,1658,1293 \
359 # --cpu 'name': This option generates code for a specific ARM processor or architecture.
360 ifeq ($(TARGETCPU),2153)
361 GCFLAGS += --cpu ARM1136J-S
363 $(error "Unknown target CPU type!")
366 #CPPFLAGS := -embeddedcplusplus
376 AR := armar -c -r --create
378 INSTALL := install -c
383 GLDLIBS := --ELF --symbols --debug --map --info sizes,totals --errors link.err --list link.map --verbose
385 # Convert windows style directories to cygwin style.
386 # It should be used in situations where the host environment is cygwin, and
387 # the host compiler is a native Win32 app (non-cygwin). It will convert the
388 # Windows style directories in the dependencies list to cygwin style. This is
389 # necessary for the dependency files to be included by cygwin make.
390 ifeq ($(HOSTOS),Windows_NT)
391 FILTER_DEPENDS_IN_C_TO_OBJ_RULE := 1
394 endif # $(TARGETENV) == nucleusarm
396 ifeq ($(TARGETENV), bcmmips)
399 GCINCS = -I$(SRCBASE)/include
400 GCDEFS = -DTARGETENV_$(TARGETENV) -DTARGETOS_$(TARGETOS) \
401 -DTARGETARCH_$(TARGETARCH) -D__mips__
404 GLDFLAGS = -Wl,-tidt.dld
412 endif # $(TARGETENV) == bcmmips
414 ifeq ($(TARGETENV), klsi)
417 GCINCS = -I$(SRCBASE)/include
418 GCDEFS = -DTARGETENV_$(TARGETENV) -DTARGETOS_$(TARGETOS) \
419 -DTARGETARCH_$(TARGETARCH) -D__klsi__
424 TCFLAGS = -w asm=$(GASFLAGS) +c -Vcdv -w cc=+reginfo
426 endif # $(TARGETENV) == klsi
428 CFLAGS = $(LCINCS) $(GCINCS) $(GCDEFS) $(GCOPTS) $(GCFLAGS) $(TCFLAGS) $(HCFLAGS) \
429 $(LCDEFS) $(LCOPTS) $(LCFLAGS) $(CENV)
431 ASFLAGS = $(GASFLAGS) $(LASFLAGS) $(ASENV)
432 LDFLAGS = $(GLDFLAGS) $(LLDFLAGS) $(LDENV)
433 LDLIBS = $(LLDLIBS) $(GLDLIBS)
435 # dependency files including the .d file itself.
436 # note the example in GNU documentation seems to have a bug:
437 # two backslashes where one is correct.
439 ifeq ($(findstring s, $(MAKEFLAGS) ),)
442 @ $(SHELL) -ec '$(CC) -MM $(CFLAGS) $(CPPFLAGS) $< \
443 | sed '\''s/$*\.o[ :]*/$@ &/g'\'' >$@'
445 ifeq ($(TARGETENV), win32)
447 # win32 needs different command line args
450 $(CC) /FAs $(CFLAGS) $(CPPFLAGS) /Fa$@ /c $<
453 $(CC) /E $(CFLAGS) $(CPPFLAGS) $< > $@
458 $(CC) -S $(CFLAGS) $(CPPFLAGS) -o $@ $<
461 $(CC) -o $@ -E -dD $(CFLAGS) $(CPPFLAGS) $<
465 ifeq ($(TARGETENV), klsi)
471 $(AS) $(ASFLAGS) $*.asm
474 $(CC) $(CFLAGS) -asm $*.c
477 $(CC) $(CFLAGS) -cc -peep -asm $*.c
483 # This command sequence will:
484 # - Convert back-slashes to foward-slashes
485 # - Convert long filenames to 8.3 format (e.g. Program Files --> PROGRA~1)
486 # - Convert windows-style drive letters to cygwin style.
488 # It should be used in situations where the host environment is cygwin, and
489 # the host compiler is a native Win32 app (non-cygwin). It will convert the
490 # Windows style directories in the dependencies list to cygwin style. This is
491 # necessary for the dependency files to be included by cygwin make.
492 define FILTER_DEPENDS
494 -e 's/Program Files/PROGRA~1/g' \
495 -e 's/\([A-Za-z]\):\//\/cygdrive\/\1\//' < $(notdir $(@:.o=.d)) > $(@:.o=.d) && \
496 rm -f $(notdir $(@:.o=.d))
500 $(OBJDIR)%$(OBJEXT): %.c
501 $(CC) -c $(CFLAGS) $(CPPFLAGS) $(CC_TARGET) $<
502 ifeq ($(FILTER_DEPENDS_IN_C_TO_OBJ_RULE),1)
506 $(OBJDIR)%$(OBJEXT): %.cpp
507 $(CPP) -c $(CFLAGS) $(CPPFLAGS) $(CPP_TARGET) $<
508 ifeq ($(FILTER_DEPENDS_IN_C_TO_OBJ_RULE),1)
519 @ (if [ ! -f `basename $<` ] ; then ln -s $< . ; fi; true)
520 rpcgen -C -c -i 0 `basename $<` > $@
522 # Makefile debugging rule
526 # if the user mistakenly specified RELEASE_DIR in unix-style notation,
527 # convert it to Win32 notation for them.
529 # RELEASE_DIR is assumed to be in windows-style notation if it has both
530 # backslashes ('\') and colons (':').
533 ifneq ("$(subst \,,$(RELEASE_DIR))", "$(RELEASE_DIR)")
534 ifneq ("$(subst :,,$(RELEASE_DIR))", "$(RELEASE_DIR)")
535 RELEASE_DIR := $(subst :,,$(RELEASE_DIR))
536 RELEASE_DIR := $(subst \,/,$(RELEASE_DIR))
537 RELEASE_DIR := //$(RELEASE_DIR)
541 # all release rules depend on a valid RELEASE_DIR
542 release: check_release_dir
544 @if [ "x$(RELEASE_DIR)" = "x" ]; then \
545 echo "RELEASE_DIR is not set!"; \
549 include ${SRCBASE}/branding.inc