/[ascend]/trunk/SConstruct
ViewVC logotype

Annotation of /trunk/SConstruct

Parent Directory Parent Directory | Revision Log Revision Log


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

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