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
|
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
|
|
|
|
|
|
|
specify one or more options, order does not matter
|
|
|
|
|
2017-08-09 05:00:09 +08:00
|
|
|
-b = download and unpack/configure the Eigen library
|
2017-07-29 02:03:29 +08:00
|
|
|
-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-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
|
|
|
"""
|
|
|
|
|
|
|
|
# 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-08-10 21:05:23 +08:00
|
|
|
def which(program):
|
|
|
|
def is_exe(fpath):
|
|
|
|
return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
|
|
|
|
|
|
|
|
fpath, fname = os.path.split(program)
|
|
|
|
if fpath:
|
|
|
|
if is_exe(program):
|
|
|
|
return program
|
|
|
|
else:
|
|
|
|
for path in os.environ["PATH"].split(os.pathsep):
|
|
|
|
path = path.strip('"')
|
|
|
|
exe_file = os.path.join(path, program)
|
|
|
|
if is_exe(exe_file):
|
|
|
|
return exe_file
|
|
|
|
|
|
|
|
return None
|
|
|
|
|
2017-08-09 05:00:09 +08:00
|
|
|
def geturl(url,fname):
|
2017-08-11 09:15:35 +08:00
|
|
|
success = False
|
|
|
|
|
2017-08-10 21:05:23 +08:00
|
|
|
if which('curl') != None:
|
|
|
|
cmd = 'curl -L -o "%s" %s' % (fname,url)
|
2017-08-11 09:15:35 +08:00
|
|
|
try:
|
|
|
|
subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
|
|
|
|
success = True
|
|
|
|
except subprocess.CalledProcessError as e:
|
|
|
|
print("Calling curl failed with: %s" % e.output.decode('UTF-8'))
|
|
|
|
|
|
|
|
if not success and which('wget') != None:
|
2017-08-10 21:05:23 +08:00
|
|
|
cmd = 'wget -O "%s" %s' % (fname,url)
|
2017-08-11 09:15:35 +08:00
|
|
|
try:
|
|
|
|
subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
|
|
|
|
success = True
|
|
|
|
except subprocess.CalledProcessError as e:
|
|
|
|
print("Calling wget failed with: %s" % e.output.decode('UTF-8'))
|
|
|
|
|
|
|
|
if not success:
|
|
|
|
error("Failed to download source code with 'curl' or 'wget'")
|
|
|
|
return
|
2017-08-09 05:00:09 +08:00
|
|
|
|
2017-05-05 01:22:20 +08:00
|
|
|
# parse args
|
|
|
|
|
|
|
|
args = sys.argv[1:]
|
|
|
|
nargs = len(args)
|
2017-08-09 05:00:09 +08:00
|
|
|
if nargs == 0: error()
|
2017-05-05 01:22:20 +08:00
|
|
|
|
|
|
|
homepath = "."
|
2017-07-29 02:03:29 +08:00
|
|
|
homedir = "eigen3"
|
2017-05-05 01:22:20 +08:00
|
|
|
|
2017-08-09 05:00:09 +08:00
|
|
|
buildflag = False
|
2017-07-29 02:03:29 +08:00
|
|
|
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
|
|
|
|
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
|
|
|
|
2017-08-09 05:00:09 +08:00
|
|
|
if (not buildflag and not pathflag):
|
|
|
|
error("Have to use either -b or -p flag")
|
|
|
|
|
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-08-08 19:20:33 +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)
|
2017-08-08 19:20:33 +08:00
|
|
|
cmd = 'ln -s "%s" includelink' % linkdir
|
2017-07-29 02:03:29 +08:00
|
|
|
subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
|