#!/usr/bin/env python from __future__ import print_function from util.aafabricate import * import glob #import setup as sup d1 = dir() def env( key ) : try : return os.environ[key] except : return None print("in make.py") aadir = env('AADIR') km3netformatdir = env('KM3NET_DATAFORMAT_DIR') if not aadir : print("Please run 'source setenv.sh' first, to set the AAnet environment.") raise SystemExit build_dir = "." lib_dir = aadir+"/lib/" aa3dwww = os.environ['HOME']+"/www/aa3d/" cc = "g++" gccopt = "-fPIC -Wall -g -O3 -std=c++11 " root_config = os.environ['ROOTSYS'] + '/bin/root-config' inckm3fmt = "-I/home/anders/" #= "-I" + km3netformatdir incroot = shell(root_config,'--cflags') libroot = shell(root_config,'--libs') +' -lEG -lPyROOT' rootcintopt = "-std=c++11 -I"+shell(root_config,'--incdir') fortran_comp= 'gfortran -fPIC -fno-second-underscore ' libfortran = " -lgfortran " dirjpp = env('JPP_DIR') or aadir+'/jpp' libjpp = "-L"+dirjpp + "/out/Linux/lib/ -Wl,--unresolved-symbols=ignore-all -ltriggerROOT -llang -levtROOT -L/pbs/home/h/heijboer/sps/aanet_df/lib " incjpp = "-I" + dirjpp + "/software/ -I"+dirjpp+"/externals/antares-daq/include/" haveantcc = os.path.exists( dirjpp+"/externals/antares-daq/include/antcc") incaa = "-I" + aadir + "/evt -I"+aadir+"/astro -I" + aadir +" -I"+aadir+"/km3net-dataformat/offline " +"-I"+aadir+"/km3net-dataformat/online" libaa = aadir + "/km3net-dataformat/lib/libKM3NeTROOT.so " + aadir + "/lib//aasearch.so " + aadir + "/lib//libaaevt.so " + aadir + "/lib//libaastro.so " + libfortran # --------------------------------- # Check jpp and antcc # --------------------------------- if os.path.exists( dirjpp ) : gccopt += " -D HAVEJPP " rootcintopt += " -DHAVEJPP " if not dirjpp in env("LD_LIBRARY_PATH"): print ("note: JPP lib dir not in LD_LIBRARY_PATH -> using full-path linking") w = " -Wl,-rpath,"+dirjpp+"/out/Linux/lib " #$v = [x.replace("-l",dirjpp+"/out/Linux/lib/lib")+".so" for x in libjpp.split()[1:] ] #print (v) libjpp = w + libjpp else : print ("NOTE: will build without JPP") libjpp = incjpp = dirjpp = "" if haveantcc : gccopt += " -D HAVEANTCC " rootcintopt += "-DHAVEANTCC " libjpp += dirjpp + "/externals/antares-daq/out/Linux/lib/libantccROOT.so " # ================================================= # default functions to compile, build, etc # ================================================= def base( s ): return s.rsplit('.',1)[0].rsplit("/")[-1] def write_dictionary( source_file ) : "call rootcint on a source file. If the source file is a .cc, the dictonary uses the .hh" dict_cc_file = build_dir+"/"+base(source_file)+'.dict.cc' linkdef = base(source_file)+'.linkdef.h' source_file = source_file.replace(".cc",".hh") run('rootcint -f {dict_cc_file} {rootcintopt} {inckm3fmt} {incaa} {incjpp} {source_file} {linkdef}') return dict_cc_file def compile( source_file ) : #obj = build_dir+"/"+base(source_file)+'.o' obj = base(source_file) # tell gcc we really want to build an obj file, even if it's a .hh xopt = "-x c++" if source_file.endswith("h") else "" run('{cc} {gccopt} -c -o {obj} -I. {incaa} {inckm3fmt} {incroot} {incjpp} {xopt} {source_file} ') print(cc, gccopt, " -c -o ",obj, " -I. ",incaa,inckm3fmt,incroot,incjpp,xopt,source_file) return obj def compile_fortran( source_file ): obj = source_file.replace(".f",".o") run('{fortran_comp} -c -o {obj} {source_file} ') return obj def make_library( object_files, target , extra_link_args = "" ): objs = " ".join( object_files ) res = run('{cc} {gccopt} -shared {objs} {libroot} {libjpp} {extra_link_args} -o {target} ') return res def make_executable( source_file, target = 'auto', extra_args = '' ): if target == 'auto' : target = source_file.replace(".cc","") res = run('{cc} -Wl,--no-as-needed {gccopt} {inckm3fmt} {incaa} {incroot} {incjpp} {libroot} {libjpp} {libaa} {extra_args} -o {target} {source_file} ') def default_build_shared_library( sources, target, extra_link_args = "" ): #with subjob("generating root dictionaries") : # dict_files = [ write_dictionary( s ) for s in sources ] with subjob("compiling c++ files"): #obj_files = [ compile( s ) for s in sources + dict_files ] #obj_files = [ compile( s ) for s in sources ] obj_files = [ make_executable( s ) for s in sources ] #with subjob("linking and copying pcm files"): # make_library( obj_files , target , extra_link_args ) # pcm_files = " ".join( s.replace('.cc' , '_rdict.pcm' ) for s in dict_files ) # run("cp {pcm_files} {lib_dir}") subjobs_report() # ------------------------------------------------- # Parameters that control the build process # ------------------------------------------------- dependency_dirs = [ '.', aadir ] parallel_jobs = 4 build_debug = True # ------------------------------------------------- # Nice output # ------------------------------------------------- D = locals() setup_s = "\n".join( [ "%15s : %s " % (k, D[k]) for k in dir() if k not in d1 and k != 'd1' \ and not k.startswith("__") ] ) def print_setup(): print ("========================================================================") print (setup_s) print ("========================================================================") #if __name__ == "__main__" : # print_setup() # --------------------------------------------------------------------------------------------- def clean(): autoclean() def build(): sources = glob.glob("*.cc") return default_build_shared_library( sources, target = aadir+"/lib/aasearch.so" ) status = main() if status : print ("exit status = ", status)