#
# 'make depend' uses makedepend to automatically generate dependencies
#               (dependencies are added to end of Makefile)
# 'make'        build executable file 'mycc'
# 'make clean'  removes all .o and executable files
#

# define the C compiler to use
CC ?= gcc
CXX ?= g++
NVCC ?= $(CUDA_TOOLKIT_ROOT_DIR)/bin/nvcc

# define any compile-time flags
DEBUG ?=
OPTI ?=
CFLAGS ?= $(DEBUG) $(OPTI)
CXXFLAGS ?= $(CFLAGS)
CuFLAGS ?= $(CFLAGS) --cudart shared

# define any directories containing header files other than /usr/include
#
CINCLUDES ?= -I$(LIBDIS_ROOT)/include \
	     $(shell pkg-config --keep-system-cflags --cflags openblas)
CXXINCLUDES ?=
CuINCLUDES ?=

# define library paths in addition to /usr/lib
#   if I wanted to include libraries not in /usr/lib I'd specify
#   their path using -Lpath, something like:
CLFLAGS ?= -L$(LIBDIS_ROOT)/lib -L$(LIBPWQ_ROOT)/lib -L$(LIBKQU_ROOT)/lib64 \
	   $(shell pkg-config --keep-system-libs --libs openblas)
CXXFLAGS ?=
CuFLAGS ?=

# define any libraries to link into executable:
#   if I want to link in libraries (libx.so or libx.a) I use the -llibname
#   option, something like (this will link in libmylib.so and libm.so:
CLIBS ?= -l:libdispatch.a -l:libpthread_workqueue.a -l:libkqueue.a -lpthread
CXXLIBS ?=
CuLIBS ?=

# define the executable file
CBINS = gcd_test_v1 gcd_test_v2 sgemm_test
CXXBINS =
CuBINS = dump_cudaGetDeviceProperties

#
# The following part of the makefile is generic; it can be used to
# build any executable just by changing the definitions above and by
# deleting dependencies appended to the file from 'make depend'
#

.PHONY: clean

all:    $(CBINS) $(CXXBINS) $(CuBINS)

$(CBINS): %: %.c
	$(CC) -o $@.exe $< $(CFLAGS) $(CINCLUDES) $(CLFLAGS) $(CLIBS)

$(CXXBINS): %: %.cpp
	$(CC) -o $@.exe $< $(CXXFLAGS) $(CXXINCLUDES) $(CXXLFLAGS) $(CXXLIBS)

$(CuBINS): %: %.cu
	$(NVCC) -o $@.exe $< $(CuFLAGS) $(CuINCLUDES) $(CuOBJS) $(CuLFLAGS) $(CuLIBS)

clean:
	$(RM) *.exe *.o *~

# DO NOT DELETE THIS LINE -- make depend needs it
