diff --git a/lib/Install.py b/lib/Install.py index 416a2319c..d30cbffcf 100644 --- a/lib/Install.py +++ b/lib/Install.py @@ -1,100 +1,101 @@ #!/usr/bin/env python # install.py tool to do a generic build of a library # soft linked to by many of the lib/Install.py files # used to automate the steps described in the corresponding lib/README from __future__ import print_function import sys,os,subprocess # help message help = """ Syntax from src dir: make lib-libname args="-m machine -e suffix" Syntax from lib dir: python Install.py -m machine -e suffix libname = name of lib dir (e.g. atc, h5md, meam, poems, etc) specify -m and optionally -e, order does not matter -m = peform a clean followed by "make -f Makefile.machine" machine = suffix of a lib/Makefile.* file -e = set EXTRAMAKE variable in Makefile.machine to Makefile.lammps.suffix does not alter existing Makefile.machine Examples: -make lib-poems args="-m g++" # build COLVARS lib with GNU g++ compiler -make lib-meam args="-m ifort" # build MEAM lib with Intel ifort compiler +make lib-poems args="-m serial" # build POEMS lib with same settings as in the serial Makefile in src +make lib-colvars args="-m mpi" # build USER-COLVARS lib with same settings as in the mpi Makefile in src +make lib-meam args="-m ifort" # build MEAM lib with custom Makefile.ifort (using Intel Fortran) """ # print error message or help def error(str=None): if not str: print(help) else: print("ERROR",str) sys.exit() # parse args args = sys.argv[1:] nargs = len(args) if nargs == 0: error() machine = None extraflag = 0 iarg = 0 while iarg < nargs: if args[iarg] == "-m": if iarg+2 > nargs: error() machine = args[iarg+1] iarg += 2 elif args[iarg] == "-e": if iarg+2 > nargs: error() extraflag = 1 suffix = args[iarg+1] iarg += 2 else: error() # set lib from working dir cwd = os.getcwd() lib = os.path.basename(cwd) # create Makefile.auto as copy of Makefile.machine # reset EXTRAMAKE if requested if not os.path.exists("Makefile.%s" % machine): error("lib/%s/Makefile.%s does not exist" % (lib,machine)) lines = open("Makefile.%s" % machine,'r').readlines() fp = open("Makefile.auto",'w') has_extramake = False for line in lines: words = line.split() if len(words) == 3 and words[0] == "EXTRAMAKE" and words[1] == '=': has_extramake = True if extraflag: line = line.replace(words[2],"Makefile.lammps.%s" % suffix) fp.write(line) fp.close() # make the library via Makefile.auto optionally with parallel make try: import multiprocessing n_cpus = multiprocessing.cpu_count() except: n_cpus = 1 print("Building lib%s.a ..." % lib) cmd = "make -f Makefile.auto clean; make -f Makefile.auto -j%d" % n_cpus txt = subprocess.check_output(cmd,shell=True,stderr=subprocess.STDOUT) print(txt.decode('UTF-8')) if os.path.exists("lib%s.a" % lib): print("Build was successful") else: error("Build of lib/%s/lib%s.a was NOT successful" % (lib,lib)) if has_extramake and not os.path.exists("Makefile.lammps"): print("lib/%s/Makefile.lammps was NOT created" % lib) diff --git a/lib/kim/Install.py b/lib/kim/Install.py index f7ddcfda9..06479d2d4 100644 --- a/lib/kim/Install.py +++ b/lib/kim/Install.py @@ -1,276 +1,280 @@ #!/usr/bin/env python -# install.py tool to setup the kim-api library +# install.py tool to download, compile, and setup the kim-api library # used to automate the steps described in the README file in this dir + from __future__ import print_function import sys,os,re,subprocess -# transparently use either urllib or an external tool -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 = """ -Syntax from src dir: make lib-kim args="-v version -a kim-name" -Syntax from lib dir: python Install.py -v version -a kim-name +Syntax from src dir: make lib-kim args="-b -v version -a kim-name" + or: make lib-kim args="-b -a everything" + or: make lib-kim args="-n -a kim-name" + or: make lib-kim args="-p /usr/local/open-kim -a kim-name" +Syntax from lib dir: python Install.py -b -v version -a kim-name + or: python Install.py -b -a everything + or: python Install.py -n -a kim-name + or: python Install.py -p /usr/local/open-kim -a kim-name specify one or more options, order does not matter -v = version of KIM API library to use default = kim-api-v1.8.2 (current as of June 2017) - -b = download and build base KIM API library with example Models (default) + -b = download and build base KIM API library with example Models this will delete any previous installation in the current folder - -n = do NOT download and build base KIM API library. Use an existing installation + -n = do NOT download and build base KIM API library. + Use an existing installation -p = specify location of KIM API installation (implies -n) -a = add single KIM model or model driver with kim-name to existing KIM API lib (see example below). If kim-name = everything, then rebuild KIM API library with - all available OpenKIM Models (this implies -b). + *all* available OpenKIM Models (make take a long time). -vv = be more verbose about what is happening while the script runs Examples: -make lib-kim # install KIM API lib with only example models +make lib-kim args="-b" # install KIM API lib with only example models make lib-kim args="-a Glue_Ercolessi_Adams_Al__MO_324507536345_001" # Ditto plus one model -make lib-kim args="-a everything" # install KIM API lib with all models +make lib-kim args="-b -a everything" # install KIM API lib with all models make lib-kim args="-n -a EAM_Dynamo_Ackland_W__MO_141627196590_002" # only add one model or model driver See the list of KIM model drivers here: https://openkim.org/kim-items/model-drivers/alphabetical See the list of all KIM models here: https://openkim.org/kim-items/models/by-model-drivers See the list of example KIM models included by default here: https://openkim.org/kim-api in the "What is in the KIM API source package?" section """ -def error(): - print(help) +def error(str=None): + 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)) +def geturl(url,fname): + cmd = 'curl -L -o "%s" %s' % (fname,url) + txt = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True) + return txt + # parse args args = sys.argv[1:] nargs = len(args) +if nargs == 0: error() thisdir = os.environ['PWD'] version = "kim-api-v1.8.2" -buildflag = True +buildflag = False everythingflag = False addflag = False verboseflag = False pathflag = False iarg = 0 while iarg < len(args): if args[iarg] == "-v": if iarg+2 > len(args): error() version = args[iarg+1] iarg += 2 elif args[iarg] == "-b": buildflag = True iarg += 1 elif args[iarg] == "-n": buildflag = False iarg += 1 elif args[iarg] == "-p": if iarg+2 > len(args): error() kimdir = fullpath(args[iarg+1]) pathflag = True buildflag = False iarg += 2 elif args[iarg] == "-a": addflag = True if iarg+2 > len(args): error() addmodelname = args[iarg+1] if addmodelname == "everything": buildflag = True everythingflag = True addflag = False iarg += 2 elif args[iarg] == "-vv": verboseflag = True iarg += 1 else: error() thisdir = os.path.abspath(thisdir) url = "https://s3.openkim.org/kim-api/%s.tgz" % version # set KIM API directory if pathflag: if not os.path.isdir(kimdir): print("\nkim-api is not installed at %s" % kimdir) error() # configure LAMMPS to use existing kim-api installation with open("%s/Makefile.KIM_DIR" % thisdir, 'w') as mkfile: mkfile.write("KIM_INSTALL_DIR=%s\n\n" % kimdir) mkfile.write(".DUMMY: print_dir\n\n") mkfile.write("print_dir:\n") mkfile.write(" @printf $(KIM_INSTALL_DIR)\n") with open("%s/Makefile.KIM_Config" % thisdir, 'w') as cfgfile: cfgfile.write("include %s/lib/kim-api/Makefile.KIM_Config" % kimdir) print("Created %s/Makefile.KIM_DIR\n using %s" % (thisdir,kimdir)) else: kimdir = os.path.join(os.path.abspath(thisdir), "installed-" + version) # download KIM tarball, unpack, build KIM if buildflag: # check to see if an installed kim-api already exists and wipe it out. if os.path.isdir(kimdir): print("kim-api is already installed at %s.\nRemoving it for re-install" % kimdir) cmd = 'rm -rf "%s"' % kimdir subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True) # configure LAMMPS to use kim-api to be installed with open("%s/Makefile.KIM_DIR" % thisdir, 'w') as mkfile: mkfile.write("KIM_INSTALL_DIR=%s\n\n" % kimdir) mkfile.write(".DUMMY: print_dir\n\n") mkfile.write("print_dir:\n") mkfile.write(" @printf $(KIM_INSTALL_DIR)\n") with open("%s/Makefile.KIM_Config" % thisdir, 'w') as cfgfile: cfgfile.write("include %s/lib/kim-api/Makefile.KIM_Config" % kimdir) print("Created %s/Makefile.KIM_DIR\n using %s" % (thisdir,kimdir)) # download entire kim-api tarball print("Downloading kim-api tarball ...") geturl(url,"%s/%s.tgz" % (thisdir,version)) print("Unpacking kim-api tarball ...") cmd = 'cd "%s"; rm -rf "%s"; tar -xzvf %s.tgz' % (thisdir,version,version) subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True) # configure kim-api print("Configuring kim-api ...") cmd = 'cd "%s/%s"; ./configure --prefix="%s"' % (thisdir,version,kimdir) subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True) # build kim-api print("Configuring example Models") cmd = 'cd "%s/%s"; make add-examples' % (thisdir,version) txt = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True) if verboseflag: print (txt.decode("UTF-8")) if everythingflag: print("Configuring all OpenKIM models, this will take a while ...") cmd = 'cd "%s/%s"; make add-OpenKIM' % (thisdir,version) txt = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True) if verboseflag: print(txt.decode("UTF-8")) print("Building kim-api ...") cmd = 'cd "%s/%s"; make' % (thisdir,version) txt = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True) if verboseflag: print(txt.decode("UTF-8")) # install kim-api print("Installing kim-api ...") cmd = 'cd "%s/%s"; make install' % (thisdir,version) txt = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True) if verboseflag: print(txt.decode("UTF-8")) cmd = 'cd "%s/%s"; make install-set-default-to-v1' %(thisdir,version) txt = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True) if verboseflag: print(txt.decode("UTF-8")) # remove source files print("Removing kim-api source and build files ...") cmd = 'cd "%s"; rm -rf %s; rm -rf %s.tgz' % (thisdir,version,version) subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True) # add a single model (and possibly its driver) to existing KIM installation if addflag: if not os.path.isdir(kimdir): print("\nkim-api is not installed") error() # download single model print("Downloading tarball for %s..." % addmodelname) url = "https://openkim.org/download/%s.tgz" % addmodelname geturl(url,"%s/%s.tgz" % (thisdir,addmodelname)) print("Unpacking item tarball ...") cmd = 'cd "%s"; tar -xzvf %s.tgz' % (thisdir,addmodelname) subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True) print("Building item ...") cmd = 'cd "%s/%s"; make; make install' %(thisdir,addmodelname) try: txt = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True) except subprocess.CalledProcessError as e: # Error: but first, check to see if it needs a driver firstRunOutput = e.output.decode("UTF-8") cmd = 'cd "%s/%s"; make kim-item-type' % (thisdir,addmodelname) txt = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True) txt = txt.decode("UTF-8") if txt == "ParameterizedModel": # Get and install driver cmd = 'cd "%s/%s"; make model-driver-name' % (thisdir,addmodelname) txt = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True) adddrivername = txt.decode("UTF-8").strip() print("First installing model driver: %s..." % adddrivername) cmd = 'cd "%s"; python Install.py -n -a %s' % (thisdir,adddrivername) try: txt = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True) except subprocess.CalledProcessError as e: print(e.output) sys.exit() if verboseflag: print(txt.decode("UTF-8")) # now install the model that needed the driver print("Now installing model : %s" % addmodelname) cmd = 'cd "%s"; python Install.py -n -a %s' % (thisdir,addmodelname) try: txt = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True) except subprocess.CalledProcessError as e: print(e.output) sys.exit() print(txt.decode("UTF-8")) sys.exit() else: print(firstRunOutput) print("Error, unable to build and install OpenKIM item: %s" \ % addmodelname) sys.exit() # success the first time if verboseflag: print(txt.decode("UTF-8")) print("Removing kim item source and build files ...") cmd = 'cd "%s"; rm -rf %s; rm -rf %s.tgz' %(thisdir,addmodelname,addmodelname) subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True) diff --git a/lib/mscg/Install.py b/lib/mscg/Install.py index 70d2eda24..e4e5ec561 100644 --- a/lib/mscg/Install.py +++ b/lib/mscg/Install.py @@ -1,149 +1,151 @@ #!/usr/bin/env python # 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 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="-p [path] -m [suffix]" + or: make lib-mscg args="-b -m [suffix]" Syntax from lib dir: python Install.py -p [path] -m [suffix] +Syntax from lib dir: python Install.py -b -m [suffix] specify one or more options, order does not matter - -b = download and build MS-CG library (default) + -b = download and build MS-CG library -p = specify folder of existing MS-CG installation -m = machine suffix specifies which src/Make/Makefile.suffix to use default suffix = g++_simple Example: -make lib-mscg args="-b " # download/build in lib/mscg/MSCG-release-master +make lib-mscg args="-b -m serial " # download/build in lib/mscg/MSCG-release-master with settings compatible with "make serial" +make lib-mscg args="-b -m mpi " # download/build in lib/mscg/MSCG-release-master with settings compatible with "make mpi" +make lib-mscg args="-p /usr/local/mscg-release " # use existing MS-CG installation in /usr/local/mscg-release """ # settings 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) sys.exit() # expand to full path name # process leading '~' or relative path def fullpath(path): return os.path.abspath(os.path.expanduser(path)) +def geturl(url,fname): + cmd = 'curl -L -o "%s" %s' % (fname,url) + txt = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True) + return txt + # parse args args = sys.argv[1:] nargs = len(args) +if nargs == 0: error() homepath = "." homedir = tardir -buildflag = True +buildflag = False pathflag = False linkflag = True msuffix = "g++_simple" iarg = 0 while iarg < nargs: 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 = True iarg += 1 else: error() homepath = fullpath(homepath) homedir = "%s/%s" % (homepath,homedir) if (pathflag): if not os.path.isdir(mscgpath): error("MS-CG path does not exist") homedir = mscgpath if (buildflag and pathflag): error("Cannot use -b and -p flag at the same time") +if (not buildflag and not pathflag): + error("Have to use either -b or -p flag") + # 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 ...") if os.path.exists("%s/src/Make/Makefile.%s" % (homedir,msuffix)): cmd = 'cd "%s/src"; cp Make/Makefile.%s .; make -f Makefile.%s' % \ (homedir,msuffix,msuffix) elif os.path.exists("Makefile.%s" % msuffix): cmd = 'cd "%s/src"; cp ../../Makefile.%s .; make -f Makefile.%s' % \ (homedir,msuffix,msuffix) else: error("Cannot find Makefile.%s" % msuffix) txt = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True) print(txt.decode('UTF-8')) if not os.path.exists("Makefile.lammps"): print("Creating Makefile.lammps") if os.path.exists("Makefile.lammps.%s" % msuffix): cmd = 'cp Makefile.lammps.%s Makefile.lammps' % msuffix else: cmd = 'cp Makefile.lammps.default Makefile.lammps' subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True) else: print("Makefile.lammps exists. Please check its settings") # create 2 links in lib/mscg to MS-CG src dir if linkflag: 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 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) diff --git a/lib/smd/Install.py b/lib/smd/Install.py index fe0283563..1c270bea5 100644 --- a/lib/smd/Install.py +++ b/lib/smd/Install.py @@ -1,117 +1,123 @@ #!/usr/bin/env python # Install.py tool to download, unpack, and point to the Eigen library # used to automate the steps described in the README file in this dir from __future__ import print_function import sys,os,re,glob,subprocess -try: from urllib.request import urlretrieve as geturl -except: from urllib import urlretrieve as geturl # help message help = """ -Syntax from src dir: make lib-smd +Syntax from src dir: make lib-smd args="-b" or: make lib-smd args="-p /usr/include/eigen3" -Syntax from lib dir: python Install.py +Syntax from lib dir: python Install.py -b or: python Install.py -p /usr/include/eigen3" or: python Install.py -v 3.3.4 -b specify one or more options, order does not matter - -b = download and unpack/configure the Eigen library (default) + -b = download and unpack/configure the Eigen library -p = specify folder holding an existing installation of Eigen -v = set version of Eigen library to download and set up (default = 3.3.4) Example: make lib-smd args="-b" # download/build in default lib/smd/eigen-eigen-* +make lib-smd args="-p /usr/include/eigen3" # use existing Eigen installation in /usr/include/eigen3 """ # settings version = '3.3.4' tarball = "eigen.tar.gz" # print error message or help def error(str=None): 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)) +def geturl(url,fname): + cmd = 'curl -L -o "%s" %s' % (fname,url) + txt = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True) + return txt + # parse args args = sys.argv[1:] nargs = len(args) +if nargs == 0: error() homepath = "." homedir = "eigen3" -grabflag = True -buildflag = True +buildflag = False pathflag = False linkflag = True iarg = 0 while iarg < nargs: if args[iarg] == "-v": if iarg+2 > nargs: error() version = args[iarg+1] iarg += 2 elif args[iarg] == "-p": if iarg+2 > nargs: error() eigenpath = fullpath(args[iarg+1]) pathflag = True - buildflag = False iarg += 2 elif args[iarg] == "-b": buildflag = True iarg += 1 else: error() homepath = fullpath(homepath) if (pathflag): if not os.path.isdir(eigenpath): error("Eigen path does not exist") if (buildflag and pathflag): error("Cannot use -b and -p flag at the same time") +if (not buildflag and not pathflag): + error("Have to use either -b or -p flag") + # download and unpack Eigen tarball # use glob to find name of dir it unpacks to if buildflag: print("Downloading Eigen ...") url = "http://bitbucket.org/eigen/eigen/get/%s.tar.gz" % version geturl(url,"%s/%s" % (homepath,tarball)) print("Unpacking Eigen tarball ...") edir = glob.glob("%s/eigen-eigen-*" % homepath) for one in edir: if os.path.isdir(one): subprocess.check_output('rm -rf "%s"' % one,stderr=subprocess.STDOUT,shell=True) cmd = 'cd "%s"; tar -xzvf %s' % (homepath,tarball) subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True) edir = glob.glob("%s/eigen-eigen-*" % homepath) os.rename(edir[0],"%s/%s" % (homepath,homedir)) os.remove(tarball) # create link in lib/smd to Eigen src dir if linkflag: print("Creating link to Eigen files") if os.path.isfile("includelink") or os.path.islink("includelink"): os.remove("includelink") if pathflag: linkdir = eigenpath else: linkdir = "%s/%s" % (homepath,homedir) cmd = 'ln -s "%s" includelink' % linkdir subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True) diff --git a/lib/voronoi/Install.py b/lib/voronoi/Install.py index 6db0495a3..5a246bbeb 100644 --- a/lib/voronoi/Install.py +++ b/lib/voronoi/Install.py @@ -1,135 +1,134 @@ #!/usr/bin/env python # Install.py tool to download, unpack, build, and link to the Voro++ library # used to automate the steps described in the README file in this dir 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-voronoi +Syntax from src dir: make lib-voronoi args="-b" or: make lib-voronoi args="-p /usr/local/voro++-0.4.6" - or: make lib-voronoi args="-v voro++-0.4.6 -b" -Syntax from lib dir: python Install.py -v voro++-0.4.6 -b - or: python Install.py + or: make lib-voronoi args="-b -v voro++-0.4.6" +Syntax from lib dir: python Install.py -b -v voro++-0.4.6 + or: python Install.py -b or: python Install.py -p /usr/local/voro++-0.4.6 specify one or more options, order does not matter - -b = download and build the Voro++ library (default) - -p = specify folder of existing Voro++ installation + -b = download and build the Voro++ library + -p = specify folder of existing Voro++ installation -v = set version of Voro++ to download and build (default voro++-0.4.6) Example: make lib-voronoi args="-b" # download/build in lib/voronoi/voro++-0.4.6 +make lib-voronoi args="-p $HOME/voro++-0.4.6" # use existing Voro++ installation in $HOME/voro++-0.4.6 """ # settings version = "voro++-0.4.6" url = "http://math.lbl.gov/voro++/download/dir/%s.tar.gz" % version # print error message or help def error(str=None): 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)) +def geturl(url,fname): + cmd = 'curl -L -o "%s" %s' % (fname,url) + txt = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True) + return txt + # parse args args = sys.argv[1:] nargs = len(args) +if nargs == 0: error() homepath = "." homedir = version -buildflag = True +buildflag = False pathflag = False linkflag = True iarg = 0 while iarg < nargs: if args[iarg] == "-v": if iarg+2 > nargs: error() version = args[iarg+1] iarg += 2 elif args[iarg] == "-p": if iarg+2 > nargs: error() voropath = fullpath(args[iarg+1]) pathflag = True - buildflag = False iarg += 2 elif args[iarg] == "-b": buildflag = True iarg += 1 else: error() homepath = fullpath(homepath) homedir = "%s/%s" % (homepath,version) if (pathflag): if not os.path.isdir(voropath): error("Voro++ path does not exist") homedir = voropath if (buildflag and pathflag): error("Cannot use -b and -p flag at the same time") +if (not buildflag and not pathflag): + error("Have to use either -b or -p flag") + # download and unpack Voro++ tarball if buildflag: print("Downloading Voro++ ...") geturl(url,"%s/%s.tar.gz" % (homepath,version)) print("Unpacking Voro++ tarball ...") if os.path.exists("%s/%s" % (homepath,version)): cmd = 'rm -rf "%s/%s"' % (homepath,version) subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True) cmd = 'cd "%s"; tar -xzvf %s.tar.gz' % (homepath,version) subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True) os.remove("%s/%s.tar.gz" % (homepath,version)) if os.path.basename(homedir) != version: if os.path.exists(homedir): cmd = 'rm -rf "%s"' % homedir subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True) os.rename("%s/%s" % (homepath,version),homedir) # build Voro++ if buildflag: print("Building Voro++ ...") cmd = 'cd "%s"; make' % homedir txt = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True) print(txt.decode('UTF-8')) # create 2 links in lib/voronoi to Voro++ src dir if linkflag: print("Creating links to Voro++ 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 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)