#
# $Id$
#

#
# Makefile for Harbour Project for Borland C/C++ 3.x, 4.x, 5.x compilers
#

#
# NOTE: You can use these envvars to configure the make process:
#       (note that these are all optional)
#
#       CFLAGS       - Extra C compiler options for libraries and for 
#                      executables
#       C_USR        - Extra C compiler options for libraries and for 
#                      executables (GNU make compatible envvar)
#       CLIBFLAGS    - Extra C compiler options for the libraries
#       HARBOURFLAGS - Extra Harbour compiler options
#       PRG_USR      - Extra Harbour compiler options
#                      (GNU make compatible envvar)
#

#
# NOTE: "echo." intentionally used instead of "echo", to avoid conflicts
#       with external commands named echo.
#

!if $d(B16)

CC = bcc
AS = tasm

# Borland C/C++ (DOS 16 bits)
CFLAGS = -mh $(CFLAGS)

BIN_DIR = bin\b16
OBJ_DIR = obj\b16
LIB_DIR = lib\b16

!else

CC = bcc32
AS = tasm32

BIN_DIR = ..\..\bin\b32
OBJ_DIR = ..\..\obj\b32
LIB_DIR = ..\..\lib\b32

# This is needed, otherwise the libs may overflow when 
# debug info is requested with -v -y
ARFLAGS = /P32

!endif

!if !$d(BCC_NOOPTIM)
CFLAGS = -O2 $(CFLAGS)
!endif

#
# Directory macros. These should never have to change.
#

INCLUDE_DIR  = ..\..\include
TOOLS_DIR    = .

#
# C compiler definition and C flags. These should never have to change.
#

CFLAGS         = -I$(INCLUDE_DIR) -d $(C_USR) $(CFLAGS)
CLIBFLAGS      = -c $(CFLAGS) $(CLIBFLAGS)
CLIBFLAGSDEBUG = -v $(CLIBFLAGS)
HARBOURFLAGS   = -i$(INCLUDE_DIR) -n -q0 -w -es2 -gc0 $(PRG_USR) $(HARBOURFLAGS)
LDFLAGS        = $(LDFLAGS)

#
# Macros to access our library names
#

TOOLS_LIB    = $(LIB_DIR)\ct3.lib

HARBOUR_EXE  = $(BIN_DIR)\harbour.exe

#
# Rules
#

#
# TOOLS.LIB rules
#

TOOLS_LIB_OBJS = \
   $(OBJ_DIR)\ctchksum.obj \
   $(OBJ_DIR)\ctchrevn.obj \
   $(OBJ_DIR)\ctchrmix.obj \
   $(OBJ_DIR)\ctchrodd.obj \
   $(OBJ_DIR)\ctcolton.obj \
   $(OBJ_DIR)\ctcrypt.obj \
   $(OBJ_DIR)\ctposupp.obj \
   \
   $(OBJ_DIR)\ctmisc.obj \
   $(OBJ_DIR)\cttoken.obj \

#
# Our default target
#

all: \
   $(TOOLS_LIB) \

#
# Library dependencies and build rules
#

$(TOOLS_LIB)  : $(TOOLS_LIB_OBJS)

#
# TOOLS.LIB dependencies
#

$(OBJ_DIR)\ctchksum.obj : $(TOOLS_DIR)\ctchksum.c
   $(CC) $(CLIBFLAGS) -o$@ $**
   tlib $(TOOLS_LIB) $(ARFLAGS) -+$@,,

$(OBJ_DIR)\ctchrevn.obj : $(TOOLS_DIR)\ctchrevn.c
   $(CC) $(CLIBFLAGS) -o$@ $**
   tlib $(TOOLS_LIB) $(ARFLAGS) -+$@,,

$(OBJ_DIR)\ctchrmix.obj : $(TOOLS_DIR)\ctchrmix.c
   $(CC) $(CLIBFLAGS) -o$@ $**
   tlib $(TOOLS_LIB) $(ARFLAGS) -+$@,,

$(OBJ_DIR)\ctchrodd.obj : $(TOOLS_DIR)\ctchrodd.c
   $(CC) $(CLIBFLAGS) -o$@ $**
   tlib $(TOOLS_LIB) $(ARFLAGS) -+$@,,

$(OBJ_DIR)\ctcolton.obj : $(TOOLS_DIR)\ctcolton.c
   $(CC) $(CLIBFLAGS) -o$@ $**
   tlib $(TOOLS_LIB) $(ARFLAGS) -+$@,,

$(OBJ_DIR)\ctcrypt.obj : $(TOOLS_DIR)\ctcrypt.c
   $(CC) $(CLIBFLAGS) -o$@ $**
   tlib $(TOOLS_LIB) $(ARFLAGS) -+$@,,

$(OBJ_DIR)\ctposupp.obj : $(TOOLS_DIR)\ctposupp.c
   $(CC) $(CLIBFLAGS) -o$@ $**
   tlib $(TOOLS_LIB) $(ARFLAGS) -+$@,,

$(OBJ_DIR)\ctmisc.c : $(TOOLS_DIR)\ctmisc.prg
   $(HARBOUR_EXE) $(HARBOURFLAGS) $** -o$@

$(OBJ_DIR)\ctmisc.obj : $(OBJ_DIR)\ctmisc.c
   $(CC) $(CLIBFLAGS) -o$@ $**
   tlib $(TOOLS_LIB) $(ARFLAGS) -+$@,,

$(OBJ_DIR)\cttoken.c : $(TOOLS_DIR)\cttoken.prg
   $(HARBOUR_EXE) $(HARBOURFLAGS) $** -o$@

$(OBJ_DIR)\cttoken.obj : $(OBJ_DIR)\cttoken.c
   $(CC) $(CLIBFLAGS) -o$@ $**
   tlib $(TOOLS_LIB) $(ARFLAGS) -+$@,,

