# Build Makefile for Watcom Make

!ifdef OVERRIDES
!include $(OVERRIDES)
!endif

SRC=src
!ifndef OBJ
OBJ=obj.watcom
!endif
INC=include
!ifndef CFLAGS
CFLAGS=-dSUPERBUILD -dPOLYMOST -dUSE_OPENGL -dKSFORBUILD
!endif

o=obj
res=res
asm=wasm

ENGINELIB=engine.lib
EDITORLIB=build.lib

DXROOT=c:\sdks\directx\dx7

!ifdef __LOADDLL__
! loaddll wcc386 wccd386
! loaddll wpp386 wppd386
!endif

# -d these to enable certain features of the port's compile process
# NOASM     When defined, uses C code instead assembly code
TARGETOPTS=#-dNOASM

CC=wcc386
CXX=wpp386
AS=wasm
RC=wrc
CFLAGS+= -zq -5r -s -orb -fp5 $(TARGETOPTS) -d2 -dRENDERTYPEWIN=1 &
	-i=$(INC) -i=$(SRC) -i=$(DXROOT)\include -i=..\jfaud\inc
LIBS=dxguid.lib wsock32.lib ..\jfaud\jfaud.lib winmm.lib #opengl32.lib
ASFLAGS=# -d1
EXESUFFIX=.exe

ENGINEOBJS=$(OBJ)\a.$o &
	$(OBJ)\baselayer.$o &
	$(OBJ)\cache1d.$o &
	$(OBJ)\compat.$o &
	$(OBJ)\crc32.$o &
	$(OBJ)\defs.$o &
	$(OBJ)\engine.$o &
	$(OBJ)\glbuild.$o &
	$(OBJ)\kplib.$o &
	$(OBJ)\lzf_c.$o &
	$(OBJ)\lzf_d.$o &
	$(OBJ)\lzwnew.$o &
	$(OBJ)\md4.$o &
	$(OBJ)\mmulti.$o &
	$(OBJ)\osd.$o &
	$(OBJ)\pragmas.$o &
	$(OBJ)\scriptfile.$o &
	$(OBJ)\winlayer.$o

EDITOROBJS=$(OBJ)\build.$o &
	$(OBJ)\config.$o &
	$(OBJ)\startwin.editor.$o

# RULES
.EXTENSIONS: .wasm .res .rc

.wasm:	$(SRC)
.c:	$(SRC)
.cpp:	$(SRC)
.c:	$(SRC)\util
.rc:	$(SRC)\misc

.wasm.$o:
	$(AS) $(ASFLAGS) -fo=$(OBJ)\.$o $[@

.c.$o:
	$(CC) $(CFLAGS) -fo=$(OBJ)\.$o $[@

.rc.$(res):
	$(RC) -i=$(SRC) -i=$(INC) -fo=$^*.$(res) -r $[@

# TARGETS
UTILS=kextract$(EXESUFFIX) kgroup$(EXESUFFIX) transpal$(EXESUFFIX) wad2art$(EXESUFFIX) wad2map$(EXESUFFIX)

all: .SYMBOLIC
	%null

utils: $(UTILS) .SYMBOLIC
	%null

enginelib: $(OBJ)\$(ENGINELIB) .SYMBOLIC
	%null

$(OBJ)\$(ENGINELIB): $(ENGINEOBJS)
	%create $(OBJ)\$(ENGINELIB).tmp
	for %i in ($(ENGINEOBJS)) do %append $(OBJ)\$(ENGINELIB).tmp +%i
	wlib -b -n $^* @$(OBJ)\$(ENGINELIB).tmp
	erase $(OBJ)\$(ENGINELIB).tmp

editorlib: $(OBJ)\$(EDITORLIB) .SYMBOLIC
	%null

$(OBJ)\$(EDITORLIB): $(EDITOROBJS)
	%create $(OBJ)\$(EDITORLIB).tmp
	for %i in ($(EDITOROBJS)) do %append $(OBJ)\$(EDITORLIB).tmp +%i
	wlib -b -n $^* @$(OBJ)\$(EDITORLIB).tmp
	erase $(OBJ)\$(EDITORLIB).tmp

kextract$(EXESUFFIX): $(OBJ)\kextract.$o $(OBJ)\compat.$o
	wlink	NAME $@  SYSTEM 386  DEBUG ALL  FILE { $< }
kgroup$(EXESUFFIX): $(OBJ)\kgroup.$o $(OBJ)\compat.$o
	wlink	NAME $@  SYSTEM 386  DEBUG ALL  FILE { $< }
transpal$(EXESUFFIX): $(OBJ)\transpal.$o $(OBJ)\pragmas.$o $(OBJ)\compat.$o
	wlink	NAME $@  SYSTEM 386  DEBUG ALL  FILE { $< }
wad2art$(EXESUFFIX): $(OBJ)\wad2art.$o $(OBJ)\pragmas.$o $(OBJ)\compat.$o
	wlink	NAME $@  SYSTEM 386  DEBUG ALL  FILE { $< }
wad2map$(EXESUFFIX): $(OBJ)\wad2map.$o $(OBJ)\pragmas.$o $(OBJ)\compat.$o
	wlink	NAME $@  SYSTEM 386  DEBUG ALL  FILE { $< }

# DEPENDENCIES
!include Makefile.deps

# PHONIES	
clean: .SYMBOLIC
	-erase /q $(OBJ)\* $(UTILS) *.err