.autodepend
.cacheautodepend
.suffixes: .cpp

!ifndef BTYPE
!error BTYPE macro not supplied
!endif

!ifndef BPATH
!error BPATH macro not supplied
!endif

!include make.cfg
!include $(BPATH)

TARGET_DIR = $(BTL4_ROOT)\$(BTYPE)
TARGET_PATH = $(TARGET_DIR)\\
.path.obj = $(TARGET_DIR)
.path.lib = $(LIBRARY_PATH)

LIB_PREFIX = -+$(TARGET_DIR)\\

CFG_FILE = $(TARGET_DIR)\$(BTYPE).cfg
HEADER_FILE = btl4$(BTYPE).csm

#------------------------------------------------------------------------------
# Library targets
#
all:\
	$(CFG_FILE) $(TARGET_DIR)\btl4$(BTYPE).exe $(TARGET_DIR)\btl4tool.exe\
	$(TARGET_DIR)\mechbld.exe

clean:
	del $(TARGET_DIR)\*.obj
	del $(TARGET_DIR)\*.lib
	del $(TARGET_DIR)\*.exe
        del $(TARGET_DIR)\*.bak
        del $(TARGET_DIR)\*.cfg

assemble:
	@echo No assembly targets

#------------------------------------------------------------------------------
# Implicit rules
#
!include $(BTYPE).mak

!ifndef STARTUP_OBJ
!error STARTUP_OBJ macro is not defined
!endif

!ifndef STARTUP_LIBS
!error STARTUP_LIBS macro is not defined
!endif

{$(INCLUDE_PATH)}.cpp{$(TARGET_DIR)}.obj:
   $(BCC) @$(CFG_FILE) $< >>error.log

{$(INCLUDE_PATH)}.c{$(TARGET_DIR)}.obj:
	$(BCC) @$(CFG_FILE) $< >>error.log

{$(BTL4_ROOT)}.asm{$(TARGET_DIR)}.obj:
	tasm32 -ml $(TASM_OPTIONS) -i$(BTL4_ROOT) $<,$@ >>error.log

#------------------------------------------------------------------------------
# Game
#
$(TARGET_DIR)\btl4$(BTYPE).exe: \
		$(BTL4_ROOT)\btl4.mak l4stub.lib stub.lib $(TARGET_DIR)\btl4.lib\
		bt.lib mungal4.lib munga.lib btl4.obj $(BTYPE).mak\
		$(DPL_ROOT)\libdpl.lib
	tlink32 @&&|
$(LINK_OPTIONS) +
$(STARTUP_OBJ)+
$(TARGET_DIR)\btl4.obj
$<,$*
l4stub.lib+
stub.lib+
munga.lib+
mungal4.lib+
$(DPL_ROOT)\libdpl.lib+
bt.lib+
$(TARGET_DIR)\btl4.lib+
$(STARTUP_LIBS)
| >>error.log

btl4.obj: $(CFG_FILE)

#------------------------------------------------------------------------------
# Tools
#
$(TARGET_DIR)\btl4tool.exe: \
		$(BTL4_ROOT)\btl4.mak l4stub.lib stub.lib $(TARGET_DIR)\btl4.lib\
		bt.lib mungal4.lib munga.lib btl4tool.obj $(BTYPE).mak\
		$(DPL_ROOT)\libdpl.lib
	tlink32 @&&|
$(LINK_OPTIONS) +
$(STARTUP_OBJ)+
$(TARGET_DIR)\btl4tool.obj
$<,$*
l4stub.lib+
stub.lib+
munga.lib+
mungal4.lib+
$(DPL_ROOT)\libdpl.lib+
bt.lib+
$(TARGET_DIR)\btl4.lib+
$(STARTUP_LIBS)
| >>error.log

btl4tool.obj: $(CFG_FILE)

#------------------------------------------------------------------------------
# Mech builder
#
$(TARGET_DIR)\mechbld.exe:\
		$(BTL4_ROOT)\btl4.mak mechbld.obj stub.lib munga.lib $(BTYPE).mak
	tlink32 @&&|
$(LINK_OPTIONS) +
$(STARTUP_OBJ)+
$(TARGET_DIR)\mechbld.obj
$<,$*
stub.lib+
munga.lib+
$(STARTUP_LIBS)
| >>error.log

mechbld.obj: $(BCC_CONFIG) $(BTYPE).mak

#------------------------------------------------------------------------------
# Battletech library
#
BTL4_OBJS = \
	?btl4mode.obj \
	?btl4rdr.obj \
	?btl4gaug.obj \
	?btl4gau2.obj \
	?btl4gau3.obj \
	?btl4grnd.obj \
	?btl4galm.obj \
	?btl4vid.obj \
	?btl4mppr.obj \
	?btl4arnd.obj \
	?btl4mssn.obj \
	?btl4app.obj \
	?btl4pb.obj

$(BTL4_OBJS:?=): $(CFG_FILE)

$(TARGET_DIR)\btl4.lib: $(BTL4_OBJS:?=) $(BTL4_ROOT)\btl4.mak
	tlib $@ $(LIB_OPTIONS) @&&|
$(BTL4_OBJS:?=$(LIB_PREFIX))
| >>error.log
