/[ascend]/trunk/SConstruct
ViewVC logotype

Annotation of /trunk/SConstruct

Parent Directory Parent Directory | Revision Log Revision Log


Revision 393 - (hide annotations) (download)
Thu Mar 30 14:46:37 2006 UTC (13 years, 8 months ago) by johnpye
File size: 6842 byte(s)
Fixed SCons build to do output of config file 'config.py' require
by PyGTK GUI. Removed requirement for 'config.h' from the C++ file
and instead supplied required flags via compiler commandline.
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 391 if platform.system()=="Windows":
148 johnpye 392 #conf.env.Append(LIBPATH='c:\Python24\libs')
149     #conf.env.Append(CPPPATH='c:\Python24\include')
150 johnpye 391 python_header='Python.h'
151 johnpye 392 python_lib=['python24']
152     #python_libpath=['c:\\Python24\\libs']
153     #python_cpppath=['c:\\Python24\\include']
154 johnpye 391 else:
155     python_header='python2.4/Python.h'
156 johnpye 392 python_lib=['python2.4']
157     #python_libpath=[]
158     #python_cpppath=['/usr/include/python2.4']
159    
160 johnpye 391
161 johnpye 387 # Python
162 johnpye 391 if not conf.CheckLibWithHeader(python_lib,python_header,'C'):
163     print "Didn't find Python 2.4 ("+python_lib+")"
164 johnpye 387 with_python = False
165     else:
166 johnpye 392 env.Append(PYTHON_LIBPATH=[distutils.sysconfig.PREFIX+"/libs"])
167     #env.Append(PYTHON_LIB=python_lib)
168     env.Append(PYTHON_CPPPATH=[distutils.sysconfig.get_python_inc()])
169     print "PYTHON_LIBPATH =",env['PYTHON_LIBPATH']
170     print "PYTHON_CPPPATH =",env['PYTHON_CPPPATH']
171 johnpye 387
172 johnpye 385 # TODO: -D_HPUX_SOURCE is needed
173    
174     # TODO: check size of void*
175    
176 johnpye 393 # TODO: detect if dynamic libraries are possible or not
177    
178 johnpye 385 #------------------------------------------------------
179 johnpye 393 # RECIPE: 'SubstInFile', used in pygtk SConscript
180    
181     import SCons.Util
182     import re
183    
184     def do_subst_in_file(targetfile, sourcefile, dict):
185     """Replace all instances of the keys of dict with their values.
186     For example, if dict is {'%VERSION%': '1.2345', '%BASE%': 'MyProg'},
187     then all instances of %VERSION% in the file will be replaced with 1.2345 etc.
188     """
189     try:
190     f = open(sourcefile, 'rb')
191     contents = f.read()
192     f.close()
193     except:
194     raise RuntimeError("Can't read source file %s" % sourcefile)
195     for (k,v) in dict.items():
196     contents = re.sub(k, v, contents)
197     try:
198     f = open(targetfile, 'wb')
199     f.write(contents)
200     f.close()
201     except:
202     raise RuntimeError("Can't write target file %s" % targetfile)
203     return 0 # success
204    
205     def subst_in_file(target, source, env):
206     if not env.has_key('SUBST_DICT'):
207     raise RuntimeError("SubstInFile requires SUBST_DICT to be set.")
208     d = dict(env['SUBST_DICT']) # copy it
209     for (k,v) in d.items():
210     if callable(v):
211     d[k] = env.subst(v())
212     elif SCons.Util.is_String(v):
213     d[k]=env.subst(v)
214     else:
215     raise RuntimeError(
216     "SubstInFile: key %s: %s must be a string or callable" % (
217     k, repr(v)
218     ))
219     for (t,s) in zip(target, source):
220     return do_subst_in_file(str(t), str(s), d)
221    
222     def subst_in_file_string(target, source, env):
223     """This is what gets printed on the console."""
224     return '\n'.join(['Substituting vars from %s into %s'%(str(s), str(t))
225     for (t,s) in zip(target, source)])
226    
227     env['BUILDERS']['SubstInFile'] = Builder(
228     action = subst_in_file
229     , suffix = ''
230     , src_suffix = '.in'
231     )
232    
233     #------------------------------------------------------
234 johnpye 385 # SUBDIRECTORIES....
235    
236 johnpye 393
237 johnpye 385 env.Append(CPPPATH=['..'])
238    
239     env.SConscript(['base/generic/general/SConscript'],'env')
240    
241     env.SConscript(['base/generic/utilities/SConscript'],'env')
242    
243     env.SConscript(['base/generic/compiler/SConscript'],'env')
244    
245     env.SConscript(['base/generic/solver/SConscript'],'env')
246    
247     env.SConscript(['base/generic/packages/SConscript'],'env')
248 johnpye 386
249     if with_tcltk_gui:
250     env.SConscript(['tcltk98/generic/interface/SConscript'],'env')
251 johnpye 391 else:
252     print "Skipping... Tcl/Tk GUI isn't being built"
253 johnpye 386
254 johnpye 387 if with_python:
255     env.SConscript(['pygtk/interface/SConscript'],'env')
256 johnpye 391 else:
257     print "Skipping... Python GUI isn't being built"
258    
259 johnpye 393

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