/[ascend]/trunk/SConstruct
ViewVC logotype

Annotation of /trunk/SConstruct

Parent Directory Parent Directory | Revision Log Revision Log


Revision 396 - (hide annotations) (download)
Fri Mar 31 06:24:11 2006 UTC (13 years, 8 months 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 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     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 johnpye 392 # TODO: add install options
74    
75     # TODO: OTHER OPTIONS?
76    
77     # TODO: flags for optimisation
78    
79 johnpye 393 # TODO: turning on/off bintoken functionality
80    
81 johnpye 385 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 johnpye 386 with_tcltk_gui = (env['WITHOUT_TCLTK_GUI']==False)
89    
90 johnpye 387 with_python = (env['WITHOUT_PYTHON']==False)
91    
92 johnpye 392 print "SOLVERS:",env['WITH_SOLVERS']
93 johnpye 393
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 johnpye 385 #------------------------------------------------------
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 johnpye 387 # Tcl/Tk
134 johnpye 386 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 johnpye 392
147 johnpye 395 # 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 johnpye 391 if platform.system()=="Windows":
151 johnpye 392 #conf.env.Append(LIBPATH='c:\Python24\libs')
152     #conf.env.Append(CPPPATH='c:\Python24\include')
153 johnpye 395 #python_header='Python.h'
154     python_lib='python24'
155 johnpye 392 #python_libpath=['c:\\Python24\\libs']
156     #python_cpppath=['c:\\Python24\\include']
157 johnpye 391 else:
158 johnpye 395 #python_header='python2.4/Python.h'
159     python_lib='python2.4'
160 johnpye 392 #python_libpath=[]
161     #python_cpppath=['/usr/include/python2.4']
162 johnpye 391
163 johnpye 395 #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 johnpye 387
171 johnpye 395
172     # SWIG version
173    
174 johnpye 396 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 johnpye 395
180 johnpye 385 # TODO: -D_HPUX_SOURCE is needed
181    
182     # TODO: check size of void*
183    
184 johnpye 393 # TODO: detect if dynamic libraries are possible or not
185    
186 johnpye 395 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 johnpye 396 if not with_python:
195     print "Can't build python interface"
196     Exit(1)
197    
198 johnpye 385 #------------------------------------------------------
199 johnpye 393 # RECIPE: 'SubstInFile', used in pygtk SConscript
200    
201     import re
202 johnpye 395 from SCons.Script import * # the usual scons stuff you get in a SConscript
203 johnpye 393
204 johnpye 395 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 johnpye 393 """
214 johnpye 395 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 johnpye 393
236 johnpye 395 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 johnpye 393
250 johnpye 395 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 johnpye 393
255 johnpye 395 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 johnpye 393
268 johnpye 395 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 johnpye 393 #------------------------------------------------------
274 johnpye 385 # SUBDIRECTORIES....
275    
276 johnpye 393
277 johnpye 385 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 johnpye 386
289     if with_tcltk_gui:
290     env.SConscript(['tcltk98/generic/interface/SConscript'],'env')
291 johnpye 391 else:
292     print "Skipping... Tcl/Tk GUI isn't being built"
293 johnpye 386
294 johnpye 387 if with_python:
295     env.SConscript(['pygtk/interface/SConscript'],'env')
296 johnpye 391 else:
297     print "Skipping... Python GUI isn't being built"
298    
299 johnpye 393

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