/[ascend]/trunk/SConstruct
ViewVC logotype

Annotation of /trunk/SConstruct

Parent Directory Parent Directory | Revision Log Revision Log


Revision 448 - (hide annotations) (download)
Wed Apr 5 01:04:59 2006 UTC (13 years, 8 months ago) by johnpye
File size: 19079 byte(s)
RPM build works now. The model library isn't being installed but the PyGTK interface opens up correctly.
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     ,os.path.expanduser("~/src/ascend/trunk/models")
85     )
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     ,"off"
109     ))
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 400 ,"off"
116     ))
117    
118 johnpye 404 # Where are the Tcl includes?
119     opts.Add(PackageOption(
120     'TCL_CPPPATH'
121     ,"Where are your Tcl include files?"
122     ,None
123     ))
124    
125     # Where are the Tcl libs?
126     opts.Add(PackageOption(
127     'TCL_LIBPATH'
128     ,"Where are your Tcl libraries?"
129     ,None
130     ))
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     ,None
144     ))
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     ,None
151     ))
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     ,'/usr'
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 448 opts.Add(
185     'INSTALL_ROOT'
186     ,'For use by RPM only: location of %{buildroot} during rpmbuild'
187     ,""
188     )
189    
190 johnpye 392 # TODO: OTHER OPTIONS?
191     # TODO: flags for optimisation
192 johnpye 393 # TODO: turning on/off bintoken functionality
193 johnpye 427 # TODO: Where will the 'Makefile.bt' file be installed?
194 johnpye 393
195 johnpye 385 opts.Update(env)
196     opts.Save('options.cache',env)
197    
198     Help(opts.GenerateHelpText(env))
199    
200 johnpye 386 with_tcltk_gui = (env['WITHOUT_TCLTK_GUI']==False)
201 johnpye 427 without_tcltk_reason = "disabled by options/config.py"
202 johnpye 386
203 johnpye 387 with_python = (env['WITHOUT_PYTHON']==False)
204 johnpye 427 without_python_reason = "disabled by options/config.py"
205 johnpye 387
206 johnpye 400 with_cunit_tests = env['WITH_CUNIT_TESTS']
207 johnpye 427 without_cunit_reason = "not requested"
208 johnpye 400
209 johnpye 392 print "SOLVERS:",env['WITH_SOLVERS']
210 johnpye 393 print "WITH_LOCAL_HELP:",env['WITH_LOCAL_HELP']
211     print "WITH_BINTOKEN:",env['WITH_BINTOKEN']
212     print "DEFAULT_ASCENDLIBRARY:",env['DEFAULT_ASCENDLIBRARY']
213    
214     subst_dict = {
215     '@WEBHELPROOT@':'http://pye.dyndns.org/ascend/manual/'
216 johnpye 436 , '@GLADE_FILE@':'ascend.glade'
217 johnpye 393 , '@DEFAULT_ASCENDLIBRARY@':env['DEFAULT_ASCENDLIBRARY']
218 johnpye 436 , '@ASCEND_ICON@':'ascend.png'
219 johnpye 393 , '@HELP_ROOT@':''
220 johnpye 436 , '@INSTALL_DATA@':env['INSTALL_DATA']
221     , '@INSTALL_BIN@':env['INSTALL_BIN']
222     , '@INSTALL_INCLUDE@':env['INSTALL_INCLUDE']
223 johnpye 439 , '@VERSION@':version
224 johnpye 393 }
225    
226     if env['WITH_LOCAL_HELP']:
227     subst_dict['@HELP_ROOT@']=env['WITH_LOCAL_HELP']
228    
229     env.Append(SUBST_DICT=subst_dict)
230    
231 johnpye 385 #------------------------------------------------------
232 johnpye 398 # SPECIAL CONFIGURATION TESTS
233    
234 johnpye 400 #----------------
235     # SWIG
236    
237 johnpye 398 import os,re
238    
239 johnpye 427 need_fortran = False
240    
241 johnpye 413 def get_swig_version(env):
242 johnpye 403 cmd = env['SWIG']+' -version'
243 johnpye 427 (cin,coutcerr) = os.popen4(cmd)
244 johnpye 403 output = coutcerr.read()
245 johnpye 398
246 johnpye 403 restr = "SWIG\\s+Version\\s+(?P<maj>[0-9]+)\\.(?P<min>[0-9]+)\\.(?P<pat>[0-9]+)\\s*$"
247     expr = re.compile(restr,re.M);
248 johnpye 398 m = expr.search(output);
249     if not m:
250 johnpye 413 return None
251 johnpye 398 maj = int(m.group('maj'))
252     min = int(m.group('min'))
253     pat = int(m.group('pat'))
254 johnpye 413
255     return (maj,min,pat)
256 johnpye 398
257 johnpye 413
258     def CheckSwigVersion(context):
259    
260     try:
261     context.Message("Checking version of SWIG... ")
262     maj,min,pat = get_swig_version(context.env)
263     except:
264     context.Result("Failed to detect version, or failed to run SWIG")
265     return 0;
266    
267 johnpye 398 if maj == 1 and (
268 johnpye 400 min > 3
269     or (min == 3 and pat >= 24)
270 johnpye 398 ):
271     context.Result("ok, %d.%d.%d" % (maj,min,pat))
272     return 1;
273 johnpye 401 else:
274     context.Result("too old, %d.%d.%d" % (maj,min,pat))
275     return 0;
276 johnpye 398
277 johnpye 400 #----------------
278     # General purpose library-and-header test
279    
280 johnpye 404 class KeepContext:
281     def __init__(self,context,varprefix):
282     self.keep = {}
283     for k in ['LIBS','LIBPATH','CPPPATH']:
284     if context.env.has_key(k):
285     self.keep[k] = context.env[k]
286    
287     libpath_add = []
288     if context.env.has_key(varprefix+'_LIBPATH'):
289     libpath_add = [env[varprefix+'_LIBPATH']]
290 johnpye 428 #print "Adding '"+str(libpath_add)+"' to lib path"
291 johnpye 400
292 johnpye 404 cpppath_add = []
293     if context.env.has_key(varprefix+'_CPPPATH'):
294     cpppath_add = [env[varprefix+'_CPPPATH']]
295 johnpye 428 #print "Adding '"+str(cpppath_add)+"' to cpp path"
296    
297     libs_add = []
298     if context.env.has_key(varprefix+'_LIB'):
299     libs_add = [env[varprefix+'_LIB']]
300     #print "Adding '"+str(libs_add)+"' to libs"
301    
302 johnpye 405 context.env.Append(
303     LIBPATH = libpath_add
304     , CPPPATH = cpppath_add
305 johnpye 428 , LIBS = libs_add
306 johnpye 405 )
307 johnpye 404
308     def restore(self,context):
309     for k in self.keep:
310     context.env[k]=self.keep[k];
311    
312 johnpye 400 def CheckExtLib(context,libname,text,ext='.c',varprefix=None):
313     """This method will check for variables LIBNAME_LIBPATH
314     and LIBNAME_CPPPATH and try to compile and link the
315     file with the provided text, linking with the
316     library libname."""
317    
318 johnpye 405 context.Message( 'Checking for '+libname+'... ' )
319 johnpye 400
320     if varprefix==None:
321     varprefix = libname.upper()
322    
323 johnpye 404 keep = KeepContext(context,varprefix)
324 johnpye 400
325 johnpye 428 # print "TryLink with CPPPATH="+str(context.env['CPPPATH'])
326     # print "TryLink with LIBS="+str(context.env['LIBS'])
327     # print "TryLink with LIBPATH="+str(context.env['LIBPATH'])
328 johnpye 405
329 johnpye 428 if not context.env.has_key(varprefix+'_LIB'):
330     context.env.AppendUnique(LIBS=libname)
331    
332 johnpye 404 is_ok = context.TryLink(text,ext)
333 johnpye 428
334     # print "Link success? ",(is_ok != 0)
335 johnpye 400
336 johnpye 405 keep.restore(context)
337 johnpye 400
338 johnpye 428 # print "Restored CPPPATH="+str(context.env['CPPPATH'])
339     # print "Restored LIBS="+libname
340     # print "Restored LIBPATH="+str(context.env['LIBPATH'])
341    
342 johnpye 404 context.Result(is_ok)
343     return is_ok
344    
345     #----------------
346     # CUnit test
347    
348 johnpye 400 cunit_test_text = """
349     #include <CUnit/Cunit.h>
350     int maxi(int i1, int i2){
351     return (i1 > i2) ? i1 : i2;
352     }
353    
354     void test_maxi(void){
355     CU_ASSERT(maxi(0,2) == 2);
356     CU_ASSERT(maxi(0,-2) == 0);
357     CU_ASSERT(maxi(2,2) == 2);
358    
359     }
360     int main(void){
361     /* CU_initialize_registry() */
362 johnpye 404 return 0;
363 johnpye 400 }
364     """
365    
366     def CheckCUnit(context):
367 johnpye 412 return context.CheckExtLib(context
368 johnpye 400 ,'cunit'
369     ,cunit_test_text
370     )
371    
372 johnpye 404 #----------------
373 johnpye 405 # Tcl test
374 johnpye 404
375     tcl_check_text = r"""
376     #include <tcl.h>
377     #include <stdio.h>
378     int main(void){
379     printf("%s",TCL_PATCH_LEVEL);
380     return 0;
381     }
382     """
383    
384     def CheckTcl(context):
385 johnpye 405 return CheckExtLib(context,'tcl',tcl_check_text)
386    
387     def CheckTclVersion(context):
388 johnpye 404 keep = KeepContext(context,'TCL')
389 johnpye 405 context.Message("Checking Tcl version... ")
390     (is_ok,output) = context.TryRun(tcl_check_text,'.c')
391 johnpye 404 keep.restore(context)
392     if not is_ok:
393 johnpye 405 context.Result("failed to run check")
394 johnpye 404 return 0
395 johnpye 405
396     major,minor,patch = tuple(int(i) for i in output.split("."))
397     if major != 8 or minor > 3:
398 johnpye 428 context.Result(output+" (bad version)")
399 johnpye 405 # bad version
400     return 0
401    
402     # good version
403 johnpye 428 context.Result(output+" (good)")
404 johnpye 404 return 1
405    
406 johnpye 405 #----------------
407     # Tcl test
408    
409     tk_check_text = r"""
410     #include <tk.h>
411     #include <stdio.h>
412     int main(void){
413     printf("%s",TK_PATCH_LEVEL);
414     return 0;
415     }
416     """
417     def CheckTk(context):
418 johnpye 428 return CheckExtLib(context,'tk',tcl_check_text)
419 johnpye 405
420 johnpye 428
421 johnpye 405 def CheckTkVersion(context):
422     keep = KeepContext(context,'TK')
423     context.Message("Checking Tk version... ")
424     (is_ok,output) = context.TryRun(tk_check_text,'.c')
425 johnpye 404 keep.restore(context)
426     if not is_ok:
427     context.Result("failed to run check")
428     return 0
429     context.Result(output)
430    
431     major,minor,patch = tuple(int(i) for i in output.split("."))
432     if major != 8 or minor > 3:
433     # bad version
434     return 0
435 johnpye 400
436 johnpye 404 # good version
437     return 1
438    
439 johnpye 398 #------------------------------------------------------
440 johnpye 385 # CONFIGURATION
441    
442     conf = Configure(env
443     , custom_tests = {
444 johnpye 398 'CheckSwigVersion' : CheckSwigVersion
445 johnpye 400 , 'CheckCUnit' : CheckCUnit
446 johnpye 404 , 'CheckTcl' : CheckTcl
447     , 'CheckTclVersion' : CheckTclVersion
448 johnpye 405 , 'CheckTk' : CheckTk
449     , 'CheckTkVersion' : CheckTkVersion
450 johnpye 400 # , 'CheckIsNan' : CheckIsNan
451     # , 'CheckCppUnitConfig' : CheckCppUnitConfig
452 johnpye 385 }
453     , config_h = "config.h"
454     )
455    
456 johnpye 398
457 johnpye 385 # Math library
458    
459 johnpye 427 #if not conf.CheckFunc('sinh') and not conf.CheckLibWithHeader(['m','c','libc'], 'math.h', 'C'):
460     # print 'Did not find math library, exiting!'
461     # Exit(1)
462    
463 johnpye 385 # Where is 'isnan'?
464    
465     if not conf.CheckFunc('isnan'):
466     print "Didn't find isnan"
467 johnpye 414 # Exit(1)
468 johnpye 385
469 johnpye 387 # Tcl/Tk
470 johnpye 386
471 johnpye 428 if conf.CheckTcl():
472     if with_tcltk_gui and conf.CheckTclVersion():
473     if conf.CheckTk():
474     if with_tcltk_gui and not conf.CheckTkVersion():
475     without_tcltk_reason = "Require Tk version <= 8.3. See 'scons -h'"
476     with_tcltk_gui = False
477     else:
478     without_tcltk_reason = "Tk not found."
479     with_tcltk_gui = False
480     else:
481 johnpye 405 without_tcltk_reason = "Require Tcl <= 8.3 Tcl."
482 johnpye 404 with_tcltk_gui = False
483 johnpye 386
484 johnpye 405 else:
485 johnpye 428 without_tcltk_reason = "Tcl not found."
486 johnpye 412 with_tcltk_gui = False
487    
488 johnpye 395 # Python... obviously we're already running python, so we just need to
489     # check that we can link to the python library OK:
490    
491 johnpye 391 if platform.system()=="Windows":
492 johnpye 395 python_lib='python24'
493 johnpye 391 else:
494 johnpye 395 python_lib='python2.4'
495 johnpye 391
496 johnpye 395 # SWIG version
497    
498 johnpye 396 if platform.system()=="Windows":
499     env['ENV']['SWIGFEATURES']='-O'
500     else:
501     env['ENV']['SWIGFEATURES']='-O'
502 johnpye 395
503 johnpye 413
504     if not conf.CheckSwigVersion():
505     without_python_reason = 'SWIG >= 1.3.24 is required'
506     with_python = False
507    
508 johnpye 400 # CUnit
509    
510     if with_cunit_tests:
511 johnpye 404 if not conf.CheckCUnit():
512 johnpye 427 without_cunit_reason = 'CUnit not found'
513    
514     # BLAS
515    
516     if conf.CheckLib('blas'):
517     print "FOUND BLAS"
518     with_local_blas = False
519     without_local_blas_reason = "Found BLAS installed on system"
520     else:
521     print "DIDN'T FIND BLAS"
522     with_local_blas = True
523     need_fortran = True
524    
525     # FORTRAN
526    
527     if need_fortran:
528     conf.env.Tool('f77')
529     detect_fortran = conf.env.Detect(['g77','f77'])
530     if detect_fortran:
531     # For some reason, g77 doesn't get detected properly on MinGW
532     if not env.has_key('F77'):
533     conf.env.Replace(F77=detect_fortran)
534     conf.env.Replace(F77COM='$F77 $F77FLAGS -c -o $TARGET $SOURCE')
535     conf.env.Replace(F77FLAGS='')
536 johnpye 428 #print "F77:",conf.env['F77']
537     #print "F77COM:",conf.env['F77COM']
538     #print "F77FLAGS:",conf.env['F77FLAGS']
539 johnpye 427 fortran_builder = Builder(
540     action='$F77COM'
541     , suffix='.o'
542     , src_suffix='.f'
543     )
544     conf.env.Append(BUILDERS={'Fortran':fortran_builder})
545     else:
546     print "FORTRAN-77 required but not found"
547 johnpye 404 Exit(1)
548 johnpye 427 else:
549     print "FORTRAN not required"
550 johnpye 400
551 johnpye 385 # TODO: -D_HPUX_SOURCE is needed
552    
553     # TODO: check size of void*
554    
555 johnpye 393 # TODO: detect if dynamic libraries are possible or not
556    
557 johnpye 427 if platform.system()=="Windows" and env.has_key('MSVS'):
558     if not conf.CheckHeader('windows.h') and env['PACKAGE_LINKING']=='DYNAMIC_PACKAGES':
559     print "Reverting to STATIC_PACKAGES since windows.h is not available. Probably you "\
560     +"need to install the Microsoft Windows Server 2003 Platform SDK, or similar."
561     env['PACKAGE_LINKING']='STATIC_PACKAGES'
562    
563     if with_python and not conf.CheckHeader('basetsd.h'):
564     with_python = 0;
565     without_python_reason = "Header file 'basetsd.h' not found. Install the MS Platform SDK."
566    
567     conf.env.Append(CPPDEFINES=env['PACKAGE_LINKING'])
568    
569 johnpye 395 conf.Finish()
570    
571     env.Append(PYTHON_LIBPATH=[distutils.sysconfig.PREFIX+"/libs"])
572     env.Append(PYTHON_LIB=[python_lib])
573     env.Append(PYTHON_CPPPATH=[distutils.sysconfig.get_python_inc()])
574    
575 johnpye 385 #------------------------------------------------------
576 johnpye 393 # RECIPE: 'SubstInFile', used in pygtk SConscript
577    
578     import re
579 johnpye 395 from SCons.Script import * # the usual scons stuff you get in a SConscript
580 johnpye 393
581 johnpye 395 def TOOL_SUBST(env):
582     """Adds SubstInFile builder, which substitutes the keys->values of SUBST_DICT
583     from the source to the target.
584     The values of SUBST_DICT first have any construction variables expanded
585     (its keys are not expanded).
586     If a value of SUBST_DICT is a python callable function, it is called and
587     the result is expanded as the value.
588     If there's more than one source and more than one target, each target gets
589     substituted from the corresponding source.
590 johnpye 393 """
591 johnpye 395 env.Append(TOOLS = 'SUBST')
592     def do_subst_in_file(targetfile, sourcefile, dict):
593     """Replace all instances of the keys of dict with their values.
594     For example, if dict is {'%VERSION%': '1.2345', '%BASE%': 'MyProg'},
595     then all instances of %VERSION% in the file will be replaced with 1.2345 etc.
596     """
597     try:
598     f = open(sourcefile, 'rb')
599     contents = f.read()
600     f.close()
601     except:
602     raise SCons.Errors.UserError, "Can't read source file %s"%sourcefile
603     for (k,v) in dict.items():
604     contents = re.sub(k, v, contents)
605     try:
606     f = open(targetfile, 'wb')
607     f.write(contents)
608     f.close()
609     except:
610     raise SCons.Errors.UserError, "Can't write target file %s"%targetfile
611     return 0 # success
612 johnpye 393
613 johnpye 395 def subst_in_file(target, source, env):
614     if not env.has_key('SUBST_DICT'):
615     raise SCons.Errors.UserError, "SubstInFile requires SUBST_DICT to be set."
616     d = dict(env['SUBST_DICT']) # copy it
617     for (k,v) in d.items():
618     if callable(v):
619     d[k] = env.subst(v())
620     elif SCons.Util.is_String(v):
621     d[k]=env.subst(v)
622     else:
623     raise SCons.Errors.UserError, "SubstInFile: key %s: %s must be a string or callable"%(k, repr(v))
624     for (t,s) in zip(target, source):
625     return do_subst_in_file(str(t), str(s), d)
626 johnpye 393
627 johnpye 395 def subst_in_file_string(target, source, env):
628     """This is what gets printed on the console."""
629     return '\n'.join(['Substituting vars from %s into %s'%(str(s), str(t))
630     for (t,s) in zip(target, source)])
631 johnpye 393
632 johnpye 395 def subst_emitter(target, source, env):
633     """Add dependency from substituted SUBST_DICT to target.
634     Returns original target, source tuple unchanged.
635     """
636     d = env['SUBST_DICT'].copy() # copy it
637     for (k,v) in d.items():
638     if callable(v):
639     d[k] = env.subst(v())
640     elif SCons.Util.is_String(v):
641     d[k]=env.subst(v)
642     Depends(target, SCons.Node.Python.Value(d))
643     return target, source
644 johnpye 393
645 johnpye 395 subst_action=SCons.Action.Action(subst_in_file, subst_in_file_string)
646     env['BUILDERS']['SubstInFile'] = Builder(action=subst_action, emitter=subst_emitter)
647    
648     TOOL_SUBST(env)
649    
650 johnpye 393 #------------------------------------------------------
651 johnpye 439 # Recipe for 'CHMOD' ACTION
652    
653     import SCons
654     from SCons.Script.SConscript import SConsEnvironment
655     SConsEnvironment.Chmod = SCons.Action.ActionFactory(os.chmod,
656     lambda dest, mode: 'Chmod("%s", 0%o)' % (dest, mode))
657    
658     def InstallPerm(env, dest, files, perm):
659     obj = env.Install(dest, files)
660     for i in obj:
661     env.AddPostAction(i, env.Chmod(str(i), perm))
662    
663     SConsEnvironment.InstallPerm = InstallPerm
664    
665     # define wrappers
666     SConsEnvironment.InstallProgram = lambda env, dest, files: InstallPerm(env, dest, files, 0755)
667     SConsEnvironment.InstallHeader = lambda env, dest, files: InstallPerm(env, dest, files, 0644)
668    
669     #------------------------------------------------------
670 johnpye 385 # SUBDIRECTORIES....
671    
672 johnpye 393
673 johnpye 385 env.Append(CPPPATH=['..'])
674    
675     env.SConscript(['base/generic/general/SConscript'],'env')
676    
677     env.SConscript(['base/generic/utilities/SConscript'],'env')
678    
679     env.SConscript(['base/generic/compiler/SConscript'],'env')
680    
681     env.SConscript(['base/generic/solver/SConscript'],'env')
682    
683     env.SConscript(['base/generic/packages/SConscript'],'env')
684 johnpye 386
685     if with_tcltk_gui:
686     env.SConscript(['tcltk98/generic/interface/SConscript'],'env')
687 johnpye 391 else:
688 johnpye 405 print "Skipping... Tcl/Tk GUI isn't being built:",without_tcltk_reason
689 johnpye 386
690 johnpye 387 if with_python:
691     env.SConscript(['pygtk/interface/SConscript'],'env')
692 johnpye 391 else:
693 johnpye 413 print "Skipping... Python GUI isn't being built:",without_python_reason
694 johnpye 400
695     if with_cunit_tests:
696     testdirs = ['general','solver','utilities']
697     for testdir in testdirs:
698     path = 'base/generic/'+testdir+'/test/'
699     env.SConscript([path+'SConscript'],'env')
700     env.SConscript(['test/SConscript'],'env')
701     env.SConscript(['base/generic/test/SConscript'],'env')
702    
703    
704     else:
705 johnpye 427 print "Skipping... CUnit tests aren't being built:",without_cunit_reason
706 johnpye 400
707 johnpye 427 #if with_tcltk_gui:
708     if with_local_blas:
709     env.SConscript(['blas/SConscript'],'env')
710     else:
711     print "Skipping... BLAS won't be build:", without_local_blas_reason
712    
713     env.SConscript(['lsod/SConscript'],'env')
714    
715     env.SConscript(['linpack/SConscript'],'env')
716    
717 johnpye 400 #------------------------------------------------------
718     # INSTALLATION
719    
720 johnpye 448 install_dirs = [env['INSTALL_ROOT']+env['INSTALL_BIN']]+[env['INSTALL_ROOT']+env['INSTALL_DATA']]
721 johnpye 435
722 johnpye 400 # TODO: add install options
723 johnpye 435 env.Alias('install',install_dirs)
724 johnpye 438
725     #------------------------------------------------------
726     # CREATE the SPEC file for generation of RPM packages
727    
728 johnpye 439 env.SubstInFile('ascend.spec.in')

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