Import('env')

def my_emitter(env, target, source):
    data = str(source[0])
target = []
with open(data, 'r') as lines:
    for line in lines:
        line = line.strip()
name, contents = line.split(' ', 1)
if not name:
    continue
generated_source = env.Command(name, [], 'echo "{0}" > $TARGET'.format(
    contents))
source.extend(generated_source)
target.append(name + '.c')
return target, source

def my_action(env, target, source):
    for t, s in zip(target, source[1:]):
        with open(t.abspath, 'w') as tf:
            with open(s.abspath, 'r') as sf:
                tf.write(sf.read())
SourcesGenerator = env.Builder(action=my_action, emitter=my_emitter)
generated_sources = SourcesGenerator(env, source='source.txt')
lib = env.Library('functions', generated_sources)
SCons to generate variable number of targets