what to to if Scons required?

EdorFaus edorfaus at xepher.net
Tue Nov 8 13:47:29 EST 2011

On 11/08/2011 08:55 AM, Xiangfu Liu wrote:
> On 11/07/2011 11:15 PM, cenobyte at dragoncrypt.com wrote:
>> Hi, I am wondering how to make a makefile if the program requires
>> being built with Scons? By the way, I am looking at Xiangfu's
> I mark it as broken because the 'Scons' :(
> we need find out how to pass the CC, CFLAGS etc to the 'Scons'
> maybe add a 'custom-openwrt.py', do you have any experience on 'Scons'?


I don't have any real experience with SCons myself, but took a look at 
it now, reading some documentation and experimenting a little bit.

SCons does, by design, not automatically copy environment variables from 
the original environment to the environment used to build programs.

However, it turns out to be fairly easy to make it do so. Simply put 
something like this at the top of the SConstruct file:

import os
env = DefaultEnvironment()
if 'CC' in os.environ:
if 'CFLAGS' in os.environ:

This makes it copy the CC and CFLAGS environment variables into the 
appropriate execution environment variables used by SCons to build C.

I tested this by setting CC to echo before running scons, using the 
hello world example in the scons user manual. :)

Of course, if the SConstruct file already does things with the execution 
environment (DefaultEnvironment() or Environment()), it might need to be 
checked to ensure it doesn't overwrite these changes.

As for making a makefile, I haven't looked at the source for the package 
this was about, but I'm guessing that your build host expects to be able 
to just run "make" to build the program, but the project doesn't have a 
Makefile already, so you need to make one.

I would guess that the solution to this is pretty obvious, but just for 
completeness, the Makefile I wrote (which works for me) looks like this:

	scons -c
.PHONY: all clean

This, of course, assumes that SCons is installed on the computer doing 
the building; if not, it would be possible to make the makefile install 
it locally first (assuming Python is installed and available), and also 
to clean it up (remove it) afterwards (when calling clean).

Frode Austvik

More information about the discussion mailing list