[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,) )
old_CFLAGS=context.env['CFLAGS']
context.env.Append(CFLAGS=option)
ret = context.TryLink("""
int main(int argc, char **argv) {
return 0;
}
""",'.c')
if not ret:
context.env.Replace(CFLAGS=old_CFLAGS)
context.Result(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'):
config.CheckCompilerOption(option)

------------------------------------------------------------------------

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
#endif
int main(int argc, char **argv) {
return 0;
}
""" % (file, define, define),'.c')
context.Result(ret)
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