CC = gcc

# asm optimizations:
USE_ASM=1

CFLAGS = -Wall -O2
CFLAGS+= -fomit-frame-pointer
CFLAGS+= -ffast-math
CPPFLAGS = -DSIN
# comment this out to enable assertions:
CPPFLAGS+= -DNDEBUG
CPPFLAGS+= -I../client -I../qcommon -I../game
DXE3GEN = dxe3gen

ifeq ($(USE_ASM),1)
CPPFLAGS+= -Did386=1
else
CPPFLAGS+= -Did386=0
endif

ifeq ($(USE_SSE),1)
CFLAGS += -march=pentium3
endif

REFSOFT = ../game/q_shared.o \
	../dos/q_shdos.o \
	../dos/swimp_dos.o \
	../dos/vid_ext.o \
	../dos/vregset.o \
	r_alias.o \
	r_main.o \
	r_light.o \
	r_misc.o \
	r_model.o \
	r_spritemod.o \
	r_sinmdl.o \
	r_console3d.o \
	r_tesselate.o \
	r_part.o \
	r_poly.o \
	r_polyse.o \
	r_rast.o \
	r_scan.o \
	r_sprite.o \
	r_surf.o \
	r_aclip.o \
	r_bsp.o \
	r_draw.o \
	r_edge.o \
	r_image.o

ifeq ($(USE_ASM),1)
REFASM = ../gas/math_ref.o \
	../gas/math.o \
	../gas/d_copy.o \
	../gas/d_polysa.o \
	../gas/d_polysa_16bit.o \
	../gas/r_aclipa.o \
	../gas/r_draw16.o \
	../gas/r_drawa.o \
	../gas/r_edgea.o \
	../gas/r_scana.o \
	../gas/r_spr8.o \
	../gas/r_surf8.o \
	../gas/r_varsa.o \
	../gas/sys_dosa.o
# D_DrawSpans16_16bit() is broken and not used.
#	../gas/r_draw16_16bit.o
endif

.PHONY: all test clean
#

OBJECTS = $(REFSOFT) $(REFASM)

all: ref_soft.dxe

ref_soft.dxe: $(OBJECTS)
	$(DXE3GEN) -U -E _GetRefAPI $(OBJECTS) -o ref_soft.dxe

clean:
	rm -f *.o
	rm -f ../dos/*.o
	rm -f ../game/*.o
	rm -f ../gas/*.o

DO_AS=$(CC) -x assembler-with-cpp

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

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