#
#===============================
# deviceXlib package
#===============================
#
-include ../make.inc

DIR=src
LIBOBJS_LOC= $(LIBOBJS)

OBJS= \
devxlib.o \
devxlib_async.o \
devxlib_auxfunc.o \
devxlib_auxfunc_addscal.o \
devxlib_auxfunc_conjg.o \
devxlib_auxfunc_mat_upd.o \
devxlib_auxfunc_vec_upd.o \
devxlib_buffer.o \
devxlib_buffers.o \
devxlib_cublas.o \
devxlib_environment.o \
devxlib_linalg.o \
devxlib_linalg_axpy.o \
devxlib_linalg_dot.o \
devxlib_linalg_gemm.o \
devxlib_linalg_gemv.o \
devxlib_malloc.o \
devxlib_malloc_alloc.o \
devxlib_malloc_allocated.o \
devxlib_malloc_free.o \
devxlib_mapping.o \
devxlib_mapping_map.o \
devxlib_mapping_mapped.o \
devxlib_mapping_unmap.o \
devxlib_memcpy.o \
devxlib_memcpy_d2d.o \
devxlib_memcpy_d2h.o \
devxlib_memcpy_h2d.o \
devxlib_memcpy_h2h.o \
devxlib_memset.o \
devxlib_memset_device.o \
devxlib_memset_host.o \
devxlib_missing.o \
devxlib_mklgpu.o \
devxlib_rocblas.o \
devxlib_pinned.o \
mod_blas95.o \
mod_cublas.o \
mod_cublas_core.o \
mod_rocblas.o \
mod_tester_fbuff.o \
nvtx_wrapper.o \
roctx_wrapper.o \
prof_tools.o 

#
# main targets
#
all: libdevXlib.a tests

tests: test_malloc.x test_mapping.x test_memcpy.x test_memcpy_async.x \
       test_buffer.x test_pinned.x test_linalg.x  test_memset.x

test_malloc.x: test_malloc.o $(OBJS)
	$(LD) $(LDFLAGS) -o $@ test_malloc.o \
	       $(OBJS) $(LIBOBJS_LOC) $(LIBS)
	- ( cd ../bin ; ln -sf ../src/$@ . )

test_mapping.x: test_mapping.o $(OBJS)
	$(LD) $(LDFLAGS) -o $@ test_mapping.o \
	       $(OBJS) $(LIBOBJS_LOC) $(LIBS)
	- ( cd ../bin ; ln -sf ../src/$@ . )

test_memcpy.x: test_memcpy.o $(OBJS)
	$(LD) $(LDFLAGS) -o $@ test_memcpy.o \
	       $(OBJS) $(LIBOBJS_LOC) $(LIBS)
	- ( cd ../bin ; ln -sf ../src/$@ . )

test_memset.x: test_memset.o $(OBJS)
	$(LD) $(LDFLAGS) -o $@ test_memset.o \
	       $(OBJS) $(LIBOBJS_LOC) $(LIBS)
	- ( cd ../bin ; ln -sf ../src/$@ . )

test_memcpy_async.x: test_memcpy_async.o $(OBJS)
	$(LD) $(LDFLAGS) -o $@ test_memcpy_async.o \
	       $(OBJS) $(LIBOBJS_LOC) $(LIBS)
	- ( cd ../bin ; ln -sf ../src/$@ . )

test_linalg.x: test_linalg.o $(OBJS)
	$(LD) $(LDFLAGS) -o $@ test_linalg.o \
	       $(OBJS) $(LIBOBJS_LOC) $(LIBS)
	- ( cd ../bin ; ln -sf ../src/$@ . )

test_buffer.x: test_buffer.o $(OBJS)
	$(LD) $(LDFLAGS) -o $@ test_buffer.o \
	       $(OBJS) $(LIBOBJS_LOC) $(LIBS)
	- ( cd ../bin ; ln -sf ../src/$@ . )

test_pinned.x: test_pinned.o $(OBJS)
	$(LD) $(LDFLAGS) -o $@ test_pinned.o \
	       $(OBJS) $(LIBOBJS_LOC) $(LIBS)
	- ( cd ../bin ; ln -sf ../src/$@ . )

libdevXlib.a : $(OBJS)
	$(AR) $(ARFLAGS) $@ $?
	$(RANLIB) $@

# clean
clean:
	 - /bin/rm -rf *.o *.a *core *.F90 work.pc work.pcl *.mod *.x *.modmic *.i *.s
	 - /bin/rm -rf *_tmp.f90 *.smod

distclean:   clean

# dependencies
include make.depend
include make.depend_aux

