# MakeFile for QuakeTools

CC=@CC@
LD=@LD@
AS=@AS@
AR=@AR@
RAN=@RANLIB@

WARN = -Wall -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations
OPTI = -fpeephole -fno-float-store -ffunction-cse -ffast-math -fstrength-reduce \
       -frerun-cse-after-loop -frerun-loop-opt -fschedule-insns -fschedule-insns2 \
       -fmove-all-movables -freg-struct-return -freduce-all-givs -fforce-addr
DEFS = @DEFS@ -DPARENTDIR="../" -DCURRENTDIR="./"
INCL = -I. -L. -I@top_srcdir@/src/include -I@top_srcdir@/lib -I@includedir@

# highly optimized flags
CFLAGS =@CFLAGS@ -O3 $(WARN) $(OPTI) $(DEFS) $(INCL) $(EXTRAOPTS) -fomit-frame-pointer
LDFLAGS=@LDFLAGS@ -O3 $(WARN) $(OPTI) $(DEFS) $(INCL) $(EXTRAOPTS) -fomit-frame-pointer -s
ASFLAGS=

#profileflags
CPFLAGS =@CFLAGS@ $(WARN) $(DEFS) $(INCL) -DNOASM -DDEBUG_C		# -pg -DPROFILE 
LDPFLAGS=@LDFLAGS@ $(WARN) $(DEFS) $(INCL) -DNOASM -DDEBUG_C		# -pg -DPROFILE
ASPFLAGS=
#gcovflags
CVFLAGS =$(CFLAGS) -DPROFILE -ftest-coverage -fprofile-arcs
LDVFLAGS=$(LDFLAGS) -DPROFILE -ftest-coverage -fprofile-arcs
ASVFLAGS=$(ASFLAGS)
CBFLAGS =$(CFLAGS) -DPROFILE -fbranch-probabilities
LDBFLAGS=$(LDFLAGS) -DPROFILE -fbranch-probabilities
ASBFLAGS=$(ASFLAGS)

# common rules
.PHONY:  default profile coverage branch all utils install ansi test \
	clean cleanprofile cleancoverage cleanall distclean backup restore

.SUFFIXES:
.SUFFIXES: .c .o .4 .6 _p.o .b .v .S

# try assembler first
%.o %.4 %.6: %.S
	$(CC) $(ASFLAGS) -c $< -o $@
# if no assembler try direct from C
%_p.o: %.S
	$(CC) $(ASPFLAGS) -c $< -o $@
# if no assembler try direct from C
%.v: %.S
	$(CC) $(ASVFLAGS) -c $< -o $@
# if no assembler try direct from C
%.b: %.S
	$(CC) $(ASBFLAGS) -c $< -o $@
# if no assembler try direct from C
%.o %.4 %.6: %.c
	$(CC) $(CFLAGS) -c $< -o $@
# if no assembler try direct from C
%_p.o: %.c
	$(CC) $(CPFLAGS) -c $< -o $@
# if no assembler try direct from C
%.v: %.c
	$(CC) $(CVFLAGS) -c $< -o $@
# if no assembler try direct from C
%.b: %.c
	$(CC) $(CBFLAGS) -c $< -o $@
# if no assembler try direct from C
%_p.oroto: %.c
	@GPROTO@ -f"extern %R %N%P;\n" -sN -o$@ $<
# this is only for manual use
%.S: %.c
	$(CC) $(CFLAGS) -fverbose-asm -S $< -o $@
