#-----------------------------------------------------------------------------
# MAKEFILE for ObjectComponents Framework
#
# Copyright (c) Borland International 1994, 1996
# All Rights Reserved
#
# $Revision:   2.22  $
#
# Defines:
#   MODEL=<d|s|m|l|f>   one of: dll(default), small, medium, large or flat
#   WIN32        enables win32 static (flat) or DLL
#   DIAGS        enables runtime diagnostics (adds 'd' to lib name before 'w')
#   DEBUG        enables debug info for TDW & TD32
#   OCFNOPCH     disables precompiled headers for OCF
#   OCFNAME=Xxx  lib & DLL name base, Defaults to 'OCF'. Req. for non-diag DLLs
#   OCFVER=nnn   version for OCF DLL. Defaults to 250. Req. for non-diag DLLs
#   USERDLL      builds OCF for use in a user DLL (adds 'u' to lib name after
#                model)
#   CODEGUARD    builds ocf with CodeGuard:  1=basic data, 2=full checking
#   ALIGN=<1|2|4|8>        Specifies the alignment
#
#
# Define these for alternate OCF build directories:
#   OCFSRCDIR    defaults to: $(BCROOT)\source\OCF
#   OCFINCDIR    defaults to: $(BCROOT)\include
#   OCFLIBDIR    defaults to: $(BCROOT)\lib
#   OCFBINDIR    defaults to: $(BCROOT)\bin
#
#-----------------------------------------------------------------------------

.autodepend
.cacheautodepend
.swap

#--------------------------------------------------------------------
# Fill in defaults. The following table describes the logic used for
# assigning defaults. Blank means "don't care", ! means not defined
#
#   MODEL | DLL | WIN16 | WIN32 | RESULTS
#  -------+-----+-------+-------+--------------------------------
#     !   |  !  |   !   |       | MODEL=f    WIN32=1  (default)
#   ==f|t | ==1 |   !   |       | MODEL=f|t  WIN32=1  DLL=1
#   ==f|t |  !  |   !   |       | MODEL=f|t  WIN32=1
#     !   |  !  |  ==1  |   !   | MODEL=l    WIN16=1  DLL=1
#         | ==1 |  ==1  |   !   | MODEL=l    WIN16=1  DLL=1
#   ==m|l |  !  |       |   !   | MODEL=m|l  WIN16=1
#---------+-----+-------+-------+--------------------------------

!if !$d(MODEL) && !defined(MT) && !$d(WIN16) && !$d(OS2)
  MODEL = f    # default build model = flat static, Win32
# MODEL = d    # default build model = flat DLL, Win32
!endif

!if $(MODEL) == d     # model d is short for building the DLL-- flat or large
  DLL = 1
! if !$d(WIN16) && !$d(OS2)
    WIN32 = 1         # DLL is 32bit by default
! endif
!endif

!if ($(MODEL) == t || $(MODEL) == f) && !$d(OS2)
  WIN32 = 1    # default to WIN32 switch on for flat or multi-threaded model
!elif $(MODEL)==l
  WIN16 = 1    # default to WIN16 switch on for large model
!endif

!if $(MODEL) == t || $d(MT)
  MT = mt       # model t implies MT. Use MT as 'mt' to build library names
!endif

!if $d(WIN32)
! if $d(MT)
    MODEL = t
! else
    MODEL = f
! endif
!elif $d(DLL)
  MODEL = l
!endif

#
# Some MODELs [l,f,t] always imply WIN16 or WIN32 - Update
# according to model.
#
!if   $(MODEL) == l  						# MODEL == l
  WIN16 = 1
!elif ($(MODEL) == t || $(MODEL) == f)  # MODEL == f|t
  WIN32 = 1
!endif

#
# Figure out default data alignment based on target
#
!if !$d(ALIGN)
! if $d(WIN32)
    ALIGN = 1
! else
    ALIGN = 1
! endif
!endif

!if $d(DOS) && $d(MT)
! error Cannot build multi-thread library for DOS.
!endif

!if $d(MODEL)
! if $(MODEL) != l && $(MODEL) != f && $(MODEL) != t && $(MODEL) != d
!   error MODEL must be m, l, d, f or t
! endif
!endif

#--------------------------------------------------------------------
# Dir & name components
#--------------------------------------------------------------------
!if $d(DLL)

! if $d(WIN32)
    KEY = w$(MODEL)i            # 32bit flat or multithread DLL import library
! else
    KEY = wi                    # 16bit DLL import library
! endif

!else

KEY = w$(MODEL)                 # Static library uses w+model

!endif  # if/else $d(DLL)

! if $d(USERDLL)
  KEY = $(KEY)u                 # Static or import library for use by dlls
! endif

!if !$d(OCFNAME)
  OCFNAME = OCF
! if !$d(OCFVER)
    OCFVER = 50
! endif
!endif

#--------------------------------------------------------------------
# Debug & diagnostic flags
#--------------------------------------------------------------------
!if $d(DEBUG)
  CDBG = -v -k -Od    # debug-info on, normal stack, no optimizations
!endif
!if 1 || $d(DEBUG)    # Leave public debug info in dll & strip to a .tds after
! if $d(WIN32)
    LDBG = -v
! else
    LDBG = -v -Vt
! endif
!endif

!if $d(DIAGS)         # default diags use precondition, check, trace & warn
  __DEBUG=2
  __TRACE=1
  __WARN=1
! if $d(WIN32)
    BD=d              # Use Bids Diag version when OCF lib is diag
! else
    BD=db             # Extension compatible with traditional DOS names
! endif
  OD=d                # OCF libs & dll get a 'd' for Diag versions
!endif

#
# Build up compiler diag switches based on settings
#
!if $d(__DEBUG)
  CDIAG = -D__DEBUG=$(__DEBUG)
!endif
!if $d(__TRACE)
  CDIAG = $(CDIAG) -D__TRACE
!endif
!if $d(__WARN)
  CDIAG = $(CDIAG) -D__WARN
!endif

#--------------------------------------------------------------------
# Dir & search paths, & precompiled headers
#--------------------------------------------------------------------

#
# BC tools BCBINDIR can be based on MAKEDIR if no BCROOT is defined
#
!if $d(BCROOT)
  BCBINDIR = $(BCROOT)\bin
!else
  BCBINDIR = $(MAKEDIR)
!endif

#
# Default bcroot to whatever is in bcroot.inc
#
!if !$d(BCROOT)
! include $(MAKEDIR)\bcroot.inc
!endif

#
# Where to find BC tools, libraries and include files
#
BCSRCDIR = $(BCROOT)\source
BCINCDIR = $(BCROOT)\include
BCLIBDIR = $(BCROOT)\lib
BCBINDIR = $(BCROOT)\bin

#
# Where to find OCF dirs-- can set these for special layouts
# Build search paths differently if OCF include dir is not below BC's
#
!if !$d(OCFSRCDIR)
  OCFSRCDIR = $(BCSRCDIR)\ocf
!endif

#
# Where to find OCF headers
#
!if !$d(OCFINCDIR)
  OCFINCDIR=$(BCINCDIR)
  RCINCLUDEPATH = -i$(BCINCDIR)
!else
  RCINCLUDEPATH = -i$(OCFINCDIR) -i$(BCINCDIR)
!endif

#
# Check if BIDS header directory was specified
#
!if $d(BIDSINCDIR)
  INCLUDE=$(OCFINCDIR);$(BIDSINCDIR);$(BCINCDIR)
!else
  INCLUDE=$(OCFINCDIR);$(BCINCDIR)
!endif

#
# Location (destination) of OCF libraries
#
!if !$d(OCFLIBDIR)
  OCFLIBDIR = $(BCLIBDIR)
!endif

#
# Location (destination) of OCF binaries
#
!if !$d(OCFBINDIR)
  OCFBINDIR = $(BCBINDIR)
!endif

OCFOBJDIR = $(OCFSRCDIR)\o\$(OD)$(KEY)   # Keep seperate diag/nondiag dirs

.PATH.obj = $(OCFOBJDIR)
.PATH.res = $(OCFOBJDIR)
.PATH.def = $(OCFOBJDIR)
.PATH.lib = $(OCFLIBDIR)
.PATH.cpp = $(OCFSRCDIR)

#
# Define OCFNOPCH to disable the use of Precompiled headers when building OCF
#
!if !$d(OCFNOPCH)
  CPCH= -H=$(OCFLIBDIR)\$(OCFNAME)$(OD)$(KEY).csm -H"pch.h" -D_OCFPCH
! if $d(WIN32) || $(__MAKE__) > 0x0370   # -Hc: !valid in earlier 16-bit
    CPCH= $(CPCH) -Hc
! endif
!endif

#--------------------------------------------------------------------
# Library names
#--------------------------------------------------------------------
OCFLIB = $(OCFLIBDIR)\$(OCFNAME)$(OD)$(KEY).lib

#--------------------------------------------------------------------
# Tools and options for Win32
#--------------------------------------------------------------------
!if $d(WIN32)
  CC       = $(BCBINDIR)\bcc32       # Compiler
#  CC       = $(BCBINDIR)\bcc32i      # Compiler
  RCC      = brcc32 -w32             # Resource compiler
  CCASM    = $(BCBINDIR)\tasm32      # Assembler
  LINK     = $(BCBINDIR)\tlink32     # Linker
  LIB      = $(BCBINDIR)\tlib        # Librarian
  IMPLIB   = $(BCBINDIR)\implib      # Import library generator
  TDSTRIP  = $(BCBINDIR)\tdstrp32    # Debug info extractor

  CFLAGS   = -d -k- -Ogmpv           # Optimizations (-O1gmpv)
! if $d(CODEGUARD)                   # d=add data, c=add calls, t=check this
    CFLAGS = $(CFLAGS) -vGd -vGt
!   if $(CODEGUARD) == 2
      CFLAGS= $(CFLAGS) -vGc
!   endif
!  endif
  CFGFILE  = bcc32.cfg               # Name of compiler's config file
! if $d(DEBUG)
    TLIBOPTS = /P512 /C
! else
    TLIBOPTS = /P64 /0 /C
! endif

! if $d(DLL)
    CFLAGS = $(CFLAGS) -WDE -D_BUILDOCFDLL
    LFLAGS = $(LDBG) -Tpd -aa -s -c
!   if !$d(BIDSILIB)
      BIDSILIB = bids$(BD)$(MODEL)i
!   endif
    STDLIBS  = import32 cw32$(MT)i   # Libs for linking the DLL
!   if $d(CODEGUARD)
      STDLIBS  = cg32 $(STDLIBS)
!   endif
! else
    CFLAGS = $(CFLAGS) -W
! endif

!if $d(MT)
  CFLAGS = $(CFLAGS) -WM
!endif

!if $d(ALIGN)
  CFLAGS = $(CFLAGS) -a$(ALIGN)
!endif

#--------------------------------------------------------------------
# Tools and options for Win16
#--------------------------------------------------------------------
!else
  CC       = $(BCBINDIR)\bcc         # Compiler
  RCC      = brcc32 -31              # Resource compiler
  CCASM    = $(BCBINDIR)\tasm        # Assembler
  LINK     = $(BCBINDIR)\tlink       # Linker
  LIB      = $(BCBINDIR)\tlib        # Librarian

  # implib needs -o switch in 16 bit for compatibility
  IMPLIB   = $(BCBINDIR)\implib -o   # Import library generator
  TDSTRIP  = $(BCBINDIR)\tdstrip     # Debug info extractor

  CFLAGS    = -3 -d -k- -O1gmpv      # Optimizations
! if $d(CODEGUARD)                   # d=add data, c=add calls, t=check this
    CFLAGS = $(CFLAGS) -vGd -vGt
!   if $(CODEGUARD) == 2
      CFLAGS= $(CFLAGS) -vGc
!   endif
!  endif

! if $(MODEL) != s && $(MODEL) != m  # Large models can put strs in code seg
    CFLAGS = $(CFLAGS) -dc
! endif
  CFLAGS   = -m$(MODEL) $(CFLAGS)    # Memory model

! if $d(OCFFARVTABLE)
    CFLAGS = $(CFLAGS) -D_OCFFARVTABLE;_BIDSFARVTABLE #;_RTLFARVTABLE
! endif
! if $d(NO_CPP_EXCEPTIONS)
    CFLAGS = $(CFLAGS) -DNO_CPP_EXCEPTIONS -x-
! endif
  CFGFILE = turboc.cfg

! if $d(DEBUG)
    TLIBOPTS = /P512 /C
! else
    TLIBOPTS = /P32 /0 /C
! endif

! if $d(DLL)                       # Build the 16bit OCF for use with RTL/BIDS DLL
!   if $d(USERDLL)
      CFLAGS = $(CFLAGS) -WDE -D_OCFDLL -xc # _BUILDOCFDLL in DLLs (not a dll)
!   else
      CFLAGS = $(CFLAGS) -WSE -D_OCFDLL     # _BUILDOCFDLL in EXEs (not a dll)
!   endif
    LFLAGS = $(LDBG) -Twd -n -s -c -C
!   if !$d(BIDSILIB)
      BIDSILIB = bids$(BD)i
!   endif
    STDLIBS  = import crtldll        # Libs for linking the OC DLL

! else
!   if $d(USERDLL)
      CFLAGS = $(CFLAGS) -WDE -xc    # Build static OCF lib for use in DLLs
!   else
      CFLAGS = $(CFLAGS) -WSE        # Build static OCF lib for use in EXEs
!   endif
! endif

! if $d(ALIGN)
    CFLAGS = $(CFLAGS) -a$(ALIGN)
! endif

!endif

#--------------------------------------------------------------------
# Rules
#--------------------------------------------------------------------
.rc.res:
  $(RCC) $(RCINCLUDEPATH) -fo$@ $.

.cpp.obj:
  $(CC) {$& }

#--------------------------------------------------------------------
# Various file lists needed for dependency checking and LIBing.
#
#   OBJS_CMN are the objs common to static libs and the dll
#   OBJS_LIB are the objs that go into libs and implibs only, not the dlls
#   OBJS_DLL are the objs that go into the dll only
#   LIBDEPOBJS is the list of object files for lib/implib dependency checking
#   LIBOBJS is the list of object files for building/addingto the libraries
#   LINKOBJS is the list of object files for building the DLL
#--------------------------------------------------------------------

# Common, unsectioned objs go into static libs and DLLs
#
OBJS_CMN = \
 PFXappdesc.obj\
 PFXautocli.obj\
 PFXautodisp.obj\
 PFXautoiter.obj\
 PFXautostck.obj\
 PFXautosrv.obj\
 PFXautosym.obj\
 PFXautoval.obj\
 PFXocreg.obj\
 PFXocstorag.obj\
 PFXoleutil.obj\
 PFXtypelib.obj\
 PFXversion.obj\
 PFXexcept.obj

OBJS_CMN = $(OBJS_CMN)\
 PFXocapp.obj\
 PFXocdoc.obj\
 PFXocpart.obj\
 PFXocremvie.obj\
 PFXocdata.obj\
 PFXoclink.obj\
 PFXocview.obj\
 PFXocguid.obj

# Modules built only in 32-bit
#
!if	$d(WIN32)
OBJS_CMN = $(OBJS_CMN) \
 PFXocctrl.obj
!endif


# Put together obj groups into lists for different targets
#
!if $d(DLL)
 LIBDEPOBJS= $(OBJS_CMN:PFX=) $(OBJS_LIB:PFX=) $(OBJS_DLL:PFX=)
 LIBOBJS   = $(OBJS_LIB:PFX=+) $(OBJS_CMN:PFX=+) $(OBJS_DLL:PFX=+)
 LINKOBJS  = $(OBJS_CMN:PFX=) $(OBJS_DLL:PFX=)
!else
 LIBDEPOBJS= $(OBJS_CMN:PFX=) $(OBJS_LIB:PFX=)
 LIBOBJS   = $(OBJS_CMN:PFX=+) $(OBJS_LIB:PFX=+)
!endif

#--------------------------------------------------------------------
# targets
#--------------------------------------------------------------------
all: cfgfile $(OCFLIB)

cfgfile:
  @-if not exist $(.PATH.obj)\..\NUL md $(.PATH.obj)\..
  @-if not exist $(.PATH.obj)\NUL md $(.PATH.obj)
  @copy &&|
-I$(INCLUDE)
-c -w $(CFLAGS) $(CDBG) $(CDIAG)
$(CPCH) -n$(.PATH.obj) $(CCFOCF)
| $(CFGFILE) > NUL

$(OCFLIB): $(LIBDEPOBJS)
  @-del $(OCFLIB)
  @cd $(.PATH.obj)
  $(LIB) $(TLIBOPTS) $(OCFLIB) @&&|
$(LIBOBJS)
|
  @cd $(.PATH.cpp)

clean:
  @echo Removing .OBJs from $(.PATH.obj)
  @if exist $(.PATH.obj)\*.obj del $(.PATH.obj)\*.obj
  @if exist $(.PATH.obj)\*.csm del $(.PATH.obj)\*.csm

!if $d(WIN32)
ocguid.obj: ocguid.cpp
  $(CC) -H- ocguid.cpp
!else
ocguid.obj: ocguid.cpp
  $(CC) -H- -zE_TEXT -zFCODE ocguid.cpp
!endif
