2017-09-20 06:27:25 +08:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
2019-01-29 06:37:05 +08:00
|
|
|
"""
|
|
|
|
Install.py tool to download, unpack, build, and link to the LATTE library
|
|
|
|
used to automate the steps described in the README file in this dir
|
|
|
|
"""
|
2017-09-20 06:27:25 +08:00
|
|
|
|
|
|
|
from __future__ import print_function
|
2019-01-29 06:37:05 +08:00
|
|
|
import sys, os, subprocess, shutil, tarfile
|
2019-01-15 05:54:44 +08:00
|
|
|
from argparse import ArgumentParser
|
|
|
|
|
2019-01-29 06:37:05 +08:00
|
|
|
sys.path.append('..')
|
|
|
|
from install_helpers import fullpath, geturl, checkmd5sum
|
|
|
|
|
2019-01-15 05:54:44 +08:00
|
|
|
parser = ArgumentParser(prog='Install.py',
|
|
|
|
description="LAMMPS library build wrapper script")
|
|
|
|
|
|
|
|
# settings
|
|
|
|
|
|
|
|
version = '1.2.1'
|
|
|
|
suffix = 'gfortran'
|
|
|
|
|
|
|
|
# known checksums for different LATTE versions. used to validate the download.
|
|
|
|
checksums = { \
|
|
|
|
'1.1.0' : '533635721ee222d0ed2925a18fb5b294', \
|
|
|
|
'1.2.0' : '68bf0db879da5e068a71281020239ae7', \
|
|
|
|
'1.2.1' : '85ac414fdada2d04619c8f936344df14', \
|
|
|
|
}
|
2017-09-20 06:27:25 +08:00
|
|
|
|
|
|
|
# help message
|
|
|
|
|
2019-01-29 06:37:05 +08:00
|
|
|
HELP = """
|
2017-09-20 06:27:25 +08:00
|
|
|
Syntax from src dir: make lib-latte args="-b"
|
2018-04-11 23:20:39 +08:00
|
|
|
or: make lib-latte args="-p /usr/local/latte"
|
|
|
|
or: make lib-latte args="-m gfortran"
|
2018-06-26 04:58:49 +08:00
|
|
|
or: make lib-latte args="-b -v 1.2.1"
|
2018-04-11 23:20:39 +08:00
|
|
|
|
2017-09-20 06:27:25 +08:00
|
|
|
Syntax from lib dir: python Install.py -b
|
2018-04-11 23:20:39 +08:00
|
|
|
or: python Install.py -p /usr/local/latte
|
|
|
|
or: python Install.py -m gfortran
|
2018-06-26 04:58:49 +08:00
|
|
|
or: python Install.py -v 1.2.1 -b
|
2017-09-20 06:27:25 +08:00
|
|
|
|
|
|
|
Example:
|
|
|
|
|
|
|
|
make lib-latte args="-b -m gfortran" # download/build in lib/latte
|
|
|
|
make lib-latte args="-p $HOME/latte" # use existing LATTE installation
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
2019-01-15 05:54:44 +08:00
|
|
|
pgroup = parser.add_mutually_exclusive_group()
|
|
|
|
pgroup.add_argument("-b", "--build", action="store_true",
|
2019-01-16 07:07:50 +08:00
|
|
|
help="download and build the LATTE library")
|
2019-01-15 05:54:44 +08:00
|
|
|
pgroup.add_argument("-p", "--path",
|
2019-01-16 07:07:50 +08:00
|
|
|
help="specify folder of existing LATTE installation")
|
2019-01-29 06:37:05 +08:00
|
|
|
parser.add_argument("-m", "--machine", choices=['gfortran', 'ifort', 'linalg', 'serial', 'mpi'],
|
2019-01-15 05:54:44 +08:00
|
|
|
help="suffix of a Makefile.lammps.* file used for linking LAMMPS with this library")
|
|
|
|
parser.add_argument("-v", "--version", default=version,
|
2019-01-16 07:07:50 +08:00
|
|
|
help="set version of LATTE to download and build (default: %s)" % version)
|
2017-09-20 06:27:25 +08:00
|
|
|
|
2019-01-15 05:54:44 +08:00
|
|
|
args = parser.parse_args()
|
2018-06-28 04:52:28 +08:00
|
|
|
|
2019-01-15 05:54:44 +08:00
|
|
|
# print help message and exit, if neither build nor path options are given
|
2019-01-29 06:37:05 +08:00
|
|
|
if not args.build and not args.path:
|
2019-01-15 05:54:44 +08:00
|
|
|
parser.print_help()
|
2019-01-29 06:37:05 +08:00
|
|
|
sys.exit(HELP)
|
2017-09-20 06:27:25 +08:00
|
|
|
|
2019-01-15 05:54:44 +08:00
|
|
|
homepath = fullpath(".")
|
|
|
|
|
|
|
|
buildflag = args.build
|
2019-01-29 06:37:05 +08:00
|
|
|
pathflag = args.path is not None
|
2019-01-15 05:54:44 +08:00
|
|
|
version = args.version
|
2019-01-29 06:37:05 +08:00
|
|
|
suffixflag = args.machine is not None
|
2019-01-15 05:54:44 +08:00
|
|
|
suffix = args.machine
|
2018-04-11 23:20:39 +08:00
|
|
|
|
2019-01-15 06:47:58 +08:00
|
|
|
if pathflag:
|
2019-01-15 05:54:44 +08:00
|
|
|
lattedir = args.path
|
2019-01-29 06:37:05 +08:00
|
|
|
if not os.path.isdir(lattedir):
|
|
|
|
sys.exit("LATTE path %s does not exist" % lattedir)
|
2019-01-15 05:54:44 +08:00
|
|
|
lattedir = fullpath(lattedir)
|
|
|
|
|
|
|
|
homedir = "LATTE-%s" % version
|
2017-09-20 06:27:25 +08:00
|
|
|
|
|
|
|
if buildflag:
|
2018-04-11 23:20:39 +08:00
|
|
|
url = "https://github.com/lanl/LATTE/archive/v%s.tar.gz" % version
|
2017-09-20 06:27:25 +08:00
|
|
|
lattepath = fullpath(homepath)
|
2019-01-29 06:37:05 +08:00
|
|
|
lattedir = os.path.join(lattepath, homedir)
|
2017-09-20 06:27:25 +08:00
|
|
|
|
|
|
|
# download and unpack LATTE tarball
|
|
|
|
|
|
|
|
if buildflag:
|
|
|
|
print("Downloading LATTE ...")
|
2019-01-29 06:37:05 +08:00
|
|
|
geturl(url, "LATTE.tar.gz")
|
2017-09-20 06:27:25 +08:00
|
|
|
|
2018-06-28 04:52:28 +08:00
|
|
|
# verify downloaded archive integrity via md5 checksum, if known.
|
|
|
|
if version in checksums:
|
2019-01-29 06:37:05 +08:00
|
|
|
if not checkmd5sum(checksums[version], 'LATTE.tar.gz'):
|
2019-01-15 05:54:44 +08:00
|
|
|
sys.exit("Checksum for LATTE library does not match")
|
2018-06-28 04:52:28 +08:00
|
|
|
|
2018-06-26 07:43:31 +08:00
|
|
|
print("Unpacking LATTE ...")
|
2017-09-20 06:27:25 +08:00
|
|
|
if os.path.exists(lattedir):
|
2018-11-29 09:46:50 +08:00
|
|
|
shutil.rmtree(lattedir)
|
2019-01-16 07:07:50 +08:00
|
|
|
if tarfile.is_tarfile('LATTE.tar.gz'):
|
|
|
|
tgz = tarfile.open('LATTE.tar.gz')
|
|
|
|
tgz.extractall()
|
|
|
|
os.remove('LATTE.tar.gz')
|
|
|
|
else:
|
|
|
|
sys.exit("File LATTE.tar.gz is not a supported archive")
|
|
|
|
|
|
|
|
# build LATTE
|
2017-09-20 06:27:25 +08:00
|
|
|
print("Building LATTE ...")
|
|
|
|
cmd = 'cd "%s"; make' % lattedir
|
2018-12-04 06:50:20 +08:00
|
|
|
try:
|
2019-01-29 06:37:05 +08:00
|
|
|
txt = subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True)
|
2018-12-04 06:50:20 +08:00
|
|
|
print(txt.decode('UTF-8'))
|
|
|
|
except subprocess.CalledProcessError as e:
|
2019-01-15 05:54:44 +08:00
|
|
|
sys.exit("Make failed with:\n %s" % e.output.decode('UTF-8'))
|
2017-09-20 06:27:25 +08:00
|
|
|
|
|
|
|
# create 3 links in lib/latte to LATTE dirs
|
2019-01-15 05:54:44 +08:00
|
|
|
|
|
|
|
print("Creating links to LATTE 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")
|
|
|
|
if os.path.isfile("filelink.o") or os.path.islink("filelink.o"):
|
|
|
|
os.remove("filelink.o")
|
2019-01-29 06:37:05 +08:00
|
|
|
os.symlink(os.path.join(lattedir, 'src'), 'includelink')
|
|
|
|
os.symlink(lattedir, 'liblink')
|
|
|
|
os.symlink(os.path.join(lattedir, 'src', 'latte_c_bind.o'), 'filelink.o')
|
2017-09-20 06:27:25 +08:00
|
|
|
|
|
|
|
# copy Makefile.lammps.suffix to Makefile.lammps
|
|
|
|
|
2019-01-15 05:54:44 +08:00
|
|
|
if suffixflag or not os.path.exists("Makefile.lammps"):
|
2019-01-29 06:37:05 +08:00
|
|
|
if suffix is None:
|
|
|
|
suffix = 'gfortran'
|
2017-09-20 06:27:25 +08:00
|
|
|
print("Creating Makefile.lammps")
|
|
|
|
if os.path.exists("Makefile.lammps.%s" % suffix):
|
2019-01-16 07:07:50 +08:00
|
|
|
shutil.copyfile("Makefile.lammps.%s" % suffix, 'Makefile.lammps')
|