import os import glob # Useful constants try: RATROOT=os.environ["RATROOT"] except KeyError: RATROOT="" RATCONFIGDIR = os.path.join(RATROOT,"config") RATENVFILE = os.path.join(RATCONFIGDIR, "RAT.scons") PSQLENVFILE = os.path.join(RATCONFIGDIR,"PSQL.scons") try: ROOTSYS = os.path.join(os.environ["ROOTSYS"], 'bin') except KeyError: ROOTSYS="" ROOTARCH = os.popen(os.path.join(ROOTSYS, 'root-config') + ' --arch').read().strip() def testenv(envname): 'Test for the presence of an environment var and if it set to 1.' return os.environ.has_key(envname) and os.environ[envname] == '1' # Construct a list of build targets def build_list(srcpath, build_dir, exclude=[]): ss = [os.path.basename(item) for item in glob.glob(srcpath)] l = [] for item in ss: if item not in exclude: l += [ os.path.join(build_dir, item) ] #l = [os.path.join(build_dir, os.path.basename(item)) for item in glob.glob(srcpath)] # Add Version.cc manually since this is called before the scons target is built if build_dir.split(os.sep)[-1] == 'core': l.append(os.path.join(build_dir, 'Version.cc')) return l # Create targets from a source directory, and add headers to the build list. def src_module(env, module_name, header_subdir="", exclude=[]): modbuilddir = os.path.join(env['BUILDDIR'], module_name) srcdir = os.path.join('src', module_name) env.VariantDir(modbuilddir, srcdir, duplicate=0) # 09-Aug-2006 WGS: Add a "builder" for the headers so that only # those headers that are needed or revised are copied. headers = glob.glob(srcdir+'/*.hh') + glob.glob(srcdir+'/*.hpp') + \ glob.glob(srcdir+'/*.tpp') + glob.glob(srcdir+'/*.icc') + \ glob.glob(srcdir+'/*.h') env['INCLUDE_SUBDIR'] = header_subdir for h in headers: env.Append(RATHEADERS=env.RATHeader(h)) return env.Object(build_list(os.path.join(srcdir,'*.cc'), modbuilddir, exclude=exclude)) def src_psql(env): assert env.has_key('PSQLSRCDIR') assert env.has_key('PSQLDEFINES') assert env.has_key('PSQLMODBUILDIR') assert env.has_key('PSQLINCSUBDIRS') srcdir=env['PSQLSRCDIR'] srclist = glob.glob(os.path.join(srcdir,'*.c')) local_defines= env['PSQLDEFINES'] if not local_defines.has_key('USE_REPL_SNPRINTF'): for entry in srclist: if os.path.basename(entry) == 'snprintf.c': srclist.remove(entry) if local_defines.has_key('HAVE_GETPEEREID'): for entry in srclist: if os.path.basename(entry) == 'getpeereid.c': srclist.remove(entry) # If this define exists, remove the source from the list if local_defines.has_key('HAVE_DECL_STRLCPY'): for entry in srclist: if os.path.basename(entry) == 'strlcpy.c': srclist.remove(entry) # If this define exists, remove the source from the list if local_defines.has_key('HAVE_DECL_STRLCAT'): for entry in srclist: if os.path.basename(entry) == 'strlcat.c': srclist.remove(entry) env.VariantDir(env['PSQLMODBUILDIR'], srcdir, duplicate=0) headers = glob.glob(srcdir+'/include/*.h') for sdir in env['PSQLINCSUBDIRS']: headers += glob.glob(srcdir+'/include/' + sdir + '/*.h') # Now attach the ta proper for h in headers: env.Append(PSQLHEADERS=env.PSQL_header(h)) return env.Object([os.path.join(env['PSQLMODBUILDIR'],os.path.basename(item)) for item in srclist]) def find_python_locations(): headers,libs = None,None arch = '' version = 2.7 try: from distutils import sysconfig; headers = sysconfig.get_python_inc() libs = sysconfig.get_config_var("LIBDIR") #libs = sysconfig.get_config_var('LIBPL') arch = sysconfig.get_config_var('MULTIARCH') version = sysconfig.get_python_version() except: pass return headers,libs,arch,version