/[ascend]/trunk/SConstruct
ViewVC logotype

Annotation of /trunk/SConstruct

Parent Directory Parent Directory | Revision Log Revision Log


Revision 459 - (hide annotations) (download)
Fri Apr 7 08:05:05 2006 UTC (13 years, 10 months ago) by johnpye
File size: 19589 byte(s)
Fixing default PackageOption values
Adding --library option to gtkbrowser for ASC_DEVELOPING override of 'models' path.
1 johnpye 393 import os, commands, platform, distutils.sysconfig, os.path
2 johnpye 385
3 johnpye 439 version = "0.9.6rc0"
4    
5 johnpye 385 #------------------------------------------------------
6     # OPTIONS
7 johnpye 392 #
8     # Note that if you set the options via the command line, they will be
9     # remembered in the file 'options.cache'. It's a feature ;-)
10 johnpye 385
11     opts = Options(['options.cache', 'config.py'])
12     print "PLATFORM = ",platform.system()
13    
14 johnpye 392 # Import the outside environment
15     env = Environment(ENV=os.environ)
16 johnpye 385
17 johnpye 415 if platform.system()=='Windows' and env.has_key('MSVS'):
18 johnpye 414 print "INCLUDE =",env['ENV']['INCLUDE']
19 johnpye 416 print "LIB =",env['ENV']['LIB']
20     print "LINK =",env['LINK']
21     print "LINKCOM =",env['LINKCOM']
22     print "AR =",env['AR']
23     print "ARCOM =",env['ARCOM']
24 johnpye 427 #env['AR']='link /lib'
25 johnpye 414 env.Append(CPPPATH=env['ENV']['INCLUDE'])
26     env.Append(LIBPATH=env['ENV']['LIB'])
27 johnpye 427 env.Append(CPPDEFINES=['_CRT_SECURE_NO_DEPRECATED','_CRT_SECURE_NO_DEPRECATE'])
28 johnpye 414
29 johnpye 385 # Package linking option
30 johnpye 386 opts.Add(EnumOption(
31     'PACKAGE_LINKING'
32 johnpye 385 , 'Style of linking for external libraries'
33     , 'DYNAMIC_PACKAGES'
34 johnpye 386 , ['DYNAMIC_PACKAGES', 'STATIC_PACKAGES', 'NO_PACKAGES']
35     ))
36 johnpye 385
37 johnpye 392 # You can turn off building of Tcl/Tk interface
38 johnpye 386 opts.Add(BoolOption(
39     'WITHOUT_TCLTK_GUI'
40     ,"Set to True if you don't want to build the original Tcl/Tk GUI."
41     , False
42     ))
43    
44 johnpye 392 # You can turn off the building of the Python interface
45 johnpye 387 opts.Add(BoolOption(
46     'WITHOUT_PYTHON'
47     ,"Set to True if you don't want to build Python wrappers."
48     , False
49     ))
50    
51 johnpye 392 # Which solvers will we allow?
52     opts.Add(ListOption(
53     'WITH_SOLVERS'
54 johnpye 393 ,"List of the solvers you want to build. The default is the minimum that"
55     +" works."
56 johnpye 392 ,["QRSLV","CMSLV"]
57     ,['QRSLV','MPS','SLV','OPTSQP'
58     ,'NGSLV','CMSLV','LRSLV','MINOS','CONOPT'
59     ,'LSOD','OPTSQP'
60     ]
61     ))
62    
63 johnpye 393 # Where will the local copy of the help files be kept?
64     opts.Add(PackageOption(
65     'WITH_LOCAL_HELP'
66     , "Directory containing the local copy of the help files (optional)"
67     , "no"
68     ))
69    
70     # Will bintoken support be enabled?
71     opts.Add(BoolOption(
72     'WITH_BINTOKEN'
73     ,"Enable bintoken support? This means compiling models as C-code before"
74     +" running them, to increase solving speed for large models."
75     ,False
76     ))
77    
78 johnpye 398 # What should the default ASCENDLIBRARY path be?
79     # Note: users can change it by editing their ~/.ascend.ini
80 johnpye 393 opts.Add(
81     'DEFAULT_ASCENDLIBRARY'
82     ,"Set the default value of the ASCENDLIBRARY -- the location where"
83     +" ASCEND will look for models when running ASCEND"
84 johnpye 459 ,"$INSTALL_DATA/models"
85 johnpye 393 )
86    
87 johnpye 398 # Where is SWIG?
88     opts.Add(
89     'SWIG'
90     ,"SWIG location, probably only required for MinGW and MSVC users."
91     +" Enter the location as a Windows-style path, for example"
92 johnpye 404 +" 'c:\\msys\\1.0\\home\\john\\swigwin-1.3.29\\swig.exe'."
93 johnpye 398 )
94    
95 johnpye 400 # Build the test suite?
96     opts.Add(BoolOption(
97     'WITH_CUNIT_TESTS'
98     ,"Whether to build the CUnit tests. Default is off. If set to on,"
99     +" you must have CUnit installed somewhere that SCons can"
100     +" find it."
101     ,False
102     ))
103 johnpye 393
104 johnpye 400 # Where are the CUnit includes?
105     opts.Add(PackageOption(
106     'CUNIT_CPPPATH'
107     ,"Where are your CUnit include files?"
108 johnpye 459 ,'off'
109 johnpye 400 ))
110 johnpye 392
111 johnpye 404 # Where are the CUnit libraries?
112 johnpye 400 opts.Add(PackageOption(
113     'CUNIT_LIBPATH'
114 johnpye 404 ,"Where are your CUnit libraries?"
115 johnpye 459 ,'off'
116 johnpye 400 ))
117    
118 johnpye 404 # Where are the Tcl includes?
119     opts.Add(PackageOption(
120     'TCL_CPPPATH'
121     ,"Where are your Tcl include files?"
122 johnpye 459 ,'off'
123 johnpye 404 ))
124    
125     # Where are the Tcl libs?
126     opts.Add(PackageOption(
127     'TCL_LIBPATH'
128     ,"Where are your Tcl libraries?"
129 johnpye 459 ,'off'
130 johnpye 404 ))
131    
132 johnpye 428 # What is the name of the Tcl lib?
133     opts.Add(
134     'TCL_LIB'
135     ,"Name of Tcl lib (eg 'tcl' or 'tcl83')"
136     ,'tcl'
137     )
138    
139 johnpye 405 # Where are the Tk includes?
140     opts.Add(PackageOption(
141     'TK_CPPPATH'
142     ,"Where are your Tk include files?"
143 johnpye 459 ,'off'
144 johnpye 405 ))
145 johnpye 404
146 johnpye 405 # Where are the Tk libs?
147     opts.Add(PackageOption(
148     'TK_LIBPATH'
149     ,"Where are your Tk libraries?"
150 johnpye 459 ,'off'
151 johnpye 405 ))
152    
153 johnpye 428 # What is the name of the Tk lib?
154     opts.Add(
155     'TK_LIB'
156     ,"Name of Tk lib (eg 'tk' or 'tk83')"
157     ,'tk'
158 johnpye 435 )
159    
160     opts.Add(
161     'INSTALL_PREFIX'
162     ,'Root location for installed files'
163 johnpye 449 ,'/usr/local'
164 johnpye 428 )
165    
166 johnpye 435 opts.Add(
167     'INSTALL_BIN'
168     ,'Location to put binaries during installation'
169     ,"$INSTALL_PREFIX/bin"
170     )
171    
172     opts.Add(
173     'INSTALL_DATA'
174     ,'Location to put data files during installation'
175     ,"$INSTALL_PREFIX/share"
176     )
177    
178     opts.Add(
179     'INSTALL_INCLUDE'
180     ,'Location to put header files during installation'
181     ,"$INSTALL_PREFIX/include"
182     )
183    
184 johnpye 455 if platform.system()=="Windows":
185     default_install_assets = "glade/"
186     icon_extension = '.png'
187     else:
188     default_install_assets = "$INSTALL_DATA/ascend/glade/"
189     icon_extension = '.svg'
190    
191 johnpye 448 opts.Add(
192 johnpye 455 'PYGTK_ASSETS'
193     ,'Default location for Glade assets (placed in pygtk/interface/config.py)'
194     ,default_install_assets
195     )
196    
197     opts.Add(
198 johnpye 448 'INSTALL_ROOT'
199     ,'For use by RPM only: location of %{buildroot} during rpmbuild'
200     ,""
201     )
202    
203 johnpye 392 # TODO: OTHER OPTIONS?
204     # TODO: flags for optimisation
205 johnpye 393 # TODO: turning on/off bintoken functionality
206 johnpye 427 # TODO: Where will the 'Makefile.bt' file be installed?
207 johnpye 393
208 johnpye 385 opts.Update(env)
209     opts.Save('options.cache',env)
210    
211     Help(opts.GenerateHelpText(env))
212    
213 johnpye 386 with_tcltk_gui = (env['WITHOUT_TCLTK_GUI']==False)
214 johnpye 427 without_tcltk_reason = "disabled by options/config.py"
215 johnpye 386
216 johnpye 387 with_python = (env['WITHOUT_PYTHON']==False)
217 johnpye 427 without_python_reason = "disabled by options/config.py"
218 johnpye 387
219 johnpye 400 with_cunit_tests = env['WITH_CUNIT_TESTS']
220 johnpye 427 without_cunit_reason = "not requested"
221 johnpye 400
222 johnpye 392 print "SOLVERS:",env['WITH_SOLVERS']
223 johnpye 393 print "WITH_LOCAL_HELP:",env['WITH_LOCAL_HELP']
224     print "WITH_BINTOKEN:",env['WITH_BINTOKEN']
225     print "DEFAULT_ASCENDLIBRARY:",env['DEFAULT_ASCENDLIBRARY']
226    
227     subst_dict = {
228     '@WEBHELPROOT@':'http://pye.dyndns.org/ascend/manual/'
229 johnpye 436 , '@GLADE_FILE@':'ascend.glade'
230 johnpye 393 , '@DEFAULT_ASCENDLIBRARY@':env['DEFAULT_ASCENDLIBRARY']
231 johnpye 455 , '@ICON_EXTENSION@':icon_extension
232 johnpye 393 , '@HELP_ROOT@':''
233 johnpye 436 , '@INSTALL_DATA@':env['INSTALL_DATA']
234     , '@INSTALL_BIN@':env['INSTALL_BIN']
235     , '@INSTALL_INCLUDE@':env['INSTALL_INCLUDE']
236 johnpye 455 , '@PYGTK_ASSETS@':env['PYGTK_ASSETS']
237 johnpye 439 , '@VERSION@':version
238 johnpye 393 }
239    
240     if env['WITH_LOCAL_HELP']:
241     subst_dict['@HELP_ROOT@']=env['WITH_LOCAL_HELP']
242    
243     env.Append(SUBST_DICT=subst_dict)
244    
245 johnpye 385 #------------------------------------------------------
246 johnpye 398 # SPECIAL CONFIGURATION TESTS
247    
248 johnpye 400 #----------------
249     # SWIG
250    
251 johnpye 398 import os,re
252    
253 johnpye 427 need_fortran = False
254    
255 johnpye 413 def get_swig_version(env):
256 johnpye 403 cmd = env['SWIG']+' -version'
257 johnpye 427 (cin,coutcerr) = os.popen4(cmd)
258 johnpye 403 output = coutcerr.read()
259 johnpye 398
260 johnpye 403 restr = "SWIG\\s+Version\\s+(?P<maj>[0-9]+)\\.(?P<min>[0-9]+)\\.(?P<pat>[0-9]+)\\s*$"
261     expr = re.compile(restr,re.M);
262 johnpye 398 m = expr.search(output);
263     if not m:
264 johnpye 413 return None
265 johnpye 398 maj = int(m.group('maj'))
266     min = int(m.group('min'))
267     pat = int(m.group('pat'))
268 johnpye 413
269     return (maj,min,pat)
270 johnpye 398
271 johnpye 413
272     def CheckSwigVersion(context):
273    
274     try:
275     context.Message("Checking version of SWIG... ")
276     maj,min,pat = get_swig_version(context.env)
277     except:
278     context.Result("Failed to detect version, or failed to run SWIG")
279     return 0;
280    
281 johnpye 398 if maj == 1 and (
282 johnpye 400 min > 3
283     or (min == 3 and pat >= 24)
284 johnpye 398 ):
285     context.Result("ok, %d.%d.%d" % (maj,min,pat))
286     return 1;
287 johnpye 401 else:
288     context.Result("too old, %d.%d.%d" % (maj,min,pat))
289     return 0;
290 johnpye 398
291 johnpye 400 #----------------
292     # General purpose library-and-header test
293    
294 johnpye 404 class KeepContext:
295     def __init__(self,context,varprefix):
296     self.keep = {}
297     for k in ['LIBS','LIBPATH','CPPPATH']:
298     if context.env.has_key(k):
299     self.keep[k] = context.env[k]
300    
301     libpath_add = []
302     if context.env.has_key(varprefix+'_LIBPATH'):
303     libpath_add = [env[varprefix+'_LIBPATH']]
304 johnpye 428 #print "Adding '"+str(libpath_add)+"' to lib path"
305 johnpye 400
306 johnpye 404 cpppath_add = []
307     if context.env.has_key(varprefix+'_CPPPATH'):
308     cpppath_add = [env[varprefix+'_CPPPATH']]
309 johnpye 428 #print "Adding '"+str(cpppath_add)+"' to cpp path"
310    
311     libs_add = []
312     if context.env.has_key(varprefix+'_LIB'):
313     libs_add = [env[varprefix+'_LIB']]
314     #print "Adding '"+str(libs_add)+"' to libs"
315    
316 johnpye 405 context.env.Append(
317     LIBPATH = libpath_add
318     , CPPPATH = cpppath_add
319 johnpye 428 , LIBS = libs_add
320 johnpye 405 )
321 johnpye 404
322     def restore(self,context):
323     for k in self.keep:
324     context.env[k]=self.keep[k];
325    
326 johnpye 400 def CheckExtLib(context,libname,text,ext='.c',varprefix=None):
327     """This method will check for variables LIBNAME_LIBPATH
328     and LIBNAME_CPPPATH and try to compile and link the
329     file with the provided text, linking with the
330     library libname."""
331    
332 johnpye 405 context.Message( 'Checking for '+libname+'... ' )
333 johnpye 400
334     if varprefix==None:
335     varprefix = libname.upper()
336    
337 johnpye 404 keep = KeepContext(context,varprefix)
338 johnpye 400
339 johnpye 428 # print "TryLink with CPPPATH="+str(context.env['CPPPATH'])
340     # print "TryLink with LIBS="+str(context.env['LIBS'])
341     # print "TryLink with LIBPATH="+str(context.env['LIBPATH'])
342 johnpye 405
343 johnpye 428 if not context.env.has_key(varprefix+'_LIB'):
344 johnpye 451 context.env.Append(LIBS=libname)
345 johnpye 428
346 johnpye 404 is_ok = context.TryLink(text,ext)
347 johnpye 428
348     # print "Link success? ",(is_ok != 0)
349 johnpye 400
350 johnpye 405 keep.restore(context)
351 johnpye 400
352 johnpye 428 # print "Restored CPPPATH="+str(context.env['CPPPATH'])
353     # print "Restored LIBS="+libname
354     # print "Restored LIBPATH="+str(context.env['LIBPATH'])
355    
356 johnpye 404 context.Result(is_ok)
357     return is_ok
358    
359     #----------------
360     # CUnit test
361    
362 johnpye 400 cunit_test_text = """
363 johnpye 451 #include <CUnit/CUnit.h>
364 johnpye 400 int maxi(int i1, int i2){
365     return (i1 > i2) ? i1 : i2;
366     }
367    
368     void test_maxi(void){
369     CU_ASSERT(maxi(0,2) == 2);
370     CU_ASSERT(maxi(0,-2) == 0);
371     CU_ASSERT(maxi(2,2) == 2);
372    
373     }
374     int main(void){
375     /* CU_initialize_registry() */
376 johnpye 404 return 0;
377 johnpye 400 }
378     """
379    
380     def CheckCUnit(context):
381 johnpye 451 return CheckExtLib(context,'cunit',cunit_test_text)
382 johnpye 400
383 johnpye 404 #----------------
384 johnpye 405 # Tcl test
385 johnpye 404
386     tcl_check_text = r"""
387     #include <tcl.h>
388     #include <stdio.h>
389     int main(void){
390     printf("%s",TCL_PATCH_LEVEL);
391     return 0;
392     }
393     """
394    
395     def CheckTcl(context):
396 johnpye 405 return CheckExtLib(context,'tcl',tcl_check_text)
397    
398     def CheckTclVersion(context):
399 johnpye 404 keep = KeepContext(context,'TCL')
400 johnpye 405 context.Message("Checking Tcl version... ")
401     (is_ok,output) = context.TryRun(tcl_check_text,'.c')
402 johnpye 404 keep.restore(context)
403     if not is_ok:
404 johnpye 405 context.Result("failed to run check")
405 johnpye 404 return 0
406 johnpye 405
407     major,minor,patch = tuple(int(i) for i in output.split("."))
408     if major != 8 or minor > 3:
409 johnpye 428 context.Result(output+" (bad version)")
410 johnpye 405 # bad version
411     return 0
412    
413     # good version
414 johnpye 428 context.Result(output+" (good)")
415 johnpye 404 return 1
416    
417 johnpye 405 #----------------
418     # Tcl test
419    
420     tk_check_text = r"""
421     #include <tk.h>
422     #include <stdio.h>
423     int main(void){
424     printf("%s",TK_PATCH_LEVEL);
425     return 0;
426     }
427     """
428     def CheckTk(context):
429 johnpye 428 return CheckExtLib(context,'tk',tcl_check_text)
430 johnpye 405
431 johnpye 428
432 johnpye 405 def CheckTkVersion(context):
433     keep = KeepContext(context,'TK')
434     context.Message("Checking Tk version... ")
435     (is_ok,output) = context.TryRun(tk_check_text,'.c')
436 johnpye 404 keep.restore(context)
437     if not is_ok:
438     context.Result("failed to run check")
439     return 0
440     context.Result(output)
441    
442     major,minor,patch = tuple(int(i) for i in output.split("."))
443     if major != 8 or minor > 3:
444     # bad version
445     return 0
446 johnpye 400
447 johnpye 404 # good version
448     return 1
449    
450 johnpye 398 #------------------------------------------------------
451 johnpye 385 # CONFIGURATION
452    
453     conf = Configure(env
454     , custom_tests = {
455 johnpye 398 'CheckSwigVersion' : CheckSwigVersion
456 johnpye 400 , 'CheckCUnit' : CheckCUnit
457 johnpye 404 , 'CheckTcl' : CheckTcl
458     , 'CheckTclVersion' : CheckTclVersion
459 johnpye 405 , 'CheckTk' : CheckTk
460     , 'CheckTkVersion' : CheckTkVersion
461 johnpye 400 # , 'CheckIsNan' : CheckIsNan
462     # , 'CheckCppUnitConfig' : CheckCppUnitConfig
463 johnpye 385 }
464 johnpye 459 # , config_h = "config.h"
465 johnpye 385 )
466    
467 johnpye 398
468 johnpye 385 # Math library
469    
470 johnpye 427 #if not conf.CheckFunc('sinh') and not conf.CheckLibWithHeader(['m','c','libc'], 'math.h', 'C'):
471     # print 'Did not find math library, exiting!'
472     # Exit(1)
473    
474 johnpye 385 # Where is 'isnan'?
475    
476     if not conf.CheckFunc('isnan'):
477     print "Didn't find isnan"
478 johnpye 414 # Exit(1)
479 johnpye 385
480 johnpye 387 # Tcl/Tk
481 johnpye 386
482 johnpye 428 if conf.CheckTcl():
483     if with_tcltk_gui and conf.CheckTclVersion():
484     if conf.CheckTk():
485     if with_tcltk_gui and not conf.CheckTkVersion():
486     without_tcltk_reason = "Require Tk version <= 8.3. See 'scons -h'"
487     with_tcltk_gui = False
488     else:
489     without_tcltk_reason = "Tk not found."
490     with_tcltk_gui = False
491     else:
492 johnpye 405 without_tcltk_reason = "Require Tcl <= 8.3 Tcl."
493 johnpye 404 with_tcltk_gui = False
494 johnpye 386
495 johnpye 405 else:
496 johnpye 428 without_tcltk_reason = "Tcl not found."
497 johnpye 412 with_tcltk_gui = False
498    
499 johnpye 395 # Python... obviously we're already running python, so we just need to
500     # check that we can link to the python library OK:
501    
502 johnpye 391 if platform.system()=="Windows":
503 johnpye 395 python_lib='python24'
504 johnpye 391 else:
505 johnpye 395 python_lib='python2.4'
506 johnpye 391
507 johnpye 395 # SWIG version
508    
509 johnpye 396 if platform.system()=="Windows":
510     env['ENV']['SWIGFEATURES']='-O'
511     else:
512     env['ENV']['SWIGFEATURES']='-O'
513 johnpye 395
514 johnpye 413
515     if not conf.CheckSwigVersion():
516     without_python_reason = 'SWIG >= 1.3.24 is required'
517     with_python = False
518    
519 johnpye 400 # CUnit
520    
521     if with_cunit_tests:
522 johnpye 404 if not conf.CheckCUnit():
523 johnpye 427 without_cunit_reason = 'CUnit not found'
524    
525     # BLAS
526    
527 johnpye 459 need_blas=False
528     if with_tcltk_gui:
529     need_blas=True
530     if need_blas:
531     if conf.CheckLib('blas'):
532     print "FOUND BLAS"
533     with_local_blas = False
534     without_local_blas_reason = "Found BLAS installed on system"
535     else:
536     print "DIDN'T FIND BLAS"
537     with_local_blas = True
538     need_fortran = True
539 johnpye 427
540     # FORTRAN
541    
542     if need_fortran:
543     conf.env.Tool('f77')
544     detect_fortran = conf.env.Detect(['g77','f77'])
545     if detect_fortran:
546     # For some reason, g77 doesn't get detected properly on MinGW
547     if not env.has_key('F77'):
548     conf.env.Replace(F77=detect_fortran)
549     conf.env.Replace(F77COM='$F77 $F77FLAGS -c -o $TARGET $SOURCE')
550     conf.env.Replace(F77FLAGS='')
551 johnpye 428 #print "F77:",conf.env['F77']
552     #print "F77COM:",conf.env['F77COM']
553     #print "F77FLAGS:",conf.env['F77FLAGS']
554 johnpye 427 fortran_builder = Builder(
555     action='$F77COM'
556     , suffix='.o'
557     , src_suffix='.f'
558     )
559     conf.env.Append(BUILDERS={'Fortran':fortran_builder})
560     else:
561     print "FORTRAN-77 required but not found"
562 johnpye 404 Exit(1)
563 johnpye 427 else:
564     print "FORTRAN not required"
565 johnpye 400
566 johnpye 385 # TODO: -D_HPUX_SOURCE is needed
567    
568     # TODO: check size of void*
569    
570 johnpye 393 # TODO: detect if dynamic libraries are possible or not
571    
572 johnpye 427 if platform.system()=="Windows" and env.has_key('MSVS'):
573     if not conf.CheckHeader('windows.h') and env['PACKAGE_LINKING']=='DYNAMIC_PACKAGES':
574     print "Reverting to STATIC_PACKAGES since windows.h is not available. Probably you "\
575     +"need to install the Microsoft Windows Server 2003 Platform SDK, or similar."
576     env['PACKAGE_LINKING']='STATIC_PACKAGES'
577    
578     if with_python and not conf.CheckHeader('basetsd.h'):
579     with_python = 0;
580     without_python_reason = "Header file 'basetsd.h' not found. Install the MS Platform SDK."
581    
582     conf.env.Append(CPPDEFINES=env['PACKAGE_LINKING'])
583    
584 johnpye 395 conf.Finish()
585    
586     env.Append(PYTHON_LIBPATH=[distutils.sysconfig.PREFIX+"/libs"])
587     env.Append(PYTHON_LIB=[python_lib])
588     env.Append(PYTHON_CPPPATH=[distutils.sysconfig.get_python_inc()])
589    
590 johnpye 385 #------------------------------------------------------
591 johnpye 393 # RECIPE: 'SubstInFile', used in pygtk SConscript
592    
593     import re
594 johnpye 395 from SCons.Script import * # the usual scons stuff you get in a SConscript
595 johnpye 393
596 johnpye 395 def TOOL_SUBST(env):
597     """Adds SubstInFile builder, which substitutes the keys->values of SUBST_DICT
598     from the source to the target.
599     The values of SUBST_DICT first have any construction variables expanded
600     (its keys are not expanded).
601     If a value of SUBST_DICT is a python callable function, it is called and
602     the result is expanded as the value.
603     If there's more than one source and more than one target, each target gets
604     substituted from the corresponding source.
605 johnpye 393 """
606 johnpye 395 env.Append(TOOLS = 'SUBST')
607     def do_subst_in_file(targetfile, sourcefile, dict):
608     """Replace all instances of the keys of dict with their values.
609     For example, if dict is {'%VERSION%': '1.2345', '%BASE%': 'MyProg'},
610     then all instances of %VERSION% in the file will be replaced with 1.2345 etc.
611     """
612     try:
613     f = open(sourcefile, 'rb')
614     contents = f.read()
615     f.close()
616     except:
617     raise SCons.Errors.UserError, "Can't read source file %s"%sourcefile
618     for (k,v) in dict.items():
619     contents = re.sub(k, v, contents)
620     try:
621     f = open(targetfile, 'wb')
622     f.write(contents)
623     f.close()
624     except:
625     raise SCons.Errors.UserError, "Can't write target file %s"%targetfile
626     return 0 # success
627 johnpye 393
628 johnpye 395 def subst_in_file(target, source, env):
629     if not env.has_key('SUBST_DICT'):
630     raise SCons.Errors.UserError, "SubstInFile requires SUBST_DICT to be set."
631     d = dict(env['SUBST_DICT']) # copy it
632     for (k,v) in d.items():
633     if callable(v):
634     d[k] = env.subst(v())
635     elif SCons.Util.is_String(v):
636     d[k]=env.subst(v)
637     else:
638     raise SCons.Errors.UserError, "SubstInFile: key %s: %s must be a string or callable"%(k, repr(v))
639     for (t,s) in zip(target, source):
640     return do_subst_in_file(str(t), str(s), d)
641 johnpye 393
642 johnpye 395 def subst_in_file_string(target, source, env):
643     """This is what gets printed on the console."""
644     return '\n'.join(['Substituting vars from %s into %s'%(str(s), str(t))
645     for (t,s) in zip(target, source)])
646 johnpye 393
647 johnpye 395 def subst_emitter(target, source, env):
648     """Add dependency from substituted SUBST_DICT to target.
649     Returns original target, source tuple unchanged.
650     """
651     d = env['SUBST_DICT'].copy() # copy it
652     for (k,v) in d.items():
653     if callable(v):
654     d[k] = env.subst(v())
655     elif SCons.Util.is_String(v):
656     d[k]=env.subst(v)
657     Depends(target, SCons.Node.Python.Value(d))
658     return target, source
659 johnpye 393
660 johnpye 395 subst_action=SCons.Action.Action(subst_in_file, subst_in_file_string)
661     env['BUILDERS']['SubstInFile'] = Builder(action=subst_action, emitter=subst_emitter)
662    
663     TOOL_SUBST(env)
664    
665 johnpye 393 #------------------------------------------------------
666 johnpye 439 # Recipe for 'CHMOD' ACTION
667    
668     import SCons
669     from SCons.Script.SConscript import SConsEnvironment
670     SConsEnvironment.Chmod = SCons.Action.ActionFactory(os.chmod,
671     lambda dest, mode: 'Chmod("%s", 0%o)' % (dest, mode))
672    
673     def InstallPerm(env, dest, files, perm):
674     obj = env.Install(dest, files)
675     for i in obj:
676     env.AddPostAction(i, env.Chmod(str(i), perm))
677    
678     SConsEnvironment.InstallPerm = InstallPerm
679    
680     # define wrappers
681     SConsEnvironment.InstallProgram = lambda env, dest, files: InstallPerm(env, dest, files, 0755)
682     SConsEnvironment.InstallHeader = lambda env, dest, files: InstallPerm(env, dest, files, 0644)
683    
684     #------------------------------------------------------
685 johnpye 385 # SUBDIRECTORIES....
686    
687 johnpye 393
688 johnpye 385 env.Append(CPPPATH=['..'])
689    
690     env.SConscript(['base/generic/general/SConscript'],'env')
691    
692     env.SConscript(['base/generic/utilities/SConscript'],'env')
693    
694     env.SConscript(['base/generic/compiler/SConscript'],'env')
695    
696     env.SConscript(['base/generic/solver/SConscript'],'env')
697    
698     env.SConscript(['base/generic/packages/SConscript'],'env')
699 johnpye 386
700     if with_tcltk_gui:
701     env.SConscript(['tcltk98/generic/interface/SConscript'],'env')
702 johnpye 391 else:
703 johnpye 405 print "Skipping... Tcl/Tk GUI isn't being built:",without_tcltk_reason
704 johnpye 386
705 johnpye 387 if with_python:
706     env.SConscript(['pygtk/interface/SConscript'],'env')
707 johnpye 391 else:
708 johnpye 413 print "Skipping... Python GUI isn't being built:",without_python_reason
709 johnpye 400
710     if with_cunit_tests:
711     testdirs = ['general','solver','utilities']
712     for testdir in testdirs:
713     path = 'base/generic/'+testdir+'/test/'
714     env.SConscript([path+'SConscript'],'env')
715     env.SConscript(['test/SConscript'],'env')
716     env.SConscript(['base/generic/test/SConscript'],'env')
717    
718    
719     else:
720 johnpye 427 print "Skipping... CUnit tests aren't being built:",without_cunit_reason
721 johnpye 400
722 johnpye 449 if with_tcltk_gui:
723     if with_local_blas:
724     env.SConscript(['blas/SConscript'],'env')
725     else:
726     print "Skipping... BLAS won't be build:", without_local_blas_reason
727 johnpye 427
728 johnpye 449 env.SConscript(['lsod/SConscript'],'env')
729 johnpye 427
730 johnpye 449 env.SConscript(['linpack/SConscript'],'env')
731 johnpye 427
732 johnpye 449 # the models directory only needs to be processed for installation
733     env.SConscript(['models/SConscript'],'env')
734    
735 johnpye 400 #------------------------------------------------------
736     # INSTALLATION
737    
738 johnpye 448 install_dirs = [env['INSTALL_ROOT']+env['INSTALL_BIN']]+[env['INSTALL_ROOT']+env['INSTALL_DATA']]
739 johnpye 435
740 johnpye 400 # TODO: add install options
741 johnpye 435 env.Alias('install',install_dirs)
742 johnpye 438
743     #------------------------------------------------------
744     # CREATE the SPEC file for generation of RPM packages
745    
746 johnpye 439 env.SubstInFile('ascend.spec.in')

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