# gamespy/server browser:
USE_GAMESPY=1

# build tools:
CC = gcc
RC = windres

# build flags:
INCLUDES = -Iclient -Igame -Iqcommon -Iserver -IGoa -IGoa/CEngine
CPPFLAGS = -DSIN
# comment this out to enable assertions:
CPPFLAGS+= -DNDEBUG
CPPFLAGS+= -Did386=0
CPPFLAGS+= -DSPLIT_NETWORK_FRAME=1
CPPFLAGS+= $(INCLUDES)

ifeq ($(DEBUG),1)
CFLAGS = -g
else
CFLAGS = -O2
endif
CFLAGS+= -m64 -Wall
CFLAGS+= -ffast-math
#CFLAGS+= -fwrapv

LDFLAGS = -m64 -mwindows
LDLIBS = -lwinmm -lws2_32
# for cin_win.c crap:
LDLIBS+= -lole32 -lddraw -lquartz -lstrmiids
EXE = sin.exe
SPEECH = speech/libspeech.a

ifeq ($(USE_GAMESPY),1)
CPPFLAGS+= -DGAMESPY
endif

WIN32 = win32/net_wins.o \
	win32/q_shwin.o \
	win32/sys_win.o

WIN32RES = win32/sin.res

WIN32CLIENT = win32/cd_win.o \
	win32/in_win.o \
	win32/snd_win.o \
	win32/cin_win.o \
	win32/vid_dll.o

CLIENT = client/cl_bspline.o \
	client/cl_console.o \
	client/cl_ents.o \
	client/cl_fx.o \
	client/cl_hud.o \
	client/cl_input.o \
	client/cl_inv.o \
	client/cl_main.o \
	client/cl_parse.o \
	client/cl_pred.o \
	client/cl_scrn.o \
	client/cl_sincmds.o \
	client/cl_sinfx.o \
	client/cl_surface.o \
	client/cl_tent.o \
	client/cl_view.o \
	client/console3d.o \
	client/keys.o \
	client/ltstyle.o \
	client/menu3d.o \
	client/menu3d_pl.o \
	client/snd_dma.o \
	client/snd_mem.o \
	client/snd_mix.o \
	client/snd_music.o
CL_SPEECH = $(SPEECH)
LIB_SPEECH = -Lspeech -lspeech

ifeq ($(USE_GAMESPY),1)
GAMESPYCLIENT = client/cl_gamespy.o \
	Goa/CEngine/gserverlist.o

GAMESPY = Goa/CEngine/gdarray.o \
	Goa/CEngine/gserver.o \
	Goa/CEngine/gutil.o \
	Goa/CEngine/hashtable.o \
	Goa/nonport.o \
	server/sv_gamespy.o \
	server/sv_gqueryreporting.o
endif

QCOMMON = qcommon/alias.o \
	qcommon/cmd.o \
	qcommon/cmodel.o \
	qcommon/common.o \
	qcommon/crc.o \
	qcommon/cvar.o \
	qcommon/files.o \
	qcommon/glob.o \
	qcommon/md4.o \
	qcommon/net_chan.o \
	qcommon/pmove.o \
	qcommon/sinmdl.o \
	qcommon/wave.o \
	game/q_shared.o

SERVER = server/sv_ccmds.o \
	server/sv_ents.o \
	server/sv_game.o \
	server/sv_init.o \
	server/sv_main.o \
	server/sv_send.o \
	server/sv_user.o \
	server/sv_world.o

OBJECTS = $(CLIENT) $(QCOMMON) $(SERVER) $(GAMESPY) $(GAMESPYCLIENT) $(WIN32CLIENT) $(WIN32) $(WIN32RES)


.PHONY: clean

all: $(EXE)

$(EXE): $(OBJECTS) $(CL_SPEECH)
	$(CC) -o $(EXE) $(LDFLAGS) $(OBJECTS) $(LIB_SPEECH) $(LDLIBS)

$(SPEECH):
	$(MAKE) -C speech WIN64=1

clean:
	rm -f qcommon/*.o
	rm -f client/*.o
	rm -f server/*.o
	rm -f win32/*.o
	rm -f win32/*.res
	rm -f null/*.o
	rm -f speech/*.o
	rm -f speech/*.a
	rm -f Goa/*.o
	rm -f Goa/CEngine/*.o
	rm -f game/*.o

%.o: %.c
	$(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@

%.res: %.rc
	$(RC) --output-format=coff --target=pe-x86-64 -o $@ $<
