2017-05-05 01:22:20 +08:00
|
|
|
#!/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
|
|
|
|
|
2017-07-19 05:37:48 +08:00
|
|
|
from __future__ import print_function
|
2018-11-29 09:46:50 +08:00
|
|
|
import sys,os,re,glob,subprocess,shutil
|
2018-12-04 06:50:20 +08:00
|
|
|
sys.path.append('..')
|
2019-01-15 02:55:22 +08:00
|
|
|
from install_helpers import fullpath,geturl
|
|
|
|
|
|
|
|
from argparse import ArgumentParser
|
|
|
|
|
|
|
|
parser = ArgumentParser(prog='Install.py',
|
|
|
|
description="LAMMPS library build wrapper script")
|
|
|
|
|
|
|
|
# settings
|
|
|
|
|
|
|
|
version = '3.3.4'
|
|
|
|
tarball = "eigen.tar.gz"
|
2017-05-05 01:22:20 +08:00
|
|
|
|
|
|
|
# help message
|
|
|
|
|
|
|
|
help = """
|
2017-08-09 05:00:09 +08:00
|
|
|
Syntax from src dir: make lib-smd args="-b"
|
2017-07-29 02:03:29 +08:00
|
|
|
or: make lib-smd args="-p /usr/include/eigen3"
|
|
|
|
|
2017-08-09 05:00:09 +08:00
|
|
|
Syntax from lib dir: python Install.py -b
|
2017-07-29 02:03:29 +08:00
|
|
|
or: python Install.py -p /usr/include/eigen3"
|
|
|
|
or: python Install.py -v 3.3.4 -b
|
2017-07-15 06:25:16 +08:00
|
|
|
|
|
|
|
Example:
|
|
|
|
|
2017-07-29 02:03:29 +08:00
|
|
|
make lib-smd args="-b" # download/build in default lib/smd/eigen-eigen-*
|
2017-08-09 05:00:09 +08:00
|
|
|
make lib-smd args="-p /usr/include/eigen3" # use existing Eigen installation in /usr/include/eigen3
|
2017-05-05 01:22:20 +08:00
|
|
|
"""
|
|
|
|
|
2019-01-15 02:55:22 +08:00
|
|
|
pgroup = parser.add_mutually_exclusive_group()
|
|
|
|
pgroup.add_argument("-b", "--build", action="store_true",
|
|
|
|
help="download and build the Eigen3 library")
|
|
|
|
pgroup.add_argument("-p", "--path",
|
|
|
|
help="specify folder of existing Eigen installation")
|
|
|
|
parser.add_argument("-v", "--version", default=version,
|
|
|
|
help="set version of Eigen to download and build (default: %s)" % version)
|
2017-05-05 01:22:20 +08:00
|
|
|
|
2019-01-15 02:55:22 +08:00
|
|
|
args = parser.parse_args()
|
2017-05-05 01:22:20 +08:00
|
|
|
|
2019-01-15 02:55:22 +08:00
|
|
|
# print help message and exit, if neither build nor path options are given
|
|
|
|
if args.build == False and not args.path:
|
|
|
|
parser.print_help()
|
|
|
|
sys.exit(help)
|
2017-05-05 01:22:20 +08:00
|
|
|
|
2019-01-15 02:55:22 +08:00
|
|
|
homepath = fullpath(".")
|
|
|
|
eigenpath = "%s/eigen3" % homepath
|
2017-05-05 01:22:20 +08:00
|
|
|
|
2019-01-15 02:55:22 +08:00
|
|
|
buildflag = args.build
|
|
|
|
pathflag = args.path != None
|
2017-07-29 02:03:29 +08:00
|
|
|
|
|
|
|
if (pathflag):
|
2019-01-15 02:55:22 +08:00
|
|
|
eigenpath = args.path
|
|
|
|
if not os.path.isdir(eigenpath): sys.exit("Eigen path %s does not exist" % eigenpath)
|
|
|
|
eigenpath = fullpath(eigenpath)
|
2017-08-09 05:00:09 +08:00
|
|
|
|
2017-05-05 01:22:20 +08:00
|
|
|
# download and unpack Eigen tarball
|
2017-07-29 02:03:29 +08:00
|
|
|
# use glob to find name of dir it unpacks to
|
2017-05-05 01:22:20 +08:00
|
|
|
|
2017-07-29 02:03:29 +08:00
|
|
|
if buildflag:
|
2017-07-19 05:37:48 +08:00
|
|
|
print("Downloading Eigen ...")
|
2017-07-29 02:03:29 +08:00
|
|
|
url = "http://bitbucket.org/eigen/eigen/get/%s.tar.gz" % version
|
2017-07-19 05:37:48 +08:00
|
|
|
geturl(url,"%s/%s" % (homepath,tarball))
|
2017-05-05 01:22:20 +08:00
|
|
|
|
2019-01-15 02:55:22 +08:00
|
|
|
print("Cleaning up old folders ...")
|
2017-05-05 01:22:20 +08:00
|
|
|
edir = glob.glob("%s/eigen-eigen-*" % homepath)
|
2019-01-15 02:55:22 +08:00
|
|
|
edir.append(eigenpath)
|
2017-05-05 01:22:20 +08:00
|
|
|
for one in edir:
|
2017-07-19 05:37:48 +08:00
|
|
|
if os.path.isdir(one):
|
2018-11-29 09:46:50 +08:00
|
|
|
shutil.rmtree(one)
|
2019-01-15 02:55:22 +08:00
|
|
|
|
|
|
|
print("Unpacking Eigen tarball ...")
|
2017-07-19 05:37:48 +08:00
|
|
|
cmd = 'cd "%s"; tar -xzvf %s' % (homepath,tarball)
|
2017-07-29 02:03:29 +08:00
|
|
|
subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
|
|
|
|
edir = glob.glob("%s/eigen-eigen-*" % homepath)
|
2019-01-15 02:55:22 +08:00
|
|
|
os.rename(edir[0],eigenpath)
|
2017-07-29 02:25:47 +08:00
|
|
|
os.remove(tarball)
|
2017-05-05 01:22:20 +08:00
|
|
|
|
|
|
|
# create link in lib/smd to Eigen src dir
|
|
|
|
|
2019-01-15 02:55:22 +08:00
|
|
|
print("Creating link to Eigen include folder")
|
|
|
|
if os.path.isfile("includelink") or os.path.islink("includelink"):
|
|
|
|
os.remove("includelink")
|
|
|
|
linkdir = eigenpath
|
|
|
|
cmd = 'ln -s "%s" includelink' % linkdir
|
|
|
|
subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
|