scons + swig
( WuErPing 2009/02/10 )
scons是个好东西,swig也是个好东西,两个好东西加起来如何 ?
本文所用开发环境:
swigwin-1.3.38 http://www.swig.org./
SCons 1.2.0.d20090113 http://www.scons.org/
python 2.6.1 http://www.python.org/
lua 5.1.4 http://www.lua.org/
vc2008+sp1
操作步骤:
1、确认自己已经设置好相应的path
2、Visual Studio 2008 Command Prompt
3、scons.py
4、runme.py/runme.lua
SConstruct:
1 # swig 生成 python 扩展
2 # 已测试
3 # swigwin-1.3.38\Examples\python\simple
4 # swigwin-1.3.38\Examples\python\std_map
5 # swigwin-1.3.38\Examples\python\std_vector
6 # swigwin-1.3.38\Examples\python\callback
7
8 import os,shutil
9
10 env = Environment()
11 env.Append(ENV = os.environ)
12 env.AppendUnique(CXXFLAGS=Split("/EHsc /MD"))
13 env.Append(CPPPATH = [r'C:\Script\Python26\include'])
14 env.Append(LIBPATH = [r'C:\Script\Python26\libs'])
15 env.AppendUnique(SWIGFLAGS = ['-c++', '-python'])
16 #env.AppendUnique(SWIGFLAGS = ['-python'])
17 env.AppendUnique(SHLIBSUFFIX = [''])
18
19 s = env.SharedLibrary('_example.dll', ['example.i'])
20
21 def DllToPyd(**v):
22 dll = str(v["target"][0]);
23 pyd = dll.replace(".dll", ".pyd");
24 shutil.move(dll, pyd)
25
26 env.AddPostAction(s, env.Action(DllToPyd))
27
28
2 # 已测试
3 # swigwin-1.3.38\Examples\python\simple
4 # swigwin-1.3.38\Examples\python\std_map
5 # swigwin-1.3.38\Examples\python\std_vector
6 # swigwin-1.3.38\Examples\python\callback
7
8 import os,shutil
9
10 env = Environment()
11 env.Append(ENV = os.environ)
12 env.AppendUnique(CXXFLAGS=Split("/EHsc /MD"))
13 env.Append(CPPPATH = [r'C:\Script\Python26\include'])
14 env.Append(LIBPATH = [r'C:\Script\Python26\libs'])
15 env.AppendUnique(SWIGFLAGS = ['-c++', '-python'])
16 #env.AppendUnique(SWIGFLAGS = ['-python'])
17 env.AppendUnique(SHLIBSUFFIX = [''])
18
19 s = env.SharedLibrary('_example.dll', ['example.i'])
20
21 def DllToPyd(**v):
22 dll = str(v["target"][0]);
23 pyd = dll.replace(".dll", ".pyd");
24 shutil.move(dll, pyd)
25
26 env.AddPostAction(s, env.Action(DllToPyd))
27
28
1 # swig 生成 lua 扩展
2 # 已测试
3 # swigwin-1.3.38\Examples\lua\class
4
5 import os,shutil
6
7 env = Environment()
8 env.Append(ENV = os.environ)
9 env.AppendUnique(CXXFLAGS=Split("/EHsc /MT"))
10 env.Append(CPPPATH = [r'C:\Script\Lua\5.1\include'])
11 env.Append(LIBPATH = [r'C:\Script\Lua\5.1\lib'])
12 env.Append(LIBS = ["lua51.lib"]);
13 env.AppendUnique(SWIGFLAGS = ['-c++', '-lua'])
14 #env.AppendUnique(SWIGFLAGS = ['-lua'])
15 env.AppendUnique(SHLIBSUFFIX = [''])
16
17 s = env.SharedLibrary('example.dll', ['example.cxx','example.i'])
18
2 # 已测试
3 # swigwin-1.3.38\Examples\lua\class
4
5 import os,shutil
6
7 env = Environment()
8 env.Append(ENV = os.environ)
9 env.AppendUnique(CXXFLAGS=Split("/EHsc /MT"))
10 env.Append(CPPPATH = [r'C:\Script\Lua\5.1\include'])
11 env.Append(LIBPATH = [r'C:\Script\Lua\5.1\lib'])
12 env.Append(LIBS = ["lua51.lib"]);
13 env.AppendUnique(SWIGFLAGS = ['-c++', '-lua'])
14 #env.AppendUnique(SWIGFLAGS = ['-lua'])
15 env.AppendUnique(SHLIBSUFFIX = [''])
16
17 s = env.SharedLibrary('example.dll', ['example.cxx','example.i'])
18