# Necessary changes for the code to work with DJGPP:
# 1. Remove the "static" statement for the isDedicated variable in SYS_DOS.C
# 2. Add the following to lines to SYS_DOS.C to fix the memory detection bug
#    #include <crt0.h>
#    int _crt0_startup_flags = _CRT0_FLAG_UNIX_SBRK;
# 3. There are more bugs in DOSQuake, for a list of known Quake bugs visit
#    the Quake Info Pool through http://www.bigfoot.com/~maddes (redirection)
# --------------------------------------------------------------------------
#
# General and compiler variables
#
CC=gcc

CFLAGS=-O9 -march=i586 -fomit-frame-pointer -ffast-math -DDOSQUAKE
LDFLAGS=
LIBS=-lm

ifdef DEBUG
	CFLAGS+=-gstabs+3 -O0 -fno-omit-frame-pointer -fno-fast-math
else
	CFLAGS+=-DNDEBUG
	LDFLAGS+=-s
endif

# Executable
BUILD=QUAKE.EXE

all:    $(BUILD)

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

%.o : %.s
	@echo Assembling $<
	@$(CC) $(CFLAGS) -x assembler-with-cpp -c $<

# Source files
NET= \
	net_dgrm.o \
	net_loop.o \
	net_main.o \

RENDER= \
	r_aclip.o \
	r_alias.o \
	r_aliasa.o \
	r_bsp.o \
	r_draw.o \
	r_edge.o \
	r_edgea.o \
	r_efrag.o \
	r_light.o \
	r_main.o \
	r_misc.o \
	r_part.o \
	r_sky.o \
	r_sprite.o \
	r_surf.o \
    r_vars.o \
    r_varsa.o


DRAW= \
 	d_copy.o \
	d_draw.o \
	d_draw16.o \
	d_edge.o \
	d_init.o \
	d_modech.o \
	d_part.o \
	d_polyse.o \
	d_polysa.o \
	d_scan.o \
	d_scana.o \
	d_sky.o \
	d_spr8.o \
	d_sprite.o \
	d_surf.o \
	d_vars.o \
	d_varsa.o \
	d_zpoint.o

CLIENT= \
	cl_demo.o \
	cl_input.o \
	cl_main.o \
	cl_parse.o \
	cl_tent.o

SERVER= \
	sv_main.o \
	sv_move.o \
	sv_phys.o \
	sv_user.o

SOUND= \
	snd_mixa.o \
	snd_dma.o \
	snd_mem.o \
	snd_mix.o

PROGRAMS= \
	pr_cmds.o \
	pr_edict.o \
	pr_exec.o

DOS= \
	vsnprintf.o \
    	cd_null.o \
	dos_v2.o \
	in_dos.o \
	mplib.o \
	mplpc.o \
	net_bw.o \
	net_dos.o \
	net_ipx.o \
	net_mp.o \
	net_ser.o \
	snd_dos.o \
	snd_gus.o \
	sys_dos.o \
	vid_vga.o \
	vid_ext.o \
	vid_dos.o \
	vregset.o \

OBJS= \
	$(CLIENT) \
	$(DRAW) \
	$(NET) \
	$(PROGRAMS) \
	$(RENDER) \
	$(SERVER) \
	$(SOUND) \
	$(DOS) \
	chase.o \
	cmd.o \
	common.o \
	console.o \
	crc.o \
	cvar.o \
	draw.o \
	host.o \
	host_cmd.o \
	keys.o \
	mathlib.o \
	menu.o \
	model.o \
	nonintel.o \
	sbar.o \
	screen.o \
	view.o \
	wad.o \
	world.o \
	zone.o


# Executable
$(BUILD) : $(OBJS)
	$(CC) $(LDFLAGS) $(OBJS) -o $(BUILD) $(LIBS)

#
# Cleaning procedures
#
clean:
	rm -f *.o $(BUILD)
