# This makefile is for the command line version
# of the Microsoft Visual Studio Compiler on Windows 10.
# The option '-O3' is unknown and replaced by '-O2'.

# location for the code for multiple double precision
MPD=../Norms
# location for the code for monomial evaluation and differentiation
CNV=../Convolutions

# architecture flag
smflag=sm_75

# location of the command line Microsoft Visual Studio Compiler
CL="C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.25.28610\bin\Hostx64\x64"

# include path for the Microsoft Visual Studio Compiler
includepath="C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.25.28610\include"

# include path for the Windows Kit
winkitucrt="C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\ucrt"

# libaries of the Microsoft Visual Studio compiler
libdirvs="C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.25.28610\lib\x64"

# libraries of the Windows Kits
libdirkitum="C:\Program Files (x86)\Windows Kits\10\Lib\10.0.18362.0\um\x64"
libdirkitucrt="C:\Program Files (x86)\Windows Kits\10\Lib\10.0.18362.0\ucrt\x64"

# include files of the CUDA SDK
CUDASDK="C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.2"
# library folder of the CUDA SDK
CUDALIB="C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.2\lib\x64"

random_numbers.obj:
	@-echo ">>> compiling double random number generators ..."
	$(CL)\cl /c -I$(MPD) -I$(winkitucrt) -I$(includepath) -O2 \
                      $(MPD)/random_numbers.cpp \
                 /Fo: random_numbers.obj /EHsc

random_series.obj:
	@-echo ">>> compiling double random series generators ..."
	$(CL)\cl /c -I$(MPD) -I$(CNV) -I$(winkitucrt) -I$(includepath) -O2 \
                      $(CNV)/random_series.cpp \
                 /Fo: random_series.obj /EHsc

random_matrices.obj:
	@-echo ">>> compiling double random_matrices generators ..."
	$(CL)\cl /c -I$(MPD) -I$(CNV) -I$(winkitucrt) -I$(includepath) -O2 \
                      random_matrices.cpp \
                 /Fo: random_matrices.obj /EHsc

dbl_convolutions_host.obj:
	@-echo ">>> compiling dbl_convolutions_host ..."
	$(CL)\cl /c -I$(CNV) $(CNV)/dbl_convolutions_host.cpp \
                 -I$(winkitucrt) -I$(includepath) -O2 \
                 /Fo: dbl_convolutions_host.obj

dbl_matrices_host.obj:
	@-echo ">>> compiling dbl_matrices_host ..."
	$(CL)\cl /c -I$(CNV) dbl_matrices_host.cpp \
                 -I$(winkitucrt) -I$(includepath) -O2 \
                 /Fo: dbl_matrices_host.obj /EHsc

dbl_matrices_kernels.obj:
	@-echo ">>> compiling dbl_matrices_kernels ..."
	nvcc -ccbin=$(CL) -arch=$(smflag) -c -O3 \
                dbl_matrices_kernels.cu \
             -o dbl_matrices_kernels.obj

dbl_vectors_testers.obj:
	@-echo ">>> compiling dbl_vectors_testers ..."
	$(CL)\cl /c -I$(MPD) -I$(CNV) dbl_vectors_testers.cpp \
                 -I$(winkitucrt) -I$(includepath) -O2 \
                 /I$(CUDASDK)/include \
                 /Fo: dbl_vectors_testers.obj /EHsc

test_dbl_vectors.obj:
	@-echo ">>> compiling test_dbl_vectors ..."
	$(CL)\cl /c test_dbl_vectors.cpp \
                 -I$(winkitucrt) -I$(includepath) -I$(MPD) -I$(CNV) -O2 \
                 /I$(CUDASDK)/include \
                 /Fo: test_dbl_vectors.obj /EHsc

test_dbl_vectors: random_numbers.obj random_series.obj \
	          random_matrices.obj dbl_convolutions_host.obj \
                  dbl_matrices_host.obj dbl_matrices_kernels.obj \
                  dbl_vectors_testers.obj test_dbl_vectors.obj
	@-echo ">>> linking ..."
	nvcc -ccbin=$(CL) -o test_dbl_vectors.exe \
              random_numbers.obj random_series.obj random_matrices.obj \
              dbl_convolutions_host.obj dbl_matrices_host.obj \
              dbl_matrices_kernels.obj dbl_vectors_testers.obj \
              test_dbl_vectors.obj

dbl_matrices_testers.obj:
	@-echo ">>> compiling dbl_matrices_testers ..."
	$(CL)\cl /c -I$(MPD) -I$(CNV) dbl_matrices_testers.cpp \
                 -I$(winkitucrt) -I$(includepath) -O2 \
                 /Fo: dbl_matrices_testers.obj /EHsc

test_dbl_matrices.obj:
	@-echo ">>> compiling test_dbl_matrices ..."
	$(CL)\cl /c test_dbl_matrices.cpp \
                 -I$(winkitucrt) -I$(includepath) -I$(MPD) -I$(CNV) -O2 \
                 /I$(CUDASDK)/include \
                 /Fo: test_dbl_matrices.obj /EHsc

test_dbl_matrices: random_numbers.obj random_series.obj \
	           random_matrices.obj dbl_convolutions_host.obj \
                   dbl_matrices_host.obj dbl_linearization.obj \
                   dbl_matrices_testers.obj test_dbl_matrices.obj
	@-echo ">>> linking ..."
	nvcc -ccbin=$(CL) -o test_dbl_matrices.exe \
              random_numbers.obj random_series.obj random_matrices.obj \
              dbl_convolutions_host.obj dbl_matrices_host.obj \
              dbl_linearization.obj dbl_matrices_testers.obj \
              test_dbl_matrices.obj

test_upper_jobs.obj:
	@-echo ">>> compiling test_upper_jobs ..."
	$(CL)\cl /c test_upper_jobs.cpp \
                 -I$(winkitucrt) -I$(includepath) -O2 \
                 /I$(CUDASDK)/include \
                 /Fo: test_upper_jobs.obj /EHsc

test_upper_jobs: test_upper_jobs.obj
	@-echo ">>> linking ..."
	nvcc -ccbin=$(CL) -o test_upper_jobs.exe test_upper_jobs.obj

dbl_linearization.obj:
	@-echo ">>> compiling dbl_linearization ..."
	$(CL)\cl /c dbl_linearization.cpp \
                 -I$(winkitucrt) -I$(includepath) -O2 \
                 /I$(CUDASDK)/include \
                 /Fo: dbl_linearization.obj /EHsc

test_dbl_linearization.obj:
	@-echo ">>> compiling test_dbl_linearization ..."
	$(CL)\cl /c test_dbl_linearization.cpp \
                 -I$(winkitucrt) -I$(includepath) -O2 \
                 /I$(CUDASDK)/include \
                 /Fo: test_dbl_linearization.obj /EHsc

test_dbl_linearization: test_dbl_linearization.obj dbl_linearization.obj \
                        random_numbers.obj random_series.obj \
                        random_matrices.obj
	@-echo ">>> linking ..."
	nvcc -ccbin=$(CL) -o test_dbl_linearization.exe \
             test_dbl_linearization.obj dbl_linearization.obj \
             random_numbers.obj random_series.obj random_matrices.obj

clean:
	del *~
	del test_dbl_vectors.obj test_dbl_vectors_lib
	del test_dbl_vectors.exe test_dbl_vectors.exp
	del test_dbl_matrices.obj test_dbl_matrices_lib
	del test_dbl_matrices.exe test_dbl_matrices.exp
	del test_upper_jobs.obj test_upper_jobs_lib
	del test_upper_jobs.exe test_upper_jobs.exp
	del dbl_linearization.obj
	del test_dbl_linearization.obj test_dbl_linearization_lib
	del test_dbl_linearization.exe test_dbl_linearization.exp
	del random_matrices.obj
	del dbl_matrices_host.obj dbl_matrices_kernels.obj
	del dbl_matrices_testers.obj dbl_vectors_testers.obj

cleanall: clean
	del *exe *obj *exp *lib
