# CONFIG.Host.Borland
#  This file is maintained by the EPICS community.
#  Sites may override these definitions in CONFIG_SITE.Borland
 
BORLAND_LIB = $(BORLAND)\\lib
BORLAND_INC = $(BORLAND)\\include
BORLAND_BIN = $(BORLAND)\\bin

#
#
ANSI = ACC
CPLUSPLUS = CCC

#
# -q supress command line banner
WINLINK = $(BORLAND_BIN)/ilink32 -q

# -l specifies default language
# -fo Renames the output .RES file
RCCMD = $(BORLAND_BIN)/brcc32 $(subst -I,-i,$(INCLUDES)) -l0x409  -fo$@ $<

ARCMD = $(BORLAND_BIN)/tlib $@

#
# Configure Borland C compiler
# -q suppress compiler identification banner
# -tWM generate a 32-bit multi-threaded target
# -tWD generate a .DLL executable
# -a8 quad word alignment
# -D_WIN32 macro defined to be consistant with Microsoft Visual C++
# -D_RTLDLL macro defined to use Borland C++ RTL library
CCLINKOPT = -q -tWM -tWD -a8 -D_WIN32 -D_RTLDLL
ACC = $(BORLAND_BIN)/bcc32 $(CCLINKOPT)

#
# __STDC__=0 works but not as cleanly as with
# Microsoft Visual C++.
# The Borland header files use ifdef __STDC__ 
# to disable many nice things. This is overridden
# by defining NO_BORLAND_STDC in the Makefile.Host.
#
ifdef NO_BORLAND_STDC
ACC_ANSI = $(ACC)
ACC_STRICT = $(ACC)
else
ACC_ANSI = $(ACC) -D__STDC__=0
ACC_STRICT = $(ACC) -D__STDC__=0
endif
ACC_TRAD = $(ACC)

# -w display warnings on
# -g0 no limit to warning messages
# some warning message here are always disabled because they are 
# trivial and numerous 
# -w-8012 Comparing signed and unsigned values
# -w-8060 Possibly incorrect assignment
# -w-8071 Conversion may lose significant digits
ACC_WARN_YES = -w -g0 -w-8012 -w-8060 -w-8071
# -w- display warnings off
ACC_WARN_NO =  -w-

#
# -k- turn off standard stack frame
# -H- turn off precompiled headers
# -R- don't include browser info in .obj files
# -O1 optimization for size
# -v- turn off source debugging
# -vi control expansion of inline functions
ACC_OPT_YES = -k- -H- -R- -O1 -v- -vi

#
ACC_OPT_NO = 


#
# no special libs for static link
#
ACC_SLIBS_YES= 
ACC_SLIBS_NO=

# Configure OS vendor C++ compiler
#
# __STDC__=0 works but not as cleanly as with
# Microsoft Visual C++.
# The Borland header files use ifdef __STDC__ 
# to disable many nice things. This is overridden
# by defining NO_BORLAND_STDC in the Makefile.Host.
#
CCC = $(BORLAND_BIN)/bcc32 $(CCLINKOPT)
ifdef NO_BORLAND_STDC
CCC_NORMAL = $(CCC)
CCC_STRICT = $(CCC)
else
CCC_NORMAL = $(CCC) -D__STDC__=0
CCC_STRICT = $(CCC) -D__STDC__=0
endif
CCC_TEMPL_INST_FLAG =

# -w display warnings on
# -g0 no limit to warning messages
# -w-8012 Comparing signed and unsigned values
# -w-8060 Possibly incorrect assignment
# -w-8071 Conversion may lose significant digits
CCC_WARN_YES = -w -g0 -w-8012 -w-8060 -w-8071 -w-8008 -w-8027 -w-8066 -w-8080 -w-8004
# -w- display warnings off
CCC_WARN_NO = -w-

#
# -k- turn off standard stack frame
# -H- Turn off precompiled headers
# -R- Don't include browser info in .obj files
# -O1 optimization for size
# -v- turn off source debugging
# -vi control expansion of inline functions
CCC_OPT_YES = -k- -H- -R- -O1 -v- -vi

#
CCC_OPT_NO = 

#
# no special libs for static link
#
CCC_SLIBS_YES=
CCC_SLIBS_NO=

PROD_VERSION=3.13
# -c case sensitive linking
# -C clear state before linking
# -Gi generate import library
# -Gn no state files
# -Tpd targets a Windows .DLL file
# -x no map
# -w display warnings on
LINK_OPT_FLAGS_YES = -c -C -Gi -Gn -Tpd -x -w
LINK_OPT_FLAGS_NO = -c -C -Gi -Gn -Tpd -x -w-
WIN32_DLLFLAGS = $(LINK_OPT_FLAGS_$(HOST_OPT))
OPT_LDFLAGS = 

ARCH_DEP_CFLAGS=

#	to identify the general architecture class:
#	should be BSD, SYSV, WIN32, ...
#	is: WIN32, sun4, hpux, linux, ...
#
ARCH_CLASS=WIN32

#	ifdef WIN32   looks better that  ifeq ($(ARCH_CLASS),WIN32)  ??
WIN32=1
BORLANDC=1

EXE=.exe
OBJ=.obj
RES=.res

#       Problem: BorlandC does not recognize  *.cc as C++ source,
#       we have to compile xx.cc  using the flag -P xx.cc,
SOURCE_CXXFLAG = -P -D__cplusplus

#	Operating system flags 
OP_SYS_CFLAGS =

#
# Borland specific include files
#
OP_SYS_INCLUDES = -I$(BORLAND_INC)
#
OP_SYS_LDLIBS =

#
# specify dll .def file only if it exists
#
#DLL_DEF_FLAG = $(addprefix /def:,$(wildcard ../$(LIBRARY).def))
DLL_DEF_FLAG = $(subst /,\\,$(wildcard ../$(LIBRARY).def))

#	HOST_OPT_FLAGS is part of CFLAGS/CXXFLAGS,
#	which in turn are used in COMPILE.c[c]
#
#	If we compile a .c, .cc into an $(OBJ),
#	we test if this object is part of the 
#	library objects LIBOBJS.
#	If so, we define _WINDLL so that
#	e.g. include/shareLib.h works correctly.
#
HOST_OPT_FLAGS += $(subst $@, /_WINDLL, $(findstring $@,$(LIBOBJS)))

#
#	A WIN32 dll has three parts:
#	x.dll: the real dll (SHRLIBNAME)
#	x.lib: what you link to progs that use the dll (LIBNAME)
#	x.exp: what you need to build the dll (in no variable)
#
LINK.shrlib = $(WINLINK) $(WIN32_DLLFLAGS) -L$(BORLAND_LIB) -L$(BORLAND_LIB)\\Psdk c0d32.obj

#	adjust names of libraries to build
#
#	But: if there are no objects LIBOBJS to include
#	in this library (may be for e.g. base/src/libCompat
#	on some archs), don't define (and build) any library!
SHRLIBNAME = $(LIBRARY).dll

#
# Under WIN32 we have the unique situation where the DLL link creates the
# DLL link library xxx.lib and we need to be very careful to avoid replacing
# the xxx.lib created by the dll link with an xxx.lib created by $(AR).
# Therefore, the object library is named xxxObj.lib
#
# SHARED_LIBRARIES is YES if we are building a DLL and NO if we aren't
#
DLL_LINK_LIBNAME_YES = $(LIBRARY).lib
DLL_LINK_LIBNAME = $(DLL_LINK_LIBNAME_$(SHARED_LIBRARIES))

#ifeq ($(strip $(SHARED_LIBRARIES)),NO)
#LIBNAME = $(LIBRARY).lib
#else
LIBNAME = $(LIBRARY)Obj.lib
#endif

#	dll install location
INSTALL_SHRLIB = $(INSTALL_BIN)

#--------------------------------------------------
# Dependancy definitions
OBJECT_LIB_EXT_YES = Obj.lib # object library extension for static build
OBJECT_LIB_EXT_NO = .lib # object library extension for dynamic build
OBJECT_LIB_EXT = $(OBJECT_LIB_EXT_$(STATIC_BUILD))

COND_PROD_DEPLIBS = $(foreach prod,$(PROD), $(foreach lib, $($(basename $(prod))_LIBS),\
 $(firstword $($(lib)_DIR) $(EPICS_BASE_LIB))/$(lib)$(OBJECT_LIB_EXT)))
PRODNAME_DEPLIBS = $(foreach lib,$(PRODNAME_LIBS),$(firstword $(wildcard $($(lib)_DIR)/$(lib).lib $($(lib)_DIR)/$(lib)Obj.lib $(EPICS_BASE_LIB)/$(lib).lib $(EPICS_BASE_LIB)/$(lib)Obj.lib ) $(filter $(LIBRARY)$(OBJECT_LIB_EXT), $(lib)$(OBJECT_LIB_EXT)) ))
PROD_DEPLIBS = $(foreach lib,$(PROD_LIBS),$(firstword $(wildcard $($(lib)_DIR)/$(lib).lib $($(lib)_DIR)/$(lib)Obj.lib $(EPICS_BASE_LIB)/$(lib).lib $(EPICS_BASE_LIB)/$(lib)Obj.lib ) $(filter $(LIBRARY)$(OBJECT_LIB_EXT), $(lib)$(OBJECT_LIB_EXT)) )) 

USR_DEPLIBS = $(foreach lib,$(USR_LIBS),$(firstword $(wildcard $($(lib)_DIR)/$(lib).lib $($(lib)_DIR)/$(lib)Obj.lib $(EPICS_BASE_LIB)/$(lib).lib $(EPICS_BASE_LIB)/$(lib)Obj.lib ) $(filter $(LIBRARY)$(OBJECT_LIB_EXT), $(lib)$(OBJECT_LIB_EXT)) )) 

# by default the libraries used when linking the DLL are just
# PROD_LIBS ans SYS_PROD_LIBS minus the DLL name
DLL_LIBS = $(patsubst $(LIBRARY),, $(PROD_LIBS))
 
#
#	EPICS libs that we need to link the DLL with
#	(it isnt necessary to rebuild the dll if these change)
DLL_DEPLIBS = $(foreach lib,$(DLL_LIBS),$(firstword $(wildcard $($(lib)_DIR)/$(lib).lib $($(lib)_DIR)/$(lib)Obj.lib $(EPICS_BASE_LIB)/$(lib).lib $(EPICS_BASE_LIB)/$(lib)Obj.lib) $(filter $(LIBRARY)$(OBJECT_LIB_EXT), $(lib)$(OBJECT_LIB_EXT)) ))

USR_LDLIBS = $(PRODNAME_DEPLIBS) $(PROD_DEPLIBS) $(USR_DEPLIBS) $(SYS_PROD_LIBS:%=%.lib)

DLL_LDLIBS = $(DLL_DEPLIBS) $(SYS_PROD_LIBS:%=%.lib) $(OP_SYS_LDLIBS)

#multithreaded import library
LIBSUF=mti
# -c case sensitive linking
# -C clear state before linking
# -Gn no state files
# -Tpe targets a Windows .EXE file
# -x no map
# -w display warnings on
LDFLAGS += -c -C -Gn -Tpe -x -w -L$(BORLAND_LIB) -L$(BORLAND_LIB)\\Psdk
LINKSTARTUP = c0x32.obj
LINKLIBS=import32.lib cw32$(LIBSUF).lib

LINK.c = $(WINLINK) $(LDFLAGS) $(LINKSTARTUP)
LINK.cc = $(WINLINK) $(LDFLAGS) $(LINKSTARTUP)

