# The default target of this Makefile is...
all::

CC	= gcc
CXX	= g++
OPT	= -mfpmath=sse -g -O
# Choose to compile with AVX, SSE4 or SSE2.
#	OPT += -mavx
#	OPT += -msse4
	OPT += -msse2

CFLAGS	= -DHAVE_ALTIVEC_EXTRAS -I. -flax-vector-conversions -Wall $(OPT)
LIBS	= -lm

EXE	= test_link test_linkxx \
	test_vec test_vecxx test_vecmo test_vecxxmo \
	time_mattrans time_innerprod time_matmul time_vsin \
	vec_add vec_sin vec_grayscale vec_tenth mat_trans abs_diff

#RUN	= ./sde --

all:: $(EXE)

test_link: test_link.c altivec2avx.h
	$(CC) $(CFLAGS) -Wno-unused test_link.c -o test_link

test_linkxx: test_link.c altivec2avx.h
	$(CXX) $(CFLAGS) test_link.c -o test_linkxx

test_vec: test_vec.c altivec2avx.h
	$(CC) $(CFLAGS) test_vec.c -o test_vec

test_vecxx: test_vec.c altivec2avx.h
	$(CXX) $(CFLAGS) test_vec.c -o test_vecxx

test_vecmo: test_vec.c altivec2avx.h
	$(CC) $(CFLAGS) -DMEMORY_ORDER test_vec.c -o test_vecmo

test_vecxxmo: test_vec.c altivec2avx.h
	$(CXX) $(CFLAGS) -DMEMORY_ORDER test_vec.c -o test_vecxxmo

time_mattrans: time_mattrans.o altivec2avx.h
	$(CC) time_mattrans.o -o time_mattrans $(LIBS)

time_innerprod: time_innerprod.o altivec2avx.h
	$(CC) time_innerprod.o -o time_innerprod $(LIBS)

time_matmul: time_matmul.o altivec2avx.h
	$(CC) time_matmul.o -o time_matmul $(LIBS)

time_vsin: time_vsin.o altivec2avx.h
	$(CC) time_vsin.o -o time_vsin $(LIBS)

test_round.o: test_round.c altivec2avx.h
	$(CC) $(CFLAGS) -msse4 -c test_round.c

test_round: test_round.o altivec2avx.h
	$(CC) test_round.o -o test_round $(LIBS)

vec_add: vec_add.o altivec2avx.h
	$(CC) vec_add.o -o vec_add $(LIBS)

vec_sin: vec_sin.o altivec2avx.h
	$(CC) vec_sin.o -o vec_sin $(LIBS)

vec_grayscale: vec_grayscale.o altivec2avx.h
	$(CC) vec_grayscale.o -o vec_grayscale $(LIBS)

vec_tenth: vec_tenth.o altivec2avx.h
	$(CC) vec_tenth.o -o vec_tenth $(LIBS)

mat_trans: mat_trans.o altivec2avx.h
	$(CC) mat_trans.o -o mat_trans $(LIBS)

abs_diff: abs_diff.o altivec2avx.h
	$(CC) abs_diff.o -o abs_diff $(LIBS)


runall: $(EXE)
	@for e in $(EXE); do echo "=== $$e ===="; $(RUN) ./$$e; done

tidy:
	-rm -f *.o

clean: tidy
	-rm -f *~ .depend $(EXE)

depend: .depend

# -mavx is needed to ensure we get all the header files.
.depend: *.h
	gcc -I. -mavx -DHAVE_ALTIVEC_EXTRAS -MM *.c > .depend

-include .depend
