forked from lijiext/lammps
improve portability by using shutil.copyfile, os.path.join, and make -C
This commit is contained in:
parent
4fcfa4987a
commit
b7ab017a76
|
@ -4,7 +4,7 @@
|
||||||
# used to automate the steps described in the README file in this dir
|
# used to automate the steps described in the README file in this dir
|
||||||
|
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import sys,os,re,subprocess
|
import sys,os,re,subprocess,shutil
|
||||||
sys.path.append('..')
|
sys.path.append('..')
|
||||||
from install_helpers import get_cpus,fullpath
|
from install_helpers import get_cpus,fullpath
|
||||||
from argparse import ArgumentParser
|
from argparse import ArgumentParser
|
||||||
|
@ -50,16 +50,16 @@ zmqflag = args.zmq
|
||||||
# copy appropriate Makefile.lammps.* to Makefile.lammps
|
# copy appropriate Makefile.lammps.* to Makefile.lammps
|
||||||
|
|
||||||
print("Building CSlib ...")
|
print("Building CSlib ...")
|
||||||
srcdir = fullpath("./cslib/src")
|
srcdir = fullpath(os.path.join("cslib","src"))
|
||||||
|
|
||||||
if mpiflag and zmqflag:
|
if mpiflag and zmqflag:
|
||||||
cmd = "cd %s; make lib_parallel" % srcdir
|
cmd = "make -C %s lib_parallel" % srcdir
|
||||||
elif mpiflag and not zmqflag:
|
elif mpiflag and not zmqflag:
|
||||||
cmd = "cd %s; make lib_parallel zmq=no" % srcdir
|
cmd = "make -C %s lib_parallel zmq=no" % srcdir
|
||||||
elif not mpiflag and zmqflag:
|
elif not mpiflag and zmqflag:
|
||||||
cmd = "cd %s; make lib_serial" % srcdir
|
cmd = "make -C %s lib_serial" % srcdir
|
||||||
elif not mpiflag and not zmqflag:
|
elif not mpiflag and not zmqflag:
|
||||||
cmd = "cd %s; make lib_serial zmq=no" % srcdir
|
cmd = "make -C %s lib_serial zmq=no" % srcdir
|
||||||
|
|
||||||
print(cmd)
|
print(cmd)
|
||||||
try:
|
try:
|
||||||
|
@ -69,14 +69,11 @@ except subprocess.CalledProcessError as e:
|
||||||
print("Make failed with:\n %s" % e.output.decode('UTF-8'))
|
print("Make failed with:\n %s" % e.output.decode('UTF-8'))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
if mpiflag: cmd = "cd %s; cp libcsmpi.a libmessage.a" % srcdir
|
slb=os.path.join(srcdir,"libcsnompi.a")
|
||||||
else: cmd = "cd %s; cp libcsnompi.a libmessage.a" % srcdir
|
if mpiflag: slb = os.path.join(srcdir,"libcsmpi.a")
|
||||||
print(cmd)
|
shutil.copyfile(slb,os.path.join(srcdir,"libmessage.a"))
|
||||||
txt = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
|
|
||||||
print(txt.decode('UTF-8'))
|
|
||||||
|
|
||||||
if zmqflag: cmd = "cp Makefile.lammps.zmq Makefile.lammps"
|
smk="Makefile.lammps.nozmq"
|
||||||
else: cmd = "cp Makefile.lammps.nozmq Makefile.lammps"
|
if zmqflag: smk="Makefile.lammps.zmq"
|
||||||
print(cmd)
|
shutil.copyfile(smk,"Makefile.lammps")
|
||||||
txt = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
|
print("Using %s for Makefile.lammps" % smk)
|
||||||
print(txt.decode('UTF-8'))
|
|
||||||
|
|
|
@ -47,7 +47,7 @@ pgroup.add_argument("-p", "--path",
|
||||||
help="specify folder of existing MSCG installation")
|
help="specify folder of existing MSCG installation")
|
||||||
parser.add_argument("-v", "--version", default=version, choices=checksums.keys(),
|
parser.add_argument("-v", "--version", default=version, choices=checksums.keys(),
|
||||||
help="set version of MSCG to download and build (default: %s)" % version)
|
help="set version of MSCG to download and build (default: %s)" % version)
|
||||||
parser.add_argument("-m", "--machine", default=machine, choices=['g++_simple','intel_simple','lapack', 'mac'],
|
parser.add_argument("-m", "--machine", default=machine, choices=['mpi','serial','g++_simple','intel_simple','lapack', 'mac'],
|
||||||
help="set machine suffix specifies which src/Make/Makefile.suffix to use. (default: %s)" % machine)
|
help="set machine suffix specifies which src/Make/Makefile.suffix to use. (default: %s)" % machine)
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
@ -66,7 +66,7 @@ mscgver = args.version
|
||||||
# settings
|
# settings
|
||||||
|
|
||||||
url = "https://github.com/uchicago-voth/MSCG-release/archive/%s.tar.gz" % mscgver
|
url = "https://github.com/uchicago-voth/MSCG-release/archive/%s.tar.gz" % mscgver
|
||||||
tarfile = "MS-CG-%s.tar.gz" % mscgver
|
tarname = "MS-CG-%s.tar.gz" % mscgver
|
||||||
tardir = "MSCG-release-%s" % mscgver
|
tardir = "MSCG-release-%s" % mscgver
|
||||||
|
|
||||||
homepath = fullpath('.')
|
homepath = fullpath('.')
|
||||||
|
@ -81,32 +81,40 @@ if pathflag:
|
||||||
|
|
||||||
if buildflag:
|
if buildflag:
|
||||||
print("Downloading MS-CG ...")
|
print("Downloading MS-CG ...")
|
||||||
geturl(url,os.path.join(homepath,tarfile))
|
tarname = os.path.join(homepath,tarname)
|
||||||
|
geturl(url,tarname)
|
||||||
|
|
||||||
print("Unpacking MS-CG tarfile ...")
|
print("Unpacking MS-CG tarfile ...")
|
||||||
if os.path.exists("%s/%s" % (homepath,tardir)):
|
|
||||||
shutil.rmtree("%s/%s" % (homepath,tardir))
|
if os.path.exists(os.path.join(homepath,tardir)):
|
||||||
cmd = 'cd "%s"; tar -xzvf %s' % (homepath,tarfile)
|
shutil.rmtree(os.path.join(homepath,tardir))
|
||||||
subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
|
|
||||||
os.remove("%s/%s" % (homepath,tarfile))
|
if tarfile.is_tarfile(tarname):
|
||||||
|
tgz = tarfile.open(tarname)
|
||||||
|
tgz.extractall(path=homepath)
|
||||||
|
os.remove(tarname)
|
||||||
|
else:
|
||||||
|
sys.exit("File %s is not a supported archive",tarname)
|
||||||
|
|
||||||
if os.path.basename(homedir) != tardir:
|
if os.path.basename(homedir) != tardir:
|
||||||
if os.path.exists(homedir):
|
if os.path.exists(homedir):
|
||||||
shutil.rmtree(homedir)
|
shutil.rmtree(homedir)
|
||||||
os.rename("%s/%s" % (homepath,tardir),homedir)
|
os.rename(os.path.join(homepath,tardir),homedir)
|
||||||
|
|
||||||
# build MS-CG
|
# build MS-CG
|
||||||
|
|
||||||
if buildflag:
|
if buildflag:
|
||||||
print("Building MS-CG ...")
|
print("Building MS-CG ...")
|
||||||
if os.path.exists("%s/src/Make/Makefile.%s" % (homedir,msuffix)):
|
mkf="Makefile.%s" % msuffix
|
||||||
cmd = 'cd "%s/src"; cp Make/Makefile.%s .; make -f Makefile.%s' % \
|
mkp=os.path.join(homedir,'src','Make',mkf)
|
||||||
(homedir,msuffix,msuffix)
|
if os.path.exists(mkp):
|
||||||
|
shutil.copyfile(mkp,os.path.join(homedir,'src',mkf))
|
||||||
elif os.path.exists("Makefile.%s" % msuffix):
|
elif os.path.exists("Makefile.%s" % msuffix):
|
||||||
cmd = 'cd "%s/src"; cp ../../Makefile.%s .; make -f Makefile.%s' % \
|
shutil.copyfile("Makefile.%s" % msuffix,os.path.join(homedir,'src',mkf))
|
||||||
(homedir,msuffix,msuffix)
|
|
||||||
else:
|
else:
|
||||||
sys.exit("Cannot find Makefile.%s" % msuffix)
|
sys.exit("Cannot find Makefile.%s" % msuffix)
|
||||||
try:
|
try:
|
||||||
|
cmd = 'make -C %s -f Makefile.%s' % (os.path.join(homedir,'src'),msuffix)
|
||||||
txt = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
|
txt = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
|
||||||
print(txt.decode('UTF-8'))
|
print(txt.decode('UTF-8'))
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
|
|
Loading…
Reference in New Issue