#!/usr/bin/python3

import os,sys,subprocess,math
from complib2 import *

import shutil
from distutils.dir_util import copy_tree as copy_tree #this version does overwrites

libname = 'assetcuda.msvc64' #prefix static library name to generate
targetname = 'tests.exe' #create this executable when compiling tests
commonincdir = "../../winx64/include"
commonlibdir = "../../winx64/lib"
localbindir = "./bin_winx64"
cc = 'nvcc' #compiler
srcexts = ['.c','.cpp']
mainsrc = ['main.c','main.cpp','main.cu'] #ignore these files when compiling the static library

kwargs = dict()
include = "-I./include -I{}".format(commonincdir)
kwargs['include'] = include
kwargs['flags'] = "/O2"
kwargs['libdir'] = "/LIBPATH:{} /LIBPATH:{}".format(localbindir,commonlibdir)
#kwargs['libflags'] = "lib{}.lib libamsearthtools.msvc64.lib libamsmeshtools.msvc64.lib libamsmathlib3.msvc64.lib libamsmatrix_cpp.msvc64.lib liblapack.a libblas.a libamsstring3.msvc64.lib libamsmathutil2.msvc64.lib".format(libname)
kwargs['libflags'] = "lib{}.lib".format(libname)
kwargs['linkerflags'] = ""
kwargs['recurse'] = True

#Pull required binary dynamic libraries to the bin folder
#shutil.copy('{}/libamsimg.dll.a'.format(commonlibdir),localbindir);
#shutil.copy('{}/libamsimg.dll'.format(commonlibdir),localbindir);
#shutil.copy('../../lib_winx64/glew32.dll','./bin_winx64');

#Designate source files for main test program
fsrc = ['./src/main.cu']
fobj = replaceexts(fsrc,'.obj')

#Compile test programs
msvc_compile_list(cc,fsrc,**kwargs)
msvc_link_list(list_to_sss(fobj),'{}/{}'.format(localbindir,targetname),**kwargs)
