# CONFIG.Common.vxWorksCommon
#
# Definitions for vxWorks target archs
# Sites may override these definitions in CONFIG_SITE.Common.vxWorksCommon
# or CONFIG_SITE.<host>.vxWorksCommon
#-------------------------------------------------------

# Vx valid build types
VALID_BUILDS = Ioc

#--------------------------------------------------
# operating system class (include/os/<os_class>)
OS_CLASS = vxWorks

#-------------------------------------------------------
# Prefix and suffix definitions
EXE =
OBJ = .o
LIB_PREFIX = lib
LIB_SUFFIX = .a
MUNCH_SUFFIX = .munch

#-------------------------------------------------------
# Compiler definitions
CMPLR_PREFIX=
CC = $(GNU_BIN)/$(CMPLR_PREFIX)cc$(CMPLR_SUFFIX)
CCC = $(GNU_BIN)/$(CMPLR_PREFIX)cc$(CMPLR_SUFFIX)

#-------------------------------------------------------
# Library definitions
LIBNAME = $(BUILD_LIBRARY:%=$(LIB_PREFIX)%$(LIB_SUFFIX))
TESTLIBNAME = $(TESTBUILD_LIBRARY:%=$(LIB_PREFIX)%$(LIB_SUFFIX))

#--------------------------------------------------
# Prod: DEPLIBS, LDFLAGS, and LDLIBS definitions

PROD_DEPLIBS = $(foreach lib,$(PROD_LIBS) $(USR_LIBS), \
  $(firstword $(wildcard \
      $(addsuffix /$(LIB_PREFIX)$(lib)$(LIB_SUFFIX), \
        $($(lib)_DIR) $(SHRLIB_SEARCH_DIRS))) \
    $(addsuffix /$(LIB_PREFIX)$(lib)$(LIB_SUFFIX), \
    $(if $(filter $(lib),$(TESTLIBRARY)),.,$(INSTALL_LIB)))))


PROD_LDLIBS = $(addprefix -l,$($*_LDLIBS) $(PROD_LIBS) $(USR_LIBS) \
    $($*_SYS_LIBS) $(PROD_SYS_LIBS) $(USR_SYS_LIBS))

PROD_DEPLIB_DIRS = $(dir $($*_DEPLIBS)) $(dir $(PROD_DEPLIBS))
PRODDIR_LDFLAGS += $(sort $(PROD_DEPLIB_DIRS:%=-L%))

#-------------------------------------------------------
# Prod definitions
MUNCHNAME = $(PRODNAME:%$(EXE)=%$(MUNCH_SUFFIX))
CTDT_SRCS = $(PRODNAME:%$(EXE)=%_ctdt.c)
CTDT_OBJS = $(PRODNAME:%$(EXE)=%_ctdt$(OBJ))
NMS = $(PRODNAME:%$(EXE)=%.nm)
MUNCH_DEPENDS = %_ctdt$(OBJ)

#--------------------------------------------------
# vxWorks version numbers

VXWORKS_MAJOR_VERSION = $(basename $(basename $(VXWORKS_VERSION)))

# These are needed for vxWorks 6.x; the GNU toolset version number
# is in the path to the compiler tools:
VX_GNU_VERSION_5.4 = 2.95
VX_GNU_VERSION_5.5 = 2.96
VX_GNU_VERSION_6.0 = 3.3.2
VX_GNU_VERSION_6.1 = 3.3.2
VX_GNU_VERSION_6.2 = 3.3.2
VX_GNU_VERSION_6.3 = 3.4.4
VX_GNU_VERSION_6.4 = 3.4.4
VX_GNU_VERSION_6.5 = 3.4.4
VX_GNU_VERSION_6.6 = 4.1.2
VX_GNU_VERSION_6.7 = 4.1.2
VX_GNU_VERSION_6.8 = 4.1.2
VX_GNU_VERSION_6.9 = 4.3.3
VX_GNU_VERSION = $(VX_GNU_VERSION_$(VXWORKS_VERSION))

VX_GNU_MAJOR_VERSION = $(basename $(basename $(VX_GNU_VERSION)))

#--------------------------------------------------
# Fix WIND_BASE for vxWorks 6.x on linux
# NB: We know the value of WIND_HOST_TYPE here, but not VXWORKS_VERSION
ifeq ($(WIND_HOST_TYPE),x86-linux)
  WIND_HOST_TYPE_5 = x86-linux
  WIND_HOST_TYPE_6 = x86-linux2
  WIND_HOST_TYPE = $(WIND_HOST_TYPE_$(VXWORKS_MAJOR_VERSION))
endif

#--------------------------------------------------
# vxWorks directory definitions
VX_DIR_5 = $(WIND_BASE)
VX_DIR_6 = $(WIND_BASE)/vxworks-$(VXWORKS_VERSION)
VX_DIR = $(VX_DIR_$(VXWORKS_MAJOR_VERSION))

VX_INCLUDE_DIRS_5 = $(VX_DIR)/target/h
VX_INCLUDE_DIRS_6 = $(VX_DIR)/target/h $(VX_DIR)/target/h/wrn/coreip
GNU_TARGET_INCLUDE_DIR = $(VX_INCLUDE_DIRS_$(VXWORKS_MAJOR_VERSION))

#--------------------------------------------------
# vxWorks GNU directories

GNU_DIR_5 = $(WIND_BASE)/host/$(WIND_HOST_TYPE)
GNU_DIR_6 = $(WIND_BASE)/gnu/$(VX_GNU_VERSION)-vxworks-$(VXWORKS_VERSION)/$(WIND_HOST_TYPE)
GNU_DIR = $(GNU_DIR_$(VXWORKS_MAJOR_VERSION))

#--------------------------------------------------
# This finds nm on any supported VxWorks version

NMPROG = $(CMPLR_PREFIX)nm$(CMPLR_SUFFIX)$(HOSTEXE)
NM = $(firstword $(wildcard $(WIND_BASE)/*/$(WIND_HOST_TYPE)/bin/$(NMPROG)))

#--------------------------------------------------
# A linker script is essential for munching from vxWorks 6.6 onwards
# (i.e. with versions that use gcc 4.1.2 or later).  It can be used
# with any vxWorks 5 or 6 version, but apparently should not be used
# when compiling for 68K (which isn't supported in vxWorks 6 anyway)
MUNCH_LDFLAGS_6 = -T $(VX_DIR)/target/h/tool/gnu/ldscripts/link.OUT
MUNCH_LDFLAGS = $(MUNCH_LDFLAGS_$(VXWORKS_MAJOR_VERSION))

#--------------------------------------------------
# These are required by some of the Wind River tools
export WIND_BASE
export WIND_HOME = $(WIND_BASE)
export WIND_HOST_TYPE
export TOOL_FAMILY = GNU

#--------------------------------------------------
# Operating system flags
OP_SYS_CPPFLAGS += -DvxWorks=vxWorks
OP_SYS_CFLAGS += -fno-builtin

# Fix for vxWorks 5 headers that use macros defined in vxWorks.h but
# which don't actually include vxWorks.h themselves, for example the
# target/h/sys/stat.h file which uses ULONG.  This also stops dbDefs.h
# from defining the OFFSET macro, which generates lots of warnings in
# both vxWorks 5 and 6.
OP_SYS_INCLUDE_CPPFLAGS += -include $(VX_DIR)/target/h/vxWorks.h

#--------------------------------------------------
# Optimization: Officially vxWorks only supports -O2 or less.
OPT_CFLAGS_YES = -O2
OPT_CXXFLAGS_YES = -O2

#--------------------------------------------------
# code flags
CODE_CFLAGS =
#
# For vxWorks versions before 6.3 we need this g++ compiler flag
CODE_CXXFLAGS_5 = -fno-implicit-templates
CODE_CXXFLAGS_6.0 = -fno-implicit-templates
CODE_CXXFLAGS_6.1 = -fno-implicit-templates
CODE_CXXFLAGS_6.2 = -fno-implicit-templates
CODE_CXXFLAGS_6 = $(CODE_CXXFLAGS_$(VXWORKS_VERSION))
CODE_CXXFLAGS = $(CODE_CXXFLAGS_$(VXWORKS_MAJOR_VERSION))

#--------------------------------------------------
# no shared libs for vxWorks
SHRLIB_CFLAGS =
SHRLIB_LDFLAGS =

#--------------------------------------------------
# Earlier versions of gcc don't understand -MF
HDEPENDS_COMPFLAGS = -MM > $@

#--------------------------------------------------
# osithead use default stack, YES or NO override
OSITHREAD_USE_DEFAULT_STACK = NO

#--------------------------------------------------
# Link definitions
CROSS_LDFLAGS =
#
LINK.cpp = $(LD) -o $@ $(STATIC_LDFLAGS) $(PRODDIR_LDFLAGS) $(LDFLAGS)
LINK.cpp += $(PROD_LDFLAGS) $(PROD_LD_OBJS) $(PROD_LD_RESS) $(PROD_LDLIBS)

#--------------------------------------------------
# Definitions for compile of *_ctdt.c file
CFLAGS_ctdt = $(filter-out -pedantic,$(CFLAGS)) -fdollars-in-identifiers
COMPILE.ctdt = $(CC) -c $(CPPFLAGS) $(CFLAGS_ctdt) $(INCLUDES) $(SOURCE_FLAG)

#--------------------------------------------------
# C preprocessor command
VXCPPFLAGS = $(filter-out $(OP_SYS_INCLUDE_CPPFLAGS),$(CPPFLAGS))
PREPROCESS.cpp = $(CPP) $(VXCPPFLAGS) $(INCLUDES) $< > $@

#--------------------------------------------------
# Allow site overrides
-include $(CONFIG)/os/CONFIG_SITE.Common.vxWorksCommon
-include $(CONFIG)/os/CONFIG_SITE.$(EPICS_HOST_ARCH).vxWorksCommon

