##################################################
#
# RAIDA module
#
##################################################

# custom imports
from baseilc import BaseILC
from util import *


class RAIDA(BaseILC):
    """ Responsible for the RAIDA software installation process. """
    
    def __init__(self, userInput):
        BaseILC.__init__(self, userInput, "RAIDA", "RAIDA")

        self.reqfiles = [ ["bin/aida-config"], ["lib/libRAIDA.a", "lib/libRAIDA.so", "lib/libRAIDA.dylib"] ]

        # ROOT is required for building RAIDA
        self.reqmodules = [ "ROOT" ]

        self.download.supportedTypes = [ "GitHub" ] 
        self.download.gituser = 'iLCSoft'
        self.download.gitrepo = 'RAIDA'


    def compile(self):
        os.chdir( self.installPath + "/build")

        if( self.rebuild ):
            tryunlink( "CMakeCache.txt" )

        # build software
        if( os.system( self.genCMakeCmd() + " 2>&1 | tee -a " + self.logfile ) != 0 ):
            self.abort( "failed to configure!!" )

        if( os.system( "make ${MAKEOPTS} 2>&1 | tee -a " + self.logfile ) != 0 ):
            self.abort( "failed to compile!!" )

        if( os.system( "make install 2>&1 | tee -a " + self.logfile ) != 0 ):
            self.abort( "failed to install!!" )

        
    def postCheckDeps(self):
        BaseILC.postCheckDeps(self)

        self.env["RAIDA_HOME"] = self.installPath
        if self.installPath != "/usr":
            self.envpath["PATH"].append( "$RAIDA_HOME/bin" )

