/[ascend]/trunk/SConstruct
ViewVC logotype

Annotation of /trunk/SConstruct

Parent Directory Parent Directory | Revision Log Revision Log


Revision 398 - (hide annotations) (download)
Fri Mar 31 07:55:11 2006 UTC (14 years, 6 months ago) by johnpye
File size: 9890 byte(s)
Added SWIG version detection.
Added some ignore patterns for files in the repository.
1 johnpye 393 import os, commands, platform, distutils.sysconfig, os.path
2 johnpye 385
3     #------------------------------------------------------
4     # OPTIONS
5 johnpye 392 #
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 johnpye 385
9     opts = Options(['options.cache', 'config.py'])
10     print "PLATFORM = ",platform.system()
11    
12 johnpye 392 # Import the outside environment
13     env = Environment(ENV=os.environ)
14 johnpye 385
15     # Package linking option
16 johnpye 386 opts.Add(EnumOption(
17     'PACKAGE_LINKING'
18 johnpye 385 , 'Style of linking for external libraries'
19     , 'DYNAMIC_PACKAGES'
20 johnpye 386 , ['DYNAMIC_PACKAGES', 'STATIC_PACKAGES', 'NO_PACKAGES']
21     ))
22 johnpye 385
23 johnpye 392 # You can turn off building of Tcl/Tk interface
24 johnpye 386 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 johnpye 392 # You can turn off the building of the Python interface
31 johnpye 387 opts.Add(BoolOption(
32     'WITHOUT_PYTHON'
33     ,"Set to True if you don't want to build Python wrappers."
34     , False
35     ))
36    
37 johnpye 392 # Which solvers will we allow?
38     opts.Add(ListOption(
39     'WITH_SOLVERS'
40 johnpye 393 ,"List of the solvers you want to build. The default is the minimum that"
41     +" works."
42 johnpye 392 ,["QRSLV","CMSLV"]
43     ,['QRSLV','MPS','SLV','OPTSQP'
44     ,'NGSLV','CMSLV','LRSLV','MINOS','CONOPT'
45     ,'LSOD','OPTSQP'
46     ]
47     ))
48    
49 johnpye 393 # 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 johnpye 398 # What should the default ASCENDLIBRARY path be?
65     # Note: users can change it by editing their ~/.ascend.ini
66 johnpye 393 opts.Add(
67     'DEFAULT_ASCENDLIBRARY'
68     ,"Set the default value of the ASCENDLIBRARY -- the location where"
69     +" ASCEND will look for models when running ASCEND"
70     ,os.path.expanduser("~/src/ascend/trunk/models")
71     )
72    
73 johnpye 398 # Where is SWIG?
74     opts.Add(
75     'SWIG'
76     ,"SWIG location, probably only required for MinGW and MSVC users."
77     +" Enter the location as a Windows-style path, for example"
78     +" 'c:\msys\1.0\home\john\swigwin-1.3.29\swig.exe'."
79     )
80    
81 johnpye 393 # Where will the 'Makefile.bt' file be installed
82    
83 johnpye 392 # TODO: add install options
84    
85     # TODO: OTHER OPTIONS?
86    
87     # TODO: flags for optimisation
88    
89 johnpye 393 # TODO: turning on/off bintoken functionality
90    
91 johnpye 385 opts.Update(env)
92     opts.Save('options.cache',env)
93    
94     Help(opts.GenerateHelpText(env))
95    
96     env.Append(CPPDEFINES=env['PACKAGE_LINKING'])
97    
98 johnpye 386 with_tcltk_gui = (env['WITHOUT_TCLTK_GUI']==False)
99    
100 johnpye 387 with_python = (env['WITHOUT_PYTHON']==False)
101    
102 johnpye 392 print "SOLVERS:",env['WITH_SOLVERS']
103 johnpye 393
104     print "WITH_LOCAL_HELP:",env['WITH_LOCAL_HELP']
105     print "WITH_BINTOKEN:",env['WITH_BINTOKEN']
106     print "DEFAULT_ASCENDLIBRARY:",env['DEFAULT_ASCENDLIBRARY']
107    
108     subst_dict = {
109     '@WEBHELPROOT@':'http://pye.dyndns.org/ascend/manual/'
110     , '@GLADE_FILE@':'glade/ascend.glade'
111     , '@DEFAULT_ASCENDLIBRARY@':env['DEFAULT_ASCENDLIBRARY']
112     , '@ASCEND_ICON@':'glade/ascend.png'
113     , '@HELP_ROOT@':''
114     }
115    
116     if env['WITH_LOCAL_HELP']:
117     subst_dict['@HELP_ROOT@']=env['WITH_LOCAL_HELP']
118    
119     env.Append(SUBST_DICT=subst_dict)
120    
121 johnpye 385 #------------------------------------------------------
122 johnpye 398 # SPECIAL CONFIGURATION TESTS
123    
124     import os,re
125    
126     def CheckSwigVersion(context):
127     context.Message("Checking version of SWIG")
128     (cin,cout,cerr) = os.popen3(env['SWIG']+' -version');
129     output = cout.read()
130     err = cerr.read()
131     if err:
132     context.Result("Error running -version cmd:"+err)
133     return 0
134    
135     expr = re.compile("^SWIG Version (?P<maj>[0-9]+)\.(?P<min>[0-9]+)\.(?P<pat>[0-9]+)$",re.M);
136     m = expr.search(output);
137     if not m:
138     context.Result("Couldn't detect version")
139     return 0
140     maj = int(m.group('maj'))
141     min = int(m.group('min'))
142     pat = int(m.group('pat'))
143    
144     if maj == 1 and (
145     min > 1
146     or (min == 1 and pat >= 24)
147     ):
148     context.Result("ok, %d.%d.%d" % (maj,min,pat))
149     return 1;
150     context.Result("ok, %d.%d.%d" % (maj,min,pat))
151     return 0;
152    
153     #------------------------------------------------------
154 johnpye 385 # CONFIGURATION
155    
156     conf = Configure(env
157     , custom_tests = {
158     # 'CheckIsNan' : CheckIsNan
159     # ,'CheckCppUnitConfig' : CheckCppUnitConfig
160 johnpye 398 'CheckSwigVersion' : CheckSwigVersion
161 johnpye 385 }
162     , config_h = "config.h"
163     )
164    
165 johnpye 398 if not conf.CheckSwigVersion():
166     print 'SWIG version is not OK'
167     Exit(1)
168    
169 johnpye 385 # Math library
170     if not conf.CheckLibWithHeader(['m','c','libc'], 'math.h', 'C'):
171     print 'Did not find libm.a or m.lib, exiting!'
172     Exit(1)
173    
174     # Where is 'isnan'?
175    
176     if not conf.CheckFunc('isnan'):
177     print "Didn't find isnan"
178     Exit(1)
179    
180 johnpye 387 # Tcl/Tk
181 johnpye 386 if not conf.CheckHeader('tcl.h'):
182     with_tcltk_gui = False
183    
184     if not conf.CheckHeader('tk.h'):
185     with_tcltk_gui = False
186    
187     if not conf.CheckLib('tcl'):
188     with_tcltk_gui = False
189    
190     if not conf.CheckLib('tk'):
191     with_tcktk_gui = False
192    
193 johnpye 392
194 johnpye 395 # Python... obviously we're already running python, so we just need to
195     # check that we can link to the python library OK:
196    
197 johnpye 391 if platform.system()=="Windows":
198 johnpye 392 #conf.env.Append(LIBPATH='c:\Python24\libs')
199     #conf.env.Append(CPPPATH='c:\Python24\include')
200 johnpye 395 #python_header='Python.h'
201     python_lib='python24'
202 johnpye 392 #python_libpath=['c:\\Python24\\libs']
203     #python_cpppath=['c:\\Python24\\include']
204 johnpye 391 else:
205 johnpye 395 #python_header='python2.4/Python.h'
206     python_lib='python2.4'
207 johnpye 392 #python_libpath=[]
208     #python_cpppath=['/usr/include/python2.4']
209 johnpye 391
210 johnpye 395 #if not conf.CheckLibWithHeader(python_lib,python_header,'C'
211     # , LIBPATH=[distutils.sysconfig.PREFIX+"/libs"]
212     # , CPPPATH=[distutils.sysconfig.get_python_inc()]
213     #):
214     # print "Didn't find Python 2.4 ("+python_lib+")"
215     # with_python = False
216     #else:
217 johnpye 387
218 johnpye 395
219     # SWIG version
220    
221 johnpye 396 if platform.system()=="Windows":
222 johnpye 398 #env['SWIG']=['c:\\msys\\1.0\\home\\john\\swigwin-1.3.29\\swig.exe']
223 johnpye 396 env['ENV']['SWIGFEATURES']='-O'
224     else:
225     env['ENV']['SWIGFEATURES']='-O'
226 johnpye 395
227 johnpye 385 # TODO: -D_HPUX_SOURCE is needed
228    
229     # TODO: check size of void*
230    
231 johnpye 393 # TODO: detect if dynamic libraries are possible or not
232    
233 johnpye 395 conf.Finish()
234    
235     env.Append(PYTHON_LIBPATH=[distutils.sysconfig.PREFIX+"/libs"])
236     env.Append(PYTHON_LIB=[python_lib])
237     env.Append(PYTHON_CPPPATH=[distutils.sysconfig.get_python_inc()])
238     print "PYTHON_LIBPATH =",env['PYTHON_LIBPATH']
239     print "PYTHON_CPPPATH =",env['PYTHON_CPPPATH']
240    
241 johnpye 396 if not with_python:
242     print "Can't build python interface"
243     Exit(1)
244    
245 johnpye 385 #------------------------------------------------------
246 johnpye 393 # RECIPE: 'SubstInFile', used in pygtk SConscript
247    
248     import re
249 johnpye 395 from SCons.Script import * # the usual scons stuff you get in a SConscript
250 johnpye 393
251 johnpye 395 def TOOL_SUBST(env):
252     """Adds SubstInFile builder, which substitutes the keys->values of SUBST_DICT
253     from the source to the target.
254     The values of SUBST_DICT first have any construction variables expanded
255     (its keys are not expanded).
256     If a value of SUBST_DICT is a python callable function, it is called and
257     the result is expanded as the value.
258     If there's more than one source and more than one target, each target gets
259     substituted from the corresponding source.
260 johnpye 393 """
261 johnpye 395 env.Append(TOOLS = 'SUBST')
262     def do_subst_in_file(targetfile, sourcefile, dict):
263     """Replace all instances of the keys of dict with their values.
264     For example, if dict is {'%VERSION%': '1.2345', '%BASE%': 'MyProg'},
265     then all instances of %VERSION% in the file will be replaced with 1.2345 etc.
266     """
267     try:
268     f = open(sourcefile, 'rb')
269     contents = f.read()
270     f.close()
271     except:
272     raise SCons.Errors.UserError, "Can't read source file %s"%sourcefile
273     for (k,v) in dict.items():
274     contents = re.sub(k, v, contents)
275     try:
276     f = open(targetfile, 'wb')
277     f.write(contents)
278     f.close()
279     except:
280     raise SCons.Errors.UserError, "Can't write target file %s"%targetfile
281     return 0 # success
282 johnpye 393
283 johnpye 395 def subst_in_file(target, source, env):
284     if not env.has_key('SUBST_DICT'):
285     raise SCons.Errors.UserError, "SubstInFile requires SUBST_DICT to be set."
286     d = dict(env['SUBST_DICT']) # copy it
287     for (k,v) in d.items():
288     if callable(v):
289     d[k] = env.subst(v())
290     elif SCons.Util.is_String(v):
291     d[k]=env.subst(v)
292     else:
293     raise SCons.Errors.UserError, "SubstInFile: key %s: %s must be a string or callable"%(k, repr(v))
294     for (t,s) in zip(target, source):
295     return do_subst_in_file(str(t), str(s), d)
296 johnpye 393
297 johnpye 395 def subst_in_file_string(target, source, env):
298     """This is what gets printed on the console."""
299     return '\n'.join(['Substituting vars from %s into %s'%(str(s), str(t))
300     for (t,s) in zip(target, source)])
301 johnpye 393
302 johnpye 395 def subst_emitter(target, source, env):
303     """Add dependency from substituted SUBST_DICT to target.
304     Returns original target, source tuple unchanged.
305     """
306     d = env['SUBST_DICT'].copy() # copy it
307     for (k,v) in d.items():
308     if callable(v):
309     d[k] = env.subst(v())
310     elif SCons.Util.is_String(v):
311     d[k]=env.subst(v)
312     Depends(target, SCons.Node.Python.Value(d))
313     return target, source
314 johnpye 393
315 johnpye 395 subst_action=SCons.Action.Action(subst_in_file, subst_in_file_string)
316     env['BUILDERS']['SubstInFile'] = Builder(action=subst_action, emitter=subst_emitter)
317    
318     TOOL_SUBST(env)
319    
320 johnpye 393 #------------------------------------------------------
321 johnpye 385 # SUBDIRECTORIES....
322    
323 johnpye 393
324 johnpye 385 env.Append(CPPPATH=['..'])
325    
326     env.SConscript(['base/generic/general/SConscript'],'env')
327    
328     env.SConscript(['base/generic/utilities/SConscript'],'env')
329    
330     env.SConscript(['base/generic/compiler/SConscript'],'env')
331    
332     env.SConscript(['base/generic/solver/SConscript'],'env')
333    
334     env.SConscript(['base/generic/packages/SConscript'],'env')
335 johnpye 386
336     if with_tcltk_gui:
337     env.SConscript(['tcltk98/generic/interface/SConscript'],'env')
338 johnpye 391 else:
339     print "Skipping... Tcl/Tk GUI isn't being built"
340 johnpye 386
341 johnpye 387 if with_python:
342     env.SConscript(['pygtk/interface/SConscript'],'env')
343 johnpye 391 else:
344     print "Skipping... Python GUI isn't being built"

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