[Scons-users] BuildPackage

dpfj at btinternet.com dpfj at btinternet.com
Sun Dec 13 15:35:40 EST 2015


I have seen various version of UnTar, AutoConfig/Configure and Make SCons tools but not one that does them all.
Below is a Tool I developed to help this hope it helps someone else?
% cat ./BuildPackage.py

import SCons.Action
import SCons.Builder
import SCons.Defaults
import SCons.Node.FS
import SCons.Util

import os

makes = ['make', 'gmake']
tars = ['tar', 'gtar']



def generate(env):
    """Add Builders and construction variables for tar to an Environment."""

    try:
        bld = env['BUILDERS']['BuildPackage']
    except KeyError:
        
        UnTarAction = SCons.Action.Action('$UNTARCOM',    '$UNTARCOMSTR')
        AutoConf    = SCons.Action.Action('$AUTOCONFCOM', '$AUTOCONFCOMSTR')
        Make        = SCons.Action.Action('$MAKECOM',     '$MAKECOMSTR')

        ##
        ## The builder
        ##
        BuildPackageBuilder = SCons.Builder.Builder( 
            action = [UnTarAction, AutoConf, Make],
            target_factory = env.fs.File,
            source_factory = env.fs.File,
            src_suffix = '.tar.gz',
            multi = False,
            chdir=True)

        bld = BuildPackageBuilder

    env['BUILDERS']['BuildPackage'] = bld

    ##
    ## Tar
    ##
    env['UNTAR']        = env.Detect(tars) or 'gtar'
    env['UNTARFLAGS']   = SCons.Util.CLVar('-xz --strip=1')
    env['UNTARCOM']     = '$UNTAR $UNTARFLAGS -f ${SOURCES.abspath}'
    env['UNTARSUFFIX']  = '.tar.gz'

    ##
    ## Make
    ##
    env['MAKE']      = env.Detect(makes) or 'gmake'
    env['MAKEFLAGS'] = SCons.Util.CLVar('-j4')
    env['MAKECOM']   = 'if [ "${MAKE_DEPEND}" ]; then make depend; fi && $MAKE $MAKEFLAGS'

    ##
    ## Configure
    ##
    env['AUTOCONF_BIN'] = './configure'
    env['AUTOCONF_FLAGS'] = ''
    env['AUTOCONFCOM'] = '$AUTOCONF_BIN $AUTOCONF_FLAGS'


def exists(env):
    return 1


An example of it's use is below to build libpcap.a and libssl.a
% cat SConscript
Import('env')


##
## Build the libpcap.a library
##
env.AppendUnique(AUTOCONF_FLAGS = '--enable-shared=no')

libpcap_a = env.BuildPackage(target='libpcap-1.7.4/libpcap.a', source=['libpcap-1.7.4.tar.gz'])
## Make sure it's not removed after all that hard workenv.NoClean(libpcap_a, 'libpcap-1.7.4')

ssl_env = env.Clone()

ssl_env['AUTOCONF_BIN'] = './Configure'

ssl_env['AUTOCONF_FLAGS'] = 'no-threads no-shared linux-x86_64'

ssl_env['MAKE_DEPEND'] = True

libcrypto_a = ssl_env.BuildPackage(target=['openssl-1.0.2e/libcrypto.a', 'openssl-1.0.2e/libssl.a'], source=['openssl-1.0.2e.tar.gz'])

env.NoClean(libcrypto_a, 'openssl-1.0.2e')




-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://pairlist4.pair.net/pipermail/scons-users/attachments/20151213/e986e52f/attachment.html>


More information about the Scons-users mailing list