import os import subprocess import SCons #import glob import re import sys import glob from hdutil import * #=========================================================== # The original loadroot function here was replaced # with the one from SBMS. The orginal was renamed to # loadroot_old below. # # 3/18/2014 David L. #--------------------- # ROOT #--------------------- def loadroot(env): # # Here we use the root-config program to give us the compiler # and linker options needed for ROOT. We use the AddCompileFlags() # and AddLinkFlags() routines (defined below) to split the arguments # into the categories scons wants. E.g. scons wants to know the # search path and basenames for libraries rather than just giving it # the full compiler options like "-L/path/to/lib -lmylib". # # We also create a builder for ROOT dictionaries and add targets to # build dictionaries for any headers with "ClassDef" in them. ROOT_CFLAGS = subprocess.Popen(["root-config", "--cflags"], stdout=subprocess.PIPE).communicate()[0] ROOT_LINKFLAGS = subprocess.Popen(["root-config", "--glibs"], stdout=subprocess.PIPE).communicate()[0] AddCompileFlags(env, ROOT_CFLAGS) AddLinkFlags(env, ROOT_LINKFLAGS) env.AppendUnique(LIBS = "Geom") # Define (DY)LD_LIBRARY_PATH env. var. name LDLPV='LD_LIBRARY_PATH' if os.getenv('DYLD_LIBRARY_PATH', 'unset') != 'unset': LDLPV='DYLD_LIBRARY_PATH' # Create Builder that can convert .h file into _Dict.cc file rootsys = os.getenv('ROOTSYS', '/usr/local/root/PRO') env.AppendENVPath(LDLPV, '%s/lib' % rootsys ) if env['SHOWBUILD']==0: rootcintaction = SCons.Script.Action("%s/bin/rootcint -f $TARGET -c $SOURCE" % (rootsys), 'ROOTCINT [$SOURCE]') else: rootcintaction = SCons.Script.Action("%s/bin/rootcint -f $TARGET -c $SOURCE" % (rootsys)) bld = SCons.Script.Builder(action = rootcintaction, suffix='_Dict.cc', src_suffix='.h') env.Append(BUILDERS = {'ROOTDict' : bld}) if LDLPV=='LD_LIBRARY_PATH': env.Append(LD_LIBRARY_PATH = os.environ[LDLPV]) else: env.Append(DYLD_LIBRARY_PATH = os.environ[LDLPV]) # Generate ROOT dictionary file targets for each header # containing "ClassDef" # # n.b. It seems if scons is run when the build directory doesn't exist, # then the cwd is set to the source directory. Otherwise, it is the # build directory. Since the headers will only exist in the source # directory, we must temporarily cd into that to look for headers that # we wish to generate dictionaries for. (This took a long time to figure # out!) curpath = os.getcwd() srcpath = env.Dir('.').srcnode().abspath if(int(env['SHOWBUILD'])>1): print "---- Scanning for headers to generate ROOT dictionaries in: %s" % srcpath os.chdir(srcpath) for f in glob.glob('*.h*'): if 'ClassDef' in open(f).read(): env.AppendUnique(ALL_SOURCES = env.ROOTDict(f)) if(int(env['SHOWBUILD'])>1): print " ROOT dictionary for %s" % f os.chdir(curpath) #import SCons #import os #import re #import subprocess #from glob import glob def loadroot_old(env) : OSENV = os.environ if(OSENV.has_key('ROOTSYS') and os.path.exists(OSENV['ROOTSYS'])==True): rootDir = OSENV['ROOTSYS'] else: print "?ROOTSYS env variable not set...using -DNO_ROOTSYS" env.Append(CPPDEFINES = {'NO_ROOTSYS':None}) return if env['SHOWENV'] == "1": print "Loading ROOT software from ", rootDir # Create Builder that can convert .h file into _Dict.cc file # make sure include directories are properly passed to rootcint incl_dir ="" if( len(env['CPPPATH']) > 0 ): incl_dir = "-I" + " -I".join( env['CPPPATH'] ) if env['SHOWBUILD']==0: rootcintaction = SCons.Script.Action("%s/bin/rootcint -f $TARGET -c %s $SOURCE" % (rootDir, incl_dir), 'ROOTCINT [$SOURCE]') else: rootcintaction = SCons.Script.Action("%s/bin/rootcint -f $TARGET -c %s $SOURCE" % (rootDir, incl_dir)) bld = SCons.Script.Builder(action = rootcintaction, suffix='_Dict.cc', src_suffix='.h') env.Append(BUILDERS = {'ROOTDict' : bld}) # Generate ROOT dictionary file targets for each header # containing "ClassDef" # # n.b. It seems if scons is run when the build directory doesn't exist, # then the cwd is set to the source directory. Otherwise, it is the # build directory. Since the headers will only exist in the source # directory, we must temporarily cd into that to look for headers that # we wish to generate dictionaries for. (This took a long time to figure # out!) curpath = os.getcwd() srcpath = env.Dir('.').srcnode().abspath if(env['SHOWBUILD']!=0): print "---- Scanning for headers to generate ROOT dictionaries in: %s" % srcpath os.chdir(srcpath) for f in glob('*.h*'): if 'ClassDef' in open(f).read(): env.AppendUnique(ROOTCINT_SOURCES = env.ROOTDict(f)) if(env['SHOWBUILD']!=0): print " ROOT dictionary for %s" % f os.chdir(curpath) # include files rootincs = os.popen('$ROOTSYS/bin/root-config --incdir').readline().strip() env.AppendUnique(CPPPATH = rootincs) # library directories rootldir = os.popen('$ROOTSYS/bin/root-config --libdir').readline().strip() env.AppendUnique(LIBPATH = rootldir) # libs rootlinkflags = os.popen('$ROOTSYS/bin/root-config --noldflags --glibs').readline().strip().split() env.AppendUnique(LINKFLAGS = rootlinkflags) env.AppendUnique(LIBS = 'Geom') # returns list of header files in directory which has a root ClassDef macro in it def find_classdefs(directory): result = [] find_classdef_regex = re.compile(r'^\s*ClassDef\s*\(.*$') for fullname in glob(directory+'/*.h'): head,basename=os.path.split(fullname) for line in open(fullname,'r'): if find_classdef_regex.match(line): result.append(basename) break return result