Scons help!

Steven Knight knight at baldmt.com
Wed Mar 24 22:28:21 EST 2004


Anuj--
                                                                                
One of my searches turned up your message to comp.lang.python.
It would have been more appropriate for you to send this message to the
SCons users mailing list, users at scons.tigris.org.
                                                                                
As to your specific problem:
                                                                                
> opt = Options(None, ARGUMENTS)
> opt.AddOptions(
>  EnumOption(
>   'COMPILER',
>   'The compiler you want to use',
>   'cl',
>   ['cl','gcc']))
>
> env = Environment(options=opt)
>
> CLDEBUGCPPFLAGS = r'/nologo /MDd /W3 /Gm /GR /GX /ZI /Od /D "_DEBUG"
> /D "WIN32" /D "_WINDOWS" /D "BOBO_DLL_EXPORT" /D "USE_STANDARD_HEAP"
> /YX /FD /c'
>
> env['BUILDERS']['cl'] = Builder(action = 'cl '+ CLDEBUGCPPFLAGS +' %SOURCE')
> env['BUILDERS']['gcc'] = Builder(action = 'gcc -co %TARGET %SOURCE')
>
>
> env['BUILDERS']['MyCompiler'] = env['BUILDERS'][env['COMPILER']]
>
> env.MyCompiler('myheap.cpp')
>
>
> and here is the output.
>
> F:\work\src\mallocheap>scons
> scons: Reading SConscript files ...
> scons: done reading SConscript files.
> scons: Building targets ...
> cl /nologo /MDd /W3 /Gm /GR /GX /ZI /Od /D "_DEBUG" /D "WIN32" /D
> "_WINDOWS" /D "BOBO_DLL_EXPORT" /D "USE_STANDARD_HEAP"
>  /YX /FD /c %SOURCE
> Command line warning D4024 : unrecognized source file type '%SOURCE',
> object file assumed
> Command line warning D4027 : source file '%SOURCE' ignored
> Command line warning D4021 : no action performed
> scons: done building targets.
                                                                                
First, it would help if you would use the correct SCons syntax for
construction variable interpolation.  The proper syntax is $SOURCE
(note dollar sign), not %SOURCE.
                                                                                
Second, trying to do this with custom Builders is making things much more
difficult than they need to be.  SCons already comes with canned tool
specifications for Microsoft Visual C++ and GCC (and a host of other tools).
It would be a lot easier to let SCons do the hard stuff for you.
                                                                                
First, you need to account for the fact that the tool specification in
SCons is named "msvc," not "cl".  To allow your users to specify
"COMPILER=cl" on the command line, you just need to add a dictionary to
map "cl" to the correct SCons tool name of "msvc":
                                                                                
        opt.AddOptions(
         EnumOption(
          'COMPILER',
          'The compiler you want to use',
          'msvc',
          ['msvc','gcc'],
          {'cl':'msvc'}))
                                                                                
Then, you can let SCons initialize the Environment as follows, allowing
it to expand $COMPILER to the specified value:
                                                                                
        env = Environment(options=opt,
                          tools=['default', '$COMPILER'])
                                                                                
After that, you can use env.Program(), env.Library(), etc. to build
whatever you want.
                                                                                
        --SK



More information about the Python-list mailing list