rootsys.py
Go to the documentation of this file.
1 import os
2 import os.path as osp
3 import waflib
4 import waflib.Utils
5 from waflib.Configure import conf
6 
7 _tooldir = osp.dirname(osp.abspath(__file__))
8 
9 
10 def options(opt):
11  opt = opt.add_option_group('ROOT Options')
12  opt.add_option('--with-root', default=None,
13  help="give ROOT installation location")
14  return
15 
16 @conf
17 def check_root(cfg, mandatory=False):
18  instdir = cfg.options.with_root
19 
20  if instdir and instdir.lower() in ['no','off','false']:
21  if mandatory:
22  raise RuntimeError("ROOT is mandatory but disabled via command line")
23  print ("optional ROOT dependency disabled by command line")
24  return
25 
26  cfg.env.CXXFLAGS += ['-fPIC']
27 
28  path_list = list()
29  for topdir in [getattr(cfg.options, 'with_root', None), os.getenv('ROOTSYS', None)]:
30  if topdir:
31  path_list.append(osp.join(topdir, "bin"))
32 
33  kwargs = dict(path_list=path_list)
34 
35  cfg.find_program('root-config', var='ROOT-CONFIG', mandatory=mandatory, **kwargs)
36  if not 'ROOT-CONFIG' in cfg.env:
37  if mandatory:
38  raise RuntimeError("root-config not found but ROOT required")
39  print ("skipping non mandatory ROOT, use --with-root to force")
40  return
41 
42  cfg.check_cfg(path=cfg.env['ROOT-CONFIG'], uselib_store='ROOTSYS',
43  args = '--cflags --libs --ldflags', package='', mandatory=mandatory)
44  cfg.env.LIB_ROOTSYS += ['Minuit2','TreePlayer', 'EG']
45 
46  cfg.find_program('rootcling', var='ROOTCLING', path_list=path_list, mandatory=mandatory)
47  # cfg.find_program('rootcint', var='ROOTCINT', path_list=path_list, mandatory=mandatory)
48  # cfg.find_program('rlibmap', var='RLIBMAP', path_list=path_list, mandatory=False)
49 
50  cfg.check_cxx(header_name="Rtypes.h", use='ROOTSYS',
51  mandatory=mandatory)
52 
53 
54  return
55 
56 def configure(cfg):
57  cfg.check_root()
58 
59 @conf
60 def gen_rootcling_dict(bld, name, linkdef, headers = '', includes = '', use=''):
61  '''
62  rootcling -f NAMEDict.cxx -rml libNAME.so -rmf libNAME.rootmap myHeader1.h myHeader2.h ... LinkDef.h
63  '''
64  use = waflib.Utils.to_list(use) + ['ROOTSYS']
65  includes = waflib.Utils.to_list(includes)
66  for u in use:
67  more = bld.env['INCLUDES_'+u]
68  #print 'USE(%s)=%s: %s' % (name, u, more)
69  includes += more
70 
71  # make into -I...
72  incs = list()
73  for inc in includes:
74  if inc.startswith('/'):
75  newinc = '-I%s' % inc
76  else:
77  newinc = '-I%s' % bld.path.find_dir(inc).abspath()
78  if not newinc in incs:
79  incs.append(newinc)
80  incs = ' '.join(incs)
81  #print 'INCS(%s): %s' % (name, str(incs))
82 
83  dict_src = name + 'Dict.cxx'
84  # dict_lib = 'lib' + name + 'Dict.so' # what for Mac OS X?
85  # dict_map = 'lib' + name + 'Dict.rootmap'
86  # dict_pcm = name + 'Dict_rdict.pcm'
87  dict_lib = 'lib' + name + '.so' # what for Mac OS X?
88  dict_map = 'lib' + name + '.rootmap'
89  dict_pcm = name + 'Dict_rdict.pcm'
90 
91  if type(linkdef) == type(""):
92  linkdef = bld.path.find_resource(linkdef)
93  source_nodes = headers + [linkdef]
94  sources = ' '.join([x.abspath() for x in source_nodes])
95  rule = '${ROOTCLING} -f ${TGT[0].abspath()} -rml %s -rmf ${TGT[1].abspath()} %s %s' % (dict_lib, incs, sources)
96  #print 'RULE:',rule
97  bld(source = source_nodes,
98  target = [dict_src, dict_map, dict_pcm],
99  rule=rule, use = use)
100 
101  # bld.shlib(source = dict_src,
102  # target = name+'Dict',
103  # includes = includes,
104  # use = use + [name])
105 
106  bld.install_files('${PREFIX}/lib/', dict_map)
107  bld.install_files('${PREFIX}/lib/', dict_pcm)
108 
109 
110 @conf
111 def gen_rootcint_dict(bld, name, linkdef, headers = '', includes=''):
112  '''Generate a rootcint dictionary, compile it to a shared lib,
113  produce its rootmap file and install it all.
114  '''
115  headers = waflib.Utils.to_list(headers)
116  incs = ['-I%s' % bld.path.find_dir(x).abspath() for x in waflib.Utils.to_list(includes)]
117  incs = ' '.join(incs)
118 
119  dict_src = name + 'Dict.cxx'
120 
121  bld(source = headers + [linkdef],
122  target = dict_src,
123  rule='${ROOTCINT} -f ${TGT} -c %s ${SRC}' % incs)
124 
125  bld.shlib(source = dict_src,
126  target = name+'Dict',
127  includes = includes,
128  use = 'ROOTSYS')
129 
130  rootmap = 'lib%sDict.rootmap'%name
131  bld(source = [linkdef], target=rootmap,
132  rule='${RLIBMAP} -o ${TGT} -l lib%sDict.so -d lib%s.so -c ${SRC}' % (name, name))
133 
134  bld.install_files('${PREFIX}/lib/', rootmap)
135 
def options(opt)
Definition: rootsys.py:10
def check_root(cfg, mandatory=False)
Definition: rootsys.py:17
def gen_rootcint_dict(bld, name, linkdef, headers='', includes='')
Definition: rootsys.py:111
Proc * join(Pipeline &pipeline, Proc *src, Proc *dst)
Definition: GenPipeline.h:218
def configure(cfg)
Definition: rootsys.py:56
def gen_rootcling_dict(bld, name, linkdef, headers='', includes='', use='')
Definition: rootsys.py:60