#//////////////////////////////////////////////////////////////////////////////
#   -- micMAGMA (version 0.1) --
#      Univ. of Tennessee, Knoxville
#      Univ. of California, Berkeley
#      Univ. of Colorado, Denver
#      April 2012
#//////////////////////////////////////////////////////////////////////////////

MAGMA_DIR = ..
include ../Makefile.internal
#        testing_ztrmm.cpp       \
#        testing_ztrmv.cpp       \
#        testing_ztrsm.cpp       \
#        testing_ztrsv.cpp       \
#	testing_cpu_mic_data_transfer.cpp	\
#	testing_kernel_launch_overhead.cpp	\
	#\
     #   testing_zgehrd.cpp      \
      #  testing_zhetrd_he2hb.cpp

ZSRC =  \
        testing_zgemm.cpp       \
        testing_zgemv.cpp       \
        testing_zhemv.cpp       \
        testing_zsymv.cpp       \
        testing_zherk.cpp		\
        testing_zher2k.cpp		\
        \
	testing_parse_opts.cpp	\
	testing_zutil.cpp	\
	\
	testing_zpotrf_mic.cpp	\
	testing_zgeqrf_mic.cpp  \
	testing_zgetrf.cpp      \
	testing_zgetrf_mic.cpp	\
        \
	testing_zpotrf_mmic.cpp	\
	testing_zgeqrf_mmic.cpp \
	testing_zgetrf_mmic.cpp	\
	\
	testing_zposv_mic.cpp   \
	testing_zgesv_mic.cpp   \
	testing_zcgesv.cpp      \
	testing_zcgesv_mic.cpp  \
	testing_zgeqrs_mic.cpp  \
	\
	testing_zgehrd.cpp      \
	testing_zhetrd.cpp	\
	testing_zhetrd_he2hb.cpp\
	testing_zgebrd.cpp      \
        

#ifeq ($(FORT), pgfortran)
#	FOBJ := fortran_thunking.o
#	ZSRCF = testing_zgetrf_gpu_f.cuf
#else
#	FOBJ := fortran.o
#	ZSRCF = testing_zgetrf_gpu_f.f90	\
#		testing_zgetrf_f.f90
#endif

ZSRC += $(ZSRCF)
-include Makefile.src

INC += -I../interface_opencl/cl_magma_runtime/

#ALLSRC  = $(ZSRC) $(CSRC) $(DSRC) $(SSRC) 
ALLSRC  = $(DSRC) $(SSRC) \
	testing_constants.cpp
ALLOBJF  = $(ALLSRC:.f90=.o)
ALLOBJF := $(ALLOBJF:.cuf=.o)
ALLOBJ   = $(ALLOBJF:.cpp=.o)
EXE      = $(ALLOBJ:.o=)

LIBTEST := libtest.a
LIBSRC  := testing_zutil.o testing_cutil.o testing_dutil.o testing_sutil.o testing_util.o
LIBOBJ  := $(LIBSRC:.cpp=.o)
LIBEXE  := $(LIBOBJ:.o=)

# strip out fake exe files generated from LIBSRC
EXE := $(filter-out $(LIBEXE), $(EXE))

all: $(EXE)

lib: $(LIBMAGMA) $(LIBMAGMABLAS)

# depend on header
$(ALLOBJ): testings.h

$(LIBTEST): $(LIBOBJ)
	$(ARCH) $(ARCHFLAGS) $@ $^
	$(RANLIB) $@

LIBLAPACKTEST = lin/liblapacktest.a

$(LIBLAPACKTEST):
	cd lin && make liblapacktest.a

$(EXE): $(LIBMAGMA) $(LIBMAGMABLAS) $(LIBLAPACKTEST) $(LIBTEST)

clean:
	rm -f *.o *~ $(LIBTEST)

cleanall: clean
	rm -f $(EXE)

#ifeq ($(FORT), pgfortran)
#testing_%.o : testing_%.cuf
#	$(FORT) $(FOPTS) $(INC) -c $< -o $@ 
#else
#testing_%.o : testing_%.f90
#	$(FORT) $(FOPTS) $(INC) -c $< -o $@ 
#endif

%.o: %.cpp
	$(CC) $(OPTS) $(INC) -c $< -o $@

#
# MAGMA Fortran module. Once finalized, the generated magma.mod
# has to be moved in the include directory
#
# lin/liblapacktest.a
testing_%_f : testing_%_f.o $(FOBJ)
	$(FORT) $(OPTS) $(LDOPTS) $< $(FOBJ) -o $@ lin/liblapacktest.a \
	$(LIBMAGMA) $(LIBMAGMABLAS) $(LIBDIR) $(LIB) 

# lin/liblapacktest.a
testing_% : testing_%.o
	$(CC) $(OPTS) $(LDOPTS) $(NOMAIN) $< $(OBJ) -o $@ $(LIBTEST) lin/liblapacktest.a \
	$(LIBMAGMA) $(LIBMAGMABLAS) $(LIBDIR) $(LIB) 

#
# These two files are provided by cuda
#
#fortran.o : $(CUDADIR)/src/fortran.c
#	$(CC) $(OPTS) $(INC) -c $< -o $@
#
#fortran_thunking.o : $(CUDADIR)/src/fortran_thunking.c
#	$(CC) $(OPTS) $(INC) -c $< -o $@

# keep intermediate object files, to speed up re-compiling when library changes
.SECONDARY: $(ALLOBJ)
