cuda library updates
This commit is contained in:
7
amsculib2.code-workspace
Normal file
7
amsculib2.code-workspace
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"folders": [
|
||||||
|
{
|
||||||
|
"path": "."
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
8
backup.sh
Normal file
8
backup.sh
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
|
||||||
|
rm ./test_scripts/*.bin
|
||||||
|
|
||||||
|
tar --exclude='./data' -czvf ../amsculib2.tar.gz ./*
|
||||||
|
|
||||||
|
scp ../amsculib2.tar.gz aschinder@amssolarempire.com:~/workspace/projects
|
||||||
BIN
build/__pycache__/amsbuildlib4.cpython-310.pyc
Normal file
BIN
build/__pycache__/amsbuildlib4.cpython-310.pyc
Normal file
Binary file not shown.
BIN
build/__pycache__/amsbuildlib4.cpython-311.pyc
Normal file
BIN
build/__pycache__/amsbuildlib4.cpython-311.pyc
Normal file
Binary file not shown.
BIN
build/__pycache__/amsbuildlib4.cpython-312.pyc
Normal file
BIN
build/__pycache__/amsbuildlib4.cpython-312.pyc
Normal file
Binary file not shown.
BIN
build/__pycache__/amsbuildlib4.cpython-39.pyc
Normal file
BIN
build/__pycache__/amsbuildlib4.cpython-39.pyc
Normal file
Binary file not shown.
813
build/amsbuildlib4.py
Normal file
813
build/amsbuildlib4.py
Normal file
@ -0,0 +1,813 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
import os,sys,math
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
"""
|
||||||
|
Copyright Aaron M. Schinder, 2011 - MIT/BSD License
|
||||||
|
|
||||||
|
This script contains a bunch of helper functions for generating simple, imperative, hopefully
|
||||||
|
transparent build scripts using the python language (and nothing else).
|
||||||
|
|
||||||
|
I just want the script to do the compiling and linking operations I want it to do in the order
|
||||||
|
I want it to do it in, finding every relevant source file.
|
||||||
|
|
||||||
|
That's it. That's what I want in a build system.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def flist(pth,**kwargs):
|
||||||
|
"""
|
||||||
|
flist - list all files in a given directory pth
|
||||||
|
optional arguments:
|
||||||
|
recurse - (T/F): Whether to recursively search for files in directory tree
|
||||||
|
exts - (list): A list of file extensions to search for, otherwise all files
|
||||||
|
normpath (T/F): whether to normalize path variables after
|
||||||
|
filelist = flist(pth,**kwargs):
|
||||||
|
"""
|
||||||
|
flst = []
|
||||||
|
if(not('recurse' in kwargs)):
|
||||||
|
recurse_ = False
|
||||||
|
else:
|
||||||
|
recurse_ = kwargs['recurse']
|
||||||
|
if(not('exts' in kwargs)):
|
||||||
|
filterexts_ = False
|
||||||
|
else:
|
||||||
|
filterexts_ = True
|
||||||
|
exts = kwargs['exts']
|
||||||
|
if(not('normpath' in kwargs)):
|
||||||
|
normpath_ = True
|
||||||
|
else:
|
||||||
|
normpath_ = kwargs['normpath']
|
||||||
|
if(not('linuxpath' in kwargs)):
|
||||||
|
linuxpath_ = False
|
||||||
|
else:
|
||||||
|
linuxpath_ = kwargs['linuxpath']
|
||||||
|
if(not('followlinks' in kwargs)):
|
||||||
|
followlinks_ = False
|
||||||
|
else:
|
||||||
|
followlinks_ = kwargs['followlinks']
|
||||||
|
|
||||||
|
dirlist = []
|
||||||
|
rawlist = os.listdir(pth)
|
||||||
|
|
||||||
|
for F in rawlist:
|
||||||
|
F2 = os.path.join(pth,F)
|
||||||
|
if(os.path.isdir(F2)):
|
||||||
|
b = (followlinks_) or ((not followlinks_) and not(os.path.islink(F2)))
|
||||||
|
if(b):
|
||||||
|
if((F2!=".")&(F2!="..")):
|
||||||
|
dirlist.append(F2)
|
||||||
|
elif(os.path.isfile(F2)):
|
||||||
|
flst.append(F2)
|
||||||
|
|
||||||
|
#Recurse through directories
|
||||||
|
if(recurse_):
|
||||||
|
for D in dirlist:
|
||||||
|
lst = flist(D,**kwargs)
|
||||||
|
for L in lst:
|
||||||
|
flst.append(L)
|
||||||
|
|
||||||
|
#Postprocess:
|
||||||
|
#Filter out all extensions except the selected ext list
|
||||||
|
if(filterexts_):
|
||||||
|
flst = filterexts(flst,exts)
|
||||||
|
|
||||||
|
#Normalize filename path according to os
|
||||||
|
if(normpath_):
|
||||||
|
flst2 = list(flst)
|
||||||
|
for I in range(0,len(flst2)):
|
||||||
|
flst[I] = os.path.normpath(flst2[I])
|
||||||
|
|
||||||
|
#If linuxpath, convert all \\ to /
|
||||||
|
#if(linuxpath_):
|
||||||
|
# flst2 = list(flst)
|
||||||
|
# for I in range(0,len(flst2)):
|
||||||
|
# flst[I] = linuxpath(flst2[I])
|
||||||
|
|
||||||
|
return flst
|
||||||
|
|
||||||
|
|
||||||
|
def filterexts(flst,exts):
|
||||||
|
"""
|
||||||
|
Filters by extensions in a list of files
|
||||||
|
flst = def filterexts(flst,exts):
|
||||||
|
"""
|
||||||
|
flst2 = []
|
||||||
|
if(isinstance(exts,str)):
|
||||||
|
exts = list([exts])
|
||||||
|
for F in flst:
|
||||||
|
b = False
|
||||||
|
for ext in exts:
|
||||||
|
if(ext[0]!='.'):
|
||||||
|
ext = '.'+ext
|
||||||
|
F2 = os.path.splitext(F)
|
||||||
|
if(len(F2)>=2):
|
||||||
|
ex = F2[1]
|
||||||
|
if(len(ex)>0):
|
||||||
|
if(ex[0]!='.'):
|
||||||
|
ex = '.'+ex
|
||||||
|
if(ex==ext):
|
||||||
|
b = True
|
||||||
|
if(b):
|
||||||
|
flst2.append(F)
|
||||||
|
|
||||||
|
return flst2
|
||||||
|
|
||||||
|
#Find a file fname, starting in pth and recursing
|
||||||
|
#Used for finding library files to link
|
||||||
|
def findfile(fname,pth,**kwargs):
|
||||||
|
fullfname = ""
|
||||||
|
flst = flist(pth,recurse=True)
|
||||||
|
for F in flst:
|
||||||
|
F2 = os.path.split(F)[1]
|
||||||
|
if(F2 == fname):
|
||||||
|
fullfname = F
|
||||||
|
|
||||||
|
return fullfname
|
||||||
|
|
||||||
|
def replaceext(fname,ext):
|
||||||
|
fname2 = ""
|
||||||
|
if(len(ext)>0):
|
||||||
|
if(ext[0]!='.'):
|
||||||
|
ext = '.'+ext
|
||||||
|
fname2 = os.path.splitext(fname)[0]+ext
|
||||||
|
else:
|
||||||
|
fname2 = os.path.splitext(fname)[0]
|
||||||
|
return fname2
|
||||||
|
|
||||||
|
def replaceexts(fnamelist,ext):
|
||||||
|
"""Takes a list of filenames and returns a list with the extensions replaced by ext """
|
||||||
|
fname2list = []
|
||||||
|
for F in fnamelist:
|
||||||
|
F2 = replaceext(F,ext)
|
||||||
|
fname2list.append(F2)
|
||||||
|
return fname2list
|
||||||
|
|
||||||
|
def except_contains(lst1,exc):
|
||||||
|
"""
|
||||||
|
Takes a list of file names lst1, and removes filenams that match the
|
||||||
|
list of exceptions exc. Returns a list without the exceptions.
|
||||||
|
"""
|
||||||
|
lst2 = []
|
||||||
|
for item in lst1:
|
||||||
|
b = 1
|
||||||
|
for item2 in exc:
|
||||||
|
fsplit = os.path.split(item)
|
||||||
|
fn = fsplit[len(fsplit)-1]
|
||||||
|
if(fn==item2):
|
||||||
|
b = 0
|
||||||
|
break
|
||||||
|
if(b==1):
|
||||||
|
lst2.append(item)
|
||||||
|
return lst2
|
||||||
|
|
||||||
|
|
||||||
|
def list_to_sss(lst):
|
||||||
|
"""List of strings to space-seperated-string"""
|
||||||
|
lout = ""
|
||||||
|
for I in range(0,len(lst)-1):
|
||||||
|
lout = lout + lst[I] + " "
|
||||||
|
if(len(lst)>0):
|
||||||
|
lout = lout + lst[len(lst)-1]
|
||||||
|
return lout
|
||||||
|
|
||||||
|
##########################
|
||||||
|
##System Call Procedures##
|
||||||
|
##########################
|
||||||
|
|
||||||
|
def callproc(cmd, **kwargs):
|
||||||
|
if(not('logfile' in kwargs)):
|
||||||
|
use_lf = False
|
||||||
|
else:
|
||||||
|
logfile = kwargs['logfile']
|
||||||
|
if(logfile!=""):
|
||||||
|
fp = open(kwargs['logfile'],'a+')
|
||||||
|
use_lf = True
|
||||||
|
else:
|
||||||
|
use_lf = False
|
||||||
|
|
||||||
|
if(not('echo' in kwargs)):
|
||||||
|
echo = True
|
||||||
|
else:
|
||||||
|
echo = kwargs['echo']
|
||||||
|
|
||||||
|
if(echo):
|
||||||
|
print(cmd)
|
||||||
|
|
||||||
|
#encoding/deconding to/from bytes is necessary to use the subprocess command
|
||||||
|
#in python3.7
|
||||||
|
#However, only do this in linux
|
||||||
|
if(sys.platform!='win32'):
|
||||||
|
cmd2 = cmd.encode(encoding='utf-8')
|
||||||
|
else:
|
||||||
|
cmd2 = cmd
|
||||||
|
proc = subprocess.Popen(cmd2,stderr = subprocess.STDOUT, stdout=subprocess.PIPE, shell=True)
|
||||||
|
(out, err) = proc.communicate()
|
||||||
|
|
||||||
|
out = out.decode(encoding='utf-8')
|
||||||
|
|
||||||
|
if(echo):
|
||||||
|
print(out)
|
||||||
|
#print(err);
|
||||||
|
if(use_lf):
|
||||||
|
fp.writelines(cmd+'\n')
|
||||||
|
fp.writelines(out+'\n')
|
||||||
|
|
||||||
|
if(use_lf):
|
||||||
|
fp.close()
|
||||||
|
|
||||||
|
|
||||||
|
#############################################
|
||||||
|
## Compiler, Archive, and Linker Functions ##
|
||||||
|
#############################################
|
||||||
|
|
||||||
|
#MSVC compiler wrapper
|
||||||
|
def msvc_compile(compilername, srcfile, **kwargs):
|
||||||
|
|
||||||
|
if(not('include' in kwargs)):
|
||||||
|
include = ''
|
||||||
|
else:
|
||||||
|
include = kwargs['include']
|
||||||
|
if(isinstance(include,list)):
|
||||||
|
include = list_to_sss(include)
|
||||||
|
|
||||||
|
if(not('flags' in kwargs)):
|
||||||
|
flags = ''
|
||||||
|
else:
|
||||||
|
flags = kwargs['flags']
|
||||||
|
if(isinstance(flags,list)):
|
||||||
|
flags = list_to_sss(flags)
|
||||||
|
|
||||||
|
if(not('objext' in kwargs)):
|
||||||
|
objext = '.obj'
|
||||||
|
else:
|
||||||
|
objext = kwargs['objext']
|
||||||
|
|
||||||
|
if(not('srcfileflag' in kwargs)):
|
||||||
|
srcfileflag = '/c'
|
||||||
|
else:
|
||||||
|
srcfileflag = kwargs['srcfileflag']
|
||||||
|
|
||||||
|
if(not('outfileflag' in kwargs)):
|
||||||
|
outfileflag = '/Fo:'
|
||||||
|
else:
|
||||||
|
outfileflag = kwargs['outfileflag']
|
||||||
|
if(not('logfile' in kwargs)):
|
||||||
|
logfile = ""
|
||||||
|
else:
|
||||||
|
logfile = kwargs['logfile']
|
||||||
|
|
||||||
|
outfile = replaceext(srcfile,objext)
|
||||||
|
ln = compilername+" "+flags+" "+" "+srcfileflag+" "+srcfile+" "+outfileflag+'"'+outfile+'"'
|
||||||
|
ln = ln + " " + include
|
||||||
|
|
||||||
|
callproc(ln,echo=True,logfile=logfile)
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
#MSVC compiler wrapper
|
||||||
|
def msvc_compile_list(compiler,srclist,**kwargs):
|
||||||
|
for S in srclist:
|
||||||
|
msvc_compile(compiler,S,**kwargs)
|
||||||
|
return
|
||||||
|
|
||||||
|
#gnu-style compiler compile: Should work with gcc, g++, gfortran
|
||||||
|
def gs_compile(compiler,srcfile,**kwargs):
|
||||||
|
if(not('include' in kwargs)):
|
||||||
|
include = ''
|
||||||
|
else:
|
||||||
|
include = kwargs['include']
|
||||||
|
if(isinstance(include,list)):
|
||||||
|
include = list_to_sss(include)
|
||||||
|
|
||||||
|
if(not('flags' in kwargs)):
|
||||||
|
flags = ''
|
||||||
|
else:
|
||||||
|
flags = kwargs['flags']
|
||||||
|
if(isinstance(flags,list)):
|
||||||
|
flags = list_to_sss(flags)
|
||||||
|
|
||||||
|
if(not('objext' in kwargs)):
|
||||||
|
objext = '.o'
|
||||||
|
else:
|
||||||
|
objext = kwargs['objext']
|
||||||
|
|
||||||
|
if(not('srcfileflag' in kwargs)):
|
||||||
|
srcfileflag = '-c'
|
||||||
|
else:
|
||||||
|
srcfileflag = kwargs['srcfileflag']
|
||||||
|
|
||||||
|
if(not('outfileflag' in kwargs)):
|
||||||
|
outfileflag = '-o'
|
||||||
|
else:
|
||||||
|
outfileflag = kwargs['outfileflag']
|
||||||
|
|
||||||
|
if(not('logfile' in kwargs)):
|
||||||
|
logfile = ""
|
||||||
|
else:
|
||||||
|
logfile = kwargs['logfile']
|
||||||
|
|
||||||
|
if(not('smartcompile' in kwargs)):
|
||||||
|
_smartcompile = True
|
||||||
|
else:
|
||||||
|
_smartcompile = kwargs['smartcompile']
|
||||||
|
|
||||||
|
#Do I want to make this thing this general?
|
||||||
|
|
||||||
|
# if(not(_smartcompile) or smartcompile(srcfile,objext)):
|
||||||
|
# outfile = replaceext(srcfile,objext)
|
||||||
|
# ln = compiler+" "+flags+" " + outfileflag+" "+outfile+" "+srcfileflag+" "+srcfile
|
||||||
|
# ln = ln + " " + include
|
||||||
|
|
||||||
|
# callproc(ln,echo=True,logfile=logfile)
|
||||||
|
|
||||||
|
outfile = replaceext(srcfile,objext)
|
||||||
|
ln = compiler+" "+flags+" " + outfileflag+" "+outfile+" "+srcfileflag+" "+srcfile
|
||||||
|
ln = ln + " " + include
|
||||||
|
|
||||||
|
callproc(ln,echo=True,logfile=logfile)
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
def gs_compile_list(compiler,srclist,**kwargs):
|
||||||
|
for S in srclist:
|
||||||
|
gs_compile(compiler,S,**kwargs)
|
||||||
|
return
|
||||||
|
|
||||||
|
def gs_compile_all(compiler,srcdir,srcexts,**kwargs):
|
||||||
|
if(not('recurse' in kwargs)):
|
||||||
|
recurse = True
|
||||||
|
else:
|
||||||
|
recurse = kwargs['recurse']
|
||||||
|
|
||||||
|
srcfils = flist(srcdir,exts=srcexts,recurse=recurse)
|
||||||
|
|
||||||
|
for S in srcfils:
|
||||||
|
gs_compile(compiler,S,**kwargs)
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
def gs_link_all(linker,srcpath,target,**kwargs):
|
||||||
|
|
||||||
|
if(not('objext' in kwargs)):
|
||||||
|
objext = '.o'
|
||||||
|
else:
|
||||||
|
objext = kwargs['objext']
|
||||||
|
|
||||||
|
if(not('recurse' in kwargs)):
|
||||||
|
recurse = True
|
||||||
|
else:
|
||||||
|
recurse = kwargs['recurse']
|
||||||
|
|
||||||
|
|
||||||
|
objfils = flist(srcpath,exts=objext,recurse=recurse)
|
||||||
|
oflst = list_to_sss(objfils)
|
||||||
|
|
||||||
|
gs_link_list(linker,oflst,target,**kwargs)
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
def gs_link_list(linker,objlist,target,**kwargs):
|
||||||
|
|
||||||
|
if(not('objext' in kwargs)):
|
||||||
|
objext = '.o'
|
||||||
|
else:
|
||||||
|
objext = kwargs['objext']
|
||||||
|
|
||||||
|
if(not('libdir' in kwargs)):
|
||||||
|
libdir = ''
|
||||||
|
else:
|
||||||
|
libdir = kwargs['libdir']
|
||||||
|
|
||||||
|
if(not('staticlibs' in kwargs)):
|
||||||
|
staticlibs = ''
|
||||||
|
else:
|
||||||
|
staticlibs = kwargs['staticlibs']
|
||||||
|
|
||||||
|
if(not('libflags' in kwargs)):
|
||||||
|
libflags = ''
|
||||||
|
else:
|
||||||
|
libflags = kwargs['libflags']
|
||||||
|
|
||||||
|
if(not('linkerflags' in kwargs)):
|
||||||
|
linkerflags = ''
|
||||||
|
else:
|
||||||
|
linkerflags = kwargs['linkerflags']
|
||||||
|
|
||||||
|
if(not('recurse' in kwargs)):
|
||||||
|
recurse = True
|
||||||
|
else:
|
||||||
|
recurse = kwargs['recurse']
|
||||||
|
|
||||||
|
if(not('logfile' in kwargs)):
|
||||||
|
logfile = ''
|
||||||
|
else:
|
||||||
|
logfile = kwargs['logfile']
|
||||||
|
|
||||||
|
ln = linker+" -o "+target+" "+libdir
|
||||||
|
ln = ln+" "+objlist+" "+staticlibs+" "+libflags+" "+linkerflags
|
||||||
|
|
||||||
|
callproc(ln,logfile=logfile)
|
||||||
|
return
|
||||||
|
|
||||||
|
def msvc_link_list(objlist,target,**kwargs):
|
||||||
|
|
||||||
|
linker = 'link'
|
||||||
|
|
||||||
|
if(not('objext' in kwargs)):
|
||||||
|
objext = '.obj'
|
||||||
|
else:
|
||||||
|
objext = kwargs['objext']
|
||||||
|
|
||||||
|
if(not('libdir' in kwargs)):
|
||||||
|
libdir = ''
|
||||||
|
else:
|
||||||
|
libdir = kwargs['libdir']
|
||||||
|
|
||||||
|
if(not('staticlibs' in kwargs)):
|
||||||
|
staticlibs = ''
|
||||||
|
else:
|
||||||
|
staticlibs = kwargs['staticlibs']
|
||||||
|
|
||||||
|
if(not('libflags' in kwargs)):
|
||||||
|
libflags = ''
|
||||||
|
else:
|
||||||
|
libflags = kwargs['libflags']
|
||||||
|
|
||||||
|
if(not('linkerflags' in kwargs)):
|
||||||
|
linkerflags = ''
|
||||||
|
else:
|
||||||
|
linkerflags = kwargs['linkerflags']
|
||||||
|
|
||||||
|
if(not('recurse' in kwargs)):
|
||||||
|
recurse = True
|
||||||
|
else:
|
||||||
|
recurse = kwargs['recurse']
|
||||||
|
|
||||||
|
if(not('logfile' in kwargs)):
|
||||||
|
logfile = ''
|
||||||
|
else:
|
||||||
|
logfile = kwargs['logfile']
|
||||||
|
|
||||||
|
ln = linker+" "+libdir
|
||||||
|
ln = ln+" "+objlist+" "+staticlibs+" "+linkerflags
|
||||||
|
ln = ln+" /out:"+target+" "+libflags
|
||||||
|
|
||||||
|
callproc(ln,logfile=logfile)
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
def ar_all(srcpath,arname,**kwargs):
|
||||||
|
if(not('recurse' in kwargs)):
|
||||||
|
recurse = True
|
||||||
|
else:
|
||||||
|
recurse = kwargs['recurse']
|
||||||
|
if(not('objext' in kwargs)):
|
||||||
|
objext = '.o'
|
||||||
|
else:
|
||||||
|
objext = kwargs['objext']
|
||||||
|
|
||||||
|
objlist = flist(srcpath,exts=objext,recurse=recurse)
|
||||||
|
ar_list(objlist,arname,**kwargs)
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
def msvc_lib_list(objlist,arname,**kwargs):
|
||||||
|
objlist2 = list_to_sss(objlist)
|
||||||
|
|
||||||
|
ln = "lib "+objlist2+" /out:"+arname
|
||||||
|
callproc(ln)
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
def ar_list(objlist,arname,**kwargs):
|
||||||
|
objlist2 = list_to_sss(objlist)
|
||||||
|
|
||||||
|
ln = "ar cr "+ arname+" "+objlist2
|
||||||
|
callproc(ln)
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
def ar_add_list(objlist,arname,**kwargs):
|
||||||
|
objlist2 = list_to_sss(objlist)
|
||||||
|
|
||||||
|
ln = "ar t "+arname+" "+objlist2
|
||||||
|
callproc(ln)
|
||||||
|
return
|
||||||
|
|
||||||
|
#####################################
|
||||||
|
## Incremental Compilation Library ##
|
||||||
|
#####################################
|
||||||
|
|
||||||
|
#silently read lines from a text file if exists
|
||||||
|
def readtextlines(fname):
|
||||||
|
txtlns = []
|
||||||
|
|
||||||
|
if(not os.path.isfile(fname)):
|
||||||
|
return txtlns
|
||||||
|
|
||||||
|
try:
|
||||||
|
fp = open(fname,"r")
|
||||||
|
except:
|
||||||
|
return txtlns
|
||||||
|
|
||||||
|
ln = " "
|
||||||
|
while(ln!=""):
|
||||||
|
ln = fp.readline()
|
||||||
|
txtlns.append(ln)
|
||||||
|
|
||||||
|
fp.close()
|
||||||
|
|
||||||
|
return txtlns
|
||||||
|
|
||||||
|
def getincludefnfrage(includeline):
|
||||||
|
|
||||||
|
fnfrag = ""
|
||||||
|
I1 = -1
|
||||||
|
I2 = -1
|
||||||
|
|
||||||
|
for I in range(0,len(includeline)):
|
||||||
|
if(I1<0 and (includeline[I]=='<' or includeline[I]=='"')):
|
||||||
|
I1 = I
|
||||||
|
if(I1>=0 and (includeline[I]=='>' or includeline[I]=='"')):
|
||||||
|
I2 = I
|
||||||
|
break
|
||||||
|
if(I1>=0 and I2>=0):
|
||||||
|
fnfrag = includeline[I1+1:I2]
|
||||||
|
|
||||||
|
return fnfrag
|
||||||
|
|
||||||
|
#Returns the name of the source file fname (if it exists)
|
||||||
|
#and all included filenames
|
||||||
|
def getsrcandincludes(fname, incdirs):
|
||||||
|
|
||||||
|
flist = []
|
||||||
|
if(os.path.isfile(fname)):
|
||||||
|
flist.append(fname)
|
||||||
|
|
||||||
|
Ilist = 0
|
||||||
|
while(Ilist<len(flist)):
|
||||||
|
#recurse through files
|
||||||
|
f1 = flist[Ilist]
|
||||||
|
lns = readtextlines(f1)
|
||||||
|
for J in range(0,len(lns)):
|
||||||
|
if(lns[J].find("#include")>=0):
|
||||||
|
fnfrag = getincludefnfrage(lns[J])
|
||||||
|
for K in range(0,len(incdirs)):
|
||||||
|
tfn = os.path.join(incdirs[K],fnfrag)
|
||||||
|
if(os.path.isfile(tfn)):
|
||||||
|
flist.append(tfn)
|
||||||
|
break
|
||||||
|
|
||||||
|
Ilist = Ilist + 1
|
||||||
|
|
||||||
|
return flist
|
||||||
|
|
||||||
|
#Returns the name of the object file associated with the source file
|
||||||
|
#within the object store folder (if it exists)
|
||||||
|
def getobjfile(fname,objstore,objext = ".o"):
|
||||||
|
|
||||||
|
fret = ""
|
||||||
|
f1 = os.path.split(fname)[1]
|
||||||
|
f2 = f1
|
||||||
|
while(os.path.splitext(f2)[1]!=""):
|
||||||
|
f2 = os.path.splitext(f2)[0]
|
||||||
|
objext = objext.strip('.')
|
||||||
|
f3 = os.path.join(objstore,"{}.{}".format(f2,objext))
|
||||||
|
if(os.path.exists(f3)):
|
||||||
|
fret = f3
|
||||||
|
|
||||||
|
return fret
|
||||||
|
|
||||||
|
def getsrctimes(fname, incdirs):
|
||||||
|
|
||||||
|
ftimes = []
|
||||||
|
flst = getsrcandincludes(fname, incdirs)
|
||||||
|
for I in range(0,len(flst)):
|
||||||
|
f = flst[I]
|
||||||
|
mt = os.path.getmtime(f)
|
||||||
|
ftimes.append(mt)
|
||||||
|
|
||||||
|
return ftimes
|
||||||
|
|
||||||
|
def getobjtime(fname,objstore,objext=".o"):
|
||||||
|
ret = -1
|
||||||
|
fret = getobjfile(fname,objstore,objext)
|
||||||
|
if(fret!=""):
|
||||||
|
ret = os.path.getmtime(fret)
|
||||||
|
|
||||||
|
return ret
|
||||||
|
|
||||||
|
#Decide whether or not to compile source file
|
||||||
|
def decidecompile(fname,**kwargs):
|
||||||
|
ret = True
|
||||||
|
|
||||||
|
if(not os.path.isfile(fname)):
|
||||||
|
ret = False
|
||||||
|
return ret
|
||||||
|
|
||||||
|
##unpack kwargs
|
||||||
|
if("searchincdirs" in kwargs):
|
||||||
|
incdirs = kwargs["searchincdirs"]
|
||||||
|
else:
|
||||||
|
incdirs = ["./include"]
|
||||||
|
|
||||||
|
if("objext" in kwargs):
|
||||||
|
objext = kwargs["objext"]
|
||||||
|
else:
|
||||||
|
objext = ".o"
|
||||||
|
if("objstore" in kwargs):
|
||||||
|
objstore = kwargs["objstore"]
|
||||||
|
else:
|
||||||
|
objstore = "./objstore"
|
||||||
|
|
||||||
|
|
||||||
|
srclist = getsrcandincludes(fname,incdirs)
|
||||||
|
srctlist = getsrctimes(fname,incdirs)
|
||||||
|
obj = getobjfile(fname,objstore,objext)
|
||||||
|
objt = getobjtime(fname,objstore,objext)
|
||||||
|
|
||||||
|
if(obj!=""):
|
||||||
|
ret = False
|
||||||
|
for I in range(0,len(srctlist)):
|
||||||
|
if(srctlist[I]>objt):
|
||||||
|
ret = True
|
||||||
|
break
|
||||||
|
|
||||||
|
return ret
|
||||||
|
|
||||||
|
def gs_incremental_compile(compiler,srcfile,**kwargs):
|
||||||
|
|
||||||
|
if(not('include' in kwargs)):
|
||||||
|
include = ''
|
||||||
|
else:
|
||||||
|
include = kwargs['include']
|
||||||
|
if(isinstance(include,list)):
|
||||||
|
include = list_to_sss(include)
|
||||||
|
if(not('flags' in kwargs)):
|
||||||
|
flags = ''
|
||||||
|
else:
|
||||||
|
flags = kwargs['flags']
|
||||||
|
if(isinstance(flags,list)):
|
||||||
|
flags = list_to_sss(flags)
|
||||||
|
if(not('objext' in kwargs)):
|
||||||
|
objext = '.o'
|
||||||
|
else:
|
||||||
|
objext = kwargs['objext']
|
||||||
|
if(not('srcfileflag' in kwargs)):
|
||||||
|
srcfileflag = '-c'
|
||||||
|
else:
|
||||||
|
srcfileflag = kwargs['srcfileflag']
|
||||||
|
if(not('outfileflag' in kwargs)):
|
||||||
|
outfileflag = '-o'
|
||||||
|
else:
|
||||||
|
outfileflag = kwargs['outfileflag']
|
||||||
|
|
||||||
|
if(not('logfile' in kwargs)):
|
||||||
|
logfile = ""
|
||||||
|
else:
|
||||||
|
logfile = kwargs['logfile']
|
||||||
|
if(not('smartcompile' in kwargs)):
|
||||||
|
_smartcompile = True
|
||||||
|
else:
|
||||||
|
_smartcompile = kwargs['smartcompile']
|
||||||
|
|
||||||
|
#incrementalcompile
|
||||||
|
if("searchincdirs" in kwargs):
|
||||||
|
incdirs = kwargs["searchincdirs"]
|
||||||
|
else:
|
||||||
|
incdirs = ["./include"]
|
||||||
|
|
||||||
|
if("objstore" in kwargs):
|
||||||
|
objstore = kwargs["objstore"]
|
||||||
|
else:
|
||||||
|
objstore = "./objstore"
|
||||||
|
|
||||||
|
#Do I want to make this thing this general?
|
||||||
|
|
||||||
|
docompile = decidecompile(srcfile,**kwargs)
|
||||||
|
|
||||||
|
if(docompile):
|
||||||
|
f1 = os.path.split(srcfile)[1]
|
||||||
|
f2 = f1
|
||||||
|
while(os.path.splitext(f2)[1]!=""):
|
||||||
|
f2 = os.path.splitext(f2)[0]
|
||||||
|
outfile = os.path.join(objstore,"{}{}".format(f2,objext))
|
||||||
|
|
||||||
|
ln = compiler+" "+flags+" " + outfileflag+" "+outfile+" "+srcfileflag+" "+srcfile
|
||||||
|
ln = ln + " " + include
|
||||||
|
|
||||||
|
callproc(ln,echo=True,logfile=logfile)
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
def msvc_incremental_compile(compiler,srcfile,**kwargs):
|
||||||
|
|
||||||
|
if(not('include' in kwargs)):
|
||||||
|
include = ''
|
||||||
|
else:
|
||||||
|
include = kwargs['include']
|
||||||
|
if(isinstance(include,list)):
|
||||||
|
include = list_to_sss(include)
|
||||||
|
if(not('flags' in kwargs)):
|
||||||
|
flags = ''
|
||||||
|
else:
|
||||||
|
flags = kwargs['flags']
|
||||||
|
if(isinstance(flags,list)):
|
||||||
|
flags = list_to_sss(flags)
|
||||||
|
if(not('objext' in kwargs)):
|
||||||
|
objext = '.obj'
|
||||||
|
else:
|
||||||
|
objext = kwargs['objext']
|
||||||
|
if(not('srcfileflag' in kwargs)):
|
||||||
|
srcfileflag = '/c'
|
||||||
|
else:
|
||||||
|
srcfileflag = kwargs['srcfileflag']
|
||||||
|
if(not('outfileflag' in kwargs)):
|
||||||
|
outfileflag = '/Fo'
|
||||||
|
else:
|
||||||
|
outfileflag = kwargs['outfileflag']
|
||||||
|
|
||||||
|
if(not('logfile' in kwargs)):
|
||||||
|
logfile = ""
|
||||||
|
else:
|
||||||
|
logfile = kwargs['logfile']
|
||||||
|
|
||||||
|
#incrementalcompile
|
||||||
|
if("searchincdirs" in kwargs):
|
||||||
|
incdirs = kwargs["searchincdirs"]
|
||||||
|
else:
|
||||||
|
incdirs = ["./include"]
|
||||||
|
|
||||||
|
if("objstore" in kwargs):
|
||||||
|
objstore = kwargs["objstore"]
|
||||||
|
else:
|
||||||
|
objstore = "./objstore"
|
||||||
|
|
||||||
|
#Do I want to make this thing this general?
|
||||||
|
|
||||||
|
docompile = decidecompile(srcfile,**kwargs)
|
||||||
|
|
||||||
|
if(docompile):
|
||||||
|
f1 = os.path.split(srcfile)[1]
|
||||||
|
f2 = f1
|
||||||
|
while(os.path.splitext(f2)[1]!=""):
|
||||||
|
f2 = os.path.splitext(f2)[0]
|
||||||
|
outfile = os.path.join(objstore,"{}{}".format(f2,objext))
|
||||||
|
outfile = os.path.normpath(outfile)
|
||||||
|
|
||||||
|
ln = compiler+" "+flags+" "+srcfileflag+" "+srcfile+" "+ outfileflag+'"'+outfile+'"'
|
||||||
|
ln = ln + " " + include
|
||||||
|
|
||||||
|
callproc(ln,echo=True,logfile=logfile)
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
|
def gs_incremental_compile_list(compiler,srclist,**kwargs):
|
||||||
|
|
||||||
|
for s in srclist:
|
||||||
|
gs_incremental_compile(compiler,s,**kwargs)
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
def msvc_incremental_compile_list(compiler,srclist,**kwargs):
|
||||||
|
|
||||||
|
for s in srclist:
|
||||||
|
msvc_incremental_compile(compiler,s,**kwargs)
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
#######################
|
||||||
|
## Main Script Tests ##
|
||||||
|
#######################
|
||||||
|
|
||||||
|
def testtimes(args):
|
||||||
|
if(len(args)>=2):
|
||||||
|
flist = getsrcandincludes(args[1],["./include"])
|
||||||
|
ftlist = getsrctimes(args[1],["./include"])
|
||||||
|
for I in range(0,len(flist)):
|
||||||
|
print("{}\t\t{}".format(flist[I],ftlist[I]))
|
||||||
|
|
||||||
|
print("associated obj file:")
|
||||||
|
fobj = getobjfile(args[1],"./objstore")
|
||||||
|
ftobj = getobjtime(args[1],"./objstore")
|
||||||
|
if(fobj!=""):
|
||||||
|
print("{}\t\t{}".format(fobj,ftobj))
|
||||||
|
else:
|
||||||
|
print("none found")
|
||||||
|
|
||||||
|
cflag = decidecompile(args[1])
|
||||||
|
print("compile? : {}".format(cflag))
|
||||||
|
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
# if(__name__ == "__main__"):
|
||||||
|
|
||||||
|
# args = sys.argv
|
||||||
|
# testtimes(args)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
58
build/make.linux64.lib.py
Normal file
58
build/make.linux64.lib.py
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
import os,sys,math
|
||||||
|
import subprocess
|
||||||
|
import shutil
|
||||||
|
from shutil import copytree
|
||||||
|
|
||||||
|
from amsbuildlib4 import *
|
||||||
|
|
||||||
|
libname = "amsculib2.linux64" #static library name to generate
|
||||||
|
binname = "test" #create this executable when compiling main.c or main.cpp
|
||||||
|
commondir = "../../linux64" #common directory to pul libraries and includes from
|
||||||
|
depdir = "./dependencies/linux64" #local pre-compiled dependency libraries and their includes
|
||||||
|
installdir = "../../linux64" #directory to install to when finished
|
||||||
|
builddir = "./build_linux64"
|
||||||
|
|
||||||
|
doinstall = True #copies the build_output to the install dir when finished
|
||||||
|
cc = "nvcc" #compiler
|
||||||
|
cflags = "-dc --compiler-options '-fPIC -O3'"
|
||||||
|
libraries = "-l{}".format(libname)
|
||||||
|
libdirs = "-L{} -L{}/lib -L{}/lib".format(builddir,commondir,depdir)
|
||||||
|
linkerflags = " -Xlinker=-rpath,."
|
||||||
|
srcexts = [".c",".cpp",".cu"]
|
||||||
|
binsrc = ["main.c","main.cpp", "main.cu"] #ignore these files when compiling the static library
|
||||||
|
|
||||||
|
#keyword list to control the compilers/linkers
|
||||||
|
kwargs = dict()
|
||||||
|
include = "-I./include -I{}/include -I{}/include".format(commondir, depdir)
|
||||||
|
kwargs["include"] = include
|
||||||
|
kwargs["flags"] = cflags
|
||||||
|
kwargs["libdir"] = libdirs
|
||||||
|
kwargs["libflags"] = libraries
|
||||||
|
kwargs["linkerflags"] = linkerflags
|
||||||
|
kwargs["recurse"] = True
|
||||||
|
kwargs["objstore"] = "{}/objstore".format(builddir)
|
||||||
|
kwargs["searchincdirs"] = "./include"
|
||||||
|
|
||||||
|
#Find all source files, except the main project files
|
||||||
|
srcfiles = flist('./src',exts = srcexts, recurse=True)
|
||||||
|
srcfiles = except_contains(srcfiles,binsrc)
|
||||||
|
|
||||||
|
#compile all the source files in the list
|
||||||
|
#gs_compile_list(cc,files,**kwargs)
|
||||||
|
gs_incremental_compile_list(cc,srcfiles,**kwargs)
|
||||||
|
|
||||||
|
#archive all the source files into a static library
|
||||||
|
objlist = flist(kwargs['objstore'],exts='.o',recurse=True)
|
||||||
|
ar_list(objlist,'{}/lib{}.a'.format(builddir,libname))
|
||||||
|
|
||||||
|
if(doinstall):
|
||||||
|
#Push any libraries to the common lib folder
|
||||||
|
shutil.copy(
|
||||||
|
'{}/lib{}.a'.format(builddir,libname),
|
||||||
|
"{}/lib".format(installdir)
|
||||||
|
)
|
||||||
|
|
||||||
|
#Copy include files to the common include folder
|
||||||
|
copytree('./include/',installdir+'/include/',dirs_exist_ok=True)
|
||||||
49
build/make.linux64.test.py
Normal file
49
build/make.linux64.test.py
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
import os,sys,math
|
||||||
|
import subprocess
|
||||||
|
import shutil
|
||||||
|
from shutil import copytree
|
||||||
|
|
||||||
|
from amsbuildlib4 import *
|
||||||
|
|
||||||
|
libname = "amsculib2.linux64" #static library name to generate
|
||||||
|
binname = "test" #create this executable when compiling main.c or main.cpp
|
||||||
|
commondir = "../../linux64" #common directory to pul libraries and includes from
|
||||||
|
depdir = "./dependencies/linux64" #local pre-compiled dependency libraries and their includes
|
||||||
|
installdir = "../../linux64" #directory to install to when finished
|
||||||
|
builddir = "./build_linux64"
|
||||||
|
|
||||||
|
doinstall = True #copies the build_output to the install dir when finished
|
||||||
|
cc = "nvcc" #compiler
|
||||||
|
cflags = "-dc --compiler-options '-fPIC -O3'"
|
||||||
|
libraries = "-l{}".format(libname)
|
||||||
|
libdirs = "-L{} -L{}/lib -L{}/lib".format(builddir,commondir,depdir)
|
||||||
|
linkerflags = " -Xlinker=-rpath,."
|
||||||
|
srcexts = [".c",".cpp",".cu"]
|
||||||
|
binsrc = ["main.c","main.cpp", "main.cu"] #ignore these files when compiling the static library
|
||||||
|
|
||||||
|
#keyword list to control the compilers/linkers
|
||||||
|
kwargs = dict()
|
||||||
|
include = "-I./include -I{}/include -I{}/include".format(commondir, depdir)
|
||||||
|
kwargs["include"] = include
|
||||||
|
kwargs["flags"] = cflags
|
||||||
|
kwargs["libdir"] = libdirs
|
||||||
|
kwargs["libflags"] = libraries
|
||||||
|
kwargs["linkerflags"] = linkerflags
|
||||||
|
kwargs["recurse"] = True
|
||||||
|
kwargs["objstore"] = "{}/objstore".format(builddir)
|
||||||
|
kwargs["searchincdirs"] = "./include"
|
||||||
|
|
||||||
|
#Pull required binary dynamic libraries to the bin folder
|
||||||
|
#shutil.copy('{}/lib/libcamsimg3.linux64.so'.format(commondir),builddir);
|
||||||
|
#shutil.copy('{}/lib/libamsimg.dll'.format(commondir),builddir);
|
||||||
|
#shutil.copy('{}/lib/glew32.dll','./bin_winx64');
|
||||||
|
|
||||||
|
#Designate source files for main test program
|
||||||
|
fsrc = ['./src/main.cu']
|
||||||
|
fobj = replaceexts(fsrc,'.o')
|
||||||
|
|
||||||
|
#Compile test programs
|
||||||
|
gs_compile_list(cc,fsrc,**kwargs)
|
||||||
|
gs_link_list(cc,list_to_sss(fobj),'{}/{}'.format(builddir,binname),**kwargs)
|
||||||
61
build/make.msvc64.lib.py
Normal file
61
build/make.msvc64.lib.py
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
import os,sys,math
|
||||||
|
import subprocess
|
||||||
|
import shutil
|
||||||
|
from shutil import copytree
|
||||||
|
|
||||||
|
from amsbuildlib4 import *
|
||||||
|
|
||||||
|
libname = "amsculib2.msvc64" #static library name to generate
|
||||||
|
binname = "test" #create this executable when compiling main.c or main.cpp
|
||||||
|
commondir = "../../winx64" #common directory to pul libraries and includes from
|
||||||
|
depdir = "./dependencies/winx64" #local pre-compiled dependency libraries and their includes
|
||||||
|
installdir = "../../winx64" #directory to install to when finished
|
||||||
|
builddir = "./build_msvc64"
|
||||||
|
|
||||||
|
doinstall = True #copies the build_output to the install dir when finished
|
||||||
|
cc = "nvcc" #compiler
|
||||||
|
cflags = "-dc --compiler-options '-fPIC -O3'"
|
||||||
|
libraries = "-l{}".format(libname)
|
||||||
|
libdirs = "-L{} -L{}/lib -L{}/lib".format(builddir,commondir,depdir)
|
||||||
|
linkerflags = " -Xlinker=-rpath,."
|
||||||
|
srcexts = [".c",".cpp",".cu"]
|
||||||
|
binsrc = ["main.c","main.cpp","main.cu"] #ignore these files when compiling the static library
|
||||||
|
|
||||||
|
|
||||||
|
#keyword list to control the compilers/linkers
|
||||||
|
kwargs = dict()
|
||||||
|
include = "-I./include -I{}/include -I{}/include".format(commondir, depdir)
|
||||||
|
kwargs["include"] = include
|
||||||
|
kwargs["flags"] = cflags
|
||||||
|
kwargs["libdir"] = libdirs
|
||||||
|
kwargs["libflags"] = libraries
|
||||||
|
kwargs["linkerflags"] = linkerflags
|
||||||
|
kwargs["recurse"] = True
|
||||||
|
kwargs["objstore"] = "{}/objstore".format(builddir)
|
||||||
|
kwargs["searchincdirs"] = "./include"
|
||||||
|
kwargs["objext"] = ".obj"
|
||||||
|
|
||||||
|
|
||||||
|
#Find all source files, except the main project files
|
||||||
|
srcfiles = flist('./src',exts = srcexts, recurse=True)
|
||||||
|
srcfiles = except_contains(srcfiles,binsrc)
|
||||||
|
|
||||||
|
#compile all the source files in the list
|
||||||
|
#gs_compile_list(cc,files,**kwargs)
|
||||||
|
msvc_incremental_compile_list(cc,srcfiles,**kwargs)
|
||||||
|
|
||||||
|
#archive all the source files into a static library
|
||||||
|
objlist = flist(kwargs['objstore'],exts='.obj',recurse=True)
|
||||||
|
msvc_lib_list(objlist,'{}/lib{}.lib'.format(builddir,libname))
|
||||||
|
|
||||||
|
if(doinstall):
|
||||||
|
#Push any libraries to the common lib folder
|
||||||
|
shutil.copy(
|
||||||
|
'{}/lib{}.lib'.format(builddir,libname),
|
||||||
|
"{}/lib".format(installdir)
|
||||||
|
)
|
||||||
|
|
||||||
|
#Copy include files to the common include folder
|
||||||
|
copytree('./include/',installdir+'/include/',dirs_exist_ok=True)
|
||||||
49
build/make.msvc64.test.py
Normal file
49
build/make.msvc64.test.py
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
import os,sys,math
|
||||||
|
import subprocess
|
||||||
|
import shutil
|
||||||
|
from shutil import copytree
|
||||||
|
|
||||||
|
from amsbuildlib4 import *
|
||||||
|
|
||||||
|
libname = "amsculib2.msvc64" #static library name to generate
|
||||||
|
binname = "test.exe" #create this executable when compiling main.c or main.cpp
|
||||||
|
commondir = "../../winx64" #common directory to pul libraries and includes from
|
||||||
|
depdir = "./dependencies/winx64" #local pre-compiled dependency libraries and their includes
|
||||||
|
installdir = "../../winx64" #directory to install to when finished
|
||||||
|
builddir = "./build_msvc64"
|
||||||
|
|
||||||
|
doinstall = False #copies the build_output to the install dir when finished
|
||||||
|
cc = "nvcc" #compiler
|
||||||
|
cflags = "-dc --compiler-options '-fPIC -O3'"
|
||||||
|
libraries = "-l{}".format(libname)
|
||||||
|
libdirs = "-L{} -L{}/lib -L{}/lib".format(builddir,commondir,depdir)
|
||||||
|
linkerflags = " -Xlinker=-rpath,."
|
||||||
|
srcexts = [".c",".cpp",".cu"]
|
||||||
|
binsrc = ["main.c","main.cpp","main.cu"] #ignore these files when compiling the static library
|
||||||
|
|
||||||
|
#keyword list to control the compilers/linkers
|
||||||
|
kwargs = dict()
|
||||||
|
include = "-I./include -I{}/include -I{}/include".format(commondir, depdir)
|
||||||
|
kwargs["include"] = include
|
||||||
|
kwargs["flags"] = cflags
|
||||||
|
kwargs["libdir"] = libdirs
|
||||||
|
kwargs["libflags"] = libraries
|
||||||
|
kwargs["linkerflags"] = linkerflags
|
||||||
|
kwargs["recurse"] = True
|
||||||
|
kwargs["objstore"] = "{}/objstore".format(builddir)
|
||||||
|
kwargs["searchincdirs"] = "./include"
|
||||||
|
|
||||||
|
#Pull required binary dynamic libraries to the bin folder
|
||||||
|
#shutil.copy('{}/lib/libcamsimg3.linux64.so'.format(commondir),builddir);
|
||||||
|
#shutil.copy('{}/lib/libamsimg.dll'.format(commondir),builddir);
|
||||||
|
#shutil.copy('{}/lib/glew32.dll','./bin_winx64');
|
||||||
|
|
||||||
|
#Designate source files for main test program
|
||||||
|
fsrc = ['./src/main.cpp']
|
||||||
|
fobj = replaceexts(fsrc,'.obj')
|
||||||
|
|
||||||
|
#Compile test programs
|
||||||
|
msvc_compile_list(cc,fsrc,**kwargs)
|
||||||
|
msvc_link_list(list_to_sss(fobj),'{}/{}'.format(builddir,binname),**kwargs)
|
||||||
BIN
build_linux64/libamsculib2.linux64.a
Normal file
BIN
build_linux64/libamsculib2.linux64.a
Normal file
Binary file not shown.
0
build_linux64/objstore/.placeholder
Normal file
0
build_linux64/objstore/.placeholder
Normal file
BIN
build_linux64/objstore/amscu_comp128.o
Normal file
BIN
build_linux64/objstore/amscu_comp128.o
Normal file
Binary file not shown.
BIN
build_linux64/objstore/amscu_comp64.o
Normal file
BIN
build_linux64/objstore/amscu_comp64.o
Normal file
Binary file not shown.
BIN
build_linux64/objstore/amscu_cudafunctions.o
Normal file
BIN
build_linux64/objstore/amscu_cudafunctions.o
Normal file
Binary file not shown.
BIN
build_linux64/objstore/amscu_random.o
Normal file
BIN
build_linux64/objstore/amscu_random.o
Normal file
Binary file not shown.
BIN
build_linux64/objstore/amscuarray.o
Normal file
BIN
build_linux64/objstore/amscuarray.o
Normal file
Binary file not shown.
BIN
build_linux64/objstore/amscuarray_dops.o
Normal file
BIN
build_linux64/objstore/amscuarray_dops.o
Normal file
Binary file not shown.
BIN
build_linux64/objstore/amscugeom.o
Normal file
BIN
build_linux64/objstore/amscugeom.o
Normal file
Binary file not shown.
BIN
build_linux64/objstore/amsculib2.o
Normal file
BIN
build_linux64/objstore/amsculib2.o
Normal file
Binary file not shown.
BIN
build_linux64/objstore/amscumath.o
Normal file
BIN
build_linux64/objstore/amscumath.o
Normal file
Binary file not shown.
BIN
build_linux64/objstore/amscurarray.o
Normal file
BIN
build_linux64/objstore/amscurarray.o
Normal file
Binary file not shown.
BIN
build_linux64/objstore/cuvect2.o
Normal file
BIN
build_linux64/objstore/cuvect2.o
Normal file
Binary file not shown.
BIN
build_linux64/objstore/cuvect2f.o
Normal file
BIN
build_linux64/objstore/cuvect2f.o
Normal file
Binary file not shown.
BIN
build_linux64/objstore/cuvect3.o
Normal file
BIN
build_linux64/objstore/cuvect3.o
Normal file
Binary file not shown.
BIN
build_linux64/objstore/cuvect3f.o
Normal file
BIN
build_linux64/objstore/cuvect3f.o
Normal file
Binary file not shown.
BIN
build_linux64/objstore/cuvect4.o
Normal file
BIN
build_linux64/objstore/cuvect4.o
Normal file
Binary file not shown.
BIN
build_linux64/objstore/cuvect4f.o
Normal file
BIN
build_linux64/objstore/cuvect4f.o
Normal file
Binary file not shown.
BIN
build_linux64/test
Normal file
BIN
build_linux64/test
Normal file
Binary file not shown.
0
build_msvc64/objstore/.placeholder
Normal file
0
build_msvc64/objstore/.placeholder
Normal file
@ -75,6 +75,7 @@ namespace amscuda
|
|||||||
__host__ __device__ cuvect2 mat2_mult(double *mat2a, cuvect2 b);
|
__host__ __device__ cuvect2 mat2_mult(double *mat2a, cuvect2 b);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void test_cuvect2_1();
|
void test_cuvect2_1();
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -22,6 +22,7 @@ namespace amscuda
|
|||||||
__host__ __device__ cuvect2f operator-(cuvect2f lhs);
|
__host__ __device__ cuvect2f operator-(cuvect2f lhs);
|
||||||
__host__ __device__ cuvect2f operator*(float lhs);
|
__host__ __device__ cuvect2f operator*(float lhs);
|
||||||
__host__ __device__ cuvect2f operator/(float lhs);
|
__host__ __device__ cuvect2f operator/(float lhs);
|
||||||
|
__host__ __device__ friend cuvect2f operator-(cuvect2f rhs);
|
||||||
};
|
};
|
||||||
|
|
||||||
class cumat2f
|
class cumat2f
|
||||||
|
|||||||
@ -23,6 +23,7 @@ namespace amscuda
|
|||||||
__host__ __device__ cuvect3f operator-(cuvect3f lhs);
|
__host__ __device__ cuvect3f operator-(cuvect3f lhs);
|
||||||
__host__ __device__ cuvect3f operator*(float lhs);
|
__host__ __device__ cuvect3f operator*(float lhs);
|
||||||
__host__ __device__ cuvect3f operator/(float lhs);
|
__host__ __device__ cuvect3f operator/(float lhs);
|
||||||
|
__host__ __device__ friend cuvect3f operator-(cuvect3f rhs);
|
||||||
};
|
};
|
||||||
|
|
||||||
class cumat3f
|
class cumat3f
|
||||||
|
|||||||
@ -23,6 +23,7 @@ namespace amscuda
|
|||||||
__host__ __device__ cuvect4f operator-(cuvect4f lhs);
|
__host__ __device__ cuvect4f operator-(cuvect4f lhs);
|
||||||
__host__ __device__ cuvect4f operator*(float lhs);
|
__host__ __device__ cuvect4f operator*(float lhs);
|
||||||
__host__ __device__ cuvect4f operator/(float lhs);
|
__host__ __device__ cuvect4f operator/(float lhs);
|
||||||
|
__host__ __device__ friend cuvect4f operator-(cuvect4f rhs);
|
||||||
};
|
};
|
||||||
|
|
||||||
class cumat4f
|
class cumat4f
|
||||||
|
|||||||
22
make_linux.py
Normal file
22
make_linux.py
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
import os,sys,math
|
||||||
|
from build.amsbuildlib4 import *
|
||||||
|
|
||||||
|
if(len(sys.argv)>=2):
|
||||||
|
if(sys.argv[1]=="clean"):
|
||||||
|
obj_list = flist('./build_linux64',recurse=True,exts=['.o'])
|
||||||
|
for o in obj_list:
|
||||||
|
os.remove('{}'.format(o))
|
||||||
|
exit()
|
||||||
|
|
||||||
|
os.system('python3 ./build/make.linux64.lib.py')
|
||||||
|
os.system('python3 ./build/make.linux64.test.py')
|
||||||
|
|
||||||
|
obj_list = flist('./src',recurse=True,exts=['.o'])
|
||||||
|
for o in obj_list:
|
||||||
|
os.remove('{}'.format(o))
|
||||||
|
|
||||||
|
os.chdir('./build_linux64')
|
||||||
|
callproc('./test')
|
||||||
|
os.chdir('..')
|
||||||
28
make_mingw.py
Normal file
28
make_mingw.py
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
import os,sys,math
|
||||||
|
from build.amsbuildlib4 import *
|
||||||
|
|
||||||
|
if(len(sys.argv)>=2):
|
||||||
|
if(sys.argv[1]=="clean"):
|
||||||
|
obj_list = flist('./build_mingw64',recurse=True,exts=['.o'])
|
||||||
|
for o in obj_list:
|
||||||
|
os.remove('{}'.format(o))
|
||||||
|
exit()
|
||||||
|
|
||||||
|
os.system('python3 ./build/make.mingw64.lib.py')
|
||||||
|
os.system('python3 ./build/make.mingw64.test.py')
|
||||||
|
|
||||||
|
obj_list = flist('./src',recurse=True,exts=['.o','.obj'])
|
||||||
|
for o in obj_list:
|
||||||
|
os.remove('{}'.format(o))
|
||||||
|
|
||||||
|
if(sys.platform!="win32"):
|
||||||
|
os.chdir('./build_mingw64')
|
||||||
|
callproc('wine ./test.exe')
|
||||||
|
os.chdir('..')
|
||||||
|
else:
|
||||||
|
os.chdir('./build_mingw64')
|
||||||
|
callproc('test.exe')
|
||||||
|
os.chdir('..')
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
old/bin_linux64/libamsculib2.linux64.a
Normal file
BIN
old/bin_linux64/libamsculib2.linux64.a
Normal file
Binary file not shown.
BIN
old/bin_linux64/test
Normal file
BIN
old/bin_linux64/test
Normal file
Binary file not shown.
BIN
old/bin_winx64/libamsculib2.msvc64.lib
Normal file
BIN
old/bin_winx64/libamsculib2.msvc64.lib
Normal file
Binary file not shown.
BIN
old/bin_winx64/test.exe
Normal file
BIN
old/bin_winx64/test.exe
Normal file
Binary file not shown.
BIN
old/bin_winx64/test.exp
Normal file
BIN
old/bin_winx64/test.exp
Normal file
Binary file not shown.
BIN
old/bin_winx64/test.lib
Normal file
BIN
old/bin_winx64/test.lib
Normal file
Binary file not shown.
BIN
old/compscripts/__pycache__/complib2.cpython-310.pyc
Normal file
BIN
old/compscripts/__pycache__/complib2.cpython-310.pyc
Normal file
Binary file not shown.
BIN
old/compscripts/__pycache__/complib2.cpython-312.pyc
Normal file
BIN
old/compscripts/__pycache__/complib2.cpython-312.pyc
Normal file
Binary file not shown.
BIN
old/compscripts/__pycache__/complib2.cpython-36.pyc
Normal file
BIN
old/compscripts/__pycache__/complib2.cpython-36.pyc
Normal file
Binary file not shown.
BIN
old/compscripts/__pycache__/complib2.cpython-38.pyc
Normal file
BIN
old/compscripts/__pycache__/complib2.cpython-38.pyc
Normal file
Binary file not shown.
BIN
old/compscripts/__pycache__/complib2.cpython-39.pyc
Normal file
BIN
old/compscripts/__pycache__/complib2.cpython-39.pyc
Normal file
Binary file not shown.
BIN
old/compscripts/__pycache__/complib3.cpython-310.pyc
Normal file
BIN
old/compscripts/__pycache__/complib3.cpython-310.pyc
Normal file
Binary file not shown.
BIN
old/compscripts/__pycache__/complib3.cpython-312.pyc
Normal file
BIN
old/compscripts/__pycache__/complib3.cpython-312.pyc
Normal file
Binary file not shown.
BIN
old/compscripts/__pycache__/complib3.cpython-39.pyc
Normal file
BIN
old/compscripts/__pycache__/complib3.cpython-39.pyc
Normal file
Binary file not shown.
639
old/compscripts/complib2.py
Normal file
639
old/compscripts/complib2.py
Normal file
@ -0,0 +1,639 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
#Python3 compilation library
|
||||||
|
#Aaron M. Schinder
|
||||||
|
#29 Dec 2020
|
||||||
|
#
|
||||||
|
#Cleanup and refactor from 2017 python2 version compilation libraries
|
||||||
|
|
||||||
|
import os,sys,math,subprocess
|
||||||
|
|
||||||
|
#####################
|
||||||
|
#Directory Functions#
|
||||||
|
#####################
|
||||||
|
|
||||||
|
##flist - list all files in a given directory pth
|
||||||
|
##optional arguments:
|
||||||
|
# recurse - (T/F): Whether to recursively search for files in directory tree
|
||||||
|
# exts - (list): A list of file extensions to filter on
|
||||||
|
# normpath (T/F): whether to normalize path variables after
|
||||||
|
#filelist = flist(pth,**kwargs):
|
||||||
|
def flist(pth,**kwargs):
|
||||||
|
flst = []
|
||||||
|
if(not('recurse' in kwargs)):
|
||||||
|
recurse_ = False
|
||||||
|
else:
|
||||||
|
recurse_ = kwargs['recurse']
|
||||||
|
if(not('exts' in kwargs)):
|
||||||
|
filterexts_ = False
|
||||||
|
else:
|
||||||
|
filterexts_ = True
|
||||||
|
exts = kwargs['exts']
|
||||||
|
if(not('normpath' in kwargs)):
|
||||||
|
normpath_ = True
|
||||||
|
else:
|
||||||
|
normpath_ = kwargs['normpath']
|
||||||
|
if(not('linuxpath' in kwargs)):
|
||||||
|
linuxpath_ = False
|
||||||
|
else:
|
||||||
|
linuxpath_ = kwargs['linuxpath']
|
||||||
|
if(not('followlinks' in kwargs)):
|
||||||
|
followlinks_ = False
|
||||||
|
else:
|
||||||
|
followlinks_ = kwargs['followlinks']
|
||||||
|
|
||||||
|
dirlist = []
|
||||||
|
rawlist = os.listdir(pth)
|
||||||
|
|
||||||
|
for F in rawlist:
|
||||||
|
F2 = os.path.join(pth,F)
|
||||||
|
if(os.path.isdir(F2)):
|
||||||
|
b = (followlinks_) or ((not followlinks_) and not(os.path.islink(F2)))
|
||||||
|
if(b):
|
||||||
|
if((F2!=".")&(F2!="..")):
|
||||||
|
dirlist.append(F2)
|
||||||
|
elif(os.path.isfile(F2)):
|
||||||
|
flst.append(F2)
|
||||||
|
|
||||||
|
#Recurse through directories
|
||||||
|
if(recurse_):
|
||||||
|
for D in dirlist:
|
||||||
|
lst = flist(D,**kwargs)
|
||||||
|
for L in lst:
|
||||||
|
flst.append(L)
|
||||||
|
|
||||||
|
#Postprocess:
|
||||||
|
#Filter out all extensions except the selected ext list
|
||||||
|
if(filterexts_):
|
||||||
|
flst = filterexts(flst,exts)
|
||||||
|
|
||||||
|
#Normalize filename path according to os
|
||||||
|
if(normpath_):
|
||||||
|
flst2 = list(flst)
|
||||||
|
for I in range(0,len(flst2)):
|
||||||
|
flst[I] = os.path.normpath(flst2[I])
|
||||||
|
|
||||||
|
#If linuxpath, convert all \\ to /
|
||||||
|
#if(linuxpath_):
|
||||||
|
# flst2 = list(flst)
|
||||||
|
# for I in range(0,len(flst2)):
|
||||||
|
# flst[I] = linuxpath(flst2[I])
|
||||||
|
|
||||||
|
return flst
|
||||||
|
|
||||||
|
#Filters by extensions in a list of files
|
||||||
|
#flst = def filterexts(flst,exts):
|
||||||
|
def filterexts(flst,exts):
|
||||||
|
flst2 = []
|
||||||
|
if(isinstance(exts,str)):
|
||||||
|
exts = list([exts])
|
||||||
|
for F in flst:
|
||||||
|
b = False
|
||||||
|
for ext in exts:
|
||||||
|
if(ext[0]!='.'):
|
||||||
|
ext = '.'+ext
|
||||||
|
F2 = os.path.splitext(F)
|
||||||
|
if(len(F2)>=2):
|
||||||
|
ex = F2[1]
|
||||||
|
if(len(ex)>0):
|
||||||
|
if(ex[0]!='.'):
|
||||||
|
ex = '.'+ex
|
||||||
|
if(ex==ext):
|
||||||
|
b = True
|
||||||
|
if(b):
|
||||||
|
flst2.append(F)
|
||||||
|
|
||||||
|
return flst2
|
||||||
|
|
||||||
|
#Find a file fname, starting in pth and recursing
|
||||||
|
#Used for finding library files to link
|
||||||
|
def findfile(fname,pth,**kwargs):
|
||||||
|
fullfname = ""
|
||||||
|
flst = flist(pth,recurse=True)
|
||||||
|
for F in flst:
|
||||||
|
F2 = os.path.split(F)[1]
|
||||||
|
if(F2 == fname):
|
||||||
|
fullfname = F
|
||||||
|
|
||||||
|
return fullfname
|
||||||
|
|
||||||
|
#List to space-seperated-string
|
||||||
|
def list_to_sss(lst):
|
||||||
|
lout = ""
|
||||||
|
for I in range(0,len(lst)-1):
|
||||||
|
lout = lout + lst[I] + " "
|
||||||
|
if(len(lst)>0):
|
||||||
|
lout = lout + lst[len(lst)-1]
|
||||||
|
return lout
|
||||||
|
|
||||||
|
def strip_whitespace(strin):
|
||||||
|
strout = ""
|
||||||
|
I1 = -1
|
||||||
|
I2 = -1
|
||||||
|
for I in range(0,len(strin)):
|
||||||
|
if(strin[I]!=' ' and strin[I]!='\t' and strin[I]!='\r'and strin[I]!='\n'):
|
||||||
|
I1 = I
|
||||||
|
break
|
||||||
|
q = list(range(0,len(strin)))
|
||||||
|
q.reverse()
|
||||||
|
for I in q:
|
||||||
|
if(strin[I]!=' ' and strin[I]!='\t' and strin[I]!='\r'and strin[I]!='\n'):
|
||||||
|
I2 = I+1
|
||||||
|
break
|
||||||
|
if(I1>=0 and I2>=0):
|
||||||
|
strout = strin[I1:I2]
|
||||||
|
return strout
|
||||||
|
|
||||||
|
def sss_to_list(sss):
|
||||||
|
lout = []
|
||||||
|
l1 = sss.split(' ')
|
||||||
|
for l in l1:
|
||||||
|
l2 = strip_whitespace(l)
|
||||||
|
lout.append(l2)
|
||||||
|
return lout
|
||||||
|
|
||||||
|
|
||||||
|
def replaceext(fname,ext):
|
||||||
|
fname2 = ""
|
||||||
|
if(len(ext)>0):
|
||||||
|
if(ext[0]!='.'):
|
||||||
|
ext = '.'+ext
|
||||||
|
fname2 = os.path.splitext(fname)[0]+ext
|
||||||
|
else:
|
||||||
|
fname2 = os.path.splitext(fname)[0]
|
||||||
|
return fname2
|
||||||
|
|
||||||
|
def replaceexts(fnamelist,ext):
|
||||||
|
fname2list = []
|
||||||
|
for F in fnamelist:
|
||||||
|
F2 = replaceext(F,ext)
|
||||||
|
fname2list.append(F2)
|
||||||
|
return fname2list
|
||||||
|
|
||||||
|
# def except_contains_oldv(lst1,exc):
|
||||||
|
# lst2 = []
|
||||||
|
# for item in lst1:
|
||||||
|
# b = 1
|
||||||
|
# for item2 in exc:
|
||||||
|
# if(item.find(item2)>=0):
|
||||||
|
# b = 0
|
||||||
|
# break
|
||||||
|
# if(b==1):
|
||||||
|
# lst2.append(item)
|
||||||
|
# return lst2
|
||||||
|
|
||||||
|
#filenames must match
|
||||||
|
def except_contains(lst1,exc):
|
||||||
|
lst2 = []
|
||||||
|
for item in lst1:
|
||||||
|
b = 1
|
||||||
|
for item2 in exc:
|
||||||
|
fsplit = os.path.split(item)
|
||||||
|
fn = fsplit[len(fsplit)-1]
|
||||||
|
if(fn==item2):
|
||||||
|
b = 0
|
||||||
|
break
|
||||||
|
if(b==1):
|
||||||
|
lst2.append(item)
|
||||||
|
return lst2
|
||||||
|
|
||||||
|
##########################
|
||||||
|
##System Call Procedures##
|
||||||
|
##########################
|
||||||
|
|
||||||
|
def callproc(cmd, **kwargs):
|
||||||
|
if(not('logfile' in kwargs)):
|
||||||
|
use_lf = False
|
||||||
|
else:
|
||||||
|
logfile = kwargs['logfile']
|
||||||
|
if(logfile!=""):
|
||||||
|
fp = open(kwargs['logfile'],'a+')
|
||||||
|
use_lf = True
|
||||||
|
else:
|
||||||
|
use_lf = False
|
||||||
|
|
||||||
|
if(not('echo' in kwargs)):
|
||||||
|
echo = True
|
||||||
|
else:
|
||||||
|
echo = kwargs['echo']
|
||||||
|
|
||||||
|
if(echo):
|
||||||
|
print(cmd)
|
||||||
|
|
||||||
|
#encoding/deconding to/from bytes is necessary to use the subprocess command
|
||||||
|
#in python3.7
|
||||||
|
#However, only do this in linux
|
||||||
|
if(sys.platform!='win32'):
|
||||||
|
cmd2 = cmd.encode(encoding='utf-8')
|
||||||
|
else:
|
||||||
|
cmd2 = cmd
|
||||||
|
proc = subprocess.Popen(cmd2,stderr = subprocess.STDOUT, stdout=subprocess.PIPE, shell=True)
|
||||||
|
(out, err) = proc.communicate()
|
||||||
|
|
||||||
|
out = out.decode(encoding='utf-8')
|
||||||
|
|
||||||
|
if(echo):
|
||||||
|
print(out)
|
||||||
|
#print(err);
|
||||||
|
if(use_lf):
|
||||||
|
fp.writelines(cmd+'\n')
|
||||||
|
fp.writelines(out+'\n')
|
||||||
|
|
||||||
|
if(use_lf):
|
||||||
|
fp.close()
|
||||||
|
|
||||||
|
#######################################
|
||||||
|
##Compiler, Archive, and Linker Calls##
|
||||||
|
#######################################
|
||||||
|
|
||||||
|
def smartcompile(srcfile,objext='.o'):
|
||||||
|
mtsrc = os.path.getmtime(srcfile)
|
||||||
|
objfile = replaceext(srcfile,objext)
|
||||||
|
objexists = os.path.exists(objfile)
|
||||||
|
ret = True
|
||||||
|
if(objexists):
|
||||||
|
mtobj = os.path.getmtime(objfile)
|
||||||
|
if(mtobj>=mtsrc):
|
||||||
|
ret = False
|
||||||
|
|
||||||
|
return ret
|
||||||
|
|
||||||
|
#MSVC compiler wrapper
|
||||||
|
def msvc_compile(compilername, srcfile, **kwargs):
|
||||||
|
|
||||||
|
if(not('include' in kwargs)):
|
||||||
|
include = ''
|
||||||
|
else:
|
||||||
|
include = kwargs['include']
|
||||||
|
if(isinstance(include,list)):
|
||||||
|
include = list_to_sss(include)
|
||||||
|
|
||||||
|
if(not('flags' in kwargs)):
|
||||||
|
flags = ''
|
||||||
|
else:
|
||||||
|
flags = kwargs['flags']
|
||||||
|
if(isinstance(flags,list)):
|
||||||
|
flags = list_to_sss(flags)
|
||||||
|
|
||||||
|
if(not('objext' in kwargs)):
|
||||||
|
objext = '.obj'
|
||||||
|
else:
|
||||||
|
objext = kwargs['objext']
|
||||||
|
|
||||||
|
if(not('srcfileflag' in kwargs)):
|
||||||
|
srcfileflag = '/c'
|
||||||
|
else:
|
||||||
|
srcfileflag = kwargs['srcfileflag']
|
||||||
|
|
||||||
|
if(not('outfileflag' in kwargs)):
|
||||||
|
outfileflag = '/Fo:'
|
||||||
|
else:
|
||||||
|
outfileflag = kwargs['outfileflag']
|
||||||
|
if(not('logfile' in kwargs)):
|
||||||
|
logfile = ""
|
||||||
|
else:
|
||||||
|
logfile = kwargs['logfile']
|
||||||
|
|
||||||
|
outfile = replaceext(srcfile,objext)
|
||||||
|
ln = compilername+" "+flags+" "+" "+srcfileflag+" "+srcfile+" "+outfileflag+outfile
|
||||||
|
ln = ln + " " + include
|
||||||
|
|
||||||
|
callproc(ln,echo=True,logfile=logfile)
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
#MSVC compiler wrapper
|
||||||
|
def msvc_compile_list(compiler,srclist,**kwargs):
|
||||||
|
for S in srclist:
|
||||||
|
msvc_compile(compiler,S,**kwargs)
|
||||||
|
return
|
||||||
|
|
||||||
|
#gnu-style compiler compile: Should work with gcc, g++, gfortran
|
||||||
|
def gs_compile(compiler,srcfile,**kwargs):
|
||||||
|
if(not('include' in kwargs)):
|
||||||
|
include = ''
|
||||||
|
else:
|
||||||
|
include = kwargs['include']
|
||||||
|
if(isinstance(include,list)):
|
||||||
|
include = list_to_sss(include)
|
||||||
|
|
||||||
|
if(not('flags' in kwargs)):
|
||||||
|
flags = ''
|
||||||
|
else:
|
||||||
|
flags = kwargs['flags']
|
||||||
|
if(isinstance(flags,list)):
|
||||||
|
flags = list_to_sss(flags)
|
||||||
|
|
||||||
|
if(not('objext' in kwargs)):
|
||||||
|
objext = '.o'
|
||||||
|
else:
|
||||||
|
objext = kwargs['objext']
|
||||||
|
|
||||||
|
if(not('srcfileflag' in kwargs)):
|
||||||
|
srcfileflag = '-c'
|
||||||
|
else:
|
||||||
|
srcfileflag = kwargs['srcfileflag']
|
||||||
|
|
||||||
|
if(not('outfileflag' in kwargs)):
|
||||||
|
outfileflag = '-o'
|
||||||
|
else:
|
||||||
|
outfileflag = kwargs['outfileflag']
|
||||||
|
|
||||||
|
if(not('logfile' in kwargs)):
|
||||||
|
logfile = ""
|
||||||
|
else:
|
||||||
|
logfile = kwargs['logfile']
|
||||||
|
|
||||||
|
if(not('smartcompile' in kwargs)):
|
||||||
|
_smartcompile = True
|
||||||
|
else:
|
||||||
|
_smartcompile = kwargs['smartcompile']
|
||||||
|
|
||||||
|
#Do I want to make this thing this general?
|
||||||
|
|
||||||
|
if(not(_smartcompile) or smartcompile(srcfile,objext)):
|
||||||
|
outfile = replaceext(srcfile,objext)
|
||||||
|
ln = compiler+" "+flags+" " + outfileflag+" "+outfile+" "+srcfileflag+" "+srcfile
|
||||||
|
ln = ln + " " + include
|
||||||
|
|
||||||
|
callproc(ln,echo=True,logfile=logfile)
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
def gs_compile_list(compiler,srclist,**kwargs):
|
||||||
|
for S in srclist:
|
||||||
|
gs_compile(compiler,S,**kwargs)
|
||||||
|
return
|
||||||
|
|
||||||
|
def gs_compile_all(compiler,srcdir,srcexts,**kwargs):
|
||||||
|
if(not('recurse' in kwargs)):
|
||||||
|
recurse = True
|
||||||
|
else:
|
||||||
|
recurse = kwargs['recurse']
|
||||||
|
|
||||||
|
srcfils = flist(srcdir,exts=srcexts,recurse=recurse)
|
||||||
|
|
||||||
|
for S in srcfils:
|
||||||
|
gs_compile(compiler,S,**kwargs)
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
def gs_link_all(linker,srcpath,target,**kwargs):
|
||||||
|
|
||||||
|
if(not('objext' in kwargs)):
|
||||||
|
objext = '.o'
|
||||||
|
else:
|
||||||
|
objext = kwargs['objext']
|
||||||
|
|
||||||
|
if(not('recurse' in kwargs)):
|
||||||
|
recurse = True
|
||||||
|
else:
|
||||||
|
recurse = kwargs['recurse']
|
||||||
|
|
||||||
|
|
||||||
|
objfils = flist(srcpath,exts=objext,recurse=recurse)
|
||||||
|
oflst = list_to_sss(objfils)
|
||||||
|
|
||||||
|
gs_link_list(linker,oflst,target,**kwargs)
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
def gs_link_list(linker,objlist,target,**kwargs):
|
||||||
|
|
||||||
|
if(not('objext' in kwargs)):
|
||||||
|
objext = '.o'
|
||||||
|
else:
|
||||||
|
objext = kwargs['objext']
|
||||||
|
|
||||||
|
if(not('libdir' in kwargs)):
|
||||||
|
libdir = ''
|
||||||
|
else:
|
||||||
|
libdir = kwargs['libdir']
|
||||||
|
|
||||||
|
if(not('staticlibs' in kwargs)):
|
||||||
|
staticlibs = ''
|
||||||
|
else:
|
||||||
|
staticlibs = kwargs['staticlibs']
|
||||||
|
|
||||||
|
if(not('libflags' in kwargs)):
|
||||||
|
libflags = ''
|
||||||
|
else:
|
||||||
|
libflags = kwargs['libflags']
|
||||||
|
|
||||||
|
if(not('linkerflags' in kwargs)):
|
||||||
|
linkerflags = ''
|
||||||
|
else:
|
||||||
|
linkerflags = kwargs['linkerflags']
|
||||||
|
|
||||||
|
if(not('recurse' in kwargs)):
|
||||||
|
recurse = True
|
||||||
|
else:
|
||||||
|
recurse = kwargs['recurse']
|
||||||
|
|
||||||
|
if(not('logfile' in kwargs)):
|
||||||
|
logfile = ''
|
||||||
|
else:
|
||||||
|
logfile = kwargs['logfile']
|
||||||
|
|
||||||
|
ln = linker+" -o "+target+" "+libdir
|
||||||
|
ln = ln+" "+objlist+" "+staticlibs+" "+libflags+" "+linkerflags
|
||||||
|
|
||||||
|
callproc(ln,logfile=logfile)
|
||||||
|
return
|
||||||
|
|
||||||
|
def msvc_link_list(objlist,target,**kwargs):
|
||||||
|
|
||||||
|
linker = 'link'
|
||||||
|
|
||||||
|
if(not('objext' in kwargs)):
|
||||||
|
objext = '.obj'
|
||||||
|
else:
|
||||||
|
objext = kwargs['objext']
|
||||||
|
|
||||||
|
if(not('libdir' in kwargs)):
|
||||||
|
libdir = ''
|
||||||
|
else:
|
||||||
|
libdir = kwargs['libdir']
|
||||||
|
|
||||||
|
if(not('staticlibs' in kwargs)):
|
||||||
|
staticlibs = ''
|
||||||
|
else:
|
||||||
|
staticlibs = kwargs['staticlibs']
|
||||||
|
|
||||||
|
if(not('libflags' in kwargs)):
|
||||||
|
libflags = ''
|
||||||
|
else:
|
||||||
|
libflags = kwargs['libflags']
|
||||||
|
|
||||||
|
if(not('linkerflags' in kwargs)):
|
||||||
|
linkerflags = ''
|
||||||
|
else:
|
||||||
|
linkerflags = kwargs['linkerflags']
|
||||||
|
|
||||||
|
if(not('recurse' in kwargs)):
|
||||||
|
recurse = True
|
||||||
|
else:
|
||||||
|
recurse = kwargs['recurse']
|
||||||
|
|
||||||
|
if(not('logfile' in kwargs)):
|
||||||
|
logfile = ''
|
||||||
|
else:
|
||||||
|
logfile = kwargs['logfile']
|
||||||
|
|
||||||
|
ln = linker+" "+libdir
|
||||||
|
ln = ln+" "+objlist+" "+staticlibs+" "+linkerflags
|
||||||
|
ln = ln+" /out:"+target+" "+libflags
|
||||||
|
|
||||||
|
callproc(ln,logfile=logfile)
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
def ar_all(srcpath,arname,**kwargs):
|
||||||
|
if(not('recurse' in kwargs)):
|
||||||
|
recurse = True
|
||||||
|
else:
|
||||||
|
recurse = kwargs['recurse']
|
||||||
|
if(not('objext' in kwargs)):
|
||||||
|
objext = '.o'
|
||||||
|
else:
|
||||||
|
objext = kwargs['objext']
|
||||||
|
|
||||||
|
objlist = flist(srcpath,exts=objext,recurse=recurse)
|
||||||
|
ar_list(objlist,arname,**kwargs)
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
def msvc_lib_list(objlist,arname,**kwargs):
|
||||||
|
objlist2 = list_to_sss(objlist)
|
||||||
|
|
||||||
|
ln = "lib "+objlist2+" /out:"+arname
|
||||||
|
callproc(ln)
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
def ar_list(objlist,arname,**kwargs):
|
||||||
|
objlist2 = list_to_sss(objlist)
|
||||||
|
|
||||||
|
ln = "ar cr "+ arname+" "+objlist2
|
||||||
|
callproc(ln)
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
def ar_add_list(objlist,arname,**kwargs):
|
||||||
|
objlist2 = list_to_sss(objlist)
|
||||||
|
|
||||||
|
ln = "ar t "+arname+" "+objlist2
|
||||||
|
callproc(ln)
|
||||||
|
return
|
||||||
|
|
||||||
|
##############################
|
||||||
|
##Derived Compiler Functions##
|
||||||
|
##############################
|
||||||
|
|
||||||
|
def gcc_compile(srcfile,**kwargs):
|
||||||
|
compiler = 'gcc'
|
||||||
|
kwargs['objext'] = '.o'
|
||||||
|
#srcexts = ['.c']
|
||||||
|
|
||||||
|
gs_compile(compiler,srcfile,**kwargs)
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
def gcc_compile_all(srcdir,**kwargs):
|
||||||
|
compiler = 'gcc'
|
||||||
|
kwargs['objext'] = '.o'
|
||||||
|
srcexts = ['.c']
|
||||||
|
|
||||||
|
gs_compile_all(compiler,srcdir,srcexts,**kwargs)
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
def gcc_compile_list(srclist,**kwargs):
|
||||||
|
compiler = 'gcc'
|
||||||
|
kwargs['objext'] = '.o'
|
||||||
|
#srcexts = ['.c']
|
||||||
|
|
||||||
|
gs_compile_list(compiler,srclist,**kwargs)
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
def gpp_compile(srcfile,**kwargs):
|
||||||
|
compiler = 'g++'
|
||||||
|
kwargs['objext'] = '.o'
|
||||||
|
#srcexts = ['.c','.cpp']
|
||||||
|
|
||||||
|
gs_compile(compiler,srcfile,**kwargs)
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
def gpp_compile_all(srcdir,**kwargs):
|
||||||
|
compiler = 'g++'
|
||||||
|
kwargs['objext'] = '.o'
|
||||||
|
srcexts = ['.c','.cpp']
|
||||||
|
|
||||||
|
gs_compile_all(compiler,srcdir,srcexts,**kwargs)
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
def gpp_compile_list(srclist,**kwargs):
|
||||||
|
compiler = 'g++'
|
||||||
|
kwargs['objext'] = '.o'
|
||||||
|
#srcexts = ['.c','.cpp']
|
||||||
|
|
||||||
|
gs_compile_list(compiler,srclist,**kwargs)
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
def gfortran_compile(srcfile,**kwargs):
|
||||||
|
compiler = 'gfortran'
|
||||||
|
kwargs['objext'] = '.o'
|
||||||
|
#srcexts = ['.f','.f90','.f77']
|
||||||
|
|
||||||
|
gs_compile(compiler,srcfile,**kwargs)
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
def gfortran_compile_all(srcdir,**kwargs):
|
||||||
|
compiler = 'gfortran'
|
||||||
|
kwargs['objext'] = '.o'
|
||||||
|
srcexts = ['.f','.f90','.f77']
|
||||||
|
|
||||||
|
gs_compile_all(compiler,srcdir,srcexts,**kwargs)
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
def gfortran_compile_list(srclist,**kwargs):
|
||||||
|
compiler = 'gfortran'
|
||||||
|
kwargs['objext'] = '.o'
|
||||||
|
#srcexts = ['.f','.f90','.f77']
|
||||||
|
|
||||||
|
gs_compile_list(compiler,srclist,**kwargs)
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
def clang_compile(srcfile,**kwargs):
|
||||||
|
compiler = 'clang++'
|
||||||
|
kwargs['objext'] = '.o'
|
||||||
|
#srcexts = ['.c','.cpp']
|
||||||
|
|
||||||
|
gs_compile(compiler,srcfile,**kwargs)
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
def clang_compile_all(srcdir,**kwargs):
|
||||||
|
compiler = 'clang++'
|
||||||
|
kwargs['objext'] = '.o'
|
||||||
|
srcexts = ['.c','.cpp']
|
||||||
|
|
||||||
|
gs_compile_all(compiler,srcdir,srcexts,**kwargs)
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
def clang_compile_list(srclist,**kwargs):
|
||||||
|
compiler = 'clang++'
|
||||||
|
kwargs['objext'] = '.o'
|
||||||
|
#srcexts = ['.c','.cpp']
|
||||||
|
|
||||||
|
gs_compile_list(compiler,srclist,**kwargs)
|
||||||
|
|
||||||
|
return
|
||||||
524
old/compscripts/complib3.py
Normal file
524
old/compscripts/complib3.py
Normal file
@ -0,0 +1,524 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
import os,sys,math
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
##flist - list all files in a given directory pth
|
||||||
|
##optional arguments:
|
||||||
|
# recurse - (T/F): Whether to recursively search for files in directory tree
|
||||||
|
# exts - (list): A list of file extensions to filter on
|
||||||
|
# normpath (T/F): whether to normalize path variables after
|
||||||
|
#filelist = flist(pth,**kwargs):
|
||||||
|
def flist(pth,**kwargs):
|
||||||
|
flst = []
|
||||||
|
if(not('recurse' in kwargs)):
|
||||||
|
recurse_ = False
|
||||||
|
else:
|
||||||
|
recurse_ = kwargs['recurse']
|
||||||
|
if(not('exts' in kwargs)):
|
||||||
|
filterexts_ = False
|
||||||
|
else:
|
||||||
|
filterexts_ = True
|
||||||
|
exts = kwargs['exts']
|
||||||
|
if(not('normpath' in kwargs)):
|
||||||
|
normpath_ = True
|
||||||
|
else:
|
||||||
|
normpath_ = kwargs['normpath']
|
||||||
|
if(not('linuxpath' in kwargs)):
|
||||||
|
linuxpath_ = False
|
||||||
|
else:
|
||||||
|
linuxpath_ = kwargs['linuxpath']
|
||||||
|
if(not('followlinks' in kwargs)):
|
||||||
|
followlinks_ = False
|
||||||
|
else:
|
||||||
|
followlinks_ = kwargs['followlinks']
|
||||||
|
|
||||||
|
dirlist = []
|
||||||
|
rawlist = os.listdir(pth)
|
||||||
|
|
||||||
|
for F in rawlist:
|
||||||
|
F2 = os.path.join(pth,F)
|
||||||
|
if(os.path.isdir(F2)):
|
||||||
|
b = (followlinks_) or ((not followlinks_) and not(os.path.islink(F2)))
|
||||||
|
if(b):
|
||||||
|
if((F2!=".")&(F2!="..")):
|
||||||
|
dirlist.append(F2)
|
||||||
|
elif(os.path.isfile(F2)):
|
||||||
|
flst.append(F2)
|
||||||
|
|
||||||
|
#Recurse through directories
|
||||||
|
if(recurse_):
|
||||||
|
for D in dirlist:
|
||||||
|
lst = flist(D,**kwargs)
|
||||||
|
for L in lst:
|
||||||
|
flst.append(L)
|
||||||
|
|
||||||
|
#Postprocess:
|
||||||
|
#Filter out all extensions except the selected ext list
|
||||||
|
if(filterexts_):
|
||||||
|
flst = filterexts(flst,exts)
|
||||||
|
|
||||||
|
#Normalize filename path according to os
|
||||||
|
if(normpath_):
|
||||||
|
flst2 = list(flst)
|
||||||
|
for I in range(0,len(flst2)):
|
||||||
|
flst[I] = os.path.normpath(flst2[I])
|
||||||
|
|
||||||
|
#If linuxpath, convert all \\ to /
|
||||||
|
#if(linuxpath_):
|
||||||
|
# flst2 = list(flst)
|
||||||
|
# for I in range(0,len(flst2)):
|
||||||
|
# flst[I] = linuxpath(flst2[I])
|
||||||
|
|
||||||
|
return flst
|
||||||
|
|
||||||
|
#Filters by extensions in a list of files
|
||||||
|
#flst = def filterexts(flst,exts):
|
||||||
|
def filterexts(flst,exts):
|
||||||
|
flst2 = []
|
||||||
|
if(isinstance(exts,str)):
|
||||||
|
exts = list([exts])
|
||||||
|
for F in flst:
|
||||||
|
b = False
|
||||||
|
for ext in exts:
|
||||||
|
if(ext[0]!='.'):
|
||||||
|
ext = '.'+ext
|
||||||
|
F2 = os.path.splitext(F)
|
||||||
|
if(len(F2)>=2):
|
||||||
|
ex = F2[1]
|
||||||
|
if(len(ex)>0):
|
||||||
|
if(ex[0]!='.'):
|
||||||
|
ex = '.'+ex
|
||||||
|
if(ex==ext):
|
||||||
|
b = True
|
||||||
|
if(b):
|
||||||
|
flst2.append(F)
|
||||||
|
|
||||||
|
return flst2
|
||||||
|
|
||||||
|
#Find a file fname, starting in pth and recursing
|
||||||
|
#Used for finding library files to link
|
||||||
|
def findfile(fname,pth,**kwargs):
|
||||||
|
fullfname = ""
|
||||||
|
flst = flist(pth,recurse=True)
|
||||||
|
for F in flst:
|
||||||
|
F2 = os.path.split(F)[1]
|
||||||
|
if(F2 == fname):
|
||||||
|
fullfname = F
|
||||||
|
|
||||||
|
return fullfname
|
||||||
|
|
||||||
|
def replaceext(fname,ext):
|
||||||
|
fname2 = ""
|
||||||
|
if(len(ext)>0):
|
||||||
|
if(ext[0]!='.'):
|
||||||
|
ext = '.'+ext
|
||||||
|
fname2 = os.path.splitext(fname)[0]+ext
|
||||||
|
else:
|
||||||
|
fname2 = os.path.splitext(fname)[0]
|
||||||
|
return fname2
|
||||||
|
|
||||||
|
def replaceexts(fnamelist,ext):
|
||||||
|
fname2list = []
|
||||||
|
for F in fnamelist:
|
||||||
|
F2 = replaceext(F,ext)
|
||||||
|
fname2list.append(F2)
|
||||||
|
return fname2list
|
||||||
|
|
||||||
|
#filenames must match
|
||||||
|
def except_contains(lst1,exc):
|
||||||
|
lst2 = []
|
||||||
|
for item in lst1:
|
||||||
|
b = 1
|
||||||
|
for item2 in exc:
|
||||||
|
fsplit = os.path.split(item)
|
||||||
|
fn = fsplit[len(fsplit)-1]
|
||||||
|
if(fn==item2):
|
||||||
|
b = 0
|
||||||
|
break
|
||||||
|
if(b==1):
|
||||||
|
lst2.append(item)
|
||||||
|
return lst2
|
||||||
|
|
||||||
|
##########################
|
||||||
|
##System Call Procedures##
|
||||||
|
##########################
|
||||||
|
|
||||||
|
def callproc(cmd, **kwargs):
|
||||||
|
if(not('logfile' in kwargs)):
|
||||||
|
use_lf = False
|
||||||
|
else:
|
||||||
|
logfile = kwargs['logfile']
|
||||||
|
if(logfile!=""):
|
||||||
|
fp = open(kwargs['logfile'],'a+')
|
||||||
|
use_lf = True
|
||||||
|
else:
|
||||||
|
use_lf = False
|
||||||
|
|
||||||
|
if(not('echo' in kwargs)):
|
||||||
|
echo = True
|
||||||
|
else:
|
||||||
|
echo = kwargs['echo']
|
||||||
|
|
||||||
|
if(echo):
|
||||||
|
print(cmd)
|
||||||
|
|
||||||
|
#encoding/deconding to/from bytes is necessary to use the subprocess command
|
||||||
|
#in python3.7
|
||||||
|
#However, only do this in linux
|
||||||
|
if(sys.platform!='win32'):
|
||||||
|
cmd2 = cmd.encode(encoding='utf-8')
|
||||||
|
else:
|
||||||
|
cmd2 = cmd
|
||||||
|
proc = subprocess.Popen(cmd2,stderr = subprocess.STDOUT, stdout=subprocess.PIPE, shell=True)
|
||||||
|
(out, err) = proc.communicate()
|
||||||
|
|
||||||
|
out = out.decode(encoding='utf-8')
|
||||||
|
|
||||||
|
if(echo):
|
||||||
|
print(out)
|
||||||
|
#print(err);
|
||||||
|
if(use_lf):
|
||||||
|
fp.writelines(cmd+'\n')
|
||||||
|
fp.writelines(out+'\n')
|
||||||
|
|
||||||
|
if(use_lf):
|
||||||
|
fp.close()
|
||||||
|
|
||||||
|
#List to space-seperated-string
|
||||||
|
def list_to_sss(lst):
|
||||||
|
lout = ""
|
||||||
|
for I in range(0,len(lst)-1):
|
||||||
|
lout = lout + lst[I] + " "
|
||||||
|
if(len(lst)>0):
|
||||||
|
lout = lout + lst[len(lst)-1]
|
||||||
|
return lout
|
||||||
|
|
||||||
|
#####################################
|
||||||
|
## Incremental Compilation Library ##
|
||||||
|
#####################################
|
||||||
|
|
||||||
|
#silently read lines from a text file if exists
|
||||||
|
def readtextlines(fname):
|
||||||
|
txtlns = []
|
||||||
|
|
||||||
|
if(not os.path.isfile(fname)):
|
||||||
|
return txtlns
|
||||||
|
|
||||||
|
try:
|
||||||
|
fp = open(fname,"r")
|
||||||
|
except:
|
||||||
|
return txtlns
|
||||||
|
|
||||||
|
ln = " "
|
||||||
|
while(ln!=""):
|
||||||
|
ln = fp.readline()
|
||||||
|
txtlns.append(ln)
|
||||||
|
|
||||||
|
fp.close()
|
||||||
|
|
||||||
|
return txtlns
|
||||||
|
|
||||||
|
def getincludefnfrage(includeline):
|
||||||
|
|
||||||
|
fnfrag = ""
|
||||||
|
I1 = -1
|
||||||
|
I2 = -1
|
||||||
|
|
||||||
|
for I in range(0,len(includeline)):
|
||||||
|
if(I1<0 and (includeline[I]=='<' or includeline[I]=='"')):
|
||||||
|
I1 = I
|
||||||
|
if(I1>=0 and (includeline[I]=='>' or includeline[I]=='"')):
|
||||||
|
I2 = I
|
||||||
|
break
|
||||||
|
if(I1>=0 and I2>=0):
|
||||||
|
fnfrag = includeline[I1+1:I2]
|
||||||
|
|
||||||
|
return fnfrag
|
||||||
|
|
||||||
|
#Returns the name of the source file fname (if it exists)
|
||||||
|
#and all included filenames
|
||||||
|
def getsrcandincludes(fname, incdirs):
|
||||||
|
|
||||||
|
flist = []
|
||||||
|
if(os.path.isfile(fname)):
|
||||||
|
flist.append(fname)
|
||||||
|
|
||||||
|
Ilist = 0
|
||||||
|
while(Ilist<len(flist)):
|
||||||
|
#recurse through files
|
||||||
|
f1 = flist[Ilist]
|
||||||
|
lns = readtextlines(f1)
|
||||||
|
for J in range(0,len(lns)):
|
||||||
|
if(lns[J].find("#include")>=0):
|
||||||
|
fnfrag = getincludefnfrage(lns[J])
|
||||||
|
for K in range(0,len(incdirs)):
|
||||||
|
tfn = os.path.join(incdirs[K],fnfrag)
|
||||||
|
if(os.path.isfile(tfn)):
|
||||||
|
flist.append(tfn)
|
||||||
|
break
|
||||||
|
|
||||||
|
Ilist = Ilist + 1
|
||||||
|
|
||||||
|
return flist
|
||||||
|
|
||||||
|
#Returns the name of the object file associated with the source file
|
||||||
|
#within the object store folder (if it exists)
|
||||||
|
def getobjfile(fname,objstore,objext = ".o"):
|
||||||
|
|
||||||
|
fret = ""
|
||||||
|
f1 = os.path.split(fname)[1]
|
||||||
|
f2 = f1
|
||||||
|
while(os.path.splitext(f2)[1]!=""):
|
||||||
|
f2 = os.path.splitext(f2)[0]
|
||||||
|
objext = objext.strip('.')
|
||||||
|
f3 = os.path.join(objstore,"{}.{}".format(f2,objext))
|
||||||
|
if(os.path.exists(f3)):
|
||||||
|
fret = f3
|
||||||
|
|
||||||
|
return fret
|
||||||
|
|
||||||
|
def getsrctimes(fname, incdirs):
|
||||||
|
|
||||||
|
ftimes = []
|
||||||
|
flst = getsrcandincludes(fname, incdirs)
|
||||||
|
for I in range(0,len(flst)):
|
||||||
|
f = flst[I]
|
||||||
|
mt = os.path.getmtime(f)
|
||||||
|
ftimes.append(mt)
|
||||||
|
|
||||||
|
return ftimes
|
||||||
|
|
||||||
|
def getobjtime(fname,objstore,objext=".o"):
|
||||||
|
ret = -1
|
||||||
|
fret = getobjfile(fname,objstore,objext)
|
||||||
|
if(fret!=""):
|
||||||
|
ret = os.path.getmtime(fret)
|
||||||
|
|
||||||
|
return ret
|
||||||
|
|
||||||
|
#Decide whether or not to compile source file
|
||||||
|
def decidecompile(fname,**kwargs):
|
||||||
|
ret = True
|
||||||
|
|
||||||
|
if(not os.path.isfile(fname)):
|
||||||
|
ret = False
|
||||||
|
return ret
|
||||||
|
|
||||||
|
##unpack kwargs
|
||||||
|
if("searchincdirs" in kwargs):
|
||||||
|
incdirs = kwargs["searchincdirs"]
|
||||||
|
else:
|
||||||
|
incdirs = ["./include"]
|
||||||
|
|
||||||
|
if("objext" in kwargs):
|
||||||
|
objext = kwargs["objext"]
|
||||||
|
else:
|
||||||
|
objext = ".o"
|
||||||
|
if("objstore" in kwargs):
|
||||||
|
objstore = kwargs["objstore"]
|
||||||
|
else:
|
||||||
|
objstore = "./objstore"
|
||||||
|
|
||||||
|
|
||||||
|
srclist = getsrcandincludes(fname,incdirs)
|
||||||
|
srctlist = getsrctimes(fname,incdirs)
|
||||||
|
obj = getobjfile(fname,objstore,objext)
|
||||||
|
objt = getobjtime(fname,objstore,objext)
|
||||||
|
|
||||||
|
if(obj!=""):
|
||||||
|
ret = False
|
||||||
|
for I in range(0,len(srctlist)):
|
||||||
|
if(srctlist[I]>objt):
|
||||||
|
ret = True
|
||||||
|
break
|
||||||
|
|
||||||
|
return ret
|
||||||
|
|
||||||
|
def gs_incremental_compile(compiler,srcfile,**kwargs):
|
||||||
|
|
||||||
|
if(not('include' in kwargs)):
|
||||||
|
include = ''
|
||||||
|
else:
|
||||||
|
include = kwargs['include']
|
||||||
|
if(isinstance(include,list)):
|
||||||
|
include = list_to_sss(include)
|
||||||
|
if(not('flags' in kwargs)):
|
||||||
|
flags = ''
|
||||||
|
else:
|
||||||
|
flags = kwargs['flags']
|
||||||
|
if(isinstance(flags,list)):
|
||||||
|
flags = list_to_sss(flags)
|
||||||
|
if(not('objext' in kwargs)):
|
||||||
|
objext = '.o'
|
||||||
|
else:
|
||||||
|
objext = kwargs['objext']
|
||||||
|
if(not('srcfileflag' in kwargs)):
|
||||||
|
srcfileflag = '-c'
|
||||||
|
else:
|
||||||
|
srcfileflag = kwargs['srcfileflag']
|
||||||
|
if(not('outfileflag' in kwargs)):
|
||||||
|
outfileflag = '-o'
|
||||||
|
else:
|
||||||
|
outfileflag = kwargs['outfileflag']
|
||||||
|
|
||||||
|
if(not('logfile' in kwargs)):
|
||||||
|
logfile = ""
|
||||||
|
else:
|
||||||
|
logfile = kwargs['logfile']
|
||||||
|
if(not('smartcompile' in kwargs)):
|
||||||
|
_smartcompile = True
|
||||||
|
else:
|
||||||
|
_smartcompile = kwargs['smartcompile']
|
||||||
|
|
||||||
|
#incrementalcompile
|
||||||
|
if("searchincdirs" in kwargs):
|
||||||
|
incdirs = kwargs["searchincdirs"]
|
||||||
|
else:
|
||||||
|
incdirs = ["./include"]
|
||||||
|
|
||||||
|
if("objext" in kwargs):
|
||||||
|
objext = kwargs["objext"]
|
||||||
|
else:
|
||||||
|
objext = ".o"
|
||||||
|
if("objstore" in kwargs):
|
||||||
|
objstore = kwargs["objstore"]
|
||||||
|
else:
|
||||||
|
objstore = "./objstore"
|
||||||
|
|
||||||
|
#Do I want to make this thing this general?
|
||||||
|
|
||||||
|
docompile = decidecompile(srcfile,**kwargs)
|
||||||
|
|
||||||
|
if(docompile):
|
||||||
|
f1 = os.path.split(srcfile)[1]
|
||||||
|
f2 = f1
|
||||||
|
while(os.path.splitext(f2)[1]!=""):
|
||||||
|
f2 = os.path.splitext(f2)[0]
|
||||||
|
outfile = os.path.join(objstore,"{}{}".format(f2,objext))
|
||||||
|
|
||||||
|
ln = compiler+" "+flags+" " + outfileflag+" "+outfile+" "+srcfileflag+" "+srcfile
|
||||||
|
ln = ln + " " + include
|
||||||
|
|
||||||
|
callproc(ln,echo=True,logfile=logfile)
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
def gs_incremental_compile_list(compiler,srclist,**kwargs):
|
||||||
|
|
||||||
|
for s in srclist:
|
||||||
|
gs_incremental_compile(compiler,s,**kwargs)
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
#MSVC compiler wrapper
|
||||||
|
|
||||||
|
def msvc_incremental_compile(compilername, srcfile, **kwargs):
|
||||||
|
|
||||||
|
if(not('include' in kwargs)):
|
||||||
|
include = ''
|
||||||
|
else:
|
||||||
|
include = kwargs['include']
|
||||||
|
if(isinstance(include,list)):
|
||||||
|
include = list_to_sss(include)
|
||||||
|
|
||||||
|
if(not('flags' in kwargs)):
|
||||||
|
flags = ''
|
||||||
|
else:
|
||||||
|
flags = kwargs['flags']
|
||||||
|
if(isinstance(flags,list)):
|
||||||
|
flags = list_to_sss(flags)
|
||||||
|
|
||||||
|
if(not('objext' in kwargs)):
|
||||||
|
objext = '.obj'
|
||||||
|
else:
|
||||||
|
objext = kwargs['objext']
|
||||||
|
|
||||||
|
if(not('srcfileflag' in kwargs)):
|
||||||
|
srcfileflag = '/c'
|
||||||
|
else:
|
||||||
|
srcfileflag = kwargs['srcfileflag']
|
||||||
|
|
||||||
|
if(not('outfileflag' in kwargs)):
|
||||||
|
outfileflag = '/Fo:'
|
||||||
|
else:
|
||||||
|
outfileflag = kwargs['outfileflag']
|
||||||
|
if(not('logfile' in kwargs)):
|
||||||
|
logfile = ""
|
||||||
|
else:
|
||||||
|
logfile = kwargs['logfile']
|
||||||
|
|
||||||
|
#incrementalcompile
|
||||||
|
if("searchincdirs" in kwargs):
|
||||||
|
incdirs = kwargs["searchincdirs"]
|
||||||
|
else:
|
||||||
|
incdirs = ["./include"]
|
||||||
|
# if("objext" in kwargs):
|
||||||
|
# objext = kwargs["objext"]
|
||||||
|
# else:
|
||||||
|
# objext = ".o"
|
||||||
|
if("objstore" in kwargs):
|
||||||
|
objstore = kwargs["objstore"]
|
||||||
|
else:
|
||||||
|
objstore = "./objstore"
|
||||||
|
|
||||||
|
docompile = decidecompile(srcfile,**kwargs)
|
||||||
|
|
||||||
|
if(docompile):
|
||||||
|
f1 = os.path.split(srcfile)[1]
|
||||||
|
f2 = f1
|
||||||
|
while(os.path.splitext(f2)[1]!=""):
|
||||||
|
f2 = os.path.splitext(f2)[0]
|
||||||
|
outfile = os.path.join(objstore,"{}{}".format(f2,objext))
|
||||||
|
|
||||||
|
ln = compilername+" "+flags+" "+srcfileflag+" "+srcfile+" "+outfileflag+" "+outfile
|
||||||
|
ln = ln + " " + include
|
||||||
|
|
||||||
|
callproc(ln,echo=True,logfile=logfile)
|
||||||
|
|
||||||
|
# outfile = replaceext(srcfile,objext)
|
||||||
|
# ln = compilername+" "+flags+" "+" "+srcfileflag+" "+srcfile+" "+outfileflag+outfile
|
||||||
|
# ln = ln + " " + include
|
||||||
|
|
||||||
|
callproc(ln,echo=True,logfile=logfile)
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
def msvc_incremental_compile_list(compiler,srclist,**kwargs):
|
||||||
|
for S in srclist:
|
||||||
|
msvc_incremental_compile(compiler,S,**kwargs)
|
||||||
|
return
|
||||||
|
|
||||||
|
#######################
|
||||||
|
## Main Script Tests ##
|
||||||
|
#######################
|
||||||
|
|
||||||
|
def testtimes(args):
|
||||||
|
if(len(args)>=2):
|
||||||
|
flist = getsrcandincludes(args[1],["./include"])
|
||||||
|
ftlist = getsrctimes(args[1],["./include"])
|
||||||
|
for I in range(0,len(flist)):
|
||||||
|
print("{}\t\t{}".format(flist[I],ftlist[I]))
|
||||||
|
|
||||||
|
print("associated obj file:")
|
||||||
|
fobj = getobjfile(args[1],"./objstore")
|
||||||
|
ftobj = getobjtime(args[1],"./objstore")
|
||||||
|
if(fobj!=""):
|
||||||
|
print("{}\t\t{}".format(fobj,ftobj))
|
||||||
|
else:
|
||||||
|
print("none found")
|
||||||
|
|
||||||
|
cflag = decidecompile(args[1])
|
||||||
|
print("compile? : {}".format(cflag))
|
||||||
|
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
# if(__name__ == "__main__"):
|
||||||
|
|
||||||
|
# args = sys.argv
|
||||||
|
# testtimes(args)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
52
old/compscripts/linux64.makelib.py
Normal file
52
old/compscripts/linux64.makelib.py
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
import os,sys,subprocess,math
|
||||||
|
from complib2 import *
|
||||||
|
from complib3 import gs_incremental_compile, gs_incremental_compile_list
|
||||||
|
|
||||||
|
import shutil
|
||||||
|
#from distutils.dir_util import copy_tree as copy_tree #this version does overwrites
|
||||||
|
from shutil import copytree
|
||||||
|
|
||||||
|
libname = 'amsculib2.linux64' #prefix static library name to generate
|
||||||
|
targetname = 'test' #create this executable when compiling tests
|
||||||
|
commonincdir = "../../linux64/include"
|
||||||
|
commonlibdir = "../../linux64/lib"
|
||||||
|
localbindir = "./bin_linux64"
|
||||||
|
cc = 'nvcc' #compiler
|
||||||
|
srcexts = ['.c','.cpp','.cu']
|
||||||
|
mainsrc = ['main.cu'] #ignore these files when compiling the static library
|
||||||
|
|
||||||
|
kwargs = dict()
|
||||||
|
include = "-I./include -I{}".format(commonincdir)
|
||||||
|
kwargs['include'] = include
|
||||||
|
#-dc flag: relocatable device code - needed for device functions to link in different "execution units"
|
||||||
|
#--ptxas-options=-v
|
||||||
|
kwargs['flags'] = "-dc --compiler-options '-fPIC -O3'"
|
||||||
|
kwargs['libdir'] = "-L{} -L{}".format(localbindir,commonlibdir)
|
||||||
|
kwargs['libflags'] = "-l{}".format(libname)
|
||||||
|
kwargs['linkerflags'] = ""
|
||||||
|
kwargs['recurse'] = True
|
||||||
|
kwargs['objstore'] = "./objstore"
|
||||||
|
kwargs['searchincdirs'] = ['./include']
|
||||||
|
|
||||||
|
#find all source files, except the main project files
|
||||||
|
files = flist('./src',exts = srcexts, recurse=True)
|
||||||
|
files = except_contains(files,mainsrc)
|
||||||
|
objfiles = replaceexts(files,'.o')
|
||||||
|
objfiles_sss = list_to_sss(objfiles)
|
||||||
|
|
||||||
|
#compile all the source files in the list
|
||||||
|
#gs_compile_list(cc,files,**kwargs)
|
||||||
|
gs_incremental_compile_list(cc,files,**kwargs)
|
||||||
|
|
||||||
|
#archive all the source files into a static library
|
||||||
|
#ar_list(objfiles,'{}/lib{}.a'.format(localbindir,libname))
|
||||||
|
objlist = flist(kwargs['objstore'],exts='.o',recurse=True)
|
||||||
|
ar_list(objlist,'{}/lib{}.a'.format(localbindir,libname))
|
||||||
|
|
||||||
|
# #Push any libraries to the common lib folder
|
||||||
|
shutil.copy('{}/lib{}.a'.format(localbindir,libname),commonlibdir)
|
||||||
|
|
||||||
|
# #Copy include files to the common include folder
|
||||||
|
copytree('./include/',commonincdir+'/',dirs_exist_ok=True)
|
||||||
43
old/compscripts/linux64.maketest.py
Normal file
43
old/compscripts/linux64.maketest.py
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
import os,sys,subprocess,math
|
||||||
|
from complib2 import *
|
||||||
|
from complib3 import gs_incremental_compile, gs_incremental_compile_list
|
||||||
|
|
||||||
|
import shutil
|
||||||
|
|
||||||
|
libname = 'amsculib2.linux64' #prefix static library name to generate
|
||||||
|
targetname = 'test' #create this executable when compiling tests
|
||||||
|
commonincdir = "../../linux64/include"
|
||||||
|
commonlibdir = "../../linux64/lib"
|
||||||
|
localbindir = "./bin_linux64"
|
||||||
|
cc = 'nvcc' #compiler
|
||||||
|
srcexts = ['.c','.cpp','.cu']
|
||||||
|
mainsrc = ['main.cu'] #ignore these files when compiling the static library
|
||||||
|
|
||||||
|
kwargs = dict()
|
||||||
|
include = "-I./include -I{}".format(commonincdir)
|
||||||
|
kwargs['include'] = include
|
||||||
|
#-dc flag: relocatable device code - needed for device functions to link in different "execution units"
|
||||||
|
kwargs['flags'] = "-dc --compiler-options '-fPIC'"
|
||||||
|
kwargs['libdir'] = "-L{} -L{}".format(localbindir,commonlibdir)
|
||||||
|
kwargs['libflags'] = "-l{} -lamsculib2.linux64".format(libname)
|
||||||
|
kwargs['linkerflags'] = ""
|
||||||
|
kwargs['recurse'] = True
|
||||||
|
kwargs['objstore'] = "./objstore"
|
||||||
|
kwargs['searchincdirs'] = ['./include']
|
||||||
|
|
||||||
|
#-lamsmathlib3.linux64 -lamsstring3.linux64 -lamsmatrix_cpp.linux64 -llapack -lblas -lgfortran -lamsmathutilthread.linux64 -lamsmathutil2.linux64
|
||||||
|
|
||||||
|
#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,'.o')
|
||||||
|
|
||||||
|
#Compile test programs
|
||||||
|
gs_compile_list(cc,fsrc,**kwargs)
|
||||||
|
gs_link_list(cc,list_to_sss(fobj),'{}/{}'.format(localbindir,targetname),**kwargs)
|
||||||
639
old/compscripts/old/complib2.py
Normal file
639
old/compscripts/old/complib2.py
Normal file
@ -0,0 +1,639 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
#Python3 compilation library
|
||||||
|
#Aaron M. Schinder
|
||||||
|
#29 Dec 2020
|
||||||
|
#
|
||||||
|
#Cleanup and refactor from 2017 python2 version compilation libraries
|
||||||
|
|
||||||
|
import os,sys,math,subprocess
|
||||||
|
|
||||||
|
#####################
|
||||||
|
#Directory Functions#
|
||||||
|
#####################
|
||||||
|
|
||||||
|
##flist - list all files in a given directory pth
|
||||||
|
##optional arguments:
|
||||||
|
# recurse - (T/F): Whether to recursively search for files in directory tree
|
||||||
|
# exts - (list): A list of file extensions to filter on
|
||||||
|
# normpath (T/F): whether to normalize path variables after
|
||||||
|
#filelist = flist(pth,**kwargs):
|
||||||
|
def flist(pth,**kwargs):
|
||||||
|
flst = []
|
||||||
|
if(not('recurse' in kwargs)):
|
||||||
|
recurse_ = False
|
||||||
|
else:
|
||||||
|
recurse_ = kwargs['recurse']
|
||||||
|
if(not('exts' in kwargs)):
|
||||||
|
filterexts_ = False
|
||||||
|
else:
|
||||||
|
filterexts_ = True
|
||||||
|
exts = kwargs['exts']
|
||||||
|
if(not('normpath' in kwargs)):
|
||||||
|
normpath_ = True
|
||||||
|
else:
|
||||||
|
normpath_ = kwargs['normpath']
|
||||||
|
if(not('linuxpath' in kwargs)):
|
||||||
|
linuxpath_ = False
|
||||||
|
else:
|
||||||
|
linuxpath_ = kwargs['linuxpath']
|
||||||
|
if(not('followlinks' in kwargs)):
|
||||||
|
followlinks_ = False
|
||||||
|
else:
|
||||||
|
followlinks_ = kwargs['followlinks']
|
||||||
|
|
||||||
|
dirlist = []
|
||||||
|
rawlist = os.listdir(pth)
|
||||||
|
|
||||||
|
for F in rawlist:
|
||||||
|
F2 = os.path.join(pth,F)
|
||||||
|
if(os.path.isdir(F2)):
|
||||||
|
b = (followlinks_) or ((not followlinks_) and not(os.path.islink(F2)))
|
||||||
|
if(b):
|
||||||
|
if((F2!=".")&(F2!="..")):
|
||||||
|
dirlist.append(F2)
|
||||||
|
elif(os.path.isfile(F2)):
|
||||||
|
flst.append(F2)
|
||||||
|
|
||||||
|
#Recurse through directories
|
||||||
|
if(recurse_):
|
||||||
|
for D in dirlist:
|
||||||
|
lst = flist(D,**kwargs)
|
||||||
|
for L in lst:
|
||||||
|
flst.append(L)
|
||||||
|
|
||||||
|
#Postprocess:
|
||||||
|
#Filter out all extensions except the selected ext list
|
||||||
|
if(filterexts_):
|
||||||
|
flst = filterexts(flst,exts)
|
||||||
|
|
||||||
|
#Normalize filename path according to os
|
||||||
|
if(normpath_):
|
||||||
|
flst2 = list(flst)
|
||||||
|
for I in range(0,len(flst2)):
|
||||||
|
flst[I] = os.path.normpath(flst2[I])
|
||||||
|
|
||||||
|
#If linuxpath, convert all \\ to /
|
||||||
|
#if(linuxpath_):
|
||||||
|
# flst2 = list(flst)
|
||||||
|
# for I in range(0,len(flst2)):
|
||||||
|
# flst[I] = linuxpath(flst2[I])
|
||||||
|
|
||||||
|
return flst
|
||||||
|
|
||||||
|
#Filters by extensions in a list of files
|
||||||
|
#flst = def filterexts(flst,exts):
|
||||||
|
def filterexts(flst,exts):
|
||||||
|
flst2 = []
|
||||||
|
if(isinstance(exts,str)):
|
||||||
|
exts = list([exts])
|
||||||
|
for F in flst:
|
||||||
|
b = False
|
||||||
|
for ext in exts:
|
||||||
|
if(ext[0]!='.'):
|
||||||
|
ext = '.'+ext
|
||||||
|
F2 = os.path.splitext(F)
|
||||||
|
if(len(F2)>=2):
|
||||||
|
ex = F2[1]
|
||||||
|
if(len(ex)>0):
|
||||||
|
if(ex[0]!='.'):
|
||||||
|
ex = '.'+ex
|
||||||
|
if(ex==ext):
|
||||||
|
b = True
|
||||||
|
if(b):
|
||||||
|
flst2.append(F)
|
||||||
|
|
||||||
|
return flst2
|
||||||
|
|
||||||
|
#Find a file fname, starting in pth and recursing
|
||||||
|
#Used for finding library files to link
|
||||||
|
def findfile(fname,pth,**kwargs):
|
||||||
|
fullfname = ""
|
||||||
|
flst = flist(pth,recurse=True)
|
||||||
|
for F in flst:
|
||||||
|
F2 = os.path.split(F)[1]
|
||||||
|
if(F2 == fname):
|
||||||
|
fullfname = F
|
||||||
|
|
||||||
|
return fullfname
|
||||||
|
|
||||||
|
#List to space-seperated-string
|
||||||
|
def list_to_sss(lst):
|
||||||
|
lout = ""
|
||||||
|
for I in range(0,len(lst)-1):
|
||||||
|
lout = lout + lst[I] + " "
|
||||||
|
if(len(lst)>0):
|
||||||
|
lout = lout + lst[len(lst)-1]
|
||||||
|
return lout
|
||||||
|
|
||||||
|
def strip_whitespace(strin):
|
||||||
|
strout = ""
|
||||||
|
I1 = -1
|
||||||
|
I2 = -1
|
||||||
|
for I in range(0,len(strin)):
|
||||||
|
if(strin[I]!=' ' and strin[I]!='\t' and strin[I]!='\r'and strin[I]!='\n'):
|
||||||
|
I1 = I
|
||||||
|
break
|
||||||
|
q = list(range(0,len(strin)))
|
||||||
|
q.reverse()
|
||||||
|
for I in q:
|
||||||
|
if(strin[I]!=' ' and strin[I]!='\t' and strin[I]!='\r'and strin[I]!='\n'):
|
||||||
|
I2 = I+1
|
||||||
|
break
|
||||||
|
if(I1>=0 and I2>=0):
|
||||||
|
strout = strin[I1:I2]
|
||||||
|
return strout
|
||||||
|
|
||||||
|
def sss_to_list(sss):
|
||||||
|
lout = []
|
||||||
|
l1 = sss.split(' ')
|
||||||
|
for l in l1:
|
||||||
|
l2 = strip_whitespace(l)
|
||||||
|
lout.append(l2)
|
||||||
|
return lout
|
||||||
|
|
||||||
|
|
||||||
|
def replaceext(fname,ext):
|
||||||
|
fname2 = ""
|
||||||
|
if(len(ext)>0):
|
||||||
|
if(ext[0]!='.'):
|
||||||
|
ext = '.'+ext
|
||||||
|
fname2 = os.path.splitext(fname)[0]+ext
|
||||||
|
else:
|
||||||
|
fname2 = os.path.splitext(fname)[0]
|
||||||
|
return fname2
|
||||||
|
|
||||||
|
def replaceexts(fnamelist,ext):
|
||||||
|
fname2list = []
|
||||||
|
for F in fnamelist:
|
||||||
|
F2 = replaceext(F,ext)
|
||||||
|
fname2list.append(F2)
|
||||||
|
return fname2list
|
||||||
|
|
||||||
|
# def except_contains_oldv(lst1,exc):
|
||||||
|
# lst2 = []
|
||||||
|
# for item in lst1:
|
||||||
|
# b = 1
|
||||||
|
# for item2 in exc:
|
||||||
|
# if(item.find(item2)>=0):
|
||||||
|
# b = 0
|
||||||
|
# break
|
||||||
|
# if(b==1):
|
||||||
|
# lst2.append(item)
|
||||||
|
# return lst2
|
||||||
|
|
||||||
|
#filenames must match
|
||||||
|
def except_contains(lst1,exc):
|
||||||
|
lst2 = []
|
||||||
|
for item in lst1:
|
||||||
|
b = 1
|
||||||
|
for item2 in exc:
|
||||||
|
fsplit = os.path.split(item)
|
||||||
|
fn = fsplit[len(fsplit)-1]
|
||||||
|
if(fn==item2):
|
||||||
|
b = 0
|
||||||
|
break
|
||||||
|
if(b==1):
|
||||||
|
lst2.append(item)
|
||||||
|
return lst2
|
||||||
|
|
||||||
|
##########################
|
||||||
|
##System Call Procedures##
|
||||||
|
##########################
|
||||||
|
|
||||||
|
def callproc(cmd, **kwargs):
|
||||||
|
if(not('logfile' in kwargs)):
|
||||||
|
use_lf = False
|
||||||
|
else:
|
||||||
|
logfile = kwargs['logfile']
|
||||||
|
if(logfile!=""):
|
||||||
|
fp = open(kwargs['logfile'],'a+')
|
||||||
|
use_lf = True
|
||||||
|
else:
|
||||||
|
use_lf = False
|
||||||
|
|
||||||
|
if(not('echo' in kwargs)):
|
||||||
|
echo = True
|
||||||
|
else:
|
||||||
|
echo = kwargs['echo']
|
||||||
|
|
||||||
|
if(echo):
|
||||||
|
print(cmd)
|
||||||
|
|
||||||
|
#encoding/deconding to/from bytes is necessary to use the subprocess command
|
||||||
|
#in python3.7
|
||||||
|
#However, only do this in linux
|
||||||
|
if(sys.platform!='win32'):
|
||||||
|
cmd2 = cmd.encode(encoding='utf-8')
|
||||||
|
else:
|
||||||
|
cmd2 = cmd
|
||||||
|
proc = subprocess.Popen(cmd2,stderr = subprocess.STDOUT, stdout=subprocess.PIPE, shell=True)
|
||||||
|
(out, err) = proc.communicate()
|
||||||
|
|
||||||
|
out = out.decode(encoding='utf-8')
|
||||||
|
|
||||||
|
if(echo):
|
||||||
|
print(out)
|
||||||
|
#print(err);
|
||||||
|
if(use_lf):
|
||||||
|
fp.writelines(cmd+'\n')
|
||||||
|
fp.writelines(out+'\n')
|
||||||
|
|
||||||
|
if(use_lf):
|
||||||
|
fp.close()
|
||||||
|
|
||||||
|
#######################################
|
||||||
|
##Compiler, Archive, and Linker Calls##
|
||||||
|
#######################################
|
||||||
|
|
||||||
|
def smartcompile(srcfile,objext='.o'):
|
||||||
|
mtsrc = os.path.getmtime(srcfile)
|
||||||
|
objfile = replaceext(srcfile,objext)
|
||||||
|
objexists = os.path.exists(objfile)
|
||||||
|
ret = True
|
||||||
|
if(objexists):
|
||||||
|
mtobj = os.path.getmtime(objfile)
|
||||||
|
if(mtobj>=mtsrc):
|
||||||
|
ret = False
|
||||||
|
|
||||||
|
return ret
|
||||||
|
|
||||||
|
#MSVC compiler wrapper
|
||||||
|
def msvc_compile(compilername, srcfile, **kwargs):
|
||||||
|
|
||||||
|
if(not('include' in kwargs)):
|
||||||
|
include = ''
|
||||||
|
else:
|
||||||
|
include = kwargs['include']
|
||||||
|
if(isinstance(include,list)):
|
||||||
|
include = list_to_sss(include)
|
||||||
|
|
||||||
|
if(not('flags' in kwargs)):
|
||||||
|
flags = ''
|
||||||
|
else:
|
||||||
|
flags = kwargs['flags']
|
||||||
|
if(isinstance(flags,list)):
|
||||||
|
flags = list_to_sss(flags)
|
||||||
|
|
||||||
|
if(not('objext' in kwargs)):
|
||||||
|
objext = '.obj'
|
||||||
|
else:
|
||||||
|
objext = kwargs['objext']
|
||||||
|
|
||||||
|
if(not('srcfileflag' in kwargs)):
|
||||||
|
srcfileflag = '/c'
|
||||||
|
else:
|
||||||
|
srcfileflag = kwargs['srcfileflag']
|
||||||
|
|
||||||
|
if(not('outfileflag' in kwargs)):
|
||||||
|
outfileflag = '/Fo:'
|
||||||
|
else:
|
||||||
|
outfileflag = kwargs['outfileflag']
|
||||||
|
if(not('logfile' in kwargs)):
|
||||||
|
logfile = ""
|
||||||
|
else:
|
||||||
|
logfile = kwargs['logfile']
|
||||||
|
|
||||||
|
outfile = replaceext(srcfile,objext)
|
||||||
|
ln = compilername+" "+flags+" "+" "+srcfileflag+" "+srcfile+" "+outfileflag+outfile
|
||||||
|
ln = ln + " " + include
|
||||||
|
|
||||||
|
callproc(ln,echo=True,logfile=logfile)
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
#MSVC compiler wrapper
|
||||||
|
def msvc_compile_list(compiler,srclist,**kwargs):
|
||||||
|
for S in srclist:
|
||||||
|
msvc_compile(compiler,S,**kwargs)
|
||||||
|
return
|
||||||
|
|
||||||
|
#gnu-style compiler compile: Should work with gcc, g++, gfortran
|
||||||
|
def gs_compile(compiler,srcfile,**kwargs):
|
||||||
|
if(not('include' in kwargs)):
|
||||||
|
include = ''
|
||||||
|
else:
|
||||||
|
include = kwargs['include']
|
||||||
|
if(isinstance(include,list)):
|
||||||
|
include = list_to_sss(include)
|
||||||
|
|
||||||
|
if(not('flags' in kwargs)):
|
||||||
|
flags = ''
|
||||||
|
else:
|
||||||
|
flags = kwargs['flags']
|
||||||
|
if(isinstance(flags,list)):
|
||||||
|
flags = list_to_sss(flags)
|
||||||
|
|
||||||
|
if(not('objext' in kwargs)):
|
||||||
|
objext = '.o'
|
||||||
|
else:
|
||||||
|
objext = kwargs['objext']
|
||||||
|
|
||||||
|
if(not('srcfileflag' in kwargs)):
|
||||||
|
srcfileflag = '-c'
|
||||||
|
else:
|
||||||
|
srcfileflag = kwargs['srcfileflag']
|
||||||
|
|
||||||
|
if(not('outfileflag' in kwargs)):
|
||||||
|
outfileflag = '-o'
|
||||||
|
else:
|
||||||
|
outfileflag = kwargs['outfileflag']
|
||||||
|
|
||||||
|
if(not('logfile' in kwargs)):
|
||||||
|
logfile = ""
|
||||||
|
else:
|
||||||
|
logfile = kwargs['logfile']
|
||||||
|
|
||||||
|
if(not('smartcompile' in kwargs)):
|
||||||
|
_smartcompile = True
|
||||||
|
else:
|
||||||
|
_smartcompile = kwargs['smartcompile']
|
||||||
|
|
||||||
|
#Do I want to make this thing this general?
|
||||||
|
|
||||||
|
if(not(_smartcompile) or smartcompile(srcfile,objext)):
|
||||||
|
outfile = replaceext(srcfile,objext)
|
||||||
|
ln = compiler+" "+flags+" " + outfileflag+" "+outfile+" "+srcfileflag+" "+srcfile
|
||||||
|
ln = ln + " " + include
|
||||||
|
|
||||||
|
callproc(ln,echo=True,logfile=logfile)
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
def gs_compile_list(compiler,srclist,**kwargs):
|
||||||
|
for S in srclist:
|
||||||
|
gs_compile(compiler,S,**kwargs)
|
||||||
|
return
|
||||||
|
|
||||||
|
def gs_compile_all(compiler,srcdir,srcexts,**kwargs):
|
||||||
|
if(not('recurse' in kwargs)):
|
||||||
|
recurse = True
|
||||||
|
else:
|
||||||
|
recurse = kwargs['recurse']
|
||||||
|
|
||||||
|
srcfils = flist(srcdir,exts=srcexts,recurse=recurse)
|
||||||
|
|
||||||
|
for S in srcfils:
|
||||||
|
gs_compile(compiler,S,**kwargs)
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
def gs_link_all(linker,srcpath,target,**kwargs):
|
||||||
|
|
||||||
|
if(not('objext' in kwargs)):
|
||||||
|
objext = '.o'
|
||||||
|
else:
|
||||||
|
objext = kwargs['objext']
|
||||||
|
|
||||||
|
if(not('recurse' in kwargs)):
|
||||||
|
recurse = True
|
||||||
|
else:
|
||||||
|
recurse = kwargs['recurse']
|
||||||
|
|
||||||
|
|
||||||
|
objfils = flist(srcpath,exts=objext,recurse=recurse)
|
||||||
|
oflst = list_to_sss(objfils)
|
||||||
|
|
||||||
|
gs_link_list(linker,oflst,target,**kwargs)
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
def gs_link_list(linker,objlist,target,**kwargs):
|
||||||
|
|
||||||
|
if(not('objext' in kwargs)):
|
||||||
|
objext = '.o'
|
||||||
|
else:
|
||||||
|
objext = kwargs['objext']
|
||||||
|
|
||||||
|
if(not('libdir' in kwargs)):
|
||||||
|
libdir = ''
|
||||||
|
else:
|
||||||
|
libdir = kwargs['libdir']
|
||||||
|
|
||||||
|
if(not('staticlibs' in kwargs)):
|
||||||
|
staticlibs = ''
|
||||||
|
else:
|
||||||
|
staticlibs = kwargs['staticlibs']
|
||||||
|
|
||||||
|
if(not('libflags' in kwargs)):
|
||||||
|
libflags = ''
|
||||||
|
else:
|
||||||
|
libflags = kwargs['libflags']
|
||||||
|
|
||||||
|
if(not('linkerflags' in kwargs)):
|
||||||
|
linkerflags = ''
|
||||||
|
else:
|
||||||
|
linkerflags = kwargs['linkerflags']
|
||||||
|
|
||||||
|
if(not('recurse' in kwargs)):
|
||||||
|
recurse = True
|
||||||
|
else:
|
||||||
|
recurse = kwargs['recurse']
|
||||||
|
|
||||||
|
if(not('logfile' in kwargs)):
|
||||||
|
logfile = ''
|
||||||
|
else:
|
||||||
|
logfile = kwargs['logfile']
|
||||||
|
|
||||||
|
ln = linker+" -o "+target+" "+libdir
|
||||||
|
ln = ln+" "+objlist+" "+staticlibs+" "+libflags+" "+linkerflags
|
||||||
|
|
||||||
|
callproc(ln,logfile=logfile)
|
||||||
|
return
|
||||||
|
|
||||||
|
def msvc_link_list(objlist,target,**kwargs):
|
||||||
|
|
||||||
|
linker = 'link'
|
||||||
|
|
||||||
|
if(not('objext' in kwargs)):
|
||||||
|
objext = '.obj'
|
||||||
|
else:
|
||||||
|
objext = kwargs['objext']
|
||||||
|
|
||||||
|
if(not('libdir' in kwargs)):
|
||||||
|
libdir = ''
|
||||||
|
else:
|
||||||
|
libdir = kwargs['libdir']
|
||||||
|
|
||||||
|
if(not('staticlibs' in kwargs)):
|
||||||
|
staticlibs = ''
|
||||||
|
else:
|
||||||
|
staticlibs = kwargs['staticlibs']
|
||||||
|
|
||||||
|
if(not('libflags' in kwargs)):
|
||||||
|
libflags = ''
|
||||||
|
else:
|
||||||
|
libflags = kwargs['libflags']
|
||||||
|
|
||||||
|
if(not('linkerflags' in kwargs)):
|
||||||
|
linkerflags = ''
|
||||||
|
else:
|
||||||
|
linkerflags = kwargs['linkerflags']
|
||||||
|
|
||||||
|
if(not('recurse' in kwargs)):
|
||||||
|
recurse = True
|
||||||
|
else:
|
||||||
|
recurse = kwargs['recurse']
|
||||||
|
|
||||||
|
if(not('logfile' in kwargs)):
|
||||||
|
logfile = ''
|
||||||
|
else:
|
||||||
|
logfile = kwargs['logfile']
|
||||||
|
|
||||||
|
ln = linker+" "+libdir
|
||||||
|
ln = ln+" "+objlist+" "+staticlibs+" "+linkerflags
|
||||||
|
ln = ln+" /out:"+target+" "+libflags
|
||||||
|
|
||||||
|
callproc(ln,logfile=logfile)
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
def ar_all(srcpath,arname,**kwargs):
|
||||||
|
if(not('recurse' in kwargs)):
|
||||||
|
recurse = True
|
||||||
|
else:
|
||||||
|
recurse = kwargs['recurse']
|
||||||
|
if(not('objext' in kwargs)):
|
||||||
|
objext = '.o'
|
||||||
|
else:
|
||||||
|
objext = kwargs['objext']
|
||||||
|
|
||||||
|
objlist = flist(srcpath,exts=objext,recurse=recurse)
|
||||||
|
ar_list(objlist,arname,**kwargs)
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
def msvc_lib_list(objlist,arname,**kwargs):
|
||||||
|
objlist2 = list_to_sss(objlist)
|
||||||
|
|
||||||
|
ln = "lib "+objlist2+" /out:"+arname
|
||||||
|
callproc(ln)
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
def ar_list(objlist,arname,**kwargs):
|
||||||
|
objlist2 = list_to_sss(objlist)
|
||||||
|
|
||||||
|
ln = "ar cr "+ arname+" "+objlist2
|
||||||
|
callproc(ln)
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
def ar_add_list(objlist,arname,**kwargs):
|
||||||
|
objlist2 = list_to_sss(objlist)
|
||||||
|
|
||||||
|
ln = "ar t "+arname+" "+objlist2
|
||||||
|
callproc(ln)
|
||||||
|
return
|
||||||
|
|
||||||
|
##############################
|
||||||
|
##Derived Compiler Functions##
|
||||||
|
##############################
|
||||||
|
|
||||||
|
def gcc_compile(srcfile,**kwargs):
|
||||||
|
compiler = 'gcc'
|
||||||
|
kwargs['objext'] = '.o'
|
||||||
|
#srcexts = ['.c']
|
||||||
|
|
||||||
|
gs_compile(compiler,srcfile,**kwargs)
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
def gcc_compile_all(srcdir,**kwargs):
|
||||||
|
compiler = 'gcc'
|
||||||
|
kwargs['objext'] = '.o'
|
||||||
|
srcexts = ['.c']
|
||||||
|
|
||||||
|
gs_compile_all(compiler,srcdir,srcexts,**kwargs)
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
def gcc_compile_list(srclist,**kwargs):
|
||||||
|
compiler = 'gcc'
|
||||||
|
kwargs['objext'] = '.o'
|
||||||
|
#srcexts = ['.c']
|
||||||
|
|
||||||
|
gs_compile_list(compiler,srclist,**kwargs)
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
def gpp_compile(srcfile,**kwargs):
|
||||||
|
compiler = 'g++'
|
||||||
|
kwargs['objext'] = '.o'
|
||||||
|
#srcexts = ['.c','.cpp']
|
||||||
|
|
||||||
|
gs_compile(compiler,srcfile,**kwargs)
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
def gpp_compile_all(srcdir,**kwargs):
|
||||||
|
compiler = 'g++'
|
||||||
|
kwargs['objext'] = '.o'
|
||||||
|
srcexts = ['.c','.cpp']
|
||||||
|
|
||||||
|
gs_compile_all(compiler,srcdir,srcexts,**kwargs)
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
def gpp_compile_list(srclist,**kwargs):
|
||||||
|
compiler = 'g++'
|
||||||
|
kwargs['objext'] = '.o'
|
||||||
|
#srcexts = ['.c','.cpp']
|
||||||
|
|
||||||
|
gs_compile_list(compiler,srclist,**kwargs)
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
def gfortran_compile(srcfile,**kwargs):
|
||||||
|
compiler = 'gfortran'
|
||||||
|
kwargs['objext'] = '.o'
|
||||||
|
#srcexts = ['.f','.f90','.f77']
|
||||||
|
|
||||||
|
gs_compile(compiler,srcfile,**kwargs)
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
def gfortran_compile_all(srcdir,**kwargs):
|
||||||
|
compiler = 'gfortran'
|
||||||
|
kwargs['objext'] = '.o'
|
||||||
|
srcexts = ['.f','.f90','.f77']
|
||||||
|
|
||||||
|
gs_compile_all(compiler,srcdir,srcexts,**kwargs)
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
def gfortran_compile_list(srclist,**kwargs):
|
||||||
|
compiler = 'gfortran'
|
||||||
|
kwargs['objext'] = '.o'
|
||||||
|
#srcexts = ['.f','.f90','.f77']
|
||||||
|
|
||||||
|
gs_compile_list(compiler,srclist,**kwargs)
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
def clang_compile(srcfile,**kwargs):
|
||||||
|
compiler = 'clang++'
|
||||||
|
kwargs['objext'] = '.o'
|
||||||
|
#srcexts = ['.c','.cpp']
|
||||||
|
|
||||||
|
gs_compile(compiler,srcfile,**kwargs)
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
def clang_compile_all(srcdir,**kwargs):
|
||||||
|
compiler = 'clang++'
|
||||||
|
kwargs['objext'] = '.o'
|
||||||
|
srcexts = ['.c','.cpp']
|
||||||
|
|
||||||
|
gs_compile_all(compiler,srcdir,srcexts,**kwargs)
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
def clang_compile_list(srclist,**kwargs):
|
||||||
|
compiler = 'clang++'
|
||||||
|
kwargs['objext'] = '.o'
|
||||||
|
#srcexts = ['.c','.cpp']
|
||||||
|
|
||||||
|
gs_compile_list(compiler,srclist,**kwargs)
|
||||||
|
|
||||||
|
return
|
||||||
45
old/compscripts/old/linux64.makelib.py
Normal file
45
old/compscripts/old/linux64.makelib.py
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
#!/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
|
||||||
|
from shutil import copytree as copytree
|
||||||
|
|
||||||
|
libname = 'amsculib2.linux64' #prefix static library name to generate
|
||||||
|
targetname = 'test' #create this executable when compiling tests
|
||||||
|
commonincdir = "../../linux64/include"
|
||||||
|
commonlibdir = "../../linux64/lib"
|
||||||
|
localbindir = "./bin_linux64"
|
||||||
|
cc = 'nvcc' #compiler
|
||||||
|
srcexts = ['.c','.cpp','.cu']
|
||||||
|
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
|
||||||
|
#-dc flag: relocatable device code - needed for device functions to link in different "execution units"
|
||||||
|
kwargs['flags'] = "-dc"
|
||||||
|
kwargs['libdir'] = "-L{} -L{}".format(localbindir,commonlibdir)
|
||||||
|
kwargs['libflags'] = "-l{}".format(libname)
|
||||||
|
kwargs['linkerflags'] = ""
|
||||||
|
kwargs['recurse'] = True
|
||||||
|
|
||||||
|
#find all source files, except the main project files
|
||||||
|
files = flist('./src',exts = srcexts, recurse=True)
|
||||||
|
files = except_contains(files,mainsrc)
|
||||||
|
objfiles = replaceexts(files,'.o')
|
||||||
|
objfiles_sss = list_to_sss(objfiles)
|
||||||
|
|
||||||
|
#compile all the source files in the list
|
||||||
|
gs_compile_list(cc,files,**kwargs)
|
||||||
|
|
||||||
|
#archive all the source files into a static library
|
||||||
|
ar_list(objfiles,'{}/lib{}.a'.format(localbindir,libname))
|
||||||
|
|
||||||
|
#Push any libraries to the common lib folder
|
||||||
|
shutil.copy('{}/lib{}.a'.format(localbindir,libname),commonlibdir)
|
||||||
|
|
||||||
|
#Copy include files to the common include folder
|
||||||
|
copytree('./include/',commonincdir+'/',dirs_exist_ok=True)
|
||||||
38
old/compscripts/old/linux64.maketest.py
Normal file
38
old/compscripts/old/linux64.maketest.py
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
import os,sys,subprocess,math
|
||||||
|
from complib2 import *
|
||||||
|
|
||||||
|
import shutil
|
||||||
|
|
||||||
|
libname = 'amsculib2.linux64' #prefix static library name to generate
|
||||||
|
targetname = 'test' #create this executable when compiling tests
|
||||||
|
commonincdir = "../../linux64/include"
|
||||||
|
commonlibdir = "../../linux64/lib"
|
||||||
|
localbindir = "./bin_linux64"
|
||||||
|
cc = 'nvcc' #compiler
|
||||||
|
srcexts = ['.c','.cpp','.cu']
|
||||||
|
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
|
||||||
|
#-dc flag: relocatable device code - needed for device functions to link in different "execution units"
|
||||||
|
kwargs['flags'] = "-dc"
|
||||||
|
kwargs['libdir'] = "-L{} -L{}".format(localbindir,commonlibdir)
|
||||||
|
kwargs['libflags'] = "-l{}".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,'.o')
|
||||||
|
|
||||||
|
#Compile test programs
|
||||||
|
gs_compile_list(cc,fsrc,**kwargs)
|
||||||
|
gs_link_list(cc,list_to_sss(fobj),'{}/{}'.format(localbindir,targetname),**kwargs)
|
||||||
45
old/compscripts/old/msvc.makelib.py
Normal file
45
old/compscripts/old/msvc.makelib.py
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
import os,sys,subprocess,math
|
||||||
|
from complib2 import *
|
||||||
|
|
||||||
|
import shutil
|
||||||
|
from shutil import copytree as copytree
|
||||||
|
|
||||||
|
libname = 'assetcuda.msvc64' #prefix static library name to generate
|
||||||
|
targetname = 'main' #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'] = "-l{}".format(libname)
|
||||||
|
kwargs['linkerflags'] = ""
|
||||||
|
kwargs['recurse'] = True
|
||||||
|
|
||||||
|
#find all source files, except the main project files
|
||||||
|
files = flist('./src',exts = srcexts, recurse=True)
|
||||||
|
files = except_contains(files,mainsrc)
|
||||||
|
objfiles = replaceexts(files,'.obj')
|
||||||
|
objfiles_sss = list_to_sss(objfiles)
|
||||||
|
|
||||||
|
#compile all the source files in the list
|
||||||
|
msvc_compile_list(cc,files,**kwargs)
|
||||||
|
#gs_compile_list(cc,files,**kwargs)
|
||||||
|
|
||||||
|
#archive all the source files into a static library
|
||||||
|
#ar_list(objfiles,'{}/lib{}.a'.format(localbindir,libname))
|
||||||
|
msvc_lib_list(objfiles,'{}/lib{}.lib'.format(localbindir,libname))
|
||||||
|
|
||||||
|
#Push any libraries to the common lib folder
|
||||||
|
shutil.copy('{}/lib{}.lib'.format(localbindir,libname),commonlibdir)
|
||||||
|
|
||||||
|
#Copy include files to the common include folder
|
||||||
|
copytree('./include/',commonincdir+'/',dirs_exist_ok=True)
|
||||||
39
old/compscripts/old/msvc.maketest.py
Normal file
39
old/compscripts/old/msvc.maketest.py
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
#!/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)
|
||||||
44
old/compscripts/old/winnvcc.makelib.py
Normal file
44
old/compscripts/old/winnvcc.makelib.py
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
#!/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 = 'amsculib2.msvc64' #prefix static library name to generate
|
||||||
|
targetname = 'test' #create this executable when compiling tests
|
||||||
|
commonincdir = "../../winx64/include"
|
||||||
|
commonlibdir = "../../winx64/lib"
|
||||||
|
localbindir = "./bin_winx64"
|
||||||
|
cc = 'nvcc' #compiler
|
||||||
|
srcexts = ['.c','.cpp','.cu']
|
||||||
|
mainsrc = ['main.c','main.cpp'] #ignore these files when compiling the static library
|
||||||
|
|
||||||
|
kwargs = dict()
|
||||||
|
include = "-I./include -I{}".format(commonincdir)
|
||||||
|
kwargs['include'] = include
|
||||||
|
kwargs['flags'] = "-dc"
|
||||||
|
kwargs['libdir'] = "-L{} -L{}".format(localbindir,commonlibdir)
|
||||||
|
kwargs['libflags'] = "-l{}".format(libname)
|
||||||
|
kwargs['linkerflags'] = ""
|
||||||
|
kwargs['recurse'] = True
|
||||||
|
|
||||||
|
#find all source files, except the main project files
|
||||||
|
files = flist('./src',exts = srcexts, recurse=True)
|
||||||
|
files = except_contains(files,mainsrc)
|
||||||
|
objfiles = replaceexts(files,'.o')
|
||||||
|
objfiles_sss = list_to_sss(objfiles)
|
||||||
|
|
||||||
|
#compile all the source files in the list
|
||||||
|
gs_compile_list(cc,files,**kwargs)
|
||||||
|
|
||||||
|
#archive all the source files into a static library
|
||||||
|
#ar_list(objfiles,'{}/lib{}.a'.format(localbindir,libname))
|
||||||
|
msvc_lib_list(objfiles,'{}/lib{}.lib'.format(localbindir,libname))
|
||||||
|
|
||||||
|
#Push any libraries to the common lib folder
|
||||||
|
shutil.copy('{}/lib{}.lib'.format(localbindir,libname),commonlibdir)
|
||||||
|
|
||||||
|
#Copy include files to the common include folder
|
||||||
|
copy_tree('./include/',commonincdir+'/')
|
||||||
38
old/compscripts/old/winnvcc.maketest.py
Normal file
38
old/compscripts/old/winnvcc.maketest.py
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
#!/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 = 'amsculib2.msvc64' #prefix static library name to generate
|
||||||
|
targetname = 'test' #create this executable when compiling tests
|
||||||
|
commonincdir = "../../winx64/include"
|
||||||
|
commonlibdir = "../../winx64/lib"
|
||||||
|
localbindir = "./bin_winx64"
|
||||||
|
cc = 'nvcc' #compiler
|
||||||
|
srcexts = ['.c','.cpp','.cu']
|
||||||
|
mainsrc = ['main.c','main.cpp'] #ignore these files when compiling the static library
|
||||||
|
|
||||||
|
kwargs = dict()
|
||||||
|
include = "-I./include -I{}".format(commonincdir)
|
||||||
|
kwargs['include'] = include
|
||||||
|
kwargs['flags'] = "-dc"
|
||||||
|
kwargs['libdir'] = "-L{} -L{}".format(localbindir,commonlibdir)
|
||||||
|
kwargs['libflags'] = "-llib{}".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.cpp']
|
||||||
|
fobj = replaceexts(fsrc,'.o')
|
||||||
|
|
||||||
|
#Compile test programs
|
||||||
|
gs_compile_list(cc,fsrc,**kwargs)
|
||||||
|
gs_link_list(cc,list_to_sss(fobj),'{}/{}'.format(localbindir,targetname),**kwargs)
|
||||||
49
old/compscripts/winnvcc.makelib.py
Normal file
49
old/compscripts/winnvcc.makelib.py
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
import os,sys,subprocess,math
|
||||||
|
from complib2 import *
|
||||||
|
from complib3 import gs_incremental_compile, gs_incremental_compile_list
|
||||||
|
|
||||||
|
import shutil
|
||||||
|
from shutil import copytree
|
||||||
|
|
||||||
|
libname = 'amsculib2.msvc64' #prefix static library name to generate
|
||||||
|
targetname = 'test' #create this executable when compiling tests
|
||||||
|
commonincdir = "../../winx64/include"
|
||||||
|
commonlibdir = "../../winx64/lib"
|
||||||
|
localbindir = "./bin_winx64"
|
||||||
|
cc = 'nvcc' #compiler
|
||||||
|
srcexts = ['.c','.cpp','.cu']
|
||||||
|
mainsrc = ['main.cu'] #ignore these files when compiling the static library
|
||||||
|
|
||||||
|
kwargs = dict()
|
||||||
|
include = "-I./include -I{}".format(commonincdir)
|
||||||
|
kwargs['include'] = include
|
||||||
|
kwargs['flags'] = "-dc"
|
||||||
|
kwargs['libdir'] = "-L{} -L{}".format(localbindir,commonlibdir)
|
||||||
|
kwargs['libflags'] = "-l{}".format(libname)
|
||||||
|
kwargs['linkerflags'] = ""
|
||||||
|
kwargs['recurse'] = True
|
||||||
|
kwargs['objstore'] = "./objstore"
|
||||||
|
kwargs['searchincdirs'] = ['./include']
|
||||||
|
|
||||||
|
#find all source files, except the main project files
|
||||||
|
files = flist('./src',exts = srcexts, recurse=True)
|
||||||
|
files = except_contains(files,mainsrc)
|
||||||
|
objfiles = replaceexts(files,'.o')
|
||||||
|
objfiles_sss = list_to_sss(objfiles)
|
||||||
|
|
||||||
|
#compile all the source files in the list
|
||||||
|
#gs_compile_list(cc,files,**kwargs)
|
||||||
|
gs_incremental_compile_list(cc,files,**kwargs)
|
||||||
|
|
||||||
|
#archive all the source files into a static library
|
||||||
|
#ar_list(objfiles,'{}/lib{}.a'.format(localbindir,libname))
|
||||||
|
objlist = flist(kwargs['objstore'],exts='.o',recurse=True)
|
||||||
|
msvc_lib_list(objlist,'{}/lib{}.lib'.format(localbindir,libname))
|
||||||
|
|
||||||
|
# #Push any libraries to the common lib folder
|
||||||
|
shutil.copy('{}/lib{}.lib'.format(localbindir,libname),commonlibdir)
|
||||||
|
|
||||||
|
# #Copy include files to the common include folder
|
||||||
|
copytree('./include/',commonincdir+'/',dirs_exist_ok=True)
|
||||||
43
old/compscripts/winnvcc.maketest.py
Normal file
43
old/compscripts/winnvcc.maketest.py
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
import os,sys,subprocess,math
|
||||||
|
from complib2 import *
|
||||||
|
from complib3 import gs_incremental_compile, gs_incremental_compile_list
|
||||||
|
|
||||||
|
import shutil
|
||||||
|
from shutil import copytree
|
||||||
|
|
||||||
|
libname = 'amsculib2.msvc64' #prefix static library name to generate
|
||||||
|
targetname = 'test' #create this executable when compiling tests
|
||||||
|
commonincdir = "../../winx64/include"
|
||||||
|
commonlibdir = "../../winx64/lib"
|
||||||
|
localbindir = "./bin_winx64"
|
||||||
|
cc = 'nvcc' #compiler
|
||||||
|
srcexts = ['.c','.cpp','.cu']
|
||||||
|
mainsrc = ['main.cu'] #ignore these files when compiling the static library
|
||||||
|
|
||||||
|
kwargs = dict()
|
||||||
|
include = "-I./include -I{}".format(commonincdir)
|
||||||
|
kwargs['include'] = include
|
||||||
|
kwargs['flags'] = "-dc"
|
||||||
|
kwargs['libdir'] = "-L{} -L{}".format(localbindir,commonlibdir)
|
||||||
|
kwargs['libflags'] = "-llib{} -llibamsculib2.msvc64".format(libname)
|
||||||
|
kwargs['linkerflags'] = ""
|
||||||
|
kwargs['recurse'] = True
|
||||||
|
kwargs['objstore'] = "./objstore"
|
||||||
|
kwargs['searchincdirs'] = ['./include']
|
||||||
|
|
||||||
|
#-lamsmathlib3.linux64 -lamsstring3.linux64 -lamsmatrix_cpp.linux64 -llapack -lblas -lgfortran -lamsmathutilthread.linux64 -lamsmathutil2.linux64
|
||||||
|
|
||||||
|
#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,'.o')
|
||||||
|
|
||||||
|
#Compile test programs
|
||||||
|
gs_compile_list(cc,fsrc,**kwargs)
|
||||||
|
gs_link_list(cc,list_to_sss(fobj),'{}/{}'.format(localbindir,targetname),**kwargs)
|
||||||
23
old/run.py
Normal file
23
old/run.py
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
import os,sys,math;
|
||||||
|
from compscripts.complib2 import *;
|
||||||
|
|
||||||
|
args = sys.argv
|
||||||
|
if(len(args)>=2):
|
||||||
|
if(args[1]=="clean"):
|
||||||
|
obj_list = flist('./objstore',recurse=True,exts=['.o'])
|
||||||
|
for o in obj_list:
|
||||||
|
os.remove('{}'.format(o))
|
||||||
|
exit(0)
|
||||||
|
|
||||||
|
os.system('python3 ./compscripts/linux64.makelib.py')
|
||||||
|
os.system('python3 ./compscripts/linux64.maketest.py')
|
||||||
|
|
||||||
|
# obj_list = flist('./src',recurse=True,exts=['.o'])
|
||||||
|
# for o in obj_list:
|
||||||
|
# os.remove('{}'.format(o))
|
||||||
|
|
||||||
|
#os.chdir('./bin_linux64')
|
||||||
|
callproc('./bin_linux64/test')
|
||||||
|
#os.chdir('..')
|
||||||
17
old/run3.py
Normal file
17
old/run3.py
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
import os,sys,math;
|
||||||
|
from compscripts.complib2 import *;
|
||||||
|
|
||||||
|
|
||||||
|
os.system('python ./compscripts/winnvcc.makelib.py')
|
||||||
|
os.system('python ./compscripts/winnvcc.maketest.py')
|
||||||
|
|
||||||
|
obj_list = flist('./',recurse=True,exts=['.o'])
|
||||||
|
for o in obj_list:
|
||||||
|
os.remove('{}'.format(o))
|
||||||
|
|
||||||
|
#os.chdir('./bin_winx64')
|
||||||
|
callproc('.\\bin_winx64\\test.exe')
|
||||||
|
#os.chdir('..')
|
||||||
|
|
||||||
4
pull.sh
Normal file
4
pull.sh
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
scp aschinder@amssolarempire.com:workspace/projects/amsculib2.tar.gz ../
|
||||||
|
tar xzvf ../amsculib2.tar.gz ./
|
||||||
@ -351,6 +351,14 @@ __host__ __device__ cuvect2f mat2f_mult(float *mat2a, cuvect2f b)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
__host__ __device__ cuvect2f operator-(cuvect2f rhs)
|
||||||
|
{
|
||||||
|
cuvect2f ret;
|
||||||
|
ret[0] = -rhs[0];
|
||||||
|
ret[1] = -rhs[1];
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
void test_cuvect2f_1()
|
void test_cuvect2f_1()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|||||||
@ -578,4 +578,13 @@ __host__ __device__ cumat3f cumat3f::inverse()
|
|||||||
return q;
|
return q;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
__host__ __device__ cuvect3f operator-(cuvect3f rhs)
|
||||||
|
{
|
||||||
|
cuvect3f ret;
|
||||||
|
ret[0] = -rhs[0];
|
||||||
|
ret[1] = -rhs[1];
|
||||||
|
ret[2] = -rhs[2];
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
@ -414,4 +414,14 @@ __host__ __device__ cuvect4f cuvect4f_proj(cuvect4f a, cuvect4f b)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
__host__ __device__ cuvect4f operator-(cuvect4f rhs)
|
||||||
|
{
|
||||||
|
cuvect4f ret;
|
||||||
|
ret[0] = -rhs[0];
|
||||||
|
ret[1] = -rhs[1];
|
||||||
|
ret[2] = -rhs[2];
|
||||||
|
ret[3] = -rhs[3];
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
}; //namespace amscuda
|
}; //namespace amscuda
|
||||||
|
|||||||
@ -21,7 +21,7 @@ int main(int argc, char* argv[])
|
|||||||
|
|
||||||
//test_dbuff_rand_dpr32();
|
//test_dbuff_rand_dpr32();
|
||||||
|
|
||||||
test_amscurarray1();
|
//test_amscurarray1();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
BIN
src/main.o
BIN
src/main.o
Binary file not shown.
Reference in New Issue
Block a user