tags:

views:

30

answers:

2

I am trying to write an SCons script to build lua/embed3 example distributed with swig. Build instructions by makefile as follows:

swig -c++ -lua -external-runtime swigluarun.h
swig -c++ -lua -module example -o example_wrap.cpp example.i
g++ -o embed3 embed3.cpp example_wrap.cpp example.cpp \
    -llua5.1 -I/usr/include/lua5.1

In Scons wiki, it's said that Scons has builtin swig support. Adding '.i' file among sources should do the job, however i am unable to find any detailed description about how can this script can be implemented.

Following script builds lua/simple project under swig examples. However, i am unable to find how to execute first swig directive given in my question. Thanks for reply.

env = Environment()

env.Append( SWIGFLAGS = '-lua' )
env.Append( CPPPATH = '/usr/include/lua5.1' )
env.Append( LIBS = 'lua5.1' )

env.SharedLibrary( target = 'example.so', 
                   source = ['example.c', 'example.i' ], SHLIBPREFIX='' )

Thanks in advance.

A: 

Did you try/see this example script:

import distutils.sysconfig
env = Environment(SWIGFLAGS=['-python'],
                  CPPPATH=[distutils.sysconfig.get_python_inc()],
                  SHLIBPREFIX="")
env.SharedLibrary('_example.so', ['example.c', 'example.i'])

Some more interesting details are in this blog post.

Eli Bendersky
@eli updating question with your example
abekkine
@abekkine: I think that you can just define a custom `Scons.Builder` for that
Eli Bendersky
@eli: i am beginner to Scons, and after working with gnu make, having difficulties on building -extra- dependencies with scons. Thanks for your help. I can confirm any improvements to the following script as accepted answer.
abekkine
@abekkine: I'm no Scons expert myself :) your approach looks reasonable enough for such a simple need, however, so if it works for you, I think you're all set
Eli Bendersky
A: 

Thanks to Eli's guidance, this is only way i could find to implement script. Any improvements are welcome.

env = Environment()

swigCmdLine = 'swig -c++ -lua -external-runtime swigluarun.h'
swigDefs = env.Command( 'swigluarun.h', '', swigCmdLine )
env.Depends( 'embed3', swigDefs )
env.Append( SWIGFLAGS = '-c++ -lua' )
env.Append( CPPPATH = '/usr/include/lua5.1' )
env.Append( LIBS = 'lua5.1' )
env.Program( 'embed3', ['embed3.cpp', 'example.cpp', 'example.i' ] )

Note: I am working on Ubuntu 9.10, swig-1.3.36, and scons 1.3.0.

abekkine