12from SCons.Builder 
import Builder
 
   16reg_re = re.compile(
r'^\s*(REG_[A-Z0-9_]+\s*\([\S ]+\))', re.M)
 
   19def build_map(target, source, env):
 
   23    map_file = open(str(target[0]), 
'w')
 
   27    for source_file 
in source:
 
   29        if str(source_file).endswith(env.subst(
'$SHLIBSUFFIX')):
 
   32        contents = source_file.get_text_contents()
 
   33        for entry 
in reg_re.findall(contents):
 
   34            map_file.write(entry + 
'\n')
 
   40        return "Module map file empty. Did you forget REG_MODULE(...) in your module source file?" 
   46map_builder = Builder(action=build_map)
 
   47map_builder.action.cmdstr = 
'${MAPCOMSTR}' 
   51    env[
'BUILDERS'][
'RegMap'] = map_builder