more lib compilation updates

This commit is contained in:
Axel Kohlmeyer
2017-08-08 07:20:33 -04:00
parent 8bba29d91e
commit b3244f9c98
18 changed files with 312 additions and 250 deletions

View File

@ -3,127 +3,133 @@
# Install.py tool to download, unpack, build, and link to the MS-CG library
# used to automate the steps described in the README file in this dir
import sys,os,re,commands
from __future__ import print_function
import sys,os,re,subprocess
try:
import ssl
try: from urllib.request import urlretrieve as geturl
except: from urllib import urlretrieve as geturl
except:
def geturl(url,fname):
cmd = 'curl -L -o "%s" %s' % (fname,url)
txt = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
return txt
# help message
help = """
Syntax from src dir: make lib-mscg args="-h hpath hdir -g -b [suffix] -l"
Syntax from lib dir: python Install.py -h hpath hdir -g -b [suffix] -l
Syntax from src dir: make lib-mscg args="-p [path] -m [suffix]"
Syntax from lib dir: python Install.py -p [path] -m [suffix]
specify one or more options, order does not matter
-h = set home dir of MS-CG to be hpath/hdir
hpath can be full path, contain '~' or '.' chars
default hpath = . = lib/mscg
default hdir = MSCG-release-master = what GitHub zipfile unpacks to
-g = grab (download) zipfile from MS-CG GitHub website
unpack it to hpath/hdir
hpath must already exist
if hdir already exists, it will be deleted before unpack
-b = build MS-CG library in its src dir
optional suffix specifies which src/Make/Makefile.suffix to use
-b = download and build MS-CG library (default)
-p = specify folder of existing MS-CG installation
-m = machine suffix specifies which src/Make/Makefile.suffix to use
default suffix = g++_simple
-l = create 2 softlinks (includelink,liblink) in lib/mscg to MS-CG src dir
Example:
make lib-mscg args="-g -b -l" # download/build in lib/mscg/MSCG-release-master
make lib-mscg args="-b " # download/build in lib/mscg/MSCG-release-master
"""
# settings
url = "https://github.com/uchicago-voth/MSCG-release/archive/master.zip"
zipfile = "MS-CG-master.zip"
zipdir = "MSCG-release-master"
url = "http://github.com/uchicago-voth/MSCG-release/archive/master.tar.gz"
tarfile = "MS-CG-master.tar.gz"
tardir = "MSCG-release-master"
# print error message or help
def error(str=None):
if not str: print help
else: print "ERROR",str
if not str: print(help)
else: print("ERROR",str)
sys.exit()
# expand to full path name
# process leading '~' or relative path
def fullpath(path):
return os.path.abspath(os.path.expanduser(path))
# parse args
args = sys.argv[1:]
nargs = len(args)
if nargs == 0: error()
homepath = "."
homedir = zipdir
homedir = tardir
grabflag = 0
buildflag = 0
buildflag = True
pathflag = False
linkflag = True
msuffix = "g++_simple"
linkflag = 0
iarg = 0
while iarg < nargs:
if args[iarg] == "-h":
if iarg+3 > nargs: error()
homepath = args[iarg+1]
homedir = args[iarg+2]
iarg += 3
elif args[iarg] == "-g":
grabflag = 1
iarg += 1
if args[iarg] == "-p":
if iarg+2 > nargs: error()
mscgpath = fullpath(args[iarg+1])
pathflag = True
buildflag = False
iarg += 2
elif args[iarg] == "-m":
if iarg+2 > nargs: error()
msuffix = args[iarg+1]
iarg += 2
elif args[iarg] == "-b":
buildflag = 1
if iarg+1 < nargs and args[iarg+1][0] != '-':
msuffix = args[iarg+1]
iarg += 1
iarg += 1
elif args[iarg] == "-l":
linkflag = 1
buildflag = True
iarg += 1
else: error()
homepath = fullpath(homepath)
if not os.path.isdir(homepath): error("MS-CG path does not exist")
homedir = "%s/%s" % (homepath,homedir)
# download and unpack MS-CG zipfile
if (pathflag):
if not os.path.isdir(mscgpath): error("MS-CG path does not exist")
homedir = mscgpath
if grabflag:
print "Downloading MS-CG ..."
cmd = "curl -L %s > %s/%s" % (url,homepath,zipfile)
print cmd
print commands.getoutput(cmd)
if (buildflag and pathflag):
error("Cannot use -b and -p flag at the same time")
print "Unpacking MS-CG zipfile ..."
if os.path.exists("%s/%s" % (homepath,zipdir)):
commands.getoutput("rm -rf %s/%s" % (homepath,zipdir))
cmd = "cd %s; unzip %s" % (homepath,zipfile)
commands.getoutput(cmd)
if os.path.basename(homedir) != zipdir:
if os.path.exists(homedir): commands.getoutput("rm -rf %s" % homedir)
os.rename("%s/%s" % (homepath,zipdir),homedir)
# download and unpack MS-CG tarfile
if buildflag:
print("Downloading MS-CG ...")
geturl(url,"%s/%s" % (homepath,tarfile))
print("Unpacking MS-CG tarfile ...")
if os.path.exists("%s/%s" % (homepath,tardir)):
cmd = 'rm -rf "%s/%s"' % (homepath,tardir)
subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
cmd = 'cd "%s"; tar -xzvf %s' % (homepath,tarfile)
subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
os.remove("%s/%s" % (homepath,tarfile))
if os.path.basename(homedir) != tardir:
if os.path.exists(homedir):
cmd = 'rm -rf "%s"' % homedir
subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
os.rename("%s/%s" % (homepath,tardir),homedir)
# build MS-CG
if buildflag:
print "Building MS-CG ..."
cmd = "cd %s/src; cp Make/Makefile.%s .; make -f Makefile.%s" % \
print("Building MS-CG ...")
cmd = 'cd "%s/src"; cp Make/Makefile.%s .; make -f Makefile.%s' % \
(homedir,msuffix,msuffix)
txt = commands.getoutput(cmd)
print txt
txt = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
print(txt.decode('UTF-8'))
# create 2 links in lib/mscg to MS-CG src dir
if linkflag:
print "Creating links to MS-CG include and lib files"
print("Creating links to MS-CG include and lib files")
if os.path.isfile("includelink") or os.path.islink("includelink"):
os.remove("includelink")
if os.path.isfile("liblink") or os.path.islink("liblink"):
os.remove("liblink")
cmd = "ln -s %s/src includelink" % homedir
commands.getoutput(cmd)
cmd = "ln -s %s/src liblink" % homedir
commands.getoutput(cmd)
cmd = 'ln -s "%s/src" includelink' % homedir
subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
cmd = 'ln -s "%s/src" liblink' % homedir
subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)