#
# $Id: compiler.bor 79242 2007-08-07 12:46:48Z johnnyw $
#
# Defines specific to a particular version of the compiler
#
# Inputs:
# ~~~~~~~
# STATIC - if defined means creating a static library or executable
# DEBUG - if defined means building with debug information
# UNICODE - if defined means building unicode
# CPU_FLAG - if defined the flag for CPU optimization
#
# Outputs:
# ~~~~~~~~
# CC - name of compiler
# LD - name of linker
# AR - name of librarian
# RC - name of resource compiler
# COMMON_CFLAGS - compiler flags for all targets
# COMMON_LFLAGS - linker flags for all targets
# COMMON_LIBS - linker library files for all targets
# DLL_CFLAGS - compiler flags specific to DLL targets
# DLL_LFLAGS - linker flags specific to DLL targets
# DLL_STARTUP_OBJ - start-up object files for DLL targets
# EXE_CFLAGS - compiler flags specific to EXE targets
# EXE_LFLAGS - linker flags specific to EXE targets
# EXE_STARTUP_OBJ - start-up object files for EXE targets
# LIB_CFLAGS - compiler flags specific to static lib targets
# LIB_LFLAGS - flags specific to static lib targets (passed to
#              librarian)
# OBJ_EXT - the extension to be used for object files
# LIB_EXT - the extension to be used for libs
#

# Check for BCBVER
!if $(BCBVER) == 8
!else
!if $(BCBVER) == 6
!else
!error BCBVER must be explicitly set as environment variable or is set to a not supported value.
!endif
!endif

OBJ_EXT = obj
LIB_EXT = lib

#
# Build tools
#
CC = bcc32
LD = ilink32
AR = tlib
RC = brcc32

#
# Common flags
#
!ifndef $(BCB)
BCB = $(MAKEDIR)\..
!endif

!ifdef CPU_FLAG
CPU_CFLAG = $(CPU_FLAG)
!else
CPU_CFLAG =
!endif

!ifdef DEBUG
DEBUG_CFLAGS = -v -y -Od -r- -vi- -k -D_DEBUG -DACE_NO_INLINE=1
DEBUG_LFLAGS = -v -L$(BCB)\lib\debug
!else
!if $(BCBVER) == 6
DEBUG_CFLAGS = -OS -Ov -Og -DNDEBUG
!else
DEBUG_CFLAGS = -O2 -DNDEBUG
!endif
DEBUG_LFLAGS = -L$(BCB)\lib\release
!endif

!ifdef STATIC
STATIC_CFLAGS =
STATIC_LFLAGS =
!else
STATIC_CFLAGS = -tWR
STATIC_LFLAGS =
!endif

!ifdef CODEGUARD
CODEGUARD_CFLAGS = -vG
!endif

!ifdef UNICODE
UNICODE_CFLAGS = -DACE_USES_WCHAR -WU
!endif

!ifdef PCH_HEADER
PCH_CFLAGS = -H=$(OBJDIR)\$(NAME).csm -Hh=$(PCH_HEADER)
!endif

THREAD_CFLAGS = -tWM
WARNINGS_CFLAGS = -w-rvl -w-rch -w-ccc -w-obs -w-aus -w-pia -w-inl
!ifdef VCL
DEFINES_CFLAGS = -DWIN32
!else
DEFINES_CFLAGS = -DWIN32;_NO_VCL
!endif
QUIET_CFLAGS = -q
MISC_CFLAGS =
DECORATOR_CFLAGS = -DACE_LD_DECORATOR_STR=ACE_TEXT(\"$(LIB_DECORATOR)\")

COMMON_CFLAGS = $(QUIET_CFLAGS) $(DEBUG_CFLAGS) $(THREAD_CFLAGS) \
	$(STATIC_CFLAGS) $(WARNINGS_CFLAGS) $(DEFINES_CFLAGS) \
	$(MISC_CFLAGS) $(CODEGUARD_CFLAGS) $(UNICODE_CFLAGS) \
        $(DECORATOR_CFLAGS) $(PCH_CFLAGS) $(CPU_CFLAG)

COMMON_LFLAGS = $(DEBUG_LFLAGS) $(STATIC_LFLAGS) -x -w-dup -Gn -L$(BCB)\lib -L$(BCB)\lib\psdk

!ifdef VCL
PACKAGES = rtl.bpi vcl.bpi vclx.bpi vcljpg.bpi bcbsmp.bpi qrpt.bpi dbrtl.bpi \
    vcldb.bpi bdertl.bpi ibsmp.bpi vcldbx.bpi teeui.bpi teedb.bpi tee.bpi \
    nmfast.bpi dclocx.bpi
!endif

#
# DLL specific flags
#

DLL_CFLAGS = -tWD
DLL_LFLAGS = -Tpd -Gi
!ifdef UNICODE
DLL_STARTUP_OBJ = c0d32w.$(OBJ_EXT)
!else
DLL_STARTUP_OBJ = c0d32.$(OBJ_EXT)
!endif

#
# EXE specific flags
#

EXE_CFLAGS =
EXE_LFLAGS = -Tpe
!ifdef UNICODE
!ifdef VCL
EXE_STARTUP_OBJ = c0w32w.$(OBJ_EXT)
!else
EXE_STARTUP_OBJ = c0x32w.$(OBJ_EXT)
!endif
!else
!ifdef VCL
EXE_STARTUP_OBJ = c0w32.$(OBJ_EXT)
!else
EXE_STARTUP_OBJ = c0x32.$(OBJ_EXT)
!endif
!endif

#
# Static lib specific flags
#

LIB_CFLAGS =
!ifdef DEBUG
LIB_LFLAGS = /C /P4096
!else
LIB_LFLAGS = /C /P512
!endif

#
# Libraries to be linked
#

!ifdef CODEGUARD
CODEGUARD_LIB = cg32.lib
!endif

!ifdef STATIC
COMMON_LIBS = $(CODEGUARD_LIB) import32.$(LIB_EXT) cw32mt.lib ws2_32.lib
!else
COMMON_LIBS = $(CODEGUARD_LIB) import32.$(LIB_EXT) cw32mti.lib ws2_32.lib
!endif
