#
# Quake3 Unix Game Makefile
#
# GNU Make required
#

###
### These paths are where you probably want to change things
###

#The main Quake3 directory
BDIR=..

#This is the game dir
GAMEDIR=baseq3

#Where the source is, assumed to be same directory as this Makefile
SRCDIR=.

#Location of binaries
BINDIR=../bin
LCC=$(BINDIR)/lcc # -lccdir=$(BINDIR)/
Q3ASM=$(BINDIR)/q3asm


#############################################################################
##
## You shouldn't have to touch anything below here
##
#############################################################################

GDIR=$(SRCDIR)/game
CGDIR=$(SRCDIR)/cgame
UIDIR=$(SRCDIR)/ui

LCCFLAGS=-DQ3_VM -S -Wf-target=bytecode -Wf-g -I..\cgame -I..\game -I..\ui

DO_LCC=$(LCC) $(LCCFLAGS) -o $@ -c $<

TARGETS=\
	$(BDIR)/$(GAMEDIR)/vm/cgame.qvm \
	$(BDIR)/$(GAMEDIR)/vm/qagame.qvm \
	$(BDIR)/$(GAMEDIR)/vm/ui.qvm

default: makedir $(TARGETS)

makedir:
	@-mkdir $(GDIR)/vm
	@-mkdir $(CGDIR)/vm
	@-mkdir $(UIDIR)/vm

#############################################################################
# GAME VM
#############################################################################

##NOTE:  g_main must be first.  Control passes to first function in the vm

GVMASM = \
	$(GDIR)/vm/g_main.asm \
	$(GDIR)/vm/bg_misc.asm \
	$(GDIR)/vm/bg_lib.asm \
	$(GDIR)/vm/bg_pmove.asm \
	$(GDIR)/vm/bg_slidemove.asm \
	$(GDIR)/vm/q_math.asm \
	$(GDIR)/vm/q_shared.asm \
	$(GDIR)/vm/ai_dmnet.asm \
	$(GDIR)/vm/ai_dmq3.asm \
	$(GDIR)/vm/ai_team.asm \
	$(GDIR)/vm/ai_main.asm \
	$(GDIR)/vm/ai_chat.asm \
	$(GDIR)/vm/ai_cmd.asm \
	$(GDIR)/vm/g_active.asm \
	$(GDIR)/vm/g_arenas.asm \
	$(GDIR)/vm/g_bot.asm \
	$(GDIR)/vm/g_client.asm \
	$(GDIR)/vm/g_cmds.asm \
	$(GDIR)/vm/g_combat.asm \
	$(GDIR)/vm/g_items.asm \
	$(GDIR)/vm/g_mem.asm \
	$(GDIR)/vm/g_misc.asm \
	$(GDIR)/vm/g_missile.asm \
	$(GDIR)/vm/g_mover.asm \
	$(GDIR)/vm/g_session.asm \
	$(GDIR)/vm/g_spawn.asm \
	$(GDIR)/vm/g_svcmds.asm \
	$(GDIR)/vm/g_target.asm \
	$(GDIR)/vm/g_team.asm \
	$(GDIR)/vm/g_trigger.asm \
	$(GDIR)/vm/g_utils.asm \
	$(GDIR)/vm/g_weapon.asm

$(BDIR)/$(GAMEDIR)/vm/qagame.qvm : $(GVMASM)
	$(Q3ASM) -o $@ $(GVMASM) $(SRCDIR)/game/g_syscalls.asm

$(GDIR)/vm/ai_chat.asm : $(GDIR)/ai_chat.c; $(DO_LCC) 
$(GDIR)/vm/ai_cmd.asm : $(GDIR)/ai_cmd.c; $(DO_LCC) 
$(GDIR)/vm/ai_dmnet.asm : $(GDIR)/ai_dmnet.c; $(DO_LCC) 
$(GDIR)/vm/ai_dmq3.asm : $(GDIR)/ai_dmq3.c; $(DO_LCC) 
$(GDIR)/vm/ai_main.asm : $(GDIR)/ai_main.c; $(DO_LCC) 
$(GDIR)/vm/ai_team.asm : $(GDIR)/ai_team.c; $(DO_LCC) 
$(GDIR)/vm/bg_lib.asm : $(GDIR)/bg_lib.c; $(DO_LCC) 
$(GDIR)/vm/bg_misc.asm : $(GDIR)/bg_misc.c; $(DO_LCC) 
$(GDIR)/vm/bg_pmove.asm : $(GDIR)/bg_pmove.c; $(DO_LCC) 
$(GDIR)/vm/bg_slidemove.asm : $(GDIR)/bg_slidemove.c; $(DO_LCC) 
$(GDIR)/vm/g_active.asm : $(GDIR)/g_active.c; $(DO_LCC) 
$(GDIR)/vm/g_arenas.asm : $(GDIR)/g_arenas.c; $(DO_LCC) 
$(GDIR)/vm/g_bot.asm : $(GDIR)/g_bot.c; $(DO_LCC) 
$(GDIR)/vm/g_client.asm : $(GDIR)/g_client.c; $(DO_LCC) 
$(GDIR)/vm/g_cmds.asm : $(GDIR)/g_cmds.c; $(DO_LCC) 
$(GDIR)/vm/g_combat.asm : $(GDIR)/g_combat.c; $(DO_LCC) 
$(GDIR)/vm/g_items.asm : $(GDIR)/g_items.c; $(DO_LCC) 
$(GDIR)/vm/g_main.asm : $(GDIR)/g_main.c; $(DO_LCC) 
$(GDIR)/vm/g_mem.asm : $(GDIR)/g_mem.c; $(DO_LCC) 
$(GDIR)/vm/g_misc.asm : $(GDIR)/g_misc.c; $(DO_LCC) 
$(GDIR)/vm/g_missile.asm : $(GDIR)/g_missile.c; $(DO_LCC) 
$(GDIR)/vm/g_mover.asm : $(GDIR)/g_mover.c; $(DO_LCC) 
$(GDIR)/vm/g_session.asm : $(GDIR)/g_session.c; $(DO_LCC) 
$(GDIR)/vm/g_spawn.asm : $(GDIR)/g_spawn.c; $(DO_LCC) 
$(GDIR)/vm/g_svcmds.asm : $(GDIR)/g_svcmds.c; $(DO_LCC) 
$(GDIR)/vm/g_target.asm : $(GDIR)/g_target.c; $(DO_LCC) 
$(GDIR)/vm/g_team.asm : $(GDIR)/g_team.c; $(DO_LCC) 
$(GDIR)/vm/g_trigger.asm : $(GDIR)/g_trigger.c; $(DO_LCC) 
$(GDIR)/vm/g_utils.asm : $(GDIR)/g_utils.c; $(DO_LCC) 
$(GDIR)/vm/g_weapon.asm : $(GDIR)/g_weapon.c; $(DO_LCC) 
$(GDIR)/vm/q_math.asm : $(GDIR)/q_math.c; $(DO_LCC) 
$(GDIR)/vm/q_shared.asm : $(GDIR)/q_shared.c; $(DO_LCC) 

$(BDIR)/$(GAMEDIR)/vm/cgame.qvm : 
	echo cgame.qvm disabled

$(BDIR)/$(GAMEDIR)/vm/ui.qvm : 
	echo ui.qvm disabled

#############################################################################
# CGAME
#############################################################################

CGOBJ = \
	$(SRCDIR)/cgame/bg_lib.o \
	$(SRCDIR)/cgame/bg_misc.o \
	$(SRCDIR)/cgame/bg_pmove.o \
	$(SRCDIR)/cgame/bg_slidemove.o \
	$(SRCDIR)/cgame/cg_consolecmds.o \
	$(SRCDIR)/cgame/cg_draw.o \
	$(SRCDIR)/cgame/cg_drawtools.o \
	$(SRCDIR)/cgame/cg_effects.o \
	$(SRCDIR)/cgame/cg_ents.o \
	$(SRCDIR)/cgame/cg_event.o \
	$(SRCDIR)/cgame/cg_info.o \
	$(SRCDIR)/cgame/cg_localents.o \
	$(SRCDIR)/cgame/cg_main.o \
	$(SRCDIR)/cgame/cg_marks.o \
	$(SRCDIR)/cgame/cg_players.o \
	$(SRCDIR)/cgame/cg_playerstate.o \
	$(SRCDIR)/cgame/cg_predict.o \
	$(SRCDIR)/cgame/cg_scoreboard.o \
	$(SRCDIR)/cgame/cg_servercmds.o \
	$(SRCDIR)/cgame/cg_snapshot.o \
	$(SRCDIR)/cgame/cg_view.o \
	$(SRCDIR)/cgame/cg_weapons.o \
	$(SRCDIR)/cgame/q_math.o \
	$(SRCDIR)/cgame/q_shared.o

$(SRCDIR)/cgame$(ARCH).$(SHLIBEXT) : $(CGOBJ)
	$(CC) $(CFLAGS) $(SHLIBLDFLAGS) -o $@ $(CGOBJ)

$(SRCDIR)/cgame/bg_lib.o : $(GDIR)/bg_lib.c; $(DO_SHLIB_CC) 
$(SRCDIR)/cgame/bg_misc.o : $(GDIR)/bg_misc.c; $(DO_SHLIB_CC) 
$(SRCDIR)/cgame/bg_pmove.o : $(GDIR)/bg_pmove.c; $(DO_SHLIB_CC) 
$(SRCDIR)/cgame/bg_slidemove.o : $(GDIR)/bg_slidemove.c; $(DO_SHLIB_CC) 
$(SRCDIR)/cgame/cg_consolecmds.o : $(CGDIR)/cg_consolecmds.c; $(DO_SHLIB_CC) 
$(SRCDIR)/cgame/cg_draw.o : $(CGDIR)/cg_draw.c; $(DO_SHLIB_CC) 
$(SRCDIR)/cgame/cg_drawtools.o : $(CGDIR)/cg_drawtools.c; $(DO_SHLIB_CC) 
$(SRCDIR)/cgame/cg_effects.o : $(CGDIR)/cg_effects.c; $(DO_SHLIB_CC) 
$(SRCDIR)/cgame/cg_ents.o : $(CGDIR)/cg_ents.c; $(DO_SHLIB_CC) 
$(SRCDIR)/cgame/cg_event.o : $(CGDIR)/cg_event.c; $(DO_SHLIB_CC) 
$(SRCDIR)/cgame/cg_info.o : $(CGDIR)/cg_info.c; $(DO_SHLIB_CC) 
$(SRCDIR)/cgame/cg_localents.o : $(CGDIR)/cg_localents.c; $(DO_SHLIB_CC) 
$(SRCDIR)/cgame/cg_main.o : $(CGDIR)/cg_main.c; $(DO_SHLIB_CC) 
$(SRCDIR)/cgame/cg_marks.o : $(CGDIR)/cg_marks.c; $(DO_SHLIB_CC) 
$(SRCDIR)/cgame/cg_players.o : $(CGDIR)/cg_players.c; $(DO_SHLIB_CC) 
$(SRCDIR)/cgame/cg_playerstate.o : $(CGDIR)/cg_playerstate.c; $(DO_SHLIB_CC) 
$(SRCDIR)/cgame/cg_predict.o : $(CGDIR)/cg_predict.c; $(DO_SHLIB_CC) 
$(SRCDIR)/cgame/cg_scoreboard.o : $(CGDIR)/cg_scoreboard.c; $(DO_SHLIB_CC) 
$(SRCDIR)/cgame/cg_servercmds.o : $(CGDIR)/cg_servercmds.c; $(DO_SHLIB_CC) 
$(SRCDIR)/cgame/cg_snapshot.o : $(CGDIR)/cg_snapshot.c; $(DO_SHLIB_CC) 
$(SRCDIR)/cgame/cg_view.o : $(CGDIR)/cg_view.c; $(DO_SHLIB_CC) 
$(SRCDIR)/cgame/cg_weapons.o : $(CGDIR)/cg_weapons.c; $(DO_SHLIB_CC) 
$(SRCDIR)/cgame/q_math.o : $(GDIR)/q_math.c; $(DO_SHLIB_CC) 
$(SRCDIR)/cgame/q_shared.o : $(GDIR)/q_shared.c; $(DO_SHLIB_CC) 

#############################################################################
# UI
#############################################################################

UIOBJ = \
	$(SRCDIR)/ui/bg_lib.o \
	$(SRCDIR)/ui/bg_misc.o \
	$(SRCDIR)/ui/ui_addbots.o \
	$(SRCDIR)/ui/ui_atoms.o \
	$(SRCDIR)/ui/ui_cinematics.o \
	$(SRCDIR)/ui/ui_confirm.o \
	$(SRCDIR)/ui/ui_connect.o \
	$(SRCDIR)/ui/ui_controls2.o \
	$(SRCDIR)/ui/ui_credits.o \
	$(SRCDIR)/ui/ui_demo2.o \
	$(SRCDIR)/ui/ui_display.o \
	$(SRCDIR)/ui/ui_gameinfo.o \
	$(SRCDIR)/ui/ui_ingame.o \
	$(SRCDIR)/ui/ui_loadconfig.o \
	$(SRCDIR)/ui/ui_main.o \
	$(SRCDIR)/ui/ui_menu.o \
	$(SRCDIR)/ui/ui_mfield.o \
	$(SRCDIR)/ui/ui_network.o \
	$(SRCDIR)/ui/ui_playermodel.o \
	$(SRCDIR)/ui/ui_players.o \
	$(SRCDIR)/ui/ui_playersettings.o \
	$(SRCDIR)/ui/ui_preferences.o \
	$(SRCDIR)/ui/ui_qmenu.o \
	$(SRCDIR)/ui/ui_saveconfig.o \
	$(SRCDIR)/ui/ui_serverinfo.o \
	$(SRCDIR)/ui/ui_servers2.o \
	$(SRCDIR)/ui/ui_setup.o \
	$(SRCDIR)/ui/ui_sound.o \
	$(SRCDIR)/ui/ui_sparena.o \
	$(SRCDIR)/ui/ui_specifyserver.o \
	$(SRCDIR)/ui/ui_splevel.o \
	$(SRCDIR)/ui/ui_sppostgame.o \
	$(SRCDIR)/ui/ui_spskill.o \
	$(SRCDIR)/ui/ui_startserver.o \
	$(SRCDIR)/ui/ui_team.o \
	$(SRCDIR)/ui/ui_video.o \
	\
	$(SRCDIR)/ui/q_math.o \
	$(SRCDIR)/ui/q_shared.o

$(SRCDIR)/ui$(ARCH).$(SHLIBEXT) : $(UIOBJ)
	$(CC) $(CFLAGS) $(SHLIBLDFLAGS) -o $@ $(UIOBJ)

$(SRCDIR)/ui/bg_lib.o : $(GDIR)/bg_lib.c; $(DO_CC) 
$(SRCDIR)/ui/bg_misc.o : $(GDIR)/bg_misc.c; $(DO_CC) 
$(SRCDIR)/ui/ui_addbots.o : $(UIDIR)/ui_addbots.c; $(DO_CC) 
$(SRCDIR)/ui/ui_atoms.o : $(UIDIR)/ui_atoms.c; $(DO_CC) 
$(SRCDIR)/ui/ui_cinematics.o : $(UIDIR)/ui_cinematics.c; $(DO_CC) 
$(SRCDIR)/ui/ui_confirm.o : $(UIDIR)/ui_confirm.c; $(DO_CC) 
$(SRCDIR)/ui/ui_connect.o : $(UIDIR)/ui_connect.c; $(DO_CC) 
$(SRCDIR)/ui/ui_controls2.o : $(UIDIR)/ui_controls2.c; $(DO_CC) 
$(SRCDIR)/ui/ui_credits.o : $(UIDIR)/ui_credits.c; $(DO_CC) 
$(SRCDIR)/ui/ui_demo2.o : $(UIDIR)/ui_demo2.c; $(DO_CC) 
$(SRCDIR)/ui/ui_display.o : $(UIDIR)/ui_display.c; $(DO_CC) 
$(SRCDIR)/ui/ui_gameinfo.o : $(UIDIR)/ui_gameinfo.c; $(DO_CC) 
$(SRCDIR)/ui/ui_ingame.o : $(UIDIR)/ui_ingame.c; $(DO_CC) 
$(SRCDIR)/ui/ui_loadconfig.o : $(UIDIR)/ui_loadconfig.c; $(DO_CC) 
$(SRCDIR)/ui/ui_main.o : $(UIDIR)/ui_main.c; $(DO_CC) 
$(SRCDIR)/ui/ui_menu.o : $(UIDIR)/ui_menu.c; $(DO_CC) 
$(SRCDIR)/ui/ui_mfield.o : $(UIDIR)/ui_mfield.c; $(DO_CC) 
$(SRCDIR)/ui/ui_network.o : $(UIDIR)/ui_network.c; $(DO_CC) 
$(SRCDIR)/ui/ui_playermodel.o : $(UIDIR)/ui_playermodel.c; $(DO_CC) 
$(SRCDIR)/ui/ui_players.o : $(UIDIR)/ui_players.c; $(DO_CC) 
$(SRCDIR)/ui/ui_playersettings.o : $(UIDIR)/ui_playersettings.c; $(DO_CC) 
$(SRCDIR)/ui/ui_preferences.o : $(UIDIR)/ui_preferences.c; $(DO_CC) 
$(SRCDIR)/ui/ui_qmenu.o : $(UIDIR)/ui_qmenu.c; $(DO_CC) 
$(SRCDIR)/ui/ui_quit.o : $(UIDIR)/ui_quit.c; $(DO_CC) 
$(SRCDIR)/ui/ui_saveconfig.o : $(UIDIR)/ui_saveconfig.c; $(DO_CC) 
$(SRCDIR)/ui/ui_serverinfo.o : $(UIDIR)/ui_serverinfo.c; $(DO_CC) 
$(SRCDIR)/ui/ui_servers2.o : $(UIDIR)/ui_servers2.c; $(DO_CC) 
$(SRCDIR)/ui/ui_setup.o : $(UIDIR)/ui_setup.c; $(DO_CC) 
$(SRCDIR)/ui/ui_sound.o : $(UIDIR)/ui_sound.c; $(DO_CC) 
$(SRCDIR)/ui/ui_sparena.o : $(UIDIR)/ui_sparena.c; $(DO_CC) 
$(SRCDIR)/ui/ui_specifyserver.o : $(UIDIR)/ui_specifyserver.c; $(DO_CC) 
$(SRCDIR)/ui/ui_splevel.o : $(UIDIR)/ui_splevel.c; $(DO_CC) 
$(SRCDIR)/ui/ui_sppostgame.o : $(UIDIR)/ui_sppostgame.c; $(DO_CC) 
$(SRCDIR)/ui/ui_spskill.o : $(UIDIR)/ui_spskill.c; $(DO_CC) 
$(SRCDIR)/ui/ui_startserver.o : $(UIDIR)/ui_startserver.c; $(DO_CC) 
$(SRCDIR)/ui/ui_team.o : $(UIDIR)/ui_team.c; $(DO_CC) 
$(SRCDIR)/ui/ui_video.o : $(UIDIR)/ui_video.c; $(DO_CC) 
$(SRCDIR)/ui/q_math.o : $(GDIR)/q_math.c; $(DO_SHLIB_CC) 
$(SRCDIR)/ui/q_shared.o : $(GDIR)/q_shared.c; $(DO_SHLIB_CC) 

#############################################################################
# MISC
#############################################################################

clean:
	rm -f $(GVMASM)
