#*************************************************************************
# Copyright (c) 2002 The University of Chicago, as Operator of Argonne
#     National Laboratory.
# Copyright (c) 2002 The Regents of the University of California, as
#     Operator of Los Alamos National Laboratory.
# EPICS BASE Versions 3.13.7
# and higher are distributed subject to a Software License Agreement found
# in file LICENSE that is included with this distribution. 
#*************************************************************************
#
#  $Revision-Id$
#
#  CONFIG_COMMON - Another EPICS BASE config file
#	by Matthew Needes and Mike Bordua
#
#  This file is to be maintained by the EPICS community.
#

# Common Configuration Information 

# CROSS1 will be defined only when CROSS_COMPILER_HOST_ARCHS is NOT defined
CROSS1 = $(CROSS_COMPILER_TARGET_ARCHS$(word 1,$(CROSS_COMPILER_HOST_ARCHS)))

# CROSS2 will be defined only when CROSS_COMPILER_HOST_ARCHS is defined
# and HOST_ARCH is one of it's words  
CROSS2 = $(CROSS_COMPILER_TARGET_ARCHS$(filter-out 1,$(words $(filter $(HOST_ARCH),$(CROSS_COMPILER_HOST_ARCHS)))))

BUILD_ARCHS = $(HOST_ARCH) $(CROSS1) $(CROSS2)

INSTALL_LOCATION = $(TOP)

INSTALL_LOCATION_LIB        = $(INSTALL_LOCATION)/lib
INSTALL_LOCATION_BIN        = $(INSTALL_LOCATION)/bin

INSTALL_INCLUDE             = $(INSTALL_LOCATION)/include
INSTALL_DOC                 = $(INSTALL_LOCATION)/doc
INSTALL_HTML                = $(INSTALL_LOCATION)/html
INSTALL_MAN                 = $(INSTALL_LOCATION)/man
INSTALL_TEMPLATES           = $(INSTALL_LOCATION)/templates
INSTALL_DBD                 = $(INSTALL_LOCATION)/dbd
INSTALL_CONFIG              = $(INSTALL_LOCATION)/config
INSTALL_JAVA                = $(INSTALL_LOCATION)/javalib

EPICS_BASE_INCLUDE      = $(EPICS_BASE)/include
EPICS_BASE_TOOLS        = $(EPICS_BASE)/config/tools

DIVIDER = .
OBJ = .
RES = .

EPICS_BASE_HOST_BIN = $(EPICS_BASE)/bin/$(HOST_ARCH)
EPICS_BASE_HOST_LIB = $(EPICS_BASE)/lib/$(HOST_ARCH)
INSTALL_HOST_LIB = $(INSTALL_LOCATION)/lib/$(HOST_ARCH)


# private versions of lex/yacc from EPICS
EYACC = $(EPICS_BASE_HOST_BIN)/antelope$(EXE)
ELEX = $(EPICS_BASE_HOST_BIN)/e_flex$(EXE) -S$(EPICS_BASE_INCLUDE)/flex.skel.static
YACC  = $(EYACC)
LEX   = $(ELEX)

# Default for perl if it's on the PATH,
# otherwise override this in CONFIG_SITE_HOST_ARCH.<host_arch>
PERL=perl

# install from EPICS
INSTALL = $(PERL) $(EPICS_BASE_TOOLS)/installEpics.pl
INSTALL_PRODUCT = $(INSTALL)
INSTALL_LIBRARY = $(INSTALL)

# dbtools from EPICS

# state notation language compiler (removed from base for R3.14)
SNC = $(SEQ)/bin/$(HOST_ARCH)/snc$(EXE)

ifdef T_A

INSTALL_LIB                 = $(INSTALL_LOCATION_LIB)/$(T_A)
INSTALL_TCLLIB              = $(INSTALL_LOCATION_LIB)/$(T_A)
INSTALL_BIN                 = $(INSTALL_LOCATION_BIN)/$(T_A)

EPICS_BASE_LIB          = $(EPICS_BASE)/lib/$(T_A)
EPICS_BASE_BIN          = $(EPICS_BASE)/bin/$(T_A)

#--------------------------------------------------
# GNU compiler defaults

GCC_ANSI = $(GCC) -ansi
GCC_STRICT = $(GCC) -ansi -pedantic
GCC_TRAD = $(GCC)
GCC_DEP_CFLAGS = -fPIC -D_REENTRANT

GCC_WARN_YES = -Wall -Wmissing-prototypes -Wstrict-prototypes
GCC_WARN_NO = -w
GCC_OPT_YES = -O3
GCC_OPT_NO = -g
GCC_SFLAGS_YES = -static
GCC_SFLAGS_NO =
GCC_SLIBS_YES =
GCC_SLIBS_NO =
GCC_SHRLIB_CFLAGS_YES =
GCC_SHRLIB_LDFLAGS_YES =  -shared

G++_NORMAL = $(G++) -ansi -pedantic
G++_STRICT = $(G++) -ansi -pedantic
G++_TRAD = $(G++)
G++_TEMPL_INST_FLAG = -DEXPL_TEMPL
G++_DEP_CFLAGS = -fPIC -D_REENTRANT
G++_WARN_YES = -Wall \
      -Woverloaded-virtual \
      -Wwrite-strings -Wconversion\
      -Wpointer-arith -Winline
G++_WARN_NO = -w
G++_OPT_YES = -O3
G++_OPT_NO = -g
G++_SFLAGS_YES = -static
G++_SFLAGS_NO =
G++_SLIBS_YES =
G++_SLIBS_NO =
G++_DEPENDS_FLAG = -MM
G++_SHRLIB_CFLAGS_YES =
G++_SHRLIB_LDFLAGS_YES =  -shared

#--------------------------------------------------
# C compiler

CC = $($(ANSI)_$(CMPLR))

#---------------------------------------------------------------
# Vendor compiler dependent options
VENDOR_DEP_CFLAGS = $($(ANSI)_DEP_CFLAGS)
VENDOR_DEP_CXXFLAGS = $($(CPLUSPLUS)_DEP_CFLAGS)

#--------------------------------------------------
# C++ compiler

CXX = $($(CPLUSPLUS)_$(CXXCMPLR))

#---------------------------------------------------------------
# Architecture dependent options (solaris,sun4,mv167,...)
ARCH_DEP_CFLAGS =
ARCH_DEP_CXXFLAGS = $(ARCH_DEP_CFLAGS)
ARCH_DEP_LDFLAGS =
ARCH_DEP_LDLIBS =

#---------------------------------------------------------------
# Operating system dependent options (Unix,Vx,WIN32...)
OP_SYS_CFLAGS =
OP_SYS_LDFLAGS =
OP_SYS_INCLUDES =
OP_SYS_LDLIBS =

#--------------------------------------------------
# SOURCE* used by WIN32 only
SOURCE_CFLAG =
SOURCE_CXXCFLAG =

#--------------------------------------------------
# Makefile specific options
USR_INCLUDES =
USR_CFLAGS =
USR_CXXFLAGS =
USR_LDFLAGS =
USR_LDLIBS =
USR_CPPFLAGS =
USR_DBDFLAGS =

#--------------------------------------------------
# Target specific options
TARGET_INCLUDES = $($(basename $@)_INCLUDES)
TARGET_CFLAGS = $($(basename $@)_CFLAGS)
TARGET_CXXFLAGS = $($(basename $@)_CXXFLAGS)
TARGET_LDFLAGS = $($(basename $@)_LDFLAGS)
TARGET_LDLIBS = $($(basename $@)_LDLIBS)
TARGET_CPPFLAGS = $($(basename $@)_CPPFLAGS)
TARGET_SNCFLAGS = $($(basename $@)_SNCFLAGS)

#--------------------------------------------------
# Depends flag
DEPENDS_FLAG = $($(CPLUSPLUS)_DEPENDS_FLAG)

#--------------------------------------------------
# C++ template flag option
TEMPL_INST_CXXFLAG = $($(CPLUSPLUS)_TEMPL_INST_FLAG)

#--------------------------------------------------
# Epics includes (CONFIG.Vx will override OS_CLASS)
OS_CLASS = $(ARCH_CLASS)
EPICS_INCLUDES = -I$(INSTALL_INCLUDE)/os/$(OS_CLASS) -I$(INSTALL_INCLUDE)
EPICS_DBDFLAGS = -I $(INSTALL_LOCATION)/dbd

#--------------------------------------------------
# Posix flags
POSIX=YES
POSIX_CPPFLAGS_YES += -D_POSIX_C_SOURCE=199506L
POSIX_LDLIBS_YES +=

POSIX_CPPFLAGS += $(POSIX_CPPFLAGS_$(POSIX))
POSIX_LDLIBS += $(POSIX_LDLIBS_$(POSIX))

#--------------------------------------------------
# Warnings flags  (CONFIG.Vx will override)
WARN_CFLAGS = $($(ANSI)_WARN_$(HOST_WARN))
WARN_CXXFLAGS = $($(CPLUSPLUS)_WARN_$(HOST_WARN))

#--------------------------------------------------
# Optimization flags  (CONFIG.Vx will override)
OPT_CFLAGS = $($(ANSI)_OPT_$(HOST_OPT))
OPT_CXXFLAGS = $($(CPLUSPLUS)_OPT_$(HOST_OPT))
OPT_LDFLAGS =

#--------------------------------------------------
# Static build options
STATIC_CFLAGS = $($(ANSI)_SFLAGS_$(STATIC_BUILD))
STATIC_CXXCFLAGS = $($(CPLUSPLUS)_SFLAGS_$(STATIC_BUILD))
STATIC_LDFLAGS = $($(ANSI)_SLDFLAGS_$(STATIC_BUILD))
STATIC_LDLIBS = $($(ANSI)_SLIBS_$(STATIC_BUILD))

#--------------------------------------------------
# ar definition default
ARCMD = $(AR) $(ARFLAGS) $@

#--------------------------------------------------
# depends definition 
DEPENDS_RULE = -$(COMPILE.cc) $(DEPENDS_FLAG) $^ > DEPENDS

#--------------------------------------------------

# Include files

INCLUDES = -I. -I.. $(USR_INCLUDES) $(EPICS_INCLUDES) $(TARGET_INCLUDES) $(OP_SYS_INCLUDES)

CFLAGS = $(OPT_CFLAGS) $(DEBUG_CFLAGS) $(WARN_CFLAGS) $(TARGET_CFLAGS)\
 $(USR_CFLAGS) $(ARCH_DEP_CFLAGS) $(VENDOR_DEP_CFLAGS) $(STATIC_CFLAGS)\
 $(OP_SYS_CFLAGS) $(INCLUDES)

CXXFLAGS = $(OPT_CXXFLAGS) $(DEBUG_CXXFLAGS) $(WARN_CXXFLAGS) $(TARGET_CXXFLAGS)\
 $(USR_CXXFLAGS) $(ARCH_DEP_CXXFLAGS) $(VENDOR_DEP_CXXFLAGS) $(STATIC_CXXCFLAGS)\
 $(OP_SYS_CFLAGS) $(TEMPL_INST_CXXFLAG) $(INCLUDES)

LDFLAGS = $(OPT_LDFLAGS) $(TARGET_LDFLAGS) $(USR_LDFLAGS)\
 $(ARCH_DEP_LDFLAGS) $(STATIC_LDFLAGS) $(OP_SYS_LDFLAGS) $(RUNTIME_LDFLAGS)

LDLIBS = $(TARGET_LDLIBS) $(USR_LDLIBS) $(STATIC_LDLIBS) $(ARCH_DEP_LDLIBS)\
  $(OP_SYS_LDLIBS) $(POSIX_LDLIBS)

CPPFLAGS += $(TARGET_CPPFLAGS) $(USR_CPPFLAGS) $(ARCH_DEP_CPPFLAGS) $(POSIX_CPPFLAGS)  $(OP_SYS_CPPFLAGS)

CPPSNCFLAGS = $(INCLUDES)

DBDFLAGS = -I . -I .. $(USR_DBDFLAGS) $(EPICS_DBDFLAGS)

# Build compile line here
COMPILE.c = $(CC) $(CPPFLAGS) $(CFLAGS) -c $(SOURCE_FLAG)
COMPILE.cc = $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(SOURCE_CXXFLAG)

endif

