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
|
|
|
|
import sys,os,re,glob,subprocess
|
|
|
|
try: from urllib.request import urlretrieve as geturl
|
|
|
|
except: from urllib import urlretrieve as geturl
|
2017-05-05 01:22:20 +08:00
|
|
|
|
|
|
|
# help message
|
|
|
|
|
|
|
|
help = """
|
2017-07-29 02:03:29 +08:00
|
|
|
Syntax from src dir: make lib-smd
|
|
|
|
or: make lib-smd args="-p /usr/include/eigen3"
|
|
|
|
|
|
|
|
Syntax from lib dir: python Install.py
|
|
|
|
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
|
|
|
|
|
|
|
specify one or more options, order does not matter
|
|
|
|
|
2017-07-29 02:03:29 +08:00
|
|
|
-b = download and unpack/configure the Eigen library (default)
|
|
|
|
-p = specify folder holding an existing installation of Eigen
|
|
|
|
-v = set version of Eigen library to download and set up (default = 3.3.4)
|
|
|
|
|
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-05-05 01:22:20 +08:00
|
|
|
"""
|
|
|
|
|
|
|
|
# settings
|
|
|
|
|
2017-07-19 05:37:48 +08:00
|
|
|
version = '3.3.4'
|
2017-05-05 01:22:20 +08:00
|
|
|
tarball = "eigen.tar.gz"
|
|
|
|
|
|
|
|
# print error message or help
|
|
|
|
|
|
|
|
def error(str=None):
|
2017-07-19 05:37:48 +08:00
|
|
|
if not str: print(help)
|
|
|
|
else: print("ERROR",str)
|
2017-05-05 01:22:20 +08:00
|
|
|
sys.exit()
|
|
|
|
|
|
|
|
# expand to full path name
|
|
|
|
# process leading '~' or relative path
|
2017-07-29 02:03:29 +08:00
|
|
|
|
2017-05-05 01:22:20 +08:00
|
|
|
def fullpath(path):
|
|
|
|
return os.path.abspath(os.path.expanduser(path))
|
2017-07-29 02:03:29 +08:00
|
|
|
|
2017-05-05 01:22:20 +08:00
|
|
|
# parse args
|
|
|
|
|
|
|
|
args = sys.argv[1:]
|
|
|
|
nargs = len(args)
|
|
|
|
|
|
|
|
homepath = "."
|
2017-07-29 02:03:29 +08:00
|
|
|
homedir = "eigen3"
|
2017-05-05 01:22:20 +08:00
|
|
|
|
2017-07-29 02:03:29 +08:00
|
|
|
grabflag = True
|
|
|
|
buildflag = True
|
|
|
|
pathflag = False
|
|
|
|
linkflag = True
|
2017-05-05 01:22:20 +08:00
|
|
|
|
|
|
|
iarg = 0
|
|
|
|
while iarg < nargs:
|
2017-07-29 02:03:29 +08:00
|
|
|
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
|
2017-05-05 01:22:20 +08:00
|
|
|
iarg += 1
|
|
|
|
else: error()
|
|
|
|
|
|
|
|
homepath = fullpath(homepath)
|
2017-07-29 02:03:29 +08:00
|
|
|
|
|
|
|
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")
|
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
|
|
|
|
2017-07-19 05:37:48 +08:00
|
|
|
print("Unpacking Eigen tarball ...")
|
2017-05-05 01:22:20 +08:00
|
|
|
edir = glob.glob("%s/eigen-eigen-*" % homepath)
|
|
|
|
for one in edir:
|
2017-07-19 05:37:48 +08:00
|
|
|
if os.path.isdir(one):
|
2017-07-29 02:03:29 +08:00
|
|
|
subprocess.check_output("rm -rf %s" % one,stderr=subprocess.STDOUT,shell=True)
|
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)
|
|
|
|
os.rename(edir[0],"%s/%s" % (homepath,homedir))
|
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
|
|
|
|
|
|
|
|
if linkflag:
|
2017-07-19 05:37:48 +08:00
|
|
|
print("Creating link to Eigen files")
|
2017-05-05 01:22:20 +08:00
|
|
|
if os.path.isfile("includelink") or os.path.islink("includelink"):
|
|
|
|
os.remove("includelink")
|
2017-07-29 02:03:29 +08:00
|
|
|
if pathflag: linkdir = eigenpath
|
2017-05-05 01:22:20 +08:00
|
|
|
else: linkdir = "%s/%s" % (homepath,homedir)
|
|
|
|
cmd = "ln -s %s includelink" % linkdir
|
2017-07-29 02:03:29 +08:00
|
|
|
subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
|