##############################################################################
#   $Id: makefile 1.1 1995/01/11 19:37:58 ron Exp $
#
#   Copyright (C) 1990-94 Tarma Software Research. All rights reserved.
#
#   Project:	Tarma Library for C++ V5.0
#   Author:	Ron van der Wal
#
#   MAKEFILE for Tarma Library for C++, compiler versions:
#
#   - Watcom C++ 10.0 for DOS, Windows and OS/2
#
#   Syntax depends on the target platform, as follows:
#
#   - DOS:	MAKE -DDOS [-DEBUG] [M=(t|s|c|m|l|h)] [flags..]
#   - OS/2:	MAKE -DOS2 [-DEBUG] [-DLL] [flags..]
#   - Windows:	MAKE -DWIN [-DEBUG] [-DLL] [M=(s|c|m|l)] [flags..]
#
#   $Log: makefile $
    Revision 1.1  1995/01/11  19:37:58  ron
    Initial revision
    
##############################################################################

#-----------------------------------------------------------------------------
#	MAKE parameters
#-----------------------------------------------------------------------------

!if !$d(DOS) && !$d(OS2) && !$d(WIN)

!if $d(__MSDOS__)
DOS	= 1
!elif $d(__OS2__)
OS2	= 1
!else
!error Must specify -DDOS, -DOS2, or -DWIN
!endif

!endif

#-----------------------------------------------------------------------------
#	TLX version number (used with DLLs)
#-----------------------------------------------------------------------------

TLXVER	= 500		# TLX version number

!ifndef PROJLEVEL
PROJLEVEL = Experimental
!endif

#-----------------------------------------------------------------------------
#	Compiler information
#	--------------------
#
#	The following macros are automatically defined, and in most cases,
#	they should work as given. However, check them before you use this
#	MAKEFILE.
#
#	CCDIR = base directory of your compiler. You may need to adjust
#		the names given below if your compiler is somewhere else.
#
#	CCVER = version number of your compiler. You may need to adjust it
#		if the automatic detection fails.
#-----------------------------------------------------------------------------

CCDIR	= C:\WC10
CCVER	= 1000

#-----------------------------------------------------------------------------
#	Names for files and tools
#-----------------------------------------------------------------------------

AS		= WASM
CC		= WCL386
LINK		= WLINK
LIBR		= WLIB

MAKEFILE	= makefile
DEPEND		= makefile.dep

#-----------------------------------------------------------------------------
#    Platform-dependent tool options
#
#    DOS:	TLXDm[d]
#    OS/2:	TLX2[d][i]
#    Windows:	TLXWm[d][i]
#-----------------------------------------------------------------------------

!if $d(DOS)	#--------- DOS target ----------------------------------------

!ifndef M
M		= l
!endif

POSTFIX 	= d$(M)
AFLAGS		= /mx
CFLAGS		= -c -w -D_TLXBUILD -m$(M) -xs
LFLAGS		= /c /yx
BFLAGS		= /C

!ifdef EBUG	#-----	Debugging version

POSTFIX 	= $(POSTFIX)d
AFLAGS		= $(AFLAGS) /zi
CFLAGS		= $(CFLAGS) -hw -D_TLXDBG
LFLAGS		= $(LFLAGS) D All OP Map
BFLAGS		= $(BFLAGS) -p=64

!else		#-----	Distribution version

AFLAGS		= $(AFLAGS)
CFLAGS		= $(CFLAGS) -ox
LFLAGS		= $(LFLAGS)
BFLAGS		= $(BFLAGS)

!endif	# EBUG

!ifdef LL
!error DLLs not supported under DOS
!endif

STARTUP 	=
RUNTIME 	=

!elif $d(OS2)	#-------- OS/2 target ----------------------------------------

# Under OS/2, compilation for static and dynamic libraries is identical;
# only the linking step differs. Therefore, .OBJ files for both static and
# dynamic libraries share the same directory and configuration file.

POSTFIX 	= 2
AFLAGS		= /mx
CFLAGS		= -3 -c -w -D_TLXBUILD -xs -mf
LFLAGS		=
BFLAGS		= /C

!ifdef EBUG	#-----	Debugging version

POSTFIX 	= $(POSTFIX)d
AFLAGS		= $(AFLAGS) /zi
CFLAGS		= $(CFLAGS) -hw -D_TLXDBG
LFLAGS		= $(LFLAGS) D All OP Map
BFLAGS		= $(BFLAGS) -p=64

!else		#-----	Distribution version

AFLAGS		= $(AFLAGS)
CFLAGS		= $(CFLAGS) -ox
LFLAGS		= $(LFLAGS)
BFLAGS		= $(BFLAGS)

!endif	# EBUG

!ifdef LL	#-----	DLL version

POSTFIX 	= $(POSTFIX)i
LFLAGS		= $(LFLAGS) /Tod
STARTUP 	=

!else		#-----	Static version

LFLAGS		= $(LFLAGS) FORM OS2 LX PMC
STARTUP 	=

!endif	# LL

RUNTIME 	=

!elif $d(WIN)	#-------- Windows target -------------------------------------

# Under Windows, compilation for static and dynamic libraries differs, and
# we have separate output directories and configuration files for the .OBJ
# files of each variant.

!ifndef M
M		= l
!endif

POSTFIX 	= w$(M)
AFLAGS		= /mx
CFLAGS		= -2 -c -d -O1 -w -D_TLXBUILD -m$(M)
LFLAGS		= /c /C /yx
BFLAGS		= /C

!ifdef EBUG	#-----	Debugging version

POSTFIX 	= $(POSTFIX)d
AFLAGS		= $(AFLAGS) /zi
CFLAGS		= $(CFLAGS) -N -v -D_TLXDBG
LFLAGS		= $(LFLAGS) /m /v
BFLAGS		= $(BFLAGS) -p=64

!else		#-----	Distribution version

AFLAGS		= $(AFLAGS)
CFLAGS		= $(CFLAGS) -G-
LFLAGS		= $(LFLAGS) /x
BFLAGS		= $(BFLAGS) /0

!endif	# EBUG

!ifdef LL	#-----	DLL version

POSTFIX 	= $(POSTFIX)i
CFLAGS		= $(CFLAGS) -WDE
LFLAGS		= $(LFLAGS) /Twd
STARTUP 	=

!else		#-----	Static version

CFLAGS		= $(CFLAGS) -WE
LFLAGS		= $(LFLAGS) /Twe
STARTUP 	=

!endif	# LL

RUNTIME 	=
XLIBS		= tlxtr$(TLXVER).lib

!endif		#----- DOS - OS/2 - WIN -------------------------------------

#-----------------------------------------------------------------------------
#   	Directory configuration
#-----------------------------------------------------------------------------

.PATH.asm	= ..\..\SRC
.PATH.c 	= ..\..\SRC
.PATH.cpp	= ..\..\SRC
.PATH.h 	= ..\..
.PATH.obj	= $(POSTFIX)
.PATH.dll	= .
.PATH.lib	= .

!ifndef INCLUDE
INCLUDE 	= $(CCDIR)\h
!endif
INCLUDE 	= $(.PATH.h);$(INCLUDE)

!ifndef LIB
LIB		= $(CCDIR)\lib386\os2
!endif
LIB	 	= $(.PATH.lib);$(LIB)

#-----------------------------------------------------------------------------
#	Dependency maker
#-----------------------------------------------------------------------------

MD	= makedep
MDFLAGS = /I$(.PATH.h) /O$(DEPEND) /A$(MAKEFILE)

#-----------------------------------------------------------------------------
#	Implicit rules
#-----------------------------------------------------------------------------

CFLAGS	= $(CFLAGS) -DPROJLEVEL=$(PROJLEVEL) -i=$(INCLUDE)

.suffixes:
.suffixes: .CPP .C .ASM

.asm.obj:
	$(AS) $(AFLAGS) $<

.c.obj:
	$(CC) $(CFLAGS) /fo=$@ $<

.cpp.obj:
	$(CC) $(CFLAGS) /fo=$@ $<

#-----------------------------------------------------------------------------
#   	Target files
#
#	Does *not* include TIMESTMP.OBJ, although that file will be
#	included in the library.
#-----------------------------------------------------------------------------

FILELIST 	= ..\filelist.mak
OBJ	 	= obj

!include $(FILELIST)

OBJECTS		= $(FILES:+PRE\=)
LIBFILES 	= $(FILES:PRE=$(.PATH.obj))
DLLFILES 	= $(FILES:+PRE=$(.PATH.obj))

BASENAME  	= tlx$(POSTFIX)
CCONFIG   	= $(BASENAME).cfg
DEFFILE   	= $(BASENAME).def
LIBRSP	  	= $(BASENAME).rsp
TARGET	  	= $(BASENAME).lib
DLLTARGET 	= $(BASENAME).dll
TEST	  	= $(BASENAME).exe
TESTRSP	  	= $(BASENAME).lnk

#-----------------------------------------------------------------------------
#	Default target checks if output directory exists, then builds
#	compiler configuration file and target library
#-----------------------------------------------------------------------------

all:	start $(CCONFIG) timestamp timestmp.obj $(TARGET) $(TEST)

start:
	-@if not exist $(.PATH.obj)\*.* md $(.PATH.obj)

timestamp:
	-touch $(.PATH.cpp)\timestmp.cpp

#-----------------------------------------------------------------------------
#	Library file target
#-----------------------------------------------------------------------------

!ifdef LL	#-------- DLL target

$(TARGET): $(SUBTARGET)
	implib $(.PATH.lib)\$(TARGET) $(.PATH.dll)\$(SUBTARGET)

$(DLLTARGET): $(OBJECTS) libmain.obj $(XLIBS)
	@-del $(.PATH.dll)\$(DLLTARGET) >nul
	$(LINK) @$(LIBRSP)

$(LIBRSP): $(MAKEFILE) $(FILELIST)
	copy &&|
$(LFLAGS) /L$(LIB) $(STARTUP) +
$(DLLFILES) $(.PATH.obj)\timestmp.obj
$(.PATH.dll)\$(DLLTARGET)

$(XLIBS) $(RUNTIME)
$(DEFFILE)
| $(LIBRSP)

!else		#-------- Static library target

$(TARGET): $(OBJECTS) $(LIBRSP)
	@-del $(.PATH.lib)\$(TARGET) >nul
	$(LIBR) @$(LIBRSP)

$(LIBRSP): $(MAKEFILE) $(FILELIST)
	copy &&|
$(BFLAGS) $(.PATH.lib)\$(TARGET)
$(LIBFILES) +$(.PATH.obj)\timestmp.obj
| $(LIBRSP)

!endif

#-----------------------------------------------------------------------------
#	Test program target
#-----------------------------------------------------------------------------

!ifdef DOS

$(TEST): $(TARGET) maintest.obj $(TESTRSP)
	$(LINK) @$(TESTRSP)
	$(TEST)

$(TESTRSP): $(MAKEFILE)
	copy &&|
$(LFLAGS)
LIBP $(LIB)
F $(.PATH.obj)\maintest.obj
N $(TEST)
L $(TARGET)
| $(TESTRSP)

!else

$(TEST): $(TARGET) maintest.obj $(DEFFILE) $(TESTRSP)
	$(LINK) @$(TESTRSP)
	$(TEST)

$(TESTRSP): $(MAKEFILE)
	copy &&|
$(LFLAGS)
LIBP $(LIB)
F $(.PATH.obj)\maintest.obj
N $(TEST)
L $(TARGET)
SEG TYPE CODE PRELOAD EXECUTEREAD
SEG TYPE DATA PRELOAD
| $(TESTRSP)

!endif

#-----------------------------------------------------------------------------
#	Compiler configuration file
#-----------------------------------------------------------------------------

$(CCONFIG): $(MAKEFILE)
	copy &&|
$(CFLAGS)
-DPROJLEVEL=$(PROJLEVEL)
-i=$(INCLUDE)
| $(CCONFIG)

#-----------------------------------------------------------------------------
#	Linker definition file
#-----------------------------------------------------------------------------

!if $d(DOS)

$(DEFFILE): $(MAKEFILE)
	copy &&|
; Linker definition file for $(TEST)
;
; Copyright (c) 1994 Tarma Software Research. All rights reserved.
| $(DEFFILE)

!elif $d(OS2)

$(DEFFILE): $(MAKEFILE)
	copy &&|
; Linker definition file for $(TEST)
;
; Copyright (c) 1994 Tarma Software Research. All rights reserved.

EXETYPE 	OS2

CODE	PRELOAD EXECUTEREAD
DATA	PRELOAD MULTIPLE

HEAPSIZE	4096
STACKSIZE	8192
| $(DEFFILE)

!else

$(DEFFILE): $(MAKEFILE)
	copy &&|
; Linker definition file for $(TEST)
;
; Copyright (c) 1994 Tarma Software Research. All rights reserved.

EXETYPE 	WINDOWS

CODE	PRELOAD MOVEABLE DISCARDABLE
DATA	PRELOAD MOVEABLE MULTIPLE

HEAPSIZE	4096
STACKSIZE	8192
| $(DEFFILE)

!endif

#-----------------------------------------------------------------------------
#	Tracing DLL & import library targets
#-----------------------------------------------------------------------------

!if $d(WIN)

tlxtrace: tlxtrace.lib

tlxtrace.lib: tlxtr$(TLXVER).dll
	IMPLIB $(.PATH.lib)\tlxtrace.lib $(.PATH.dll)\tlxtr$(TLXVER).dll

tlxtr$(TLXVER).dll: tracelib.def tracelib.cpp
	$(CC) -v -c -WDE -d -G- -I$(INCLUDE) -m$(M) -O1 -w -D_TRACEBUILD $(.PATH.cpp)\tracelib.cpp
	$(LINK) /v /c /yx /L$(LIB) /Twd C0D$(M).OBJ tracelib.obj, \
	     $(.PATH.dll)\tlxtr$(TLXVER).dll,,CW$(M).LIB MATHW$(M).LIB \
	     IMPORT.LIB, tracelib.def

!endif

#-----------------------------------------------------------------------------
#	Explicit rules
#-----------------------------------------------------------------------------

clean:
	del *.bak *.map *.sym *.obj

depend:
	$(MD) $(MDFLAGS) $(.PATH.cpp)\*.cpp

version:
	ci /q /u *.c *.cpp *.h $(MAKEFILE)

#-----------------------------------------------------------------------------
#	File dependencies
#-----------------------------------------------------------------------------

!include $(DEPEND)
