import re


def rootcint_emitter(target, source, env):
    """
    With ROOT >= 6, rootcling generates a <dict>_rdict.pcm mapping file
    in addition to the dictionary source file. Add this "side effect" artifact
    to the list of targets so that SCons can automatically keep track of it.
    """
    if int(env.get('ROOTVERS','0')[0]) >= 6:
        if env['PCMNAME']:
            target.append(env['PCMNAME']+'_rdict.pcm')
        else:
            # Default PCM file name that rootcling generates without -s <pcmname>
            target.append(re.sub(r'\.cxx\Z','_rdict.pcm',str(target[0])))
    return target, source