2010-08-25 06:57:11 -05:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
|
|
|
|
import re
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import string
|
|
|
|
import subprocess
|
2010-08-25 09:14:57 -05:00
|
|
|
import optparse
|
2010-08-25 06:57:11 -05:00
|
|
|
|
|
|
|
|
|
|
|
coriolisPattern = re.compile ( r".*coriolis.*" )
|
|
|
|
|
|
|
|
|
|
|
|
def stripPath ( pathName ):
|
|
|
|
pathEnv = os.getenv ( pathName )
|
|
|
|
if not pathEnv: return ""
|
|
|
|
|
|
|
|
pathList = string.split ( pathEnv, ':' )
|
|
|
|
strippedList = []
|
|
|
|
for pathElement in pathList:
|
|
|
|
if not coriolisPattern.match(pathElement):
|
|
|
|
strippedList += [ pathElement ]
|
|
|
|
|
|
|
|
if len(strippedList) == 0: return ""
|
|
|
|
|
|
|
|
strippedEnv = strippedList[0]
|
|
|
|
for pathElement in strippedList[1:]:
|
|
|
|
strippedEnv += ":" + pathElement
|
|
|
|
|
|
|
|
return strippedEnv
|
|
|
|
|
|
|
|
|
|
|
|
def guessOs ():
|
2011-02-02 04:40:25 -06:00
|
|
|
osSLSoC5x_64 = re.compile (".*Linux.*el5.*x86_64.*")
|
|
|
|
osSLSoC5x = re.compile (".*Linux.*(el5|2.6.23.13.*SoC).*")
|
|
|
|
osLinux_64 = re.compile (".*Linux.*x86_64.*")
|
|
|
|
osLinux = re.compile (".*Linux.*")
|
|
|
|
osDarwin = re.compile (".*Darwin.*")
|
|
|
|
osUbuntu1004 = re.compile (".*Linux.*ubuntu.*")
|
|
|
|
osUbuntu1004_64 = re.compile (".*Linux.*ubuntu.*x86_64.*")
|
2010-08-25 06:57:11 -05:00
|
|
|
|
|
|
|
uname = subprocess.Popen ( ["uname", "-srm"], stdout=subprocess.PIPE )
|
|
|
|
lines = uname.stdout.readlines()
|
|
|
|
|
2010-08-25 08:03:30 -05:00
|
|
|
libDir="lib"
|
|
|
|
if osSLSoC5x_64.match(lines[0]):
|
|
|
|
osType = "Linux.SLSoC5x_64"
|
|
|
|
libDir = "lib64"
|
2011-02-09 09:47:27 -06:00
|
|
|
elif osSLSoC5x.match(lines[0]):
|
|
|
|
osType = "Linux.SLSoC5x"
|
2011-02-02 04:40:25 -06:00
|
|
|
elif osUbuntu1004.match(lines[0]):
|
|
|
|
osType = "Linux.Ubuntu1004"
|
2011-02-09 09:47:27 -06:00
|
|
|
elif osUbuntu1004_64.match(lines[0]):
|
|
|
|
osType = "Linux.Ubuntu1004_64"
|
|
|
|
libDir = "lib64"
|
|
|
|
elif osLinux_64.match(lines[0]):
|
|
|
|
osType = "Linux.x86_64"
|
|
|
|
libDir = "lib64"
|
|
|
|
elif osLinux.match(lines[0]):
|
|
|
|
osType = "Linux.i386"
|
|
|
|
elif osDarwin.match(lines[0]):
|
|
|
|
osType = "Darwin"
|
2010-08-25 06:57:11 -05:00
|
|
|
else:
|
|
|
|
uname = subprocess.Popen ( ["uname", "-sr"], stdout=subprocess.PIPE )
|
|
|
|
osType = uname.stdout.readlines()[0][:-1]
|
|
|
|
|
|
|
|
#print "[WARNING] Unrecognized OS: \"%s\"." % lines[0][:-1]
|
|
|
|
#print " (using: \"%s\")" % osType
|
|
|
|
|
2010-08-25 08:03:30 -05:00
|
|
|
return (osType,libDir)
|
2010-08-25 06:57:11 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
2011-02-09 09:47:27 -06:00
|
|
|
(osType,libDir) = guessOs()
|
2011-01-09 16:55:51 -06:00
|
|
|
buildType = "Release"
|
2010-08-25 06:57:11 -05:00
|
|
|
linkType = "Shared"
|
|
|
|
coriolisVersion = None
|
2010-08-25 09:14:57 -05:00
|
|
|
rootDir = None
|
|
|
|
|
|
|
|
parser = optparse.OptionParser ()
|
|
|
|
# Build relateds.
|
2011-01-09 16:55:51 -06:00
|
|
|
parser.add_option ( "--v1" , action="store_true" , dest="v1" )
|
|
|
|
parser.add_option ( "--v2" , action="store_true" , dest="v2" )
|
|
|
|
parser.add_option ( "--release", action="store_true" , dest="release" )
|
|
|
|
parser.add_option ( "--debug" , action="store_true" , dest="debug" )
|
|
|
|
parser.add_option ( "--devel" , action="store_true" , dest="devel" )
|
|
|
|
parser.add_option ( "--static" , action="store_true" , dest="static" )
|
|
|
|
parser.add_option ( "--shared" , action="store_true" , dest="shared" )
|
|
|
|
parser.add_option ( "--python" , action="store_true" , dest="python" )
|
|
|
|
parser.add_option ( "--root" , action="store" , type="string", dest="rootDir" )
|
2010-08-25 09:14:57 -05:00
|
|
|
( options, args ) = parser.parse_args ()
|
|
|
|
|
2011-01-09 17:06:07 -06:00
|
|
|
if options.v1: coriolisVersion = 1
|
|
|
|
if options.v2: coriolisVersion = 2
|
|
|
|
if options.release: buildType = "Release"
|
|
|
|
if options.debug: buildType = "Debug"
|
|
|
|
if options.devel: buildType = "Debug"
|
|
|
|
if options.static: linkType = "Static"
|
|
|
|
if options.shared: linkType = "Shared"
|
|
|
|
if options.rootDir: rootDir = options.rootDir
|
2010-08-25 06:57:11 -05:00
|
|
|
|
|
|
|
strippedPath = stripPath ( "PATH" )
|
|
|
|
strippedLibraryPath = stripPath ( "LD_LIBRARY_PATH" )
|
|
|
|
strippedPythonPath = stripPath ( "PYTHONPATH" )
|
|
|
|
|
|
|
|
if coriolisVersion == 1:
|
|
|
|
|
2010-08-25 09:14:57 -05:00
|
|
|
if not rootDir:
|
|
|
|
rootDir = os.getenv("HOME") + "/coriolis-1.x"
|
|
|
|
|
2011-02-09 09:47:27 -06:00
|
|
|
hurricaneTop = "%s/coriolis/%s/install" % ( rootDir, osType )
|
2010-08-25 06:57:11 -05:00
|
|
|
buildDir = None
|
|
|
|
shellScript = \
|
|
|
|
"""
|
|
|
|
echo "Switching to Coriolis 1.x";
|
|
|
|
PATH=%(PATH)s;
|
|
|
|
LD_LIBRARY_PATH=%(LD_LIBRARY_PATH)s;
|
|
|
|
PYTHONPATH=%(PYTHONPATH)s;
|
|
|
|
HURRICANE_TOP=%(HURRICANE_TOP)s;
|
|
|
|
CORIOLIS_TOP=%(HURRICANE_TOP)s;
|
|
|
|
export PATH LD_LIBRARY_PATH PYTHONPATH HURRICANE_TOP CORIOLIS_TOP;
|
|
|
|
hash -r;
|
|
|
|
if [ -f "%(HURRICANE_TOP)s/share/etc/coriolis.sh" ]; then
|
|
|
|
. "%(HURRICANE_TOP)s/share/etc/coriolis.sh"
|
|
|
|
fi
|
|
|
|
"""
|
|
|
|
|
|
|
|
elif coriolisVersion == 2:
|
|
|
|
|
2011-02-09 10:40:49 -06:00
|
|
|
buildDir = buildType + "." + linkType
|
2011-02-09 09:47:27 -06:00
|
|
|
scriptDir = os.path.dirname ( os.path.abspath(__file__) )
|
2011-02-09 10:40:49 -06:00
|
|
|
print "echo %s;" % scriptDir
|
2011-02-09 09:47:27 -06:00
|
|
|
if scriptDir == "/etc/coriolis2":
|
|
|
|
coriolisTop = "/usr"
|
|
|
|
sysconfDir = scriptDir
|
|
|
|
shellMessage = "Using system-wide Coriolis 2 (/usr)"
|
2011-02-09 10:40:49 -06:00
|
|
|
elif scriptDir == "/asim/coriolis2/etc/coriolis2":
|
|
|
|
coriolisTop = "/asim/coriolis2"
|
|
|
|
sysconfDir = scriptDir
|
2011-02-09 09:47:27 -06:00
|
|
|
shellMessage = "Using SoC network-wide Coriolis 2 (/asim/coriolis2)"
|
2011-01-09 16:55:51 -06:00
|
|
|
else:
|
2011-01-09 17:06:07 -06:00
|
|
|
if not rootDir:
|
|
|
|
rootDir = os.getenv("HOME") + "/coriolis-2.x"
|
2011-02-09 09:47:27 -06:00
|
|
|
coriolisTop = "%s/%s/%s/install" % ( rootDir, osType, buildDir )
|
|
|
|
sysconfDir = coriolisTop + "/etc/coriolis2"
|
|
|
|
shellMessage = "Using user-selected Coriolis 2 (%s)" % rootDir
|
2011-01-09 16:55:51 -06:00
|
|
|
|
|
|
|
absLibDir = "%s/%s" % ( coriolisTop, libDir )
|
|
|
|
strippedPath = "%s/bin:%s" % ( coriolisTop, strippedPath )
|
2011-02-09 09:47:27 -06:00
|
|
|
strippedLibraryPath = "%s:%s" % ( absLibDir , strippedLibraryPath )
|
2010-12-13 08:00:40 -06:00
|
|
|
|
|
|
|
if options.python:
|
2011-02-02 04:40:25 -06:00
|
|
|
pyVersion = sys.version_info
|
|
|
|
version = "%d.%d" % (pyVersion[0],pyVersion[1])
|
|
|
|
if osType[8] == "Linux.SL":
|
|
|
|
sitePackagesDir = "%s/python%s/site-packages" % (absLibDir,version)
|
|
|
|
else:
|
|
|
|
sitePackagesDir = "%s/python%s/dist-packages" % (absLibDir,version)
|
|
|
|
|
2010-12-13 08:00:40 -06:00
|
|
|
strippedPythonPath = "%s:" % (sitePackagesDir) + strippedPythonPath
|
|
|
|
strippedPythonPath = "%s/cumulus:" % (sitePackagesDir) + strippedPythonPath
|
|
|
|
strippedPythonPath = "%s/stratus:" % (sitePackagesDir) + strippedPythonPath
|
2010-08-25 06:57:11 -05:00
|
|
|
|
|
|
|
shellScript = \
|
|
|
|
"""
|
2011-02-09 09:47:27 -06:00
|
|
|
echo "%(MESSAGE)s";
|
2010-08-25 06:57:11 -05:00
|
|
|
echo "Switching to Coriolis 2.x (%(buildDir)s)";
|
|
|
|
PATH=%(PATH)s;
|
|
|
|
LD_LIBRARY_PATH=%(LD_LIBRARY_PATH)s;
|
|
|
|
PYTHONPATH=%(PYTHONPATH)s;
|
2010-08-25 09:14:57 -05:00
|
|
|
BOOTSTRAP_TOP=%(BOOTSTRAP_TOP)s;
|
|
|
|
CORIOLIS_TOP=%(CORIOLIS_TOP)s;
|
2011-02-09 09:47:27 -06:00
|
|
|
STRATUS_MAPPING_NAME=%(SYSCONF_DIR)s/stratus2sxlib.xml;
|
2011-01-09 16:55:51 -06:00
|
|
|
export PATH LD_LIBRARY_PATH PYTHONPATH BOOTSTRAP_TOP CORIOLIS_TOP STRATUS_MAPPING_NAME;
|
2010-08-25 06:57:11 -05:00
|
|
|
hash -r
|
|
|
|
"""
|
|
|
|
|
|
|
|
if coriolisVersion:
|
|
|
|
print shellScript % { "PATH" : strippedPath
|
|
|
|
, "LD_LIBRARY_PATH" : strippedLibraryPath
|
|
|
|
, "PYTHONPATH" : strippedPythonPath
|
2010-08-25 09:14:57 -05:00
|
|
|
, "BOOTSTRAP_TOP" : coriolisTop
|
|
|
|
, "CORIOLIS_TOP" : coriolisTop
|
2011-02-09 09:47:27 -06:00
|
|
|
, "SYSCONF_DIR" : sysconfDir
|
|
|
|
, "MESSAGE" : shellMessage
|
2010-08-25 06:57:11 -05:00
|
|
|
, "buildDir" : buildDir
|
|
|
|
}
|