[Scons-dev] Extensions for the Configure facility

Eric S. Raymond esr at thyrsus.com
Thu Nov 7 07:14:48 EST 2013

These custom Configure tests are in production use in the GPSD scons
recipe. I donate them to the scons project to be redistributed under
its license. Documentation and a usage example follows each one.
The examples are straight from GPSD and in production use.

env['PKG_CONFIG'] = "pkg-config"

The default name of the executable for the freedesktop.org pkg-config
system, widely used for querying information about installed libraries
on Linux and *BSD systems

def CheckPKG(context, name):
context.Message( 'Checking for %s... ' % name )
ret = context.TryAction('%s --exists \'%s\'' % (env['PKG_CONFIG'], name))[0]
context.Result( ret )
return ret

Check whether a specified library registered with pkg-config exists,
returning True if so and False if not. Example:

if config.CheckPKG('ncurses'):
ncurseslibs = pkg_config('ncurses')


def CheckExecutable(context, testprogram, check_for):
context.Message( 'Checking for %s... ' %(check_for,))
ret = context.TryAction(testprogram)[0]
context.Result( ret )
return ret

Check whether a specified command exists and can be run; returns True
if so and False if not. Takes two arguments; a test command and a name
to be reported in the configure progress message. Example:

config.CheckExecutable('chrpath -v', 'chrpath')


def CheckCompilerOption(context, option):
context.Message( 'Checking if compiler accepts %s ...' %(option,) )
ret = context.TryLink("""
int main(int argc, char **argv) {
return 0;
if not ret:
return ret

Check whether your compiler accepts a specified option flag. If so,
append it to the CFLAGS variable in the context's environment. Example:

for option in ('-Wextra','-Wall', '-Wno-uninitialized','-Wno-missing-field-initializers',
'-Wcast-align','-Wmissing-declarations', '-Wmissing-prototypes',
'-Wstrict-prototypes', '-Wpointer-arith', '-Wreturn-type'):


def CheckHeaderDefines(context, file, define):
context.Message( 'Checking if %s supplies %s ...' %(file,define) )
ret = context.TryLink("""
#include <%s>
#ifndef %s
#error %s is not defined
int main(int argc, char **argv) {
return 0;
""" % (file, define, define),'.c')
return ret

Check whether a specified include file is available and defines a
specified macro; returns True if so, False if not. Example:

if not config.CheckHeaderDefines("sys/ioctl.h", "TIOCMIWAIT"):
announce("Forcing pps=no (TIOCMIWAIT not available)")
env["pps"] = False


That's all.
<a href="http://www.catb.org/~esr/">Eric S. Raymond</a>

The real point of audits is to instill fear, not to extract revenue;
the IRS aims at winning through intimidation and (thereby) getting
maximum voluntary compliance
-- Paul Strassel, former IRS Headquarters Agent Wall St. Journal 1980

More information about the Scons-dev mailing list