Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9104471
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T01:52:37+00:00 2026-06-17T01:52:37+00:00

I am trying to get SCons to generate multiple targets (number unknown directly in

  • 0

I am trying to get SCons to generate multiple targets (number unknown directly in SConscript).

I have directory like:

headers/
  Header1.h
  Header2.h
  Header3.h
  Header4.h
meta/
  headers_list.txt

Now I want SConscript to read headers_list.txt, basing on its contents pick files from headers/ directory (i.e. it might contain only Header1 and Header3), for each of those I want to generate source using some function.

I have been trying to use env.Command to do that, but the issue is that it requires caller to specify targets list which for obvious reasons is not known when invoking env.Command.

The only thing I can think of is running:

for header in parse( headers_file ):
    source = mangle_source_name_for_header( header )
    env.Command( source, header, generator_action )

But this means I will be running parse( headers_file ) each time I invoke scons.
If parsing is costly and the file is not often changed this step could be easily cached.

What SConsc construct/class/technique I am missing to achieve that caching?

edit:

It seems my question is similar to Build-time determination of SCons targets, but isn’t there a technique without artificial dummy file?

Also, even with temporary file, I don’t see how I am supposed to pass target variable from Command that generates variable number of targets to second one that would iterate over them.

edit 2:

This looks promising.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T01:52:39+00:00Added an answer on June 17, 2026 at 1:52 am

    The only way I found I can do it is with emitter.
    Below example consists of 3 files:

    ./
    |-SConstruct
    |-src/
    | |-SConscript
    | |-source.txt
    |-build/
    

    SConstruct

    env = Environment()
    
    dirname = 'build'
    VariantDir(dirname, 'src', duplicate=0)
    
    Export('env')
    
    SConscript(dirname+'/SConscript')
    

    src/SConscript

    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 )
    

    src/source.txt

    a int a(){}
    b int b(){}
    c int c(){}
    d int d(){}
    g int g(){}
    

    Output:

    $ scons
    scons: Reading SConscript files ...
    scons: done reading SConscript files.
    scons: Building targets ...
    echo "int a(){}" > build/a
    echo "int b(){}" > build/b
    echo "int c(){}" > build/c
    echo "int d(){}" > build/d
    echo "int g(){}" > build/g
    my_action(["build/a.c", "build/b.c", "build/c.c", "build/d.c", "build/g.c"], ["src/source.txt", "build/a", "build/b", "build/c", "build/d", "build/g"])
    gcc -o build/a.o -c build/a.c
    gcc -o build/b.o -c build/b.c
    gcc -o build/c.o -c build/c.c
    gcc -o build/d.o -c build/d.c
    gcc -o build/g.o -c build/g.c
    ar rc build/libfunctions.a build/a.o build/b.o build/c.o build/d.o build/g.o
    ranlib build/libfunctions.a
    scons: done building targets.
    

    Also this has one thing I don’t really like, which is parsing of headers_list.txt with each scons execution. I feel like there should be a way to parse it only if the file changed. I could cache it by hand, but I still hope there is some trick to make SCons handle that caching for me.

    And I couldn’t find a way to not duplicate files (a and a.c being the same).
    One way would be to simply generate library in my_action instead of sources (which is approach I used in my final solution).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to get started with scons . I have Python 3.0.1 and
I am trying to get names of the selected sheets in Excel. I have
I am trying get a div that I have hidden to show in the
I am trying get my first simple project in rails to run. I have
I'm trying get the offset of a regex capture in .NET just like .IndexOf()
I am new to scons and have been trying to build some files, in
So i am trying get 2 div-containers which both should contain centered text (Both
I'm trying get the visible portion of UIImage from an UIImageView . UIImageView takes
I am trying get all html links within a string and replace them using
I am trying get all html links within a string and replace them using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.