<commit_before># -*- python -*-

# stdlib imports ---
import os
import os.path as osp

# waf imports ---
import waflib.Utils
import waflib.Logs as msg
import waflib.Configure
import waflib.Build
import waflib.Task
import waflib.Tools.ccroot
from waflib.Configure import conf
from waflib.TaskGen import feature, before_method, after_method, extension, after

#
_heptooldir = osp.dirname(osp.abspath(__file__))

def options(ctx):

    ctx.load('hwaf-base', tooldir=_heptooldir)
    ctx.load('find_libxml2',      tooldir=_heptooldir)
    ctx.load('find_python',       tooldir=_heptooldir)
    ctx.load('find_gccxml', tooldir=_heptooldir)

    ctx.add_option(
        '--with-root',
        default=None,
        help="Look for CERN ROOT System at the given path")
    return

def configure(ctx):
    ctx.load('hwaf-base', tooldir=_heptooldir)
    return

@conf
def find_root(ctx, **kwargs):
    
    ctx.load('hwaf-base', tooldir=_heptooldir)
    ctx.load('find_python', tooldir=_heptooldir)
    ctx.load('find_libxml2', tooldir=_heptooldir)
    ctx.load('find_gccxml', tooldir=_heptooldir)

    if not ctx.env.HWAF_FOUND_C_COMPILER:
        ctx.fatal('load a C compiler first')
        pass

    if not ctx.env.HWAF_FOUND_CXX_COMPILER:
        ctx.fatal('load a C++ compiler first')
        pass

    if not ctx.env.HWAF_FOUND_PYTHON:
        ctx.find_python(version=kwargs.get('python_version', (2,6)))
    
    if not ctx.env.HWAF_FOUND_LIBXML2:
        ctx.find_libxml2(mandatory=False)
    
    if not ctx.env.PYTHON:
        ctx.fatal('load a python interpreter first')
        pass

    # find root
    root_cfg = "root-config"
    path_list = waflib.Utils.to_list(kwargs.get('path_list', []))
    for topdir in [getattr(ctx.options, 'with_root', None), os.getenv('ROOTSYS', None)]:
        if topdir:
            topdir = ctx.hwaf_subst_vars(topdir)
            path_list.append(
                osp.join(topdir, "bin")
                )
            pass
        pass
    kwargs['path_list']=path_list

    
    ctx.find_program(
        root_cfg, 
        var='ROOT-CONFIG',
        **kwargs)
    root_cfg = ctx.env['ROOT-CONFIG']

    ctx.check_with(
        ctx.check_cfg,
        "root",
        path=root_cfg,
        package="",
        uselib_store="ROOT",
        args='--libs --cflags --ldflags',
        **kwargs)

    ctx.find_program('genmap',      var='GENMAP',     **kwargs)
    ctx.find_program('genreflex',   var='GENREFLEX',  **kwargs)
    ctx.find_program('root',        var='ROOT-EXE',   **kwargs)
    ctx.find_program('rootcint',    var='ROOTCINT',   **kwargs)
    ctx.find_program('rlibmap',     var='RLIBMAP',     **kwargs)

    # reflex...
    ctx.copy_uselib_defs(dst='Reflex', src='ROOT')
    ctx.env['LIB_Reflex'] = ['Reflex']
    
    # cintex...
    ctx.copy_uselib_defs(dst='Cintex', src='ROOT')
    ctx.env['LIB_Cintex'] = ['Reflex', 'Cintex']
    
    # pyroot...
    ctx.copy_uselib_defs(dst='PyROOT', src='ROOT')
    ctx.env['LIB_PyROOT'] = ['PyROOT'] + ctx.env['LIB_python']

     # XMLIO...
    ctx.copy_uselib_defs(dst='XMLIO', src='ROOT')
    ctx.env['LIB_XMLIO'] = ['XMLIO']

    # XMLParser
    ctx.copy_uselib_defs(dst='XMLParser', src='ROOT')
    ctx.env['LIB_XMLParser'] = ['XMLParser']

    # check for gccxml
    if not ctx.env.HWAF_FOUND_GCCXML:
        ctx.find_gccxml()
        pass

    # -- check everything is kosher...
    version = ctx.check_cxx(
        msg="Checking ROOT version",
        okmsg="ok",
        fragment='''\
        #include "RVersion.h"<commit_msg>find_root: introduce more linkopts names (ROOT-XMLParser, ROOT-XMLIO, ROOT-TreePlayer)<commit_after># -*- python -*-

# stdlib imports ---
import os
import os.path as osp

# waf imports ---
import waflib.Utils
import waflib.Logs as msg
import waflib.Configure
import waflib.Build
import waflib.Task
import waflib.Tools.ccroot
from waflib.Configure import conf
from waflib.TaskGen import feature, before_method, after_method, extension, after

#
_heptooldir = osp.dirname(osp.abspath(__file__))

def options(ctx):

    ctx.load('hwaf-base', tooldir=_heptooldir)
    ctx.load('find_libxml2',      tooldir=_heptooldir)
    ctx.load('find_python',       tooldir=_heptooldir)
    ctx.load('find_gccxml', tooldir=_heptooldir)

    ctx.add_option(
        '--with-root',
        default=None,
        help="Look for CERN ROOT System at the given path")
    return

def configure(ctx):
    ctx.load('hwaf-base', tooldir=_heptooldir)
    return

@conf
def find_root(ctx, **kwargs):
    
    ctx.load('hwaf-base', tooldir=_heptooldir)
    ctx.load('find_python', tooldir=_heptooldir)
    ctx.load('find_libxml2', tooldir=_heptooldir)
    ctx.load('find_gccxml', tooldir=_heptooldir)

    if not ctx.env.HWAF_FOUND_C_COMPILER:
        ctx.fatal('load a C compiler first')
        pass

    if not ctx.env.HWAF_FOUND_CXX_COMPILER:
        ctx.fatal('load a C++ compiler first')
        pass

    if not ctx.env.HWAF_FOUND_PYTHON:
        ctx.find_python(version=kwargs.get('python_version', (2,6)))
    
    if not ctx.env.HWAF_FOUND_LIBXML2:
        ctx.find_libxml2(mandatory=False)
    
    if not ctx.env.PYTHON:
        ctx.fatal('load a python interpreter first')
        pass

    # find root
    root_cfg = "root-config"
    path_list = waflib.Utils.to_list(kwargs.get('path_list', []))
    for topdir in [getattr(ctx.options, 'with_root', None), os.getenv('ROOTSYS', None)]:
        if topdir:
            topdir = ctx.hwaf_subst_vars(topdir)
            path_list.append(
                osp.join(topdir, "bin")
                )
            pass
        pass
    kwargs['path_list']=path_list

    
    ctx.find_program(
        root_cfg, 
        var='ROOT-CONFIG',
        **kwargs)
    root_cfg = ctx.env['ROOT-CONFIG']

    ctx.check_with(
        ctx.check_cfg,
        "root",
        path=root_cfg,
        package="",
        uselib_store="ROOT",
        args='--libs --cflags --ldflags',
        **kwargs)

    ctx.find_program('genmap',      var='GENMAP',     **kwargs)
    ctx.find_program('genreflex',   var='GENREFLEX',  **kwargs)
    ctx.find_program('root',        var='ROOT-EXE',   **kwargs)
    ctx.find_program('rootcint',    var='ROOTCINT',   **kwargs)
    ctx.find_program('rlibmap',     var='RLIBMAP',     **kwargs)

    # reflex...
    ctx.copy_uselib_defs(dst='Reflex', src='ROOT')
    ctx.env['LIB_Reflex'] = ['Reflex']
    
    # cintex...
    ctx.copy_uselib_defs(dst='Cintex', src='ROOT')
    ctx.env['LIB_Cintex'] = ['Reflex', 'Cintex']
    
    # pyroot...
    ctx.copy_uselib_defs(dst='PyROOT', src='ROOT')
    ctx.env['LIB_PyROOT'] = ['PyROOT'] + ctx.env['LIB_python']

     # XMLIO...
    ctx.copy_uselib_defs(dst='ROOT-XMLIO', src='ROOT')
    ctx.env['LIB_ROOT-XMLIO'] = ['XMLIO']

    # XMLParser
    ctx.copy_uselib_defs(dst='ROOT-XMLParser', src='ROOT')
    ctx.env['LIB_ROOT-XMLParser'] = ['XMLParser']

    # TreePlayer
    ctx.copy_uselib_defs(dst='ROOT-TreePlayer', src='ROOT')
    ctx.env['LIB_ROOT-TreePlayer'] = ['TreePlayer']

    # check for gccxml
    if not ctx.env.HWAF_FOUND_GCCXML:
        ctx.find_gccxml()
        pass

    # -- check everything is kosher...
    version = ctx.check_cxx(
        msg="Checking ROOT version",
        okmsg="ok",
        fragment='''\
        #include "RVersion.h"
{'fraction_non_alphanumeric': 0.14344656856003302, 'fraction_numerical': 0.001650391968092422, 'mean_word_length': 2.727319323423885, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 14}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '741202', 'n_tokens_mistral': 2665, 'n_tokens_neox': 2616, 'n_words': 449}