/[ascend]/trunk/SConstruct
ViewVC logotype

Contents of /trunk/SConstruct

Parent Directory Parent Directory | Revision Log Revision Log


Revision 396 - (show annotations) (download)
Fri Mar 31 06:24:11 2006 UTC (14 years ago) by johnpye
File size: 8644 byte(s)
Fixing python interface on FC4. Still a problem with detection of the full path to swig under
Windows.
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
174 if platform.system()=="Windows":
175 env['SWIG']=['c:\\msys\\1.0\\home\\john\\swigwin-1.3.29\\swig.exe']
176 env['ENV']['SWIGFEATURES']='-O'
177 else:
178 env['ENV']['SWIGFEATURES']='-O'
179
180 # TODO: -D_HPUX_SOURCE is needed
181
182 # TODO: check size of void*
183
184 # TODO: detect if dynamic libraries are possible or not
185
186 conf.Finish()
187
188 env.Append(PYTHON_LIBPATH=[distutils.sysconfig.PREFIX+"/libs"])
189 env.Append(PYTHON_LIB=[python_lib])
190 env.Append(PYTHON_CPPPATH=[distutils.sysconfig.get_python_inc()])
191 print "PYTHON_LIBPATH =",env['PYTHON_LIBPATH']
192 print "PYTHON_CPPPATH =",env['PYTHON_CPPPATH']
193
194 if not with_python:
195 print "Can't build python interface"
196 Exit(1)
197
198 #------------------------------------------------------
199 # RECIPE: 'SubstInFile', used in pygtk SConscript
200
201 import re
202 from SCons.Script import * # the usual scons stuff you get in a SConscript
203
204 def TOOL_SUBST(env):
205 """Adds SubstInFile builder, which substitutes the keys->values of SUBST_DICT
206 from the source to the target.
207 The values of SUBST_DICT first have any construction variables expanded
208 (its keys are not expanded).
209 If a value of SUBST_DICT is a python callable function, it is called and
210 the result is expanded as the value.
211 If there's more than one source and more than one target, each target gets
212 substituted from the corresponding source.
213 """
214 env.Append(TOOLS = 'SUBST')
215 def do_subst_in_file(targetfile, sourcefile, dict):
216 """Replace all instances of the keys of dict with their values.
217 For example, if dict is {'%VERSION%': '1.2345', '%BASE%': 'MyProg'},
218 then all instances of %VERSION% in the file will be replaced with 1.2345 etc.
219 """
220 try:
221 f = open(sourcefile, 'rb')
222 contents = f.read()
223 f.close()
224 except:
225 raise SCons.Errors.UserError, "Can't read source file %s"%sourcefile
226 for (k,v) in dict.items():
227 contents = re.sub(k, v, contents)
228 try:
229 f = open(targetfile, 'wb')
230 f.write(contents)
231 f.close()
232 except:
233 raise SCons.Errors.UserError, "Can't write target file %s"%targetfile
234 return 0 # success
235
236 def subst_in_file(target, source, env):
237 if not env.has_key('SUBST_DICT'):
238 raise SCons.Errors.UserError, "SubstInFile requires SUBST_DICT to be set."
239 d = dict(env['SUBST_DICT']) # copy it
240 for (k,v) in d.items():
241 if callable(v):
242 d[k] = env.subst(v())
243 elif SCons.Util.is_String(v):
244 d[k]=env.subst(v)
245 else:
246 raise SCons.Errors.UserError, "SubstInFile: key %s: %s must be a string or callable"%(k, repr(v))
247 for (t,s) in zip(target, source):
248 return do_subst_in_file(str(t), str(s), d)
249
250 def subst_in_file_string(target, source, env):
251 """This is what gets printed on the console."""
252 return '\n'.join(['Substituting vars from %s into %s'%(str(s), str(t))
253 for (t,s) in zip(target, source)])
254
255 def subst_emitter(target, source, env):
256 """Add dependency from substituted SUBST_DICT to target.
257 Returns original target, source tuple unchanged.
258 """
259 d = env['SUBST_DICT'].copy() # copy it
260 for (k,v) in d.items():
261 if callable(v):
262 d[k] = env.subst(v())
263 elif SCons.Util.is_String(v):
264 d[k]=env.subst(v)
265 Depends(target, SCons.Node.Python.Value(d))
266 return target, source
267
268 subst_action=SCons.Action.Action(subst_in_file, subst_in_file_string)
269 env['BUILDERS']['SubstInFile'] = Builder(action=subst_action, emitter=subst_emitter)
270
271 TOOL_SUBST(env)
272
273 #------------------------------------------------------
274 # SUBDIRECTORIES....
275
276
277 env.Append(CPPPATH=['..'])
278
279 env.SConscript(['base/generic/general/SConscript'],'env')
280
281 env.SConscript(['base/generic/utilities/SConscript'],'env')
282
283 env.SConscript(['base/generic/compiler/SConscript'],'env')
284
285 env.SConscript(['base/generic/solver/SConscript'],'env')
286
287 env.SConscript(['base/generic/packages/SConscript'],'env')
288
289 if with_tcltk_gui:
290 env.SConscript(['tcltk98/generic/interface/SConscript'],'env')
291 else:
292 print "Skipping... Tcl/Tk GUI isn't being built"
293
294 if with_python:
295 env.SConscript(['pygtk/interface/SConscript'],'env')
296 else:
297 print "Skipping... Python GUI isn't being built"
298
299

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