tags:

views:

611

answers:

1

I have an SConstruct file for a python module I'm building:

import distutils.sysconfig

env = Environment(CPPPATH=['include', distutils.sysconfig.get_python_inc()], 
                  CPPFLAGS='-ggdb', SWIGFLAGS=['-python'], 
                  SWIGPATH=['include'])

env.ParseConfig( 'net-snmp-config --libs --cflags' )
env.Append( LIBS = 'pthread' )

backend_interface = 'src/backend_interface.c'
backend_thread = 'src/backend_thread.c'
python_wrapper = 'src/backend_thread.i'


lib = env.SharedLibrary( target = "_rpdu_backend", 
                         source = [ backend_interface,
                         backend_thread, python_wrapper ],
                         SHLIBPREFIX='' )

env.Install( distutils.sysconfig.get_python_lib(),
             [ lib, 'src/rpdu_backend.py'] )

Running:

$ scons --install-sandbox=./sandbox

results in the library and associated .py module being installed in ./sandbox/usr/local/lib/python2.6/site-packages. If I simply run:

# scons

as root, nothing is installed to /usr/local/lib/python2.6/site-packages.

Why isn't scons building the install target without the sandbox option?

+2  A: 

So after digging around a lot, it turns out that the best way to do this is as follows:

import distutils.sysconfig

env = Environment(CPPPATH=['include', distutils.sysconfig.get_python_inc()], 
                  CPPFLAGS='-ggdb', SWIGFLAGS=['-python'], 
                  SWIGPATH=['include'])

env.ParseConfig( 'net-snmp-config --libs --cflags' )
env.Append( LIBS = 'pthread' )

backend_interface = 'src/backend_interface.c'
backend_thread = 'src/backend_thread.c'
python_wrapper = 'src/backend_thread.i'


lib = env.SharedLibrary( target = "_rpdu_backend", 
                         source = [ backend_interface,
                         backend_thread, python_wrapper ],
                         SHLIBPREFIX='' )
inst = env.Install( distutils.sysconfig.get_python_lib(),
                    [ lib, 'src/rpdu_backend.py'] )

env.Alias( "install", inst )
env.Depends( inst, lib )
Ignore( '.', inst )

This sets up a fake target, which, when called, forces SCons outside its usual "build only in the current directory" approach. It also makes sure the build is done before the install, and provides a convenient uninstall using:

# scons install --clean
Edward Amsden