[bed2ec]: configure Maximize Restore History

Download this file

configure    555 lines (433 with data), 20.3 kB

#!/usr/bin/env python

import os, sys

# ================================================================================

class Configuration(object):

    def __init__(self):
        self.topDir = os.path.join(os.getcwd(), "..")
        self.rootDir = None

        self.aidaDir = None
        self.aidaIncDir = None
        self.localAida = False
        self.localBoost = False

        self.boostDir = None
        self.boostIncDir = None
        self.boostLibDir = None

        self.zlibDir = None
        self.zlibIncDir = None
        self.zlibLibDir = None

        self.uuidDir = None
        self.uuidIncDir = None
        self.uuidLibDir = None
        
        self.expatDir = None
        self.expatIncDir = None
        self.expatLibDir = None
        
        self.graceDir = None
        self.graceIncDir = None
        self.graceLibDir = None
        
        self.cernDir = None
        self.cernLibDir = None
        self.cernIncDir = None

        self.prefix = "/usr/local"

        return

    # --------------------------------------------------------------------------------

    def setPrefix(self, pref):

        self.prefix = os.path.normpath(os.path.abspath(pref))
        print "prefix set to :", self.prefix
        return

    # --------------------------------------------------------------------------------

    def findAidaDir(self):

        # if user has set this, don't search
        if self.aidaDir :
            self.aidaIncDir = os.path.join(self.aidaDir)
            if not os.path.exists( os.path.join(self.aidaIncDir, "AIDA", "AIDA.h") ) :
                print "\n\nFATAL ERROR: Invalid AIDA directory! (no ADIA/AIDA.h in " + self.aidaIncDir+'\n'
                sys.exit(-1)
            return

        aidaVers = "3.2.1"
        if os.environ.has_key("AIDA_DIR"):
            self.aidaDir = os.environ["AIDA_DIR"]
            self.aidaIncDir = os.path.join(self.aidaDir, "src", "cpp")
            if os.path.exists( os.path.join(self.aidaIncDir, "AIDA", "AIDA.h") ) :
                return
    
        self.aidaDir = os.path.join(self.prefix)
        self.aidaIncDir = os.path.join(self.aidaDir, "AIDA", aidaVers, "share", "src", "cpp")
        if not os.path.exists( os.path.join(self.aidaIncDir, "AIDA", "AIDA.h") ) :
            self.aidaDir = None
            
        if not self.aidaDir:
            # print "AIDA installation not found, will use local one"
            os.system("mkdir -p include/AIDA")
            os.system("cp ext/AIDA/*.h include/AIDA/.")
            self.localAida = True
            
        return None

    # --------------------------------------------------------------------------------

    def findBoostDir(self):

        if self.localBoost : return

        # if user has set this, don't search
        if self.boostDir :
            self.boostDir = os.path.abspath(self.boostDir)
            self.boostIncDir = os.path.join(self.boostDir, "include")
            vDir = os.listdir(self.boostIncDir)[0]
            self.boostIncDir = os.path.join(self.boostIncDir, vDir)
            self.boostLibDir = os.path.join(self.boostDir, "lib")
            if not os.path.exists(os.path.join(self.boostIncDir, "boost", "shared_ptr.hpp") ) :
                print "\n\nFATAL ERROR: Invalid Boost directory! (no boost/shared_ptr.hpp in: "+self.boostIncDir+'\n'
                sys.exit(-1)
            return

        boostVers = "1_33_1"
        for path in [self.prefix, "/usr", "/usr/local"]:
            self.boostDir = os.path.abspath( os.path.join(path) )
            if path == self.prefix:
                self.boostDir = os.path.join("..", path)
            self.boostIncDir = os.path.join(self.boostDir, "include", "boost-"+boostVers)

            if not os.path.exists(os.path.join(self.boostIncDir, "boost", "shared_ptr.hpp") ) :
                self.boostIncDir = os.path.join(self.boostDir, "include")
                if not os.path.exists(os.path.join(self.boostIncDir, "boost", "shared_ptr.hpp") ) :
                    self.boostDir = None
                else:
                    break

        if not self.boostDir:
            # raise str("FATAL: Boost installation not found")
            self.localBoostDir = "include/Boost-1.33.1"
            if not os.path.exists( self.localBoostDir ) :
                os.makedirs(self.localBoostDir)
            if len( os.listdir(self.localBoostDir) ) > 0: return # already set up ...
            startDir = os.getcwd()
            os.chdir(self.localBoostDir)
            # print "in ", os.getcwd()
            os.system('tar zxf ../../ext/boost1331inc.tgz')
            os.chdir(startDir)
            self.localBoost = True
            # print "using local version of boost"
        else:
            self.boostLibDir = os.path.join(self.boostDir, "lib")

        return
        
    # --------------------------------------------------------------------------------

    def findExpatDir(self):

        # if user has set this, don't search
        if self.expatDir :
            self.expatDir = os.path.abspath( self.expatDir )
            self.expatIncDir = os.path.join(self.expatDir, "include")
            self.expatLibDir = os.path.join(self.expatDir, "lib")
            if not os.path.exists(os.path.join(self.expatIncDir, "expat.h") ) :
                print "\n\nFATAL ERROR: Invalid Expat directory! (no expat in: "+self.expatIncDir+'\n'
                sys.exit(-1)
            return

        expatVers = "1.95.8"
        pathList = [self.prefix, "/", "/usr", "/usr/local"]
        for path in pathList:
            self.expatDir = os.path.abspath( os.path.join(path) )
            if path == self.prefix:
                self.expatDir = os.path.join("..", path)
            self.expatIncDir = os.path.join(self.expatDir, "include")
            self.expatLibDir = os.path.join(self.expatDir, "lib")
            if not os.path.exists(os.path.join(self.expatIncDir, "expat.h") ) :
                self.expatDir = None
            else:
                break

        if not self.expatDir:
            print "\n\nFATAL ERROR: Expat installation not found in:", pathList, '\n'
            sys.exit(-1)
            
        # check if libexpat.so is available (only libexpat.so.0 is available
        # on x86_64 machines in 32 bit mode. Set a symlink for these in our
        # lib/ dir ...
        if not os.path.exists( os.path.join(self.expatLibDir, 'libexpat.so') ):
            expatLibName0 = os.path.normpath( os.path.join(self.expatLibDir, 'libexpat.so.0') )
            if not os.path.exists( expatLibName0 ) :
                print "\n\nFATAL ERROR: libexpat.so.0 not found in "+self.expatLibDir+'\n'
                sys.exit(-1)
            else:
                if not os.path.exists('lib'): os.makedirs('lib')
                os.system('cd lib ; rm -f libexpat.so; ln -s '+expatLibName0+ ' libexpat.so')
                self.expatLibDir = os.path.join( os.getcwd(), 'lib' )
                print "(symlink for libexpat set) ",
        return

    # --------------------------------------------------------------------------------

    def findOther(self):
        self.zlibDir = self.findDir("zlib", self.zlibDir, self.zlibIncDir, self.zlibLibDir )
        self.uuidDir = self.findDir("uuid", self.uuidDir, self.uuidIncDir, self.uuidLibDir )
        return
    
    # --------------------------------------------------------------------------------

    def findDir(self, pkg, topDir, incDir, libDir):

        # if user has set this, don't search
        if topDir :
            topDir = os.path.abspath( topDir )
            incDir = os.path.join(topDir, "include")
            if topDir == '/': incDir = '/usr/include'
            libDir = os.path.join(topDir, "lib")
            if ( not os.path.exists(os.path.join(incDir, pkg+".h") ) and
                 not os.path.exists(os.path.join(incDir, pkg, pkg+".h") ) ) :
                print "\n\nFATAL ERROR: Invalid "+pkg+" directory! (no "+pkg+".h in: "+incDir+'\n'
                sys.exit(-1)
            return topDir

        pathList = [self.prefix, "/", "/usr", "/usr/local"]
        for path in pathList:
            topDir = os.path.abspath( os.path.join(path) )
            if path == self.prefix:
                topDir = os.path.join("..", path)
            incDir = os.path.join(topDir, "include")
            if topDir == '/': incDir = '/usr/include'

            libDir = os.path.join(topDir, "lib")
            # print "checking for ", pkg, incDir
            if ( os.path.exists(os.path.join(incDir, pkg+".h") ) ) :
                break
            elif ( os.path.exists(os.path.join(incDir, pkg, pkg+".h") ) ) :
                break
            else:
                topDir = None

        if not topDir:
            print "\n\nFATAL ERROR: "+pkg+" installation not found in: ", pathList, '\n'
            sys.exit(-1)
        
        return topDir
        
    # --------------------------------------------------------------------------------

    def findGraceDir(self):

        # if user has set this, don't search
        if self.graceDir :
            self.graceDir = os.path.abspath( self.graceDir )
            self.graceIncDir = os.path.join(self.graceDir, "include")
            self.graceLibDir = os.path.join(self.graceDir, "lib")
            if not os.path.exists(os.path.join(self.graceIncDir, "grace_np.h") ) :
                print "\n\nFATAL ERROR: Invalid Grace directory! (no grace in: "+self.graceIncDir+'\n'
                sys.exit(-1)
            return

        graceVers = "5.1.14"
        for path in [self.prefix, "/usr", "/usr/local", "/usr/X11R6"]:
            self.graceDir = os.path.abspath( os.path.join(path) )
            self.graceIncDir = os.path.join(self.graceDir, "include")
            self.graceLibDir = os.path.join(self.graceDir, "lib")
            if not os.path.exists(os.path.join(self.graceIncDir, "grace_np.h") ) :
                self.graceDir = None
            else:
                break
            self.graceDir = os.path.join(path,"grace")
            self.graceIncDir = os.path.join(self.graceDir, "include")
            self.graceLibDir = os.path.join(self.graceDir, "lib")
            if not os.path.exists(os.path.join(self.graceIncDir, "grace_np.h") ) :
                self.graceDir = None
            else:
                break
            
        return
        
    # --------------------------------------------------------------------------------

    def findCernlibDir(self):

        # if user has set this, don't search
        if self.cernDir :
            self.cernDir = os.path.abspath( self.cernDir )
            self.cernIncDir = os.path.join(self.cernDir, "include")
            self.cernLibDir = os.path.join(self.cernDir, "lib")
            if not os.path.exists(os.path.join(self.cernIncDir, "hbook", "hcbook.inc") ) :
                print "\n\nFATAL ERROR: Invalid Cern directory! (no cern in: "+self.cernIncDir+'\n'
                sys.exit(-1)
            return

        for path in [self.prefix, "/usr", "/usr/local"]:
            self.cernDir = os.path.abspath( os.path.join(path) )
            if path == self.prefix:
                self.cernDir = os.path.join("..", path)
            self.cernIncDir = os.path.join(self.cernDir, "include")
            self.cernLibDir = os.path.join(self.cernDir, "lib")
            if not os.path.exists(os.path.join(self.cernIncDir, "hbook/hcbook.inc") ) :
                self.cernDir = None
            else:
                break

        return

    # --------------------------------------------------------------------------------

    def checkSetup(self):

        print "checking for AIDA  ",
        self.findAidaDir()
        if self.aidaDir:
            print "found in ", self.aidaDir
        else:
            print "not found, using local version."
        sys.stdout.flush()
        
        print "checking for Boost ",
        sys.stdout.flush()
        self.findBoostDir()
        if self.boostDir:
            print "found in ", self.boostDir
        else:
            print "not found, using local version."
        sys.stdout.flush()
        
        print "checking for Expat ",
        self.findExpatDir()
        print "found in ", self.expatDir
        sys.stdout.flush()

        #if os.uname()[0] == "CYGWIN_NT-5.1" :
        print "checking for zlib, uuid ",
        self.findOther()
        print "found zlib in", self.zlibDir,
        sys.stdout.flush()
        print ' uuid in', self.uuidDir
        sys.stdout.flush()
                
        print "checking for Grace ",
        self.findGraceDir()
        if self.graceDir:
            print "found in ", self.graceDir
        else:
            print "not found, will not build Plotter."
        sys.stdout.flush()

        print "checking for CENRLIB ",
        self.findCernlibDir()
        if self.cernDir:
            print "found in ", self.cernDir
        else:
            print "not found, will not use HBOOK."
        sys.stdout.flush()
        
        return

    # --------------------------------------------------------------------------------

    def checkLinkAndSet(self, src, link):
        if not os.path.exists(link) :
            os.symlink(src,link)

        return

    # --------------------------------------------------------------------------------
        
    def setupSymlinks(self):

        startDir = os.getcwd()
        os.chdir("include")

#         self.checkLinkAndSet("AIDA_Native", "AIDA_DataPointSet_native")
#         self.checkLinkAndSet("AIDA_Native", "AIDA_Fitter")
#         self.checkLinkAndSet("AIDA_Native", "AIDA_Function")
#         self.checkLinkAndSet("AIDA_Native", "AIDA_Histogram_native")
#         self.checkLinkAndSet("AIDA_Native", "AIDA_MemoryStore")
#         self.checkLinkAndSet("AIDA_Native", "AIDA_Tuple_native")
#         self.checkLinkAndSet("AIDA_Native", "DataXML")

        os.chdir("../src")
        if self.graceDir :
            self.checkLinkAndSet("AIDAGracePlotter", "GracePlotter")
        
        os.chdir(startDir)
        return

    # --------------------------------------------------------------------------------

    def chkPrg(self, prg):
        chk = os.popen('which '+prg+' 2>/dev/null')
        info = chk.readlines()
        chk.close()
        # print "checking for", prg, 'gave:',info
        return info != []

    # --------------------------------------------------------------------------------

    def prepareMakefiles(self):

        self.haveF77 = False
        if self.chkPrg("f77") or self.chkPrg("g77") :
            print "using g77/f77"
            self.haveF77 = True
        self.haveGfor = False
        if self.chkPrg("gfortran"):
            print "using gfortran"
            self.haveGfor = True

        self.prepareMakefile()

        subDirs = ['src', 'include', 'examples', 'tests']
        for dir in subDirs:
            os.chdir(dir)
            self.prepareMakefile()
            os.chdir("..")

        return

    # --------------------------------------------------------------------------------

    def prepareMakefile(self):

        print "preparing Makefile in ", os.getcwd()

        mfi = open("Makefile.in",'r')
        lines = mfi.readlines()
        mfi.close()

        mf = open("Makefile", 'w')
        for line in lines:
            lineOut = line

            lineOut = lineOut.replace("@PREFIX_DIR@" , os.path.abspath(self.prefix) )

            if self.aidaDir:
                lineOut = lineOut.replace("@AIDA_INC_DIR@" , self.aidaIncDir)
            else:
                lineOut = lineOut.replace("@AIDA_INC_DIR@" , "../include")
                
            if self.boostDir:
                lineOut = lineOut.replace("@BOOST_INC_DIR@", self.boostIncDir)
                lineOut = lineOut.replace("@BOOST_LIB_DIR@", self.boostLibDir)
            else:
                lineOut = lineOut.replace("@BOOST_INC_DIR@" , '../'+self.localBoostDir)
                lineOut = lineOut.replace("@BOOST_LIB_DIR@" , "../lib")

            #if os.uname()[0] == "CYGWIN_NT-5.1" :
            lineOut = lineOut.replace("@ZLIB_DIR@", self.zlibDir)
            lineOut = lineOut.replace("@UUID_DIR@", self.uuidDir)

            lineOut = lineOut.replace("@EXPAT_DIR@", self.expatDir)
            lineOut = lineOut.replace("@EXPAT_INC_DIR@", self.expatIncDir)
            lineOut = lineOut.replace("@EXPAT_LIB_DIR@", self.expatLibDir)
            if self.graceDir:
                lineOut = lineOut.replace("@HAVE_GRACE@"   , "1")
                lineOut = lineOut.replace("@GRACE_DIR@", self.graceDir)
                lineOut = lineOut.replace("@GRACE_INC_DIR@", self.graceIncDir)
                lineOut = lineOut.replace("@GRACE_LIB_DIR@", self.graceLibDir)
            else:
                lineOut = lineOut.replace("@HAVE_GRACE@"   , "")
                lineOut = lineOut.replace("@GRACE_DIR@", "")
                lineOut = lineOut.replace("@GRACE_INC_DIR@", "")
                lineOut = lineOut.replace("@GRACE_LIB_DIR@", "")

            if self.cernDir:
                lineOut = lineOut.replace("@HAVE_CERN@"   , "1")
                lineOut = lineOut.replace("@CERN_DIR@", self.cernDir)
                lineOut = lineOut.replace("@CERN_INC_DIR@", self.cernIncDir)
                lineOut = lineOut.replace("@CERN_LIB_DIR@", self.cernLibDir)
            else:
                lineOut = lineOut.replace("@HAVE_CERN@"   , "")
                lineOut = lineOut.replace("@CERN_DIR@", "")
                lineOut = lineOut.replace("@CERN_INC_DIR@", "")
                lineOut = lineOut.replace("@CERN_LIB_DIR@", "")

            if self.haveF77:
                lineOut = lineOut.replace("@HAVEF77@"   , "1")
            else:
                lineOut = lineOut.replace("@HAVEF77@"   , "")

            if self.haveGfor:
                lineOut = lineOut.replace("@HAVEGFOR@"  , "1")
            else:
                lineOut = lineOut.replace("@HAVEGFOR@"  , "")

                
            mf.write(lineOut)

        mf.close()
            
        return

# ================================================================================

def usage() :

    print "configure options:"
    print """
--prefix=<path/to/your/installation/area> (default: /usr/local/)
--with-boost=<your/path/to/boost>         (default: <prefix>)
--with-aida=<your/path/to/aida>           (default: <prefix>)
--with-expat=<your/path/to/expat>         (default: <prefix>)
--with-zlib=<your/path/to/zlib>           (default: <prefix>)
--with-uuid=<your/path/to/uuid>           (default: <prefix>)
--with-grace=<your/path/to/grace>         (default: <prefix>)
--with-cernlib=<your/path/to/CERNLIB>     (default: <prefix>)
    example: 
./configure --with-boost ~/work/install/boost-1.33.1/ --with-aida ~/work/install/AIDA/3.2.1
"""
    return

# ================================================================================

def main():

    import getopt

    try:
        opts, args = getopt.getopt(sys.argv[1:], "h",
                                   ["help", "prefix=",
                                    "with-aida=", "with-boost=", "with-expat=",
                                    "with-zlib=", "with-uuid=",
                                    "with-grace=", 'with-cernlib='])
    except getopt.GetoptError, e :
        # print help information and exit:
        print str(e)
        usage()
        sys.exit(2)

    config = Configuration()

    for o, a in opts:
        if o in ("-h", "--help"):
            usage()
            sys.exit()

        if o in ("--with-aida",):
            config.aidaDir = a

        if o in ("--with-boost",):
            config.boostDir = a

        if o in ("--with-expat",):
            config.expatDir = a

        if o in ("--with-zlib",):
            config.zlibDir = a

        if o in ("--with-uuid",):
            config.uuidDir = a

        if o in ("--with-grace",):
            config.graceDir = a

        if o in ("--with-cernlib",):
            config.cernDir = a
            
        if o in ("--prefix",):
            config.setPrefix(a)

    config.checkSetup()
    config.prepareMakefiles()
    config.setupSymlinks()

    return

# ================================================================================

if __name__ == "__main__" :
    main()