/[ascend]/trunk/SConstruct
ViewVC logotype

Contents of /trunk/SConstruct

Parent Directory Parent Directory | Revision Log Revision Log


Revision 395 - (show annotations) (download)
Fri Mar 31 06:09:03 2006 UTC (14 years, 7 months ago) by johnpye
File size: 8501 byte(s)
Successful build of Python interface on Windows with MinGW/MSYS.
1 import os, commands, platform, distutils.sysconfig, os.path
2
3 #------------------------------------------------------
4 # OPTIONS
5 #
6 # Note that if you set the options via the command line, they will be
7 # remembered in the file 'options.cache'. It's a feature ;-)
8
9 opts = Options(['options.cache', 'config.py'])
10 print "PLATFORM = ",platform.system()
11
12 # Import the outside environment
13 env = Environment(ENV=os.environ)
14
15 # Package linking option
16 opts.Add(EnumOption(
17 'PACKAGE_LINKING'
18 , 'Style of linking for external libraries'
19 , 'DYNAMIC_PACKAGES'
20 , ['DYNAMIC_PACKAGES', 'STATIC_PACKAGES', 'NO_PACKAGES']
21 ))
22
23 # You can turn off building of Tcl/Tk interface
24 opts.Add(BoolOption(
25 'WITHOUT_TCLTK_GUI'
26 ,"Set to True if you don't want to build the original Tcl/Tk GUI."
27 , False
28 ))
29
30 # You can turn off the building of the Python interface
31 opts.Add(BoolOption(
32 'WITHOUT_PYTHON'
33 ,"Set to True if you don't want to build Python wrappers."
34 , False
35 ))
36
37 # Which solvers will we allow?
38 opts.Add(ListOption(
39 'WITH_SOLVERS'
40 ,"List of the solvers you want to build. The default is the minimum that"
41 +" works."
42 ,["QRSLV","CMSLV"]
43 ,['QRSLV','MPS','SLV','OPTSQP'
44 ,'NGSLV','CMSLV','LRSLV','MINOS','CONOPT'
45 ,'LSOD','OPTSQP'
46 ]
47 ))
48
49 # Where will the local copy of the help files be kept?
50 opts.Add(PackageOption(
51 'WITH_LOCAL_HELP'
52 , "Directory containing the local copy of the help files (optional)"
53 , "no"
54 ))
55
56 # Will bintoken support be enabled?
57 opts.Add(BoolOption(
58 'WITH_BINTOKEN'
59 ,"Enable bintoken support? This means compiling models as C-code before"
60 +" running them, to increase solving speed for large models."
61 ,False
62 ))
63
64 opts.Add(
65 'DEFAULT_ASCENDLIBRARY'
66 ,"Set the default value of the ASCENDLIBRARY -- the location where"
67 +" ASCEND will look for models when running ASCEND"
68 ,os.path.expanduser("~/src/ascend/trunk/models")
69 )
70
71 # Where will the 'Makefile.bt' file be installed
72
73 # TODO: add install options
74
75 # TODO: OTHER OPTIONS?
76
77 # TODO: flags for optimisation
78
79 # TODO: turning on/off bintoken functionality
80
81 opts.Update(env)
82 opts.Save('options.cache',env)
83
84 Help(opts.GenerateHelpText(env))
85
86 env.Append(CPPDEFINES=env['PACKAGE_LINKING'])
87
88 with_tcltk_gui = (env['WITHOUT_TCLTK_GUI']==False)
89
90 with_python = (env['WITHOUT_PYTHON']==False)
91
92 print "SOLVERS:",env['WITH_SOLVERS']
93
94 print "WITH_LOCAL_HELP:",env['WITH_LOCAL_HELP']
95 print "WITH_BINTOKEN:",env['WITH_BINTOKEN']
96 print "DEFAULT_ASCENDLIBRARY:",env['DEFAULT_ASCENDLIBRARY']
97
98 subst_dict = {
99 '@WEBHELPROOT@':'http://pye.dyndns.org/ascend/manual/'
100 , '@GLADE_FILE@':'glade/ascend.glade'
101 , '@DEFAULT_ASCENDLIBRARY@':env['DEFAULT_ASCENDLIBRARY']
102 , '@ASCEND_ICON@':'glade/ascend.png'
103 , '@HELP_ROOT@':''
104 }
105
106 if env['WITH_LOCAL_HELP']:
107 subst_dict['@HELP_ROOT@']=env['WITH_LOCAL_HELP']
108
109 env.Append(SUBST_DICT=subst_dict)
110
111 #------------------------------------------------------
112 # CONFIGURATION
113
114 conf = Configure(env
115 , custom_tests = {
116 # 'CheckIsNan' : CheckIsNan
117 # ,'CheckCppUnitConfig' : CheckCppUnitConfig
118 }
119 , config_h = "config.h"
120 )
121
122 # Math library
123 if not conf.CheckLibWithHeader(['m','c','libc'], 'math.h', 'C'):
124 print 'Did not find libm.a or m.lib, exiting!'
125 Exit(1)
126
127 # Where is 'isnan'?
128
129 if not conf.CheckFunc('isnan'):
130 print "Didn't find isnan"
131 Exit(1)
132
133 # Tcl/Tk
134 if not conf.CheckHeader('tcl.h'):
135 with_tcltk_gui = False
136
137 if not conf.CheckHeader('tk.h'):
138 with_tcltk_gui = False
139
140 if not conf.CheckLib('tcl'):
141 with_tcltk_gui = False
142
143 if not conf.CheckLib('tk'):
144 with_tcktk_gui = False
145
146
147 # Python... obviously we're already running python, so we just need to
148 # check that we can link to the python library OK:
149
150 if platform.system()=="Windows":
151 #conf.env.Append(LIBPATH='c:\Python24\libs')
152 #conf.env.Append(CPPPATH='c:\Python24\include')
153 #python_header='Python.h'
154 python_lib='python24'
155 #python_libpath=['c:\\Python24\\libs']
156 #python_cpppath=['c:\\Python24\\include']
157 else:
158 #python_header='python2.4/Python.h'
159 python_lib='python2.4'
160 #python_libpath=[]
161 #python_cpppath=['/usr/include/python2.4']
162
163 #if not conf.CheckLibWithHeader(python_lib,python_header,'C'
164 # , LIBPATH=[distutils.sysconfig.PREFIX+"/libs"]
165 # , CPPPATH=[distutils.sysconfig.get_python_inc()]
166 #):
167 # print "Didn't find Python 2.4 ("+python_lib+")"
168 # with_python = False
169 #else:
170
171
172 # SWIG version
173 env['SWIG']=['c:\\msys\\1.0\\home\\john\\swigwin-1.3.29\\swig.exe']
174 env['ENV']['SWIGFEATURES']='-O'
175
176
177 # TODO: -D_HPUX_SOURCE is needed
178
179 # TODO: check size of void*
180
181 # TODO: detect if dynamic libraries are possible or not
182
183 conf.Finish()
184
185 env.Append(PYTHON_LIBPATH=[distutils.sysconfig.PREFIX+"/libs"])
186 env.Append(PYTHON_LIB=[python_lib])
187 env.Append(PYTHON_CPPPATH=[distutils.sysconfig.get_python_inc()])
188 print "PYTHON_LIBPATH =",env['PYTHON_LIBPATH']
189 print "PYTHON_CPPPATH =",env['PYTHON_CPPPATH']
190
191 #------------------------------------------------------
192 # RECIPE: 'SubstInFile', used in pygtk SConscript
193
194 import re
195 from SCons.Script import * # the usual scons stuff you get in a SConscript
196
197 def TOOL_SUBST(env):
198 """Adds SubstInFile builder, which substitutes the keys->values of SUBST_DICT
199 from the source to the target.
200 The values of SUBST_DICT first have any construction variables expanded
201 (its keys are not expanded).
202 If a value of SUBST_DICT is a python callable function, it is called and
203 the result is expanded as the value.
204 If there's more than one source and more than one target, each target gets
205 substituted from the corresponding source.
206 """
207 env.Append(TOOLS = 'SUBST')
208 def do_subst_in_file(targetfile, sourcefile, dict):
209 """Replace all instances of the keys of dict with their values.
210 For example, if dict is {'%VERSION%': '1.2345', '%BASE%': 'MyProg'},
211 then all instances of %VERSION% in the file will be replaced with 1.2345 etc.
212 """
213 try:
214 f = open(sourcefile, 'rb')
215 contents = f.read()
216 f.close()
217 except:
218 raise SCons.Errors.UserError, "Can't read source file %s"%sourcefile
219 for (k,v) in dict.items():
220 contents = re.sub(k, v, contents)
221 try:
222 f = open(targetfile, 'wb')
223 f.write(contents)
224 f.close()
225 except:
226 raise SCons.Errors.UserError, "Can't write target file %s"%targetfile
227 return 0 # success
228
229 def subst_in_file(target, source, env):
230 if not env.has_key('SUBST_DICT'):
231 raise SCons.Errors.UserError, "SubstInFile requires SUBST_DICT to be set."
232 d = dict(env['SUBST_DICT']) # copy it
233 for (k,v) in d.items():
234 if callable(v):
235 d[k] = env.subst(v())
236 elif SCons.Util.is_String(v):
237 d[k]=env.subst(v)
238 else:
239 raise SCons.Errors.UserError, "SubstInFile: key %s: %s must be a string or callable"%(k, repr(v))
240 for (t,s) in zip(target, source):
241 return do_subst_in_file(str(t), str(s), d)
242
243 def subst_in_file_string(target, source, env):
244 """This is what gets printed on the console."""
245 return '\n'.join(['Substituting vars from %s into %s'%(str(s), str(t))
246 for (t,s) in zip(target, source)])
247
248 def subst_emitter(target, source, env):
249 """Add dependency from substituted SUBST_DICT to target.
250 Returns original target, source tuple unchanged.
251 """
252 d = env['SUBST_DICT'].copy() # copy it
253 for (k,v) in d.items():
254 if callable(v):
255 d[k] = env.subst(v())
256 elif SCons.Util.is_String(v):
257 d[k]=env.subst(v)
258 Depends(target, SCons.Node.Python.Value(d))
259 return target, source
260
261 subst_action=SCons.Action.Action(subst_in_file, subst_in_file_string)
262 env['BUILDERS']['SubstInFile'] = Builder(action=subst_action, emitter=subst_emitter)
263
264 TOOL_SUBST(env)
265
266 #------------------------------------------------------
267 # SUBDIRECTORIES....
268
269
270 env.Append(CPPPATH=['..'])
271
272 env.SConscript(['base/generic/general/SConscript'],'env')
273
274 env.SConscript(['base/generic/utilities/SConscript'],'env')
275
276 env.SConscript(['base/generic/compiler/SConscript'],'env')
277
278 env.SConscript(['base/generic/solver/SConscript'],'env')
279
280 env.SConscript(['base/generic/packages/SConscript'],'env')
281
282 if with_tcltk_gui:
283 env.SConscript(['tcltk98/generic/interface/SConscript'],'env')
284 else:
285 print "Skipping... Tcl/Tk GUI isn't being built"
286
287 if with_python:
288 env.SConscript(['pygtk/interface/SConscript'],'env')
289 else:
290 print "Skipping... Python GUI isn't being built"
291
292

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