Home | History | Annotate | Download | only in src
      1 #
      2 #  Top level Makerules
      3 #  it uses Makerules.env for build env vars and optional branding.inc
      4 #
      5 # Copyright (C) 1999-2010, Broadcom Corporation
      6 # 
      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:
     12 # 
     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.
     20 # 
     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.
     24 #
     25 # $Id: Makerules,v 2.69.30.3.2.6 2009/05/15 23:06:59 Exp $
     26 
     27 # first rule (default)
     28 all:
     29 
     30 # SRCBASE should be set by the Makefile that includes this.
     31 ifndef	SRCBASE
     32 	SRCBASE = .
     33 endif
     34 
     35 # Set up the build environment variables
     36 include ${SRCBASE}/Makerules.env
     37 
     38 # Define space to be a single space character. Using " " gets the quotes
     39 # as well, which we don't want.
     40 empty :=
     41 space := $(empty) $(empty)
     42 
     43 ifeq ($(HOSTOS), Windows_NT)
     44 
     45 # force use of bash, otherwise you will get the broken sh.exe.
     46 SHELL=bash
     47 
     48 endif
     49 
     50 #
     51 # Setup make variables depending on target
     52 #
     53 
     54 ifeq ($(TARGETOS), unix)
     55 
     56 	# The environment for native unix builds
     57 
     58 	EXEEXT	= 
     59 	OBJEXT	= .o
     60 	GCINCS	= -I$(SRCBASE)/include
     61 	GCDEFS	= -DTARGETENV_$(TARGETENV) -DTARGETOS_$(TARGETOS) -DTARGETARCH_$(TARGETARCH)
     62 
     63 	ifeq ($(TARGETARCH), x86_mmx)
     64 		GCDEFS	:= $(GCDEFS) -D_X86_ -D_MMX_
     65 	endif
     66 	ifeq ($(TARGETARCH), x86)
     67 		GCDEFS	:= $(GCDEFS) -D_X86_
     68 	endif
     69 	ifeq ($(TARGETARCH), mips)
     70 		GCDEFS	:= $(GCDEFS) -D_MIPS_
     71 	endif
     72 	ifeq ($(TARGETARCH), mips_be)
     73 		GCDEFS	:= $(GCDEFS) -D_MIPS_ -DIL_BIGENDIAN
     74 	endif
     75 	ifeq ($(TARGETARCH), arm)
     76 		GCDEFS	:= $(GCDEFS) -D_ARM_ -DIL_BIGENDIAN
     77 	endif
     78 	ifeq ($(TARGETARCH), arm_le)
     79 		GCDEFS	:= $(GCDEFS) -D_ARM_
     80 	endif
     81 	ifeq ($(TARGETARCH), arm_android)
     82 		GCDEFS	:= $(GCDEFS) -D_ARM_
     83 	endif
     84 
     85 	ifeq ($(TARGETENV), freebsd)
     86 		GCINCS	:= $(GCINCS) -I/usr/local/include
     87 	endif
     88 	ifeq ($(TARGETENV), sun4)
     89 		GCDEFS	:= $(GCDEFS) -D_SPARC_
     90 	endif
     91 	ifeq ($(TARGETENV), macos)
     92 		MACOS_VER := $(shell sw_vers -productVersion)
     93 
     94 		ifneq (,$(findstring 10.5,$(MACOS_VER)))
     95 			SDK=/Developer/SDKs/MacOSX10.5.sdk
     96 		else
     97 			SDK=/Developer/SDKs/MacOSX10.4u.sdk
     98 		endif
     99 
    100 		GCDEFS	:= $(GCDEFS) -DMACOSX
    101 		GCDEFS	:= $(GCDEFS) -pipe -fpascal-strings -fasm-blocks -fmessage-length=0
    102 		GCDEFS	:= $(GCDEFS) -fvisibility=hidden -isysroot $(SDK)
    103 
    104 		ifeq ($(TARGETARCH), PPC)
    105 			GCDEFS	:= $(GCDEFS) -arch ppc -mtune=G4
    106 			GLDFLAGS = -arch ppc -Wl,-syslibroot,$(SDK)
    107 		endif
    108 		ifeq ($(TARGETARCH), x86)
    109 			GCDEFS	:= $(GCDEFS) -arch i386
    110 			GLDFLAGS = -arch i386 -Wl,-syslibroot,$(SDK)
    111 		endif
    112 	endif
    113 
    114 	GCOPTS	=
    115 	GCFLAGS	= -g -Wall
    116 
    117 	CC_TARGET	=-o $@
    118 	LINK_TARGET	=-o $@
    119 
    120 	ifeq ($(TARGETENV), linuxmips)
    121 		TARGET_PREFIX = mipsel-linux-
    122 	else
    123 	ifeq ($(TARGETENV), linuxmips_be)
    124 		TARGET_PREFIX = mips-linux-
    125 	else
    126 	ifeq ($(TARGETENV), linuxarm)
    127 		TARGET_PREFIX = armeb-linux-
    128 	else
    129 	ifeq ($(TARGETENV), linuxarm_le)
    130 		TARGET_PREFIX = arm-linux-
    131 	else
    132 	ifeq ($(TARGETENV), android)
    133 		TARGET_PREFIX = arm-eabi-
    134         	GCFLAGS += -Dlinux
    135         	GCFLAGS += -I/projects/hnd/tools/linux/hndtools-arm-eabi-4.2.1/arm-eabi/include/bionic/libc/include
    136         	GCFLAGS += -I/projects/hnd/tools/linux/hndtools-arm-eabi-4.2.1/arm-eabi/include/bionic/libc/arch-arm/include/
    137         	GCFLAGS += -I/tools/linux/src/linux-2.6.25-01843-gfea26b0/include/
    138 	else
    139 	ifeq ($(TARGETENV), linuxarm_omap)
    140 		TARGET_PREFIX = arm-none-linux-gnueabi-
    141 	else
    142 		TARGET_PREFIX =
    143 	endif
    144 	endif
    145 	endif
    146 	endif
    147 	endif
    148 	endif
    149 
    150 	CC = $(TARGET_PREFIX)gcc
    151 	AS = $(TARGET_PREFIX)as
    152 	LD = $(TARGET_PREFIX)ld
    153 	AR = $(TARGET_PREFIX)ar
    154 
    155 	INSTALL = install -c
    156 
    157 	TCFLAGS =
    158 
    159 	ifeq ($(TARGETENV), freebsd)
    160 		GLDFLAGS = -static
    161 	endif
    162 	ifeq ($(TARGETENV), linuxarm)
    163 		GLDFLAGS = -static
    164 	endif
    165 	ifeq ($(TARGETENV), linuxarm_le)
    166 		GLDFLAGS = -static
    167 	endif
    168 	ifeq ($(TARGETENV), android)
    169 		GLDFLAGS = -static
    170 	endif
    171 	ifeq ($(TARGETENV), linuxarm_omap)
    172 		GLDFLAGS = -static
    173 	endif
    174 
    175 	GLDLIBS = -lgcc
    176 
    177 endif	# $(TARGETOS) == unix
    178 
    179 ifeq ($(TARGETOS), Windows_NT)
    180 
    181 	# The environment for windows builds
    182 
    183 	EXEEXT = .exe
    184 
    185 	ifeq ($(TARGETENV), win32)
    186 		# standard win32 using MS compiler
    187 		OBJEXT	= .obj
    188 		GCINCS	= /I$(SRCBASE)/include
    189 		GCDEFS	= /DTARGETENV_$(TARGETENV) /DTARGETOS_$(TARGETOS) \
    190 			/DTARGETARCH_$(TARGETARCH) /D_X86_
    191 		ifeq ($(TARGETARCH), x86_mmx)
    192 			GCDEFS += /D_MMX_
    193 		endif
    194 		GCOPTS	= /nologo
    195 		GCFLAGS	= /GM /W3 /Z7
    196 
    197 		CC_TARGET	=-Fo$@
    198 		LINK_TARGET	=-out:$@
    199 
    200 		CC = cl
    201 		AS = cl
    202 		LD = cl
    203 
    204 		TCFLAGS =
    205 		GLDFLAGS = /nologo /link /nologo /INCREMENTAL:NO
    206 
    207 		GLDLIBS =
    208 	else
    209 		# cygwin32 based environment
    210 		OBJEXT	= .o
    211 		GCINCS	= -I$(SRCBASE)/include
    212 		GCDEFS	= -DTARGETENV_$(TARGETENV) -DTARGETOS_$(TARGETOS) \
    213 			-DTARGETARCH_$(TARGETARCH) -D_X86_
    214 		ifeq ($(TARGETARCH), x86_mmx)
    215 			GCDEFS += -D_MMX_
    216 		endif
    217 		GCOPTS	=
    218 		GCFLAGS	= -g -Wall
    219 
    220 		CC_TARGET	=-o $@
    221 		LINK_TARGET	=-o $@
    222 
    223 		CC = gcc
    224 		AS = gcc
    225 		LD = gcc
    226 		INSTALL = install -c
    227 
    228 		TCFLAGS =
    229 		GLDFLAGS =
    230 
    231 		GLDLIBS = -liberty -lgcc
    232 	endif
    233 
    234 	# Tools common to cygwin/win32
    235 
    236 	INSTALL = install -c
    237 	BUILD = build -ceZ
    238 
    239 	# RELEASE_TARGET is a the directory under RELEASE_DIR where
    240 	# target dependant files go. It is composed of the OS and
    241 	# the CPU, some examples are: winnt40/i386, win98 ...
    242 	#
    243 	# NEEDSWORK: For now only NT 4.0 stuff uses it.
    244 	ifneq ($(findstring $(TARGETPLATFORM), "Wdm wdm"), )
    245 		RELEASE_TARGET = wdm/i386
    246 	else
    247 		RELEASE_TARGET = winnt40/i386
    248 	endif
    249 
    250 	# RELEASE_TOOLS_DIR is a the directory under RELEASE_DIR where
    251 	# common tools go.
    252 	# For compatability with previous installs &test scripts, old
    253 	# tools still go in "yosemite".
    254 	RELEASE_YOS_DIR = yosemite
    255 	RELEASE_TOOLS_DIR = tools
    256 
    257 endif	# $(TARGETOS) == Windows_NT
    258 
    259 ifeq ($(TARGETOS), vxWorks)
    260 	WIND_REGISTRY = sol
    261 	ifndef WIND_BASE
    262 		ifeq ($(HOSTOS), unix)
    263 			WIND_BASE = /dfs/tools/vxWorks
    264 		else
    265 			WIND_BASE = z:/tools/vxWorks
    266 		endif
    267 	endif
    268 	include $(WIND_BASE)/target/h/make/defs.default
    269 
    270 	ifeq ($(HOSTENV), Windows_NT)
    271 		WIND_HOST_TYPE = x86-win32
    272 	else
    273 		ifeq ($(HOSTENV), sun4)
    274 			WIND_HOST_TYPE = sun4-solaris2
    275 		else
    276 			WIND_HOST_TYPE = i386-freebsd
    277 		endif
    278 	endif
    279 
    280 	ifeq ($(TARGETENV), vxsim)
    281 		CPU = SIMSPARCSOLARIS
    282 	else
    283 		ifeq ($(TARGETENV), vx386)
    284 			CPU = i386
    285 		else
    286 			CPU = R4650
    287 			VXFLAGS  = -DCPU_VAR=$(CPU)
    288 		endif
    289 	endif
    290 
    291 	include $(WIND_BASE)/target/h/make/make.$(CPU)$(TOOL)
    292 	include $(WIND_BASE)/target/h/make/defs.$(WIND_HOST_TYPE)
    293 
    294 	GCINCS	= -I$(WIND_BASE)/target/h -I$(SRCBASE)/include
    295 	GCDEFS	= $(DEFINE_CC) -DCPU=$(CPU) -DTARGETENV_$(TARGETENV) -DTARGETOS_$(TARGETOS) -DTARGETARCH_$(TARGETARCH)
    296 	GCOPTS	= -g -O2
    297 	GCFLAGS	= -Wall $(CC_ARCH_SPEC)
    298 	LDFLAGS	= $(GLDFLAGS) $(LLDFLAGS)
    299 	GLDLIBS	= $(LIBS)
    300 
    301 	WIND_BIN = $(WIND_BASE)/host/$(WIND_HOST_TYPE)/bin
    302 
    303 	AR	:= $(WIND_BIN)/$(AR)
    304 	AS	:= $(WIND_BIN)/$(AS)
    305 	BINHEX	:= $(WIND_BIN)/$(BINHEX)
    306 	CC	:= $(WIND_BIN)/$(CC)
    307 	CF	:= $(WIND_BIN)/$(CF)
    308 	LD	:= $(CC)
    309 	NM	:= $(WIND_BIN)/$(NM)
    310 	RANLIB	:= $(WIND_BIN)/$(RANLIB)
    311 	BINXSYM_NAME := $(WIND_BIN)/$(BINXSYM)
    312 
    313 endif	# $(TARGETOS) == vxWorks
    314 
    315 ifeq ($(TARGETENV), nucleusarm)
    316 
    317 	# The environment for nucleus builds
    318 	ifeq ($(BSP_BASE_DIR),)
    319 		BSP_BASE_DIR := $(SRCBASE)/../bsp
    320 	endif
    321    
    322 	ifeq ($(NUCLEUS_INC_DIR),)
    323 		NUCLEUS_INC_DIR := $(BSP_BASE_DIR)/rtos/nucleus/inc
    324 	endif
    325 
    326 	EXEEXT	:= 
    327 	OBJEXT	:= .o
    328 	GCINCS	:= -I$(SRCBASE)/include -I$(NUCLEUS_INC_DIR)
    329 	GCDEFS	:= -DTARGETENV_$(TARGETENV) -DTARGETOS_$(TARGETOS) -DTARGETARCH_$(TARGETARCH)
    330 	GCOPTS	:=
    331    
    332 	ifeq ($(OBJDIR),)
    333 		OBJDIR	:= $(TARGETENV)/
    334 	endif
    335    
    336 	# --md:  This option compiles the source and writes make file dependency lines 
    337 	#        to a file. The output file is suitable for use by a make utility.
    338 	# -c:    Compiles but does not perform the link phase.
    339 	# -O2:   High optimization.
    340 	# ---memaccess -UL41: This option tells the compiler that the memory in the 
    341 	#        target system has slightly restricted or expanded capabilities.
    342 	#        Disables unaligned mode for code that uses pre-ARMv6 unaligned 
    343 	#        access behavior.
    344 	# "/adsabi" is added to "--apcs /interwork/$(SWST)" so that objects created
    345 	#	under ADS 1.2 can be linked with objects compiled under RVCT 2.2.
    346 	# --diag_suppress 2084,1658 = blocks the diagnostic warning "Warning: C2084W: support for --apcs /adsabi is deprecated"
    347 	#                 1293: Suppress "Assignment in condition" warning.
    348 	GCFLAGS	:= --md \
    349 			-c \
    350 			-O2 \
    351 			--memaccess -UL41 \
    352 			--apcs /adsabi/interwork/NOSWST \
    353 			--diag_suppress 2084,1658,1293 \
    354 			--li
    355 
    356 	# --cpu 'name': This option generates code for a specific ARM processor or architecture.
    357 	ifeq ($(TARGETCPU),2153)
    358 		GCFLAGS += --cpu ARM1136J-S
    359 	else
    360       $(error "Unknown target CPU type!")
    361 	endif
    362 
    363 	#CPPFLAGS	:= -embeddedcplusplus
    364 
    365 	CC_TARGET	=-o $@
    366 	CPP_TARGET	=-o $@
    367 	LINK_TARGET	=-o $@
    368 
    369 	CC := tcc
    370 	CPP := tcpp
    371 	AS := armasm
    372 	LD := armlink
    373 	AR := armar -c -r --create
    374 
    375 	INSTALL := install -c
    376 
    377 	TCFLAGS :=
    378 
    379 	GLDFLAGS := 
    380 	GLDLIBS := --ELF --symbols --debug --map --info sizes,totals --errors link.err --list link.map --verbose
    381 
    382 	# Convert windows style directories to cygwin style.
    383 	# It should be used in situations where the host environment is cygwin, and
    384 	# the host compiler is a native Win32 app (non-cygwin). It will convert the 
    385 	# Windows style directories in the dependencies list to cygwin style. This is
    386 	# necessary for the dependency files to be included by cygwin make.
    387 	ifeq ($(HOSTOS),Windows_NT)
    388 		FILTER_DEPENDS_IN_C_TO_OBJ_RULE := 1
    389 	endif
    390 
    391 endif	# $(TARGETENV) == nucleusarm
    392 
    393 ifeq	($(TARGETENV), bcmmips)
    394 
    395 	OBJEXT	= .o
    396 	GCINCS	= -I$(SRCBASE)/include
    397 	GCDEFS	= -DTARGETENV_$(TARGETENV) -DTARGETOS_$(TARGETOS) \
    398 		-DTARGETARCH_$(TARGETARCH) -D__mips__
    399 	GCOPTS	= -g -O2
    400 	GCFLAGS	= -Wall 
    401 	GLDFLAGS = -Wl,-tidt.dld
    402 
    403 	AS		= bcmas
    404 	CC		= bcmgcc
    405 	LD		= $(CC)
    406 	NM		= bcmnm
    407 	RANLIB		= bcmranlib
    408 
    409 endif	# $(TARGETENV) == bcmmips
    410 
    411 ifeq	($(TARGETENV), klsi)
    412 
    413 	OBJEXT	= .obj
    414 	GCINCS	= -I$(SRCBASE)/include
    415 	GCDEFS	= -DTARGETENV_$(TARGETENV) -DTARGETOS_$(TARGETOS) \
    416 		-DTARGETARCH_$(TARGETARCH) -D__klsi__
    417 
    418 	AS		= qtasm
    419 	GASFLAGS	= -m20
    420 	CC		= qtcc
    421 	TCFLAGS		= -w asm=$(GASFLAGS) +c -Vcdv -w cc=+reginfo
    422 
    423 endif	# $(TARGETENV) == klsi
    424 
    425 CFLAGS = $(LCINCS) $(GCINCS) $(GCDEFS) $(GCOPTS) $(GCFLAGS) $(TCFLAGS) $(HCFLAGS) \
    426 $(LCDEFS) $(LCOPTS) $(LCFLAGS) $(CENV)
    427 
    428 ASFLAGS	= $(GASFLAGS) $(LASFLAGS) $(ASENV)
    429 LDFLAGS	= $(GLDFLAGS) $(LLDFLAGS) $(LDENV)
    430 LDLIBS	= $(LLDLIBS) $(GLDLIBS)
    431 
    432 # dependency files including the .d file itself.
    433 # note the example in GNU documentation seems to have a bug:
    434 # two backslashes where one is correct.
    435 %.d: %.c
    436 ifeq ($(findstring s, $(MAKEFLAGS) ),)
    437 	@ echo making $@
    438 endif
    439 	@ $(SHELL) -ec '$(CC) -MM $(CFLAGS) $(CPPFLAGS) $< \
    440 	| sed '\''s/$*\.o[ :]*/$@ &/g'\'' >$@'
    441 
    442 ifeq ($(TARGETENV), win32)
    443 
    444 # win32 needs different command line args 
    445 
    446 %.s: %.c
    447 	$(CC) /FAs $(CFLAGS) $(CPPFLAGS) /Fa$@ /c $<
    448 
    449 %.i: %.c
    450 	$(CC) /E $(CFLAGS) $(CPPFLAGS) $< > $@
    451 
    452 else # !win32
    453 
    454 %.s: %.c
    455 	$(CC) -S $(CFLAGS) $(CPPFLAGS) -o $@ $<
    456 
    457 %.i: %.c
    458 	$(CC) -o $@ -E -dD $(CFLAGS) $(CPPFLAGS) $<
    459 
    460 endif # win32
    461 
    462 ifeq	($(TARGETENV), klsi)
    463 
    464 %$(OBJEXT): %.c
    465 	$(CC) $(CFLAGS) $*.c
    466 
    467 %$(OBJEXT): %.asm
    468 	$(AS) $(ASFLAGS) $*.asm
    469 
    470 %.asm: %.c
    471 	$(CC) $(CFLAGS) -asm $*.c
    472 
    473 %.i: %.c
    474 	$(CC) $(CFLAGS) -cc -peep -asm $*.c
    475 	mv $*.pp $*.i
    476 
    477 else
    478 
    479 
    480 # This command sequence will:
    481 #  - Convert back-slashes to foward-slashes
    482 #  - Convert long filenames to 8.3 format (e.g. Program Files --> PROGRA~1)
    483 #  - Convert windows-style drive letters to cygwin style.
    484 #
    485 # It should be used in situations where the host environment is cygwin, and
    486 # the host compiler is a native Win32 app (non-cygwin). It will convert the 
    487 # Windows style directories in the dependencies list to cygwin style. This is
    488 # necessary for the dependency files to be included by cygwin make.
    489 define FILTER_DEPENDS
    490 	sed -e 's/\\/\//g'		\
    491 		-e 's/Program Files/PROGRA~1/g'	\
    492 		-e 's/\([A-Za-z]\):\//\/cygdrive\/\1\//' < $(notdir $(@:.o=.d)) > $(@:.o=.d) && \
    493 	rm -f $(notdir $(@:.o=.d))
    494 endef
    495 
    496 
    497 $(OBJDIR)%$(OBJEXT): %.c
    498 	$(CC) -c $(CFLAGS) $(CPPFLAGS) $(CC_TARGET) $<
    499 ifeq ($(FILTER_DEPENDS_IN_C_TO_OBJ_RULE),1)
    500 	${FILTER_DEPENDS}
    501 endif   
    502 
    503 $(OBJDIR)%$(OBJEXT): %.cpp
    504 	$(CPP) -c $(CFLAGS) $(CPPFLAGS) $(CPP_TARGET) $<
    505 ifeq ($(FILTER_DEPENDS_IN_C_TO_OBJ_RULE),1)
    506 	${FILTER_DEPENDS}
    507 endif   
    508 
    509 
    510 endif # klsi
    511 
    512 %.h: %.x
    513 	rpcgen -C -h $< > $@
    514 
    515 %_xdr.c: %.x
    516 	@ (if [ ! -f `basename $<` ] ; then ln -s $< . ; fi; true)
    517 	rpcgen -C -c -i 0 `basename $<` > $@
    518 
    519 # Makefile debugging rule
    520 env:
    521 	printenv
    522 
    523 # if the user mistakenly specified RELEASE_DIR in unix-style notation,
    524 # convert it to Win32 notation for them.
    525 #
    526 # RELEASE_DIR is assumed to be in windows-style notation if it has both 
    527 # backslashes ('\') and colons (':').
    528 #
    529 
    530 ifneq  ("$(subst \,,$(RELEASE_DIR))", "$(RELEASE_DIR)")
    531 ifneq  ("$(subst :,,$(RELEASE_DIR))", "$(RELEASE_DIR)")
    532 RELEASE_DIR := $(subst :,,$(RELEASE_DIR))
    533 RELEASE_DIR := $(subst \,/,$(RELEASE_DIR))
    534 RELEASE_DIR := //$(RELEASE_DIR)
    535 endif
    536 endif
    537 
    538 # all release rules depend on a valid RELEASE_DIR
    539 release: check_release_dir
    540 check_release_dir:
    541 	@if [ "x$(RELEASE_DIR)" = "x" ]; then \
    542 		echo "RELEASE_DIR is not set!"; \
    543 		exit 1; \
    544 	fi;
    545 
    546 include ${SRCBASE}/branding.inc
    547