/[ascend]/trunk/pygtk/SConscript
ViewVC logotype

Contents of /trunk/pygtk/SConscript

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2068 - (show annotations) (download)
Fri Aug 21 02:48:14 2009 UTC (10 years, 10 months ago) by jpye
File size: 5285 byte(s)
Fix build of Python bindings for Mac OS X (Darwin).
1 #!/usr/bin/env python
2 Import('env')
3
4 import platform
5
6 srcs = Split("""
7 library.cpp compiler.cpp type.cpp module.cpp symchar.cpp
8 instance.cpp instanceinterfacedata.cpp
9 matrix.cpp method.cpp name.cpp
10 reporter.cpp simulation.cpp set.cpp units.cpp dimensions.cpp extmethod.cpp
11 variable.cpp registry.cpp relation.cpp
12 solver.cpp curve.cpp plot.cpp
13 solverparameters.cpp solverparameter.cpp solverparameteriterator.cpp
14 solverstatus.cpp solverreporter.cpp
15 incidencematrix.cpp
16 integrator.cpp
17 integratorreporter.cpp
18 annotation.cpp
19 """)
20
21 # Build a static library with all the sources
22
23 python_env = env.Clone()
24
25 if platform.system()=='Windows' and env.get('MSVS'):
26 python_env.Append(CCFLAGS=['/EHsc']) # for exceptions (as suggested by a MSVC error msg, dunno if it's right or not -- JP)
27
28 swig_has_gccvisibility = False
29 min,maj,pat = env['SWIGVERSION']
30 if min==1 and maj==3 and pat>=29:
31 swig_has_gccvisibility = True
32
33 if env.get('HAVE_GCC'):
34 #python_env.Append(CPPFLAGS=['-O3'])
35 if swig_has_gccvisibility and env.has_key('HAVE_GCCVISIBILITY'):
36 python_env.Append(CCFLAGS=['-fvisibility=hidden']);
37
38 objs = []
39
40 python_env.AppendUnique(
41 CPPPATH=env['PYTHON_CPPPATH']
42 )
43
44 print "PYTHON_CPPPATH = %s" % env['PYTHON_CPPPATH']
45
46 for s in srcs:
47 objs += python_env.SharedObject(s)
48
49 #----------------------------------------------
50 # SWIG wrapper
51
52 def get_new_swig_flags(env):
53 min,maj,pat = env['SWIGVERSION']
54 flags = []
55 if min==1 and maj==3 and pat>=28:
56 flags += ['-O']
57 sep = ":"
58 if platform.system=="Windows": sep=";"
59
60 #print "FLAGS=%s" % env.get('GRAPHVIZ_CPPPATH')
61 if env.get('WITH_GRAPHVIZ') and env.get('GRAPHVIZ_CPPPATH'):
62 flags += ['-I%s' % i for i in env.get('GRAPHVIZ_CPPPATH')]
63
64 if 'msvcr71' in env['LIBS']:
65 flags += ['-DHAVE_MSVCR71']
66
67 return flags
68
69 swig_env = python_env.Clone()
70 if '-Wall' in swig_env.get('CCFLAGS'):
71 swig_env['CCFLAGS'] = swig_env['CCFLAGS'].remove('-Wall')
72
73 if platform.system()=="Windows":
74 swig_env['SHLIBSUFFIX']='.pyd'
75 if 'msvcr71' in env.get('LIBS'):
76 swig_env.Append(CPPDEFINES=['HAVE_MSVCR71'])
77 elif platform.system()=="Darwin":
78 swig_env['SHLIBSUFFIX']='.so'
79
80 swigobjs = []
81
82 for swigf in Split("""
83 ascpy.i
84 """):
85 swigobj = swig_env.SharedObject(swigf
86 , SWIGFLAGS=['-python','-c++'] + get_new_swig_flags(env)
87 )
88 #swig_env.SideEffect(['ascpy.py','ascpy_wrap.h'],'ascpy$SWIGCXXFILESUFFIX')
89 swig_env.Depends('ascpy$SWIGCXXFILESUFFIX',['ascpy.i','solver.i','plot.i'])
90 swig_env.Clean('ascpy_wrap$SWIGCXXFILESUFFIX',swigobj)
91 swig_env.Clean('ascpy.py','ascpy$SWIGCXXFILESUFFIX')
92 swig_env.Clean('ascpy_wrap.h','ascpy$SWIGCXXFILESUFFIX')
93
94 swigobjs.append(swigobj)
95
96 swig_env.Append(LIBS = ['ascend']+env['PYTHON_LIB'])
97 swig_env.Append(LIBPATH = ['#'] + env['PYTHON_LIBPATH'])
98 swig_env.Append(LINKFLAGS=env['PYTHON_LINKFLAGS'])
99
100 if not env.get('MSVS'):
101 swig_env.Append(LIBS = ['stdc++'])
102
103 if env.get('WITH_DMALLOC'):
104 swig_env.Append(LIBS = ['dmalloc'])
105 swig_env.AppendUnique(LIBPATH = [env.get('DMALLOC_LIBPATH')])
106
107 if env.get('WITH_GRAPHVIZ'):
108 swig_env.Append(LIBS = env['GRAPHVIZ_LIBS'])
109 swig_env.AppendUnique(LIBPATH = [env.get('GRAPHVIZ_LIBPATH')])
110
111 swiglib = swig_env.SharedLibrary("ascpy",objs + swigobjs
112 , SHLIBPREFIX = '_'
113 )
114
115 #---------------------------------------------
116 # CONFIG & runtime shell script for posix
117
118 configpy = env.SubstInFile(source='config.py.in')
119 configh = env.SubstInFile(source='config.h.in')
120
121 ascendcmd = env.SubstInFile(source='ascend.in')
122 env.AddPostAction(ascendcmd, 'chmod 755 $TARGET')
123
124 if platform.system() != "Windows" or env.has_key('IS_MINGW'):
125 envdev = env.Clone()
126 # add 'WITH_SOLVERS' to the SUBST_DICT used by ascdev...
127 envdev['SUBST_DICT']['@WITH_SOLVERS@'] = ",".join(env.get('WITH_SOLVERS'))
128 ascdevcmd = envdev.SubstInFile(source='ascdev.in')
129 env.AddPostAction(ascdevcmd, 'chmod 755 $TARGET')
130
131 #---------------------------------------------
132 # LITTLE WEE TEST PROGRAM for debuggin the c++ wrapper
133 # currently out of order because of need for a separate builddir due to ASCXX_WITH_PYTHON flag taking different value
134 #
135 #libascxx = env.SharedLibrary('ascxx',objs
136 # , LIBS = ['ascend'] + env['PYTHON_LIB']
137 # , LIBPATH = ['.'] + ['#'] + env['PYTHON_LIBPATH']
138 #)
139
140 ipopttest = swig_env.Program('testipopt',['testipopt.cpp'] + objs)
141 conopttest = swig_env.Program('testconopt',['testconopt.cpp'] + objs)
142
143 #env.Alias('ascxx',ascxxtest)
144
145 #---------------------------------------------
146 # INSTALLATION
147
148 # python compile bytecode
149
150 import py_compile
151 def pyc_build(target, source, env):
152 py_compile.compile(str(source[0]),str(target[0]),"",True)
153 return None
154 env.Append(BUILDERS = {'PYC' : Builder(action = pyc_build,suffix='.pyc',src_suffix='.py')})
155
156 if env.get('CAN_INSTALL'):
157 env.InstallProgram(Dir(env.subst("$INSTALL_ROOT$INSTALL_BIN")),ascendcmd)
158
159 import glob
160 pythonfiles = glob.glob("*.py")
161
162 pythonpycs = []
163 for f in pythonfiles:
164 pythonpycs.append( env.PYC(f) )
165
166 for f in pythonfiles + pythonpycs:
167 env.InstallShared(Dir(env.subst("$INSTALL_ROOT$INSTALL_PYTHON")),f)
168
169 env.InstallShared(Dir(env.subst("$INSTALL_ROOT$INSTALL_PYTHON")),"config.py")
170
171 gladefiles = glob.glob("glade/*")
172 env.InstallShared(Dir(env.subst("$INSTALL_ROOT$INSTALL_ASCDATA/glade")),gladefiles)
173
174 env.InstallShared(Dir(env.subst("$INSTALL_ROOT$INSTALL_PYTHON")),swiglib)
175
176 # vim: set syntax=python:
177

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22