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