# Makefile - top level makefile for target/src to build runtime libraries
#
# Copyright (c) 1996-2012 Wind River Systems, Inc.
#
# The right to copy, distribute, modify or otherwise make use
# of this software may be licensed only pursuant to the terms
# of an applicable Wind River license agreement.
#
# modification history
# --------------------
# 04o,07dec12,jpb  Updated Makefile to build mils dir if its VSB is
#                  configured.
# 04n,29aug12,pfl  renamed milsvdk to mils
# 04m,13dec11,kab  Cleanup for MILS release
# 04l,16jun11,kab  Added MILS
# 04k,17dec10,pch  CQ:WIND00244631: build ostool/shell/shellFuncBind
#		   for small footprint
# 04j,23sep10,d_c  Integrate src/vendor with target VSB
# 04i,01sep10,swg  VxMP should not be built for LP64,
#		   current VxMP doesn't support LP64
# 04h,19jul10,mze  moving VENDOR_DEFAULT logic
# 04g,17feb10,pch  small footprint
# 04f,11jun10,mze  include defs.library before the make. fragments
# 04e,10mar10,gvm  temporarily working around problem building tests with icc
# 04d,05mar10,flu  Modified the code for diab compilation (CQ:WIND00146073)
# 04c,12aug09,mze  change build of tags dir to always build first
# 04b,20jul09,pee  adding tags directory
# 05a,20oct08,to   add wrhv to COMMON_SUBDIRS
# 04z,04jun09,pee  add interface directory support for DUAL_BUILD=false
# 04y,26may09,pee  interface directory should only build for main compiler and
#		   not for both.
# 04x,19mar09,pee  adding interface subdirctory
# 04w,24jul08,dtr  Remove wrload from the build.
# 04v,04jul08,c_c  merge from VXWORKS_ITER14_2008070401 label.
# 04u,30jun08,ebh  Add MIPC to list of directories
# 04t,16may08,tpw  Add 'analysis' subdir for /vobs/rtca target side content
# 04s,05may08,ebh  Add in wrload for building (ignored if code is not installed)
# 04r,21apr08,kkz  Fixing VENDOR_DEFAULT for gnu
# 04q,15apr08,mcm  Set GNU as default for all IA32.
# 04p,26feb08,scm  Set GNU as default for Pentium.
# 04o,14oct07,mdk  fix merge problem
# 04n,11oct07,kk   move back demo to DUAL_SUBDIRS
# 04m,09oct07,mmi  fix WIND00107245 move demo to COMMON_SUBDIR, remove
#		   duplicate boot 
# 04l,20jul07,kch  Remove pfw from COMMON_SUBDIRS.
# 04k,23jun07,tkf  Add wrn to COMMON_BASIC_SUBDIRS.
# 04j,19jun07,vik  included rule for vxbUsrCmdLine.c build
# 04i,28jun07,tat  removing cci-light
# 04h,03may07,pch  automate -basic build step
# 04g,18apr07,ebh  Add dshm builds
# 04f,12apr07,pes  Re-enable MIPS dual builds.
# 04e,22mar07,pes  Temporarily disable dual (gnu) build mechanism for MIPS.
# 04d,17mar07,kkz  Correcting merge error
# 04c,05mar07,jrp  Remove usb2 subdirectory
# 04b,12jan07,tcr  remove wv build
# 04a,11dec06,mmi  re-enable tipc
# 03z,17nov06,bha  Reabase to VXWORKS_2006_FALL_FRZ20
# 03y,23sep06,tat  adding cci-light
# 03x,05sep06,lei  temporarily disable tipc for SMP build.
# 03w,26aug06,tkf  Remove PPP from COMMON_SUBDIRS.
# 03v,04aug06,jmt  Add boot directory
# 03u,12jul06,???  add ipnet to COMMON_SUBDIRS
# 03t,30mar06,pes  Add 'boot' to COMMON_SUBDIRS.
# 03s,31jan06,mdk  add ssi to COMMON_SUBDIRS
# 03r,11jan06,yvp  LOCAL_RCLEAN now cleans out all scgen derived files.
# 03q,07nov05,mdo  Add hwif
# 03p,25aug05,ebh  Eliminate reference to vxFusion
# 03o,22jun05,pee  Filter SUBDIRS to only include installed dirs (SPR #109230)
# 03n,03jun05,dbt  Removed wdb & hwdb directories.
# 03m,27may05,jmp  added debug directory. 
# 03l,29mar05,mem  Unstitch unused MSP components, cleanup.
# 03k,21feb05,ebh  update manually (zippy merge was not running)
# 03j,15feb05,als  Added support for TIPC
# 03i,18jan04,jmp  added vxsim to DOCSUBDIRS (SPR #105749).
# 03h,01sep04,jmp  modified to only add vxsim to COMMON_SUBDIRS for simulator
#		   arches (SPR #101208).
# 03g,03aug04,edc  Reverting changes for the test directory (SPR #98483).
# 03f,22jun04,jyo  Fixing SPR #98483.
# 03e,09jun04,jyo  SPR #98078: Removing the build of security
# 03d,28may04,p_r  add dsi to directory list
# 03c,14may04,yvp  Defined LOCAL_RCLEAN to cleanup SCGEN_DERIVED_FILES
# 03b,07may04,h_k  fixed the comments for PPC and SH default compiler.
# 03a,05mar04,dat  adding offset dir
# 02z,22jan04,dbt  Added support for GNU compiler on Solaris VxSim.
# 02y,12jan04,bjl  added DOCSUBDIRS.
# 02x,10dec03,h_k  Change default SH compiler to diab.
# 02w,05dec03,dbt  Added DIAB support for Linux & Windows VxSim.
# 02v,03dec03,rp   added ppp and pfw
# 02u,13nov03,c_c  Removed CPU variant definitions.
#		   Removed WTX from build.
# 02t,18nov03,zmm  Change default Pentium compiler to diab.
# 02r,21oct03,jb   Enabling build of cache aim
# 02q,27sep03,rp   removing netwrs netinet bpf rip dhcp
# 02p,19aug03,pch  Change PPC VENDOR_DEFAULT to diab
# 02o,24jul03,jeg  added vxsim directory
# 02n,09jul03,tam  removed vxvmi directory
# 02m,19jun03,dbt  Build Solaris VxSim with DIAB compiler.
# 02l,07may03,pch  Add CPU_VARIANT definition for PPC
# 02k,16apr03,pch  Add hwdb subdirectory for PPC32
# 02j,27jan03,zmm  Add tx79xx processor family.
# 02i,17jan03,agf  add support for malta5kf
# 02h,14nov02,jmt  Add RM9000 processor family
# 02g,26jun02,pes  Remove MIPS32 builds from bcm125x
#		   CPU_VARIANT_CPU_TOOL_LIST_bcm125x.
# 02f,08may02,pes  Change MIPS r3xxx CPU_VARIANT designation to rc3000
# 02e,23apr02,pes  Add support for rc4xxx, rc5xxx, rm52xx, rm57xx, tx49xx and
#		   vr50xx processor families.
# 02d,14mar02,t_m  move the rule for man after the include so the default rule
#		   is still Default
# 02c,07mar02,pch  Add arch/Makefile dependency for "man" target to fix cpuGen
#		   fallout - SPR 73999
# 02b,27feb02,pes  Adjust per-cpu-family Library archive selections
# 02a,11jan02,pes  Insert macro definitions for MIPS repackaged libarch.a
#		   libraries
# 01z,12dec01,tam  made CPU variant builds automatic; updated comments
# 01y,12dec01,mem  Fix specialization test for MIPS.
# 01x,07dec01,tam  Added CPU variant support
# 01w,27nov01,jmp  Changed to expect simpc instead of SIMNT for VX_CPU_FAMILY.
# 01v,20nov01,tam  move demo to dual build
# 01u,16nov01,mil  Changed to expect ppc instead of PPC for VX_CPU_FAMILY.
# 01t,12nov01,tam  added dual build support
# 01s,07nov01,tam  added vxvmi directory
# 01r,31oct01,mas  added vxmp subdirectory
# 01q,30oct01,sn   pushed gnu under new tool directory
# 01p,29oct01,dbs  re-instate vxcom and vxdcom
# 01o,18oct01,dbs  temporarily remove vxcom and vxdcom from build
# 01n,11oct01,tpr  Removed VxWorks 5.5 unsupported directories
# 01m,04oct01,nel  Add VxDCOM to build.
# 01l,27apr01,mem  Added vxFusion, zinc, missing dirs, remove ospf, wweb merge
# 01k,07dec00,af   add cplus and gnu back to default build list.
# 01j,06nov00,sn   add target for just building C++
# 01i,09oct00,sn   but do build everything on tor2_x-fred-toolchain
# 01h,09oct00,sn   don't build C++
# 01g,11dec98,j_w  define CLEANLIBS -- for removing lib$(CPU)$(TOOL)*.a
# 01f,22may98,ms   removed SUBDIRS hack
# 01e,29apr98,dbt  removed rdb directory
# 01d,05nov97,kkk  added rip, dhcp directory
# 01c,28oct97,kkk  added ospf directory
# 01b,15nov96,jag  added snmpv1 directory
# 01a,17jun96,yp   written
#
# DESCRIPTION
# This file contains the makefile rules to select subdirectories that contain
# sources for building the VxWorks runtime archive and builds them.
#
# Some architecures support only one toolchain family (either GNU or DIAB). 
# The toolchain supported is defined by VENDOR_DEFAULT below. 
# For instance to build the source tree for the solaris simulator which supports
# only the GNU toolchain, you should issue the following commands:
#		> cd $WIND_BASE/target/src
#		> make CPU=SIMSPARCSOLARIS TOOL=gnu
#
# Other architecures support both toolchain families (GNU and DIAB).
# However most of the VxWorks source code under $(WIND_BASE)/target/src/
# is compiled with only one toolchain family (either GNU or DIAB). This
# default toolchain is defined again by VENDOR_DEFAULT. Nevertheless part of
# the VxWorks source tree must still be built with the secondary toolchain
# family. This dual build is accomplished in two passes.
#
# For instance to build the source tree for CPU=PPC604 which supports both
# GNU and DIAB, the following commands must be issued:
#		> cd $WIND_BASE/target/src
#		> make CPU=PPC604 TOOL=diab
#		> make CPU=PPC604 TOOL=gnu
#
#
#
# FOR TESTING PURPOSES
# If a dual build of the source tree should not be performed for a CPU type
# which by default supports both toolchain families, the value of DUAL_BUILD
# must be overwritten on the command line.
# For instance to build successfuly the entire source tree for CPU=PPC604 with
# the DIAB toolchain despite it is not the default toolchain for this 
# architecture, issue the following commands:
#		> cd $WIND_BASE/target/src
#		> make CPU=PPC604 TOOL=diab DUAL_BUILD=false
#
# You may need to build the entire source tree with both toolchain families
# (GNU and DIAB). Every source file must be compiled with both toolchains
# and the resulting objects stored in a different locations. As above 
# DUAL_BUILD must be set to false and in addition the COMMON_DIR variable
# must be overwritten and set to false:
#		> cd $WIND_BASE/target/src
#		> make CPU=PPC604 TOOL=diab DUAL_BUILD=false COMMON_DIR=false
#		> make CPU=PPC604 TOOL=gnu DUAL_BUILD=false COMMON_DIR=false
#
# INTERNAL
# The REAME.txt file under $(WIND_BASE)/target/src/ should be updated whenever
# this file is modified, if appropriate.
#*/

TGT_DIR=$(WIND_BASE)/target

# remove lib$(CPU)$(TOOL)*.a if make rclean is done at target/src level
CLEANLIBS = YES

# get _WRS_CONFIG_xxx settings so they can be used in setting xxx_SUBDIRS
include $(TGT_DIR)/h/make/defs.default
include $(TGT_DIR)/h/make/defs.library
-include $(VSB_MAKE_CONFIG_FILE)

# IMPORTANT:
#
# New directories under $WIND_BASE/src must be added to one of the following
# list, and only one:
#
#		SKIP_SUBDIRS:	directory(ies) not being compiled
#		COMMON_SUBDIRS:	directories compiled with the default compiler
#				only (cf value of VENDOR_DEFAULT)
#		DUAL_SUBDIRS:	directories compiled with each toolchain.
#				NOTE: any directory including C++ files must be
#				added to this list.
#		GNU_SUBDIRS:	directories compiled with GNU only
#		DIAB_SUBDIRS:	directories compiled with DIAB only

# Directories listed in COMMON_SUBDIRS should also be listed in
# COMMON_BASIC_SUBDIRS if they need to be built both with and
# without OPT=-basic

SKIP_SUBDIRS	= zlib usb2

ifdef _WRS_CONFIG_MEM_ALLOT
# Skip subdirectories whose contents would require memory management
SKIP_SUBDIRS += analysis boot debug demo fs ipnet posix rpc ssi \
		tffs tipc usb vxmp vxsim vxvmi wrn
endif
# Skip vxmp if define _WRS_CONFIG_LP64, current VxMP doesn't support LP64 
ifdef _WRS_CONFIG_LP64
SKIP_SUBDIRS += vxmp
endif

# interface directory. Must be built first
INTERFACE_SUBDIR = interface

# directories optionally installed

OPTIONAL_COMMON_SUBDIRS = security

COMMON_SUBDIRS	= arch aim drv event hwif libc \
		  math multios_ipc offset os ostool \
		  usr util wind wrhv \
		  $(wildcard $(OPTIONAL_COMMON_SUBDIRS))
ifndef _WRS_CONFIG_MEM_ALLOT
# Add these if not skipped above
COMMON_SUBDIRS += boot debug dshm dsi fs posix rpc tffs tipc usb \
		  wrn ssi ipnet
# VxMP should not be built for LP64, current VxMP doesn't support LP64
ifndef _WRS_CONFIG_LP64
COMMON_SUBDIRS += vxmp
endif
endif

ifdef _WRS_CONFIG_MILS_VBI
COMMON_SUBDIRS += mils
endif

COMMON_BASIC_SUBDIRS = ipnet wrn

DUAL_SUBDIRS	= vendor tags cplus tool test 
					# - other C++ based code to be added 
					# here
					# - other source directories not ported
					# to new archive directory hierarchy to
					# be added here too.

ifndef _WRS_CONFIG_MEM_ALLOT
# Add demo if not skipped above
DUAL_SUBDIRS += demo
endif

GNU_SUBDIRS	= 

DIAB_SUBDIRS	=

VXSIM_SUBDIRS	= vxsim


include $(TGT_DIR)/h/tool/$(TOOL_FAMILY)/make.$(CPU)$(TOOL)

## Architectures default toolchain and dual build status
#
# VENDOR_DEFAULT now defined in target/h/make/defs.default included above here.

#
# ARM: DIAB & GNU (DIAB as default)
#

ifeq ($(VX_CPU_FAMILY),arm)

# ARMV7-M: supports only DIAB

ifneq ($(CPU),ARMARCH7M)
    DUAL_BUILD		= true
else
    DUAL_BUILD		= false
endif

endif

#
# COLDFIRE: supports only DIAB
#

ifeq ($(VX_CPU_FAMILY),cf)
    DUAL_BUILD		= false
endif

#
# MC68K: supports only GNU
#

ifeq ($(VX_CPU_FAMILY),68k)
    DUAL_BUILD		= false
endif

#
# MIPS: DIAB & GNU (DIAB as default)
#

ifeq ($(VX_CPU_FAMILY),mips)
    DUAL_BUILD		= true
endif

#
# PENTIUM: DIAB & GNU (GNU as default)
#

ifeq ($(VX_CPU_FAMILY),pentium)
    DUAL_BUILD		= true
endif

#
# PPC: GNU & DIAB (DIAB as default)
#

ifeq ($(VX_CPU_FAMILY),ppc)
    DUAL_BUILD		= true
endif

#
# SH (Renesas): GNU & DIAB (DIAB as default)
#

ifeq ($(VX_CPU_FAMILY),sh)
    DUAL_BUILD		= true
endif

#
# SIMLINUX: supports GNU & DIAB (GNU as default)
#

ifeq ($(VX_CPU_FAMILY),simlinux)
    DUAL_BUILD		= true
    COMMON_SUBDIRS	+= $(VXSIM_SUBDIRS)
endif

#
# SIMNT: supports GNU & DIAB (GNU as default)
#

ifeq ($(VX_CPU_FAMILY),simpc)
    DUAL_BUILD		= true
    COMMON_SUBDIRS	+= $(VXSIM_SUBDIRS)
endif

#
# SIMSOLARIS: supports GNU & DIAB (DIAB as default)
#

ifeq ($(VX_CPU_FAMILY),simso)
    DUAL_BUILD		= true
    COMMON_SUBDIRS	+= $(VXSIM_SUBDIRS)
endif

#
# Analysis source is built with gnu for all target architectures except
# coldfire.
#

ifndef _WRS_CONFIG_MEM_ALLOT
# Add analysis if not skipped above
ifeq ($(VX_CPU_FAMILY),cf)
DIAB_SUBDIRS	+= analysis
else
DUAL_SUBDIRS	+= analysis
endif
endif

# defaults for  DUAL_BUILD

ifeq ($(DUAL_BUILD),)
    DUAL_BUILD		= false
endif



# Select the toolchain specific directories

ifeq ($(TOOL), $(TOOL_GNU))
    TOOL_DIRS	= $(GNU_SUBDIRS)
endif
ifeq ($(TOOL), $(TOOL_DIAB))
    TOOL_DIRS	= $(DIAB_SUBDIRS)
endif


## Compute list of directories to build: 
#
# Set SUBDIRS according to DUAL_BUILD and VENDOR_DEFAULT
# filter list to existing directories only

ifeq ($(DUAL_BUILD),false)
    __SUBDIRS = $(INTERFACE_SUBDIR) $(COMMON_SUBDIRS) $(DUAL_SUBDIRS) $(TOOL_DIRS)
else
    ifeq ($(DUAL_BUILD),true)	# just to make sure
	ifeq ($(TOOL_VENDOR),$(VENDOR_DEFAULT))
	    __SUBDIRS =  $(INTERFACE_SUBDIR) $(COMMON_SUBDIRS) $(DUAL_SUBDIRS) $(TOOL_DIRS)
	else
	    __SUBDIRS = $(DUAL_SUBDIRS) $(TOOL_DIRS)
	endif
    endif
endif

SUBDIRS = $(strip $(foreach dir, $(__SUBDIRS),$(wildcard $(dir))))

# overrides DOCSUBDIRS = $(SUBDIRS) in rules-lib.$(WIND_HOST_TYPE) to
# make sure all necessary doc directories are built.

DOCSUBDIRS = $(COMMON_SUBDIRS) $(DUAL_SUBDIRS) $(TOOL_DIRS) $(VXSIM_SUBDIRS)

include $(TGT_DIR)/h/make/rules.library
include $(TGT_DIR)/h/make/rules.vxbus

LOCAL_RCLEAN = $(SCGEN_DERIVED_FILES)

# If doing a doc build, ensure arch/Makefile is built.
# The rules are in $(TGT_DIR)/h/make/rules-lib.unix

man:	$(TGT_DIR)/src/arch/Makefile

clean_interface :
	cd $(INTERFACE_SUBDIR) && $(MAKE) clean_interface
