/[ascend]/trunk/SConstruct
ViewVC logotype

Annotation of /trunk/SConstruct

Parent Directory Parent Directory | Revision Log Revision Log


Revision 794 - (hide annotations) (download)
Fri Jul 28 06:38:35 2006 UTC (14 years, 2 months ago) by johnpye
File size: 36952 byte(s)
Bumped version number 0.9.5.96
1 johnpye 393 import os, commands, platform, distutils.sysconfig, os.path
2 johnpye 385
3 johnpye 794 version = "0.9.5.96"
4 johnpye 439
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 johnpye 464 #print "PLATFORM = ",platform.system()
13 johnpye 385
14 johnpye 464 if platform.system()=="Windows":
15 johnpye 631 default_tcl_lib = "tcl84"
16     default_tk_lib = "tk84"
17 johnpye 464 default_tktable_lib = "Tktable28"
18 johnpye 499 default_install_assets = "glade/"
19     icon_extension = '.png'
20 johnpye 521 default_tcl = "c:\\Tcl"
21 johnpye 643 if os.environ.get('MSYSTEM')=="MINGW32":
22 johnpye 642 default_tcl_libpath="$TCL\\bin"
23     else:
24     default_tcl_libpath="$TCL\\lib"
25 johnpye 627 default_rel_distdir = '.'
26 johnpye 628 default_absolute_paths = False
27 johnpye 739
28     default_ida_prefix = "c:\\MinGW"
29     if not os.path.exists(default_ida_prefix):
30     default_ida_prefix = None
31 johnpye 783
32     default_conopt_prefix = "c:\\MinGW"
33     if not os.path.exists(default_conopt_prefix):
34     default_conopt_prefix = None
35 johnpye 739
36 johnpye 673 need_libm = False
37 johnpye 683 python_exe = "c:\\Python24\\python.exe"
38 johnpye 464 else:
39 johnpye 673 default_tcl_lib = "tcl8.4"
40     default_tk_lib = "tk8.4"
41 johnpye 464 default_tktable_lib = "Tktable2.8"
42 johnpye 628 default_install_assets = "$INSTALL_ASCDATA/glade/"
43 johnpye 499 icon_extension = '.svg'
44 johnpye 684 default_tcl = '/usr'
45 johnpye 541 default_tcl_libpath = "$TCL/lib"
46 johnpye 627 default_rel_distdir = '../share/ascend'
47 johnpye 628 default_absolute_paths = True
48 johnpye 673 default_ida_prefix="/usr/local"
49 johnpye 783 default_conopt_prefix="/usr"
50 johnpye 673 need_libm = True
51 johnpye 551 if not os.path.isdir(default_tcl):
52     default_tcl = '/usr'
53 johnpye 683 python_exe = distutils.sysconfig.EXEC_PREFIX+"/bin/python"
54 johnpye 551
55 johnpye 562 opts.Add(
56     'CC'
57     ,'C Compiler command'
58     ,None
59     )
60    
61     opts.Add(
62     'CXX'
63     ,'C++ Compiler command'
64     ,None
65     )
66    
67 johnpye 591 opts.Add(BoolOption(
68     'GCOV'
69 johnpye 593 , 'Whether to enable coverage testing in object code'
70     , False
71 johnpye 591 ))
72    
73 johnpye 385 # Package linking option
74 johnpye 386 opts.Add(EnumOption(
75     'PACKAGE_LINKING'
76 johnpye 385 , 'Style of linking for external libraries'
77     , 'DYNAMIC_PACKAGES'
78 johnpye 386 , ['DYNAMIC_PACKAGES', 'STATIC_PACKAGES', 'NO_PACKAGES']
79     ))
80 johnpye 385
81 johnpye 526 opts.Add(BoolOption(
82     'WITH_GCCVISIBILITY'
83     ,"Whether to use GCC Visibility features (only applicable if available)"
84     ,True
85     ))
86    
87 johnpye 392 # You can turn off building of Tcl/Tk interface
88 johnpye 386 opts.Add(BoolOption(
89 johnpye 542 'WITH_TCLTK'
90 johnpye 673 ,"Set to False if you don't want to build the original Tcl/Tk GUI."
91 johnpye 542 , True
92 johnpye 386 ))
93    
94 johnpye 392 # You can turn off the building of the Python interface
95 johnpye 387 opts.Add(BoolOption(
96 johnpye 542 'WITH_PYTHON'
97 johnpye 673 ,"Set to False if you don't want to build Python wrappers."
98 johnpye 542 , True
99 johnpye 387 ))
100    
101 johnpye 392 # Which solvers will we allow?
102     opts.Add(ListOption(
103     'WITH_SOLVERS'
104 johnpye 393 ,"List of the solvers you want to build. The default is the minimum that"
105     +" works."
106 johnpye 784 ,["QRSLV","CMSLV","LSOD","IDA","CONOPT","LRSLV"]
107 johnpye 392 ,['QRSLV','MPS','SLV','OPTSQP'
108     ,'NGSLV','CMSLV','LRSLV','MINOS','CONOPT'
109 johnpye 673 ,'LSOD','OPTSQP',"IDA"
110 johnpye 392 ]
111     ))
112    
113 johnpye 393 # Where will the local copy of the help files be kept?
114     opts.Add(PackageOption(
115     'WITH_LOCAL_HELP'
116     , "Directory containing the local copy of the help files (optional)"
117     , "no"
118     ))
119    
120     # Will bintoken support be enabled?
121     opts.Add(BoolOption(
122     'WITH_BINTOKEN'
123     ,"Enable bintoken support? This means compiling models as C-code before"
124     +" running them, to increase solving speed for large models."
125     ,False
126     ))
127    
128 johnpye 398 # What should the default ASCENDLIBRARY path be?
129     # Note: users can change it by editing their ~/.ascend.ini
130 johnpye 393 opts.Add(
131     'DEFAULT_ASCENDLIBRARY'
132     ,"Set the default value of the ASCENDLIBRARY -- the location where"
133     +" ASCEND will look for models when running ASCEND"
134 johnpye 628 ,"$INSTALL_ASCDATA/models"
135 johnpye 393 )
136    
137 johnpye 398 # Where is SWIG?
138     opts.Add(
139     'SWIG'
140     ,"SWIG location, probably only required for MinGW and MSVC users."
141     +" Enter the location as a Windows-style path, for example"
142 johnpye 404 +" 'c:\\msys\\1.0\\home\\john\\swigwin-1.3.29\\swig.exe'."
143 johnpye 398 )
144    
145 johnpye 400 # Build the test suite?
146     opts.Add(BoolOption(
147 johnpye 593 'WITH_CUNIT'
148 johnpye 665 ,"You can disable CUnit tests with this option. This will basically stop"
149     +" SCons from parsing the SConscript files relating to the 'test'"
150     +" target, which just might make things marginally faster. Probably"
151     +" you can just ignore this option though. SCons will sniff for Cunit"
152     +" but build the tests only if you specify the 'test' target."
153     ,True
154 johnpye 400 ))
155 johnpye 393
156 johnpye 400 # Where are the CUnit includes?
157     opts.Add(PackageOption(
158     'CUNIT_CPPPATH'
159     ,"Where are your CUnit include files?"
160 johnpye 459 ,'off'
161 johnpye 400 ))
162 johnpye 392
163 johnpye 404 # Where are the CUnit libraries?
164 johnpye 400 opts.Add(PackageOption(
165     'CUNIT_LIBPATH'
166 johnpye 404 ,"Where are your CUnit libraries?"
167 johnpye 459 ,'off'
168 johnpye 400 ))
169    
170 johnpye 673 opts.Add(PackageOption(
171     "IDA_PREFIX"
172     ,"Prefix for your IDA install (IDA ./configure --prefix)"
173     ,default_ida_prefix
174     ))
175 johnpye 521
176 johnpye 534 opts.Add(
177 johnpye 782 "IDA_LIB"
178     ,"Libraries linked to for IDA"
179     ,['sundials_ida','sundials_nvecserial','m']
180     )
181    
182     opts.Add(
183 johnpye 673 'IDA_CPPPATH'
184     ,"Where is your ida.h?"
185     ,"$IDA_PREFIX/include"
186     )
187    
188     opts.Add(
189     'IDA_LIBPATH'
190     ,"Where are your SUNDIALS libraries installed?"
191     ,"$IDA_PREFIX/lib"
192     )
193    
194 johnpye 783 # conopt
195    
196     opts.Add(PackageOption(
197     "CONOPT_PREFIX"
198     ,"Prefix for your CONOPT install (CONOPT ./configure --prefix)"
199     ,default_ida_prefix
200     ))
201    
202 johnpye 673 opts.Add(
203 johnpye 783 "CONOPT_LIB"
204     ,"Library linked to for CONOPT"
205     ,'consub3'
206     )
207    
208     opts.Add(
209     'CONOPT_CPPPATH'
210     ,"Where is your conopt.h?"
211     ,"$CONOPT_PREFIX/include"
212     )
213    
214     opts.Add(
215     'CONOPT_LIBPATH'
216     ,"Where is your CONOPT libraries installed?"
217     ,"$CONOPT_PREFIX/lib"
218     )
219    
220     opts.Add(
221 johnpye 673 "F2C_LIB"
222     ,"F2C library (eg. g2c, gfortran, f2c)"
223     ,"g2c"
224     )
225    
226     opts.Add(PackageOption(
227     "F2C_LIBPATH"
228     ,"Directory containing F2C library (i.e. g2c, gfortran, f2c, etc.), if not already accessible"
229     ,"off"
230     ))
231    
232     opts.Add(
233 johnpye 521 'TCL'
234     ,'Base of Tcl distribution'
235     ,default_tcl
236 johnpye 534 )
237 johnpye 521
238 johnpye 404 # Where are the Tcl includes?
239 johnpye 534 opts.Add(
240 johnpye 404 'TCL_CPPPATH'
241     ,"Where are your Tcl include files?"
242 johnpye 521 ,"$TCL/include"
243 johnpye 534 )
244 johnpye 404
245     # Where are the Tcl libs?
246 johnpye 534 opts.Add(
247 johnpye 404 'TCL_LIBPATH'
248     ,"Where are your Tcl libraries?"
249 johnpye 541 ,default_tcl_libpath
250 johnpye 534 )
251 johnpye 404
252 johnpye 428 # What is the name of the Tcl lib?
253     opts.Add(
254     'TCL_LIB'
255 johnpye 561 ,"Name of Tcl lib (eg 'tcl' or 'tcl83'), for full path to static library (if STATIC_TCLTK is set)"
256 johnpye 464 ,default_tcl_lib
257 johnpye 428 )
258    
259 johnpye 405 # Where are the Tk includes?
260 johnpye 534 opts.Add(
261 johnpye 405 'TK_CPPPATH'
262     ,"Where are your Tk include files?"
263 johnpye 464 ,'$TCL_CPPPATH'
264 johnpye 534 )
265 johnpye 404
266 johnpye 405 # Where are the Tk libs?
267 johnpye 534 opts.Add(
268 johnpye 405 'TK_LIBPATH'
269     ,"Where are your Tk libraries?"
270 johnpye 464 ,'$TCL_LIBPATH'
271 johnpye 534 )
272 johnpye 405
273 johnpye 428 # What is the name of the Tk lib?
274     opts.Add(
275     'TK_LIB'
276 johnpye 521 ,"Name of Tk lib (eg 'tk' or 'tk83'), or full path to static library"
277 johnpye 464 ,default_tk_lib
278 johnpye 435 )
279    
280 johnpye 460 # Static linking to TkTable
281    
282     opts.Add(BoolOption(
283 johnpye 521 'STATIC_TCLTK'
284 johnpye 554 ,'Set true for static linking for Tcl/Tk and TkTable. EXPERIMENTAL'
285 johnpye 460 ,False
286     ))
287    
288 johnpye 464 opts.Add(
289 johnpye 460 'TKTABLE_LIBPATH'
290     ,'Location of TkTable static library'
291 johnpye 464 ,'$TCL_LIBPATH/Tktable2.8'
292     )
293 johnpye 460
294 johnpye 435 opts.Add(
295 johnpye 460 'TKTABLE_LIB'
296 johnpye 521 ,'Stem name of TkTable (eg tktable2.8, no ".so" or "lib") shared library, or full path of static tktable (/usr/lib/...)'
297 johnpye 464 ,default_tktable_lib
298 johnpye 460 )
299    
300     opts.Add(
301 johnpye 521 'TKTABLE_CPPPATH'
302     ,'Location of TkTable header file'
303     ,'$TCL_CPPPATH'
304     )
305    
306     opts.Add(
307     'X11'
308 johnpye 554 ,'Base X11 directory. Only used when STATIC_TCLTK is turned on. EXPERIMENTAL'
309 johnpye 521 ,'/usr/X11R6'
310     )
311    
312     opts.Add(
313     'X11_LIBPATH'
314 johnpye 554 ,'Location of X11 lib. EXPERIMENTAL'
315 johnpye 521 ,'$X11/lib'
316     )
317    
318     opts.Add(
319     'X11_CPPPATH'
320 johnpye 554 ,'Location of X11 includes. EXPERIMENTAL'
321 johnpye 521 ,'$X11/include'
322     )
323    
324     opts.Add(
325     'X11_LIB'
326 johnpye 554 ,'Name of X11 lib. EXPERIMENTAL'
327 johnpye 521 ,'X11'
328     )
329    
330     opts.Add(
331 johnpye 435 'INSTALL_PREFIX'
332     ,'Root location for installed files'
333 johnpye 449 ,'/usr/local'
334 johnpye 428 )
335    
336 johnpye 435 opts.Add(
337     'INSTALL_BIN'
338     ,'Location to put binaries during installation'
339     ,"$INSTALL_PREFIX/bin"
340     )
341    
342     opts.Add(
343 johnpye 463 'INSTALL_LIB'
344 johnpye 683 ,'Location to put libraries during installation'
345 johnpye 463 ,"$INSTALL_PREFIX/lib"
346     )
347    
348     opts.Add(
349 ben.allan 624 'INSTALL_SHARE'
350 johnpye 628 ,'Common shared-file location on this system'
351     ,"$INSTALL_PREFIX/share"
352 johnpye 435 )
353    
354 johnpye 628
355 johnpye 435 opts.Add(
356 johnpye 628 'INSTALL_ASCDATA'
357     ,"Location of ASCEND shared data (TK, python, models etc)"
358     ,"$INSTALL_SHARE/ascend"
359     )
360    
361     opts.Add(
362 johnpye 435 'INSTALL_INCLUDE'
363     ,'Location to put header files during installation'
364     ,"$INSTALL_PREFIX/include"
365     )
366    
367 johnpye 448 opts.Add(
368 johnpye 455 'PYGTK_ASSETS'
369 johnpye 532 ,'Default location for Glade assets (placed in pygtk/config.py)'
370 johnpye 455 ,default_install_assets
371     )
372    
373 johnpye 508 opts.Add(BoolOption(
374     'DEBUG'
375     ,"Compile source with debugger symbols, eg for use with 'gdb'"
376     ,False
377     ))
378    
379 johnpye 597 opts.Add(BoolOption(
380     'MALLOC_DEBUG'
381     ,"Compile with debugging version of MALLOC. Required for full CUnit testing"
382     ,False
383     ))
384    
385 johnpye 455 opts.Add(
386 johnpye 448 'INSTALL_ROOT'
387     ,'For use by RPM only: location of %{buildroot} during rpmbuild'
388     ,""
389     )
390    
391 johnpye 563 opts.Add(
392     'DISTTAR_NAME'
393     ,"Stem name of the tarball created by 'scons dist'. So for 'ascend-aaa.tar.bz2', set this to 'ascend-aaa'."
394     ,"ascend-"+version
395     )
396    
397 johnpye 656 opts.Add(
398     'RELEASE'
399     ,"Release number for use in RPM spec file. This should always start with a zero for releases made by the ASCEND group, in order that third parties can make 'patch' releases of higher version numbers."
400     ,"0"
401     )
402    
403 johnpye 605 opts.Add(BoolOption(
404 johnpye 628 'ABSOLUTE_PATHS'
405 johnpye 605 ,"Whether to use absolute or relative paths in the installed Tcl/Tk interface. If you want to build an RPM, set this to false."
406 johnpye 628 ,default_absolute_paths
407 johnpye 605 ))
408    
409 johnpye 578 opts.Add(
410     'WIN_INSTALLER_NAME'
411     ,"Name of the installer .exe to create under Windows (minus the '.exe')"
412     ,"ascend-"+version
413     )
414    
415 johnpye 594 opts.Add(BoolOption(
416     'WITH_XTERM_COLORS'
417     ,"Set to 0 if you don't want xterm colour codes in the console output"
418     ,True
419     ))
420    
421 johnpye 761 opts.Add(BoolOption(
422     'WITH_EXTFNS'
423     ,"Set to 0 if you don't want to attempt to build external modules bundled"
424     + " with ASCEND."
425     ,True
426     ))
427    
428 johnpye 546 if platform.system()!="Windows":
429     opts.Add(BoolOption(
430     'WITH_GCCVISIBILITY'
431     , 'Whether to use GCC Visibility extensions when building with GCC 4.0'
432     , True
433     ))
434    
435 johnpye 392 # TODO: OTHER OPTIONS?
436     # TODO: flags for optimisation
437 johnpye 393 # TODO: turning on/off bintoken functionality
438 johnpye 427 # TODO: Where will the 'Makefile.bt' file be installed?
439 johnpye 393
440 johnpye 498 # Import the outside environment
441    
442 johnpye 569 if os.environ.get('OSTYPE')=='msys':
443 johnpye 552 env = Environment(
444     ENV=os.environ
445 johnpye 766 , tools=['mingw','lex','yacc','fortran','swig','disttar','nsis','doxygen']
446 johnpye 552 , toolpath=['scons']
447     )
448 johnpye 529 env['IS_MINGW']=True
449 johnpye 740
450     elif platform.system()=="Windows":
451     env = Environment(
452     ENV={
453     'PATH':os.environ['PATH']
454     ,'INCLUDE':os.environ['INCLUDE']
455     ,'LIB':os.environ['LIB']
456     ,'MSVS_IGNORE_IDE_PATHS':1
457     }
458 johnpye 766 , tools = ['default','lex','yacc','fortran','swig','disttar','nsis','doxygen']
459 johnpye 740 , toolpath = ['scons']
460     )
461     env.Append(CPPDEFINES=['_CRT_SECURE_NO_DEPRECATE'])
462 johnpye 498 else:
463 johnpye 552 env = Environment(
464     ENV=os.environ
465 johnpye 766 , tools=['default','lex','yacc','fortran','swig','disttar','nsis','doxygen']
466 johnpye 552 , toolpath=['scons']
467     )
468 johnpye 498
469 johnpye 385 opts.Update(env)
470     opts.Save('options.cache',env)
471    
472     Help(opts.GenerateHelpText(env))
473    
474 johnpye 551 with_tcltk = env.get('WITH_TCLTK')
475 johnpye 427 without_tcltk_reason = "disabled by options/config.py"
476 johnpye 386
477 johnpye 551 with_python = env.get('WITH_PYTHON')
478 johnpye 427 without_python_reason = "disabled by options/config.py"
479 johnpye 387
480 johnpye 593 with_cunit = env.get('WITH_CUNIT')
481 johnpye 427 without_cunit_reason = "not requested"
482 johnpye 400
483 johnpye 761 with_extfns = env.get('WITH_EXTFNS')
484     without_extfn_reason = "disabled by options/config.py"
485    
486 johnpye 631 if platform.system()=="Windows":
487     with_installer=1
488     else:
489     with_installer=0
490     without_installer_reason = "only possible under Windows"
491    
492 johnpye 673 if 'LSOD' in env['WITH_SOLVERS']:
493     with_lsode=True
494     else:
495     with_lsode=False
496     without_lsode_reason = "not requested (WITH_SOLVERS)"
497    
498     if 'IDA' in env['WITH_SOLVERS']:
499     with_ida=True
500     else:
501     with_ida=False
502     without_ida_reason = "not requested (WITH_SOLVERS)"
503    
504    
505 johnpye 783 if 'CONOPT' in env['WITH_SOLVERS']:
506     with_conopt=True
507     else:
508     with_conopt=False
509     without_conopt_reason = "not requested (WITH_SOLVERS)"
510    
511    
512 johnpye 464 #print "SOLVERS:",env['WITH_SOLVERS']
513     #print "WITH_BINTOKEN:",env['WITH_BINTOKEN']
514     #print "DEFAULT_ASCENDLIBRARY:",env['DEFAULT_ASCENDLIBRARY']
515 johnpye 393
516 johnpye 463 can_install = True
517     if platform.system()=='Windows':
518     can_install = False
519    
520     env['CAN_INSTALL']=can_install
521    
522 johnpye 721 env['INSTALL_MODELS']=env['INSTALL_ASCDATA']+"/models/"
523    
524 johnpye 521 print "TCL_CPPPATH =",env['TCL_CPPPATH']
525     print "TCL_LIBPATH =",env['TCL_LIBPATH']
526     print "TCL_LIB =",env['TCL_LIB']
527 johnpye 562 print "CC =",env['CC']
528     print "CXX =",env['CXX']
529 johnpye 673 print "FORTRAN=",env.get('FORTRAN')
530 johnpye 393
531 johnpye 628 print "ABSOLUTE PATHS =",env['ABSOLUTE_PATHS']
532 johnpye 385 #------------------------------------------------------
533 johnpye 398 # SPECIAL CONFIGURATION TESTS
534    
535 johnpye 463 need_fortran = False
536    
537 johnpye 400 #----------------
538     # SWIG
539    
540 johnpye 398 import os,re
541    
542 johnpye 413 def get_swig_version(env):
543 johnpye 403 cmd = env['SWIG']+' -version'
544 johnpye 427 (cin,coutcerr) = os.popen4(cmd)
545 johnpye 403 output = coutcerr.read()
546 johnpye 398
547 johnpye 403 restr = "SWIG\\s+Version\\s+(?P<maj>[0-9]+)\\.(?P<min>[0-9]+)\\.(?P<pat>[0-9]+)\\s*$"
548     expr = re.compile(restr,re.M);
549 johnpye 398 m = expr.search(output);
550     if not m:
551 johnpye 413 return None
552 johnpye 398 maj = int(m.group('maj'))
553     min = int(m.group('min'))
554     pat = int(m.group('pat'))
555 johnpye 413
556     return (maj,min,pat)
557 johnpye 398
558 johnpye 413
559     def CheckSwigVersion(context):
560    
561     try:
562     context.Message("Checking version of SWIG... ")
563     maj,min,pat = get_swig_version(context.env)
564     except:
565     context.Result("Failed to detect version, or failed to run SWIG")
566     return 0;
567    
568 johnpye 478 context.env['SWIGVERSION']=tuple([maj,min,pat])
569    
570 johnpye 398 if maj == 1 and (
571 johnpye 400 min > 3
572     or (min == 3 and pat >= 24)
573 johnpye 398 ):
574     context.Result("ok, %d.%d.%d" % (maj,min,pat))
575     return 1;
576 johnpye 401 else:
577     context.Result("too old, %d.%d.%d" % (maj,min,pat))
578     return 0;
579 johnpye 398
580 johnpye 400 #----------------
581     # General purpose library-and-header test
582    
583 johnpye 404 class KeepContext:
584 johnpye 521 def __init__(self,context,varprefix,static=False):
585 johnpye 404 self.keep = {}
586 johnpye 521 for k in ['LIBS','LIBPATH','CPPPATH','LINKFLAGS']:
587 johnpye 705 #print "Keeping env %s = %s" % (k,context.env.get(k))
588     self.keep[k]=context.env.get(k)
589 johnpye 404
590     if context.env.has_key(varprefix+'_CPPPATH'):
591 johnpye 743 context.env.AppendUnique(CPPPATH=[env[varprefix+'_CPPPATH']])
592 johnpye 428 #print "Adding '"+str(cpppath_add)+"' to cpp path"
593    
594 johnpye 521 if static:
595     staticlib=env[varprefix+'_LIB']
596     #print "STATIC LIB = ",staticlib
597     context.env.Append(
598     LINKFLAGS=[staticlib]
599     )
600     else:
601     if context.env.has_key(varprefix+'_LIBPATH'):
602     context.env.Append(LIBPATH=[env[varprefix+'_LIBPATH']])
603     #print "Adding '"+str(libpath_add)+"' to lib path"
604 johnpye 428
605 johnpye 521 if context.env.has_key(varprefix+'_LIB'):
606     context.env.Append(LIBS=[env[varprefix+'_LIB']])
607 johnpye 705 #print "Adding '"+str(env[varprefix+'_LIB'])+"' to libs"
608 johnpye 404
609     def restore(self,context):
610 johnpye 464 #print "RESTORING CONTEXT"
611     #print self.keep
612     #print "..."
613 johnpye 404 for k in self.keep:
614 johnpye 463 if self.keep[k]==None:
615 johnpye 521 if context.env.has_key(k):
616     #print "Clearing "+str(k)
617     del context.env[k];
618 johnpye 463 else:
619 johnpye 705 #print "Restoring %s to '%s'" %(k,self.keep.get(k))
620 johnpye 463 context.env[k]=self.keep[k];
621 johnpye 404
622 johnpye 521 def CheckExtLib(context,libname,text,ext='.c',varprefix=None,static=False):
623 johnpye 400 """This method will check for variables LIBNAME_LIBPATH
624     and LIBNAME_CPPPATH and try to compile and link the
625     file with the provided text, linking with the
626     library libname."""
627    
628 johnpye 521 if static:
629     context.Message( 'Checking for static '+libname+'... ' )
630     else:
631     context.Message( 'Checking for '+libname+'... ' )
632    
633 johnpye 400 if varprefix==None:
634     varprefix = libname.upper()
635    
636 johnpye 705 #print "LIBS is currently:",context.env.get('LIBS')
637 johnpye 521 keep = KeepContext(context,varprefix,static)
638 johnpye 400
639 johnpye 428 if not context.env.has_key(varprefix+'_LIB'):
640 johnpye 463 # if varprefix_LIB were in env, KeepContext would
641     # have appended it already
642 johnpye 705 context.env.Append(LIBS=[libname])
643 johnpye 428
644 johnpye 404 is_ok = context.TryLink(text,ext)
645 johnpye 428
646 johnpye 521 #print "Link success? ",(is_ok != 0)
647 johnpye 400
648 johnpye 405 keep.restore(context)
649 johnpye 400
650 johnpye 428 # print "Restored CPPPATH="+str(context.env['CPPPATH'])
651 johnpye 705 # print "Restored LIBS="+str(context.env['LIBS'])
652 johnpye 428 # print "Restored LIBPATH="+str(context.env['LIBPATH'])
653    
654 johnpye 404 context.Result(is_ok)
655     return is_ok
656    
657     #----------------
658 johnpye 502 # GCC
659    
660     gcc_test_text = """
661     #ifndef __GNUC__
662     # error "Not using GCC"
663     #endif
664    
665     int main(void){
666     return __GNUC__;
667     }
668     """
669    
670     def CheckGcc(context):
671     context.Message("Checking for GCC... ")
672     is_ok = context.TryCompile(gcc_test_text,".c")
673     context.Result(is_ok)
674     return is_ok
675    
676     #----------------
677 johnpye 500 # GCC VISIBILITY feature
678    
679     gccvisibility_test_text = """
680     #if __GNUC__ < 4
681     # error "Require GCC version 4 or newer"
682     #endif
683    
684     __attribute__ ((visibility("default"))) int x;
685    
686     int main(void){
687     extern int x;
688     x = 4;
689     }
690     """
691    
692     def CheckGccVisibility(context):
693     context.Message("Checking for GCC 'visibility' capability... ")
694 johnpye 546 if not context.env.has_key('WITH_GCCVISIBILITY') or not env['WITH_GCCVISIBILITY']:
695     context.Result("disabled")
696     return 0
697 johnpye 500 is_ok = context.TryCompile(gccvisibility_test_text,".c")
698     context.Result(is_ok)
699     return is_ok
700 johnpye 502
701 johnpye 500 #----------------
702 johnpye 502 # YACC
703    
704     yacc_test_text = """
705 johnpye 646 %{
706     #include <stdio.h>
707 johnpye 741
708     /* MSVC++ needs this before it can swallow Bison output */
709     #ifdef _MSC_VER
710     # define __STDC__
711     #endif
712 johnpye 646 %}
713     %token MSG
714 johnpye 502 %start ROOT
715 johnpye 646 %%
716     ROOT:
717     MSG { printf("HELLO"); }
718     ;
719     %%
720 johnpye 502 """
721    
722     def CheckYacc(context):
723 johnpye 644 context.Message("Checking for Yacc ('%s')... " % context.env.get('YACC'))
724 johnpye 502 is_ok = context.TryCompile(yacc_test_text,".y")
725     context.Result(is_ok)
726     return is_ok
727    
728     #----------------
729 johnpye 404 # CUnit test
730    
731 johnpye 400 cunit_test_text = """
732 johnpye 451 #include <CUnit/CUnit.h>
733 johnpye 400 int maxi(int i1, int i2){
734     return (i1 > i2) ? i1 : i2;
735     }
736    
737     void test_maxi(void){
738     CU_ASSERT(maxi(0,2) == 2);
739     CU_ASSERT(maxi(0,-2) == 0);
740     CU_ASSERT(maxi(2,2) == 2);
741    
742     }
743     int main(void){
744     /* CU_initialize_registry() */
745 johnpye 404 return 0;
746 johnpye 400 }
747     """
748    
749     def CheckCUnit(context):
750 johnpye 451 return CheckExtLib(context,'cunit',cunit_test_text)
751 johnpye 400
752 johnpye 404 #----------------
753 johnpye 673 # MATH test
754    
755     math_test_text = """
756 johnpye 705 #ifndef _ALL_SOURCE
757     # define _ALL_SOURCE
758     #endif
759     #ifndef _XOPEN_SOURCE
760     # define _XOPEN_SOURCE
761     #endif
762     #ifndef _XOPEN_SOURCE_EXTENDED
763     # define _XOPEN_SOURCE_EXTENDED 1
764     #endif
765 johnpye 673 #include <math.h>
766     int main(void){
767 johnpye 705 double x = 1.0; double y = 1.0; int i = 1;
768     acosh(x); asinh(x); atanh(x); cbrt(x); expm1(x); erf(x); erfc(x); isnan(x);
769     j0(x); j1(x); jn(i,x); ilogb(x); logb(x); log1p(x); rint(x);
770     y0(x); y1(x); yn(i,x);
771     #ifdef _THREAD_SAFE
772     gamma_r(x,&i);
773     lgamma_r(x,&i);
774     #else
775     gamma(x);
776     lgamma(x);
777     #endif
778     hypot(x,y); nextafter(x,y); remainder(x,y); scalb(x,y);
779 johnpye 673 return 0;
780     }
781     """
782    
783     def CheckMath(context):
784 johnpye 705 context.Message('Checking for IEE math library... ')
785     libsave=context.env.get('LIBS');
786     context.env.AppendUnique(LIBS=['m'])
787     is_ok=context.TryLink(math_test_text,".c")
788     context.Result(is_ok)
789     if not is_ok:
790     context.env['LIBS']=libsave
791     return is_ok
792    
793 johnpye 673 #----------------
794     # IDA test
795    
796     ida_test_text = """
797 johnpye 782 #include <ida/ida.h>
798     #include <nvector/nvector_serial.h>
799     #include <ida/ida_spgmr.h>
800 johnpye 673 int main(){
801     void *ida_mem;
802     ida_mem = IDACreate();
803 johnpye 782 return 0;
804 johnpye 673 }
805     """
806    
807     def CheckIDA(context):
808     context.Message( 'Checking for IDA (SUNDIALS)... ' )
809    
810     keep = KeepContext(context,"IDA")
811    
812     is_ok = context.TryLink(ida_test_text,".c")
813     context.Result(is_ok)
814    
815     keep.restore(context)
816 johnpye 782
817 johnpye 673 return is_ok
818    
819     #----------------
820 johnpye 783 # CONOPT test
821    
822     conopt_test_text = """
823     #define FNAME_LCASE_DECOR
824     #include <conopt.h>
825     #include <stdlib.h>
826     int main(){
827     int s, *v, e;
828     s = COIDEF_Size();
829     v = (int *)malloc(s*sizeof(int));
830     e = COIDEF_Ini(v);
831     return e;
832     }
833     """
834    
835     def CheckCONOPT(context):
836     context.Message( 'Checking for CONOPT... ' )
837    
838     keep = KeepContext(context,"CONOPT")
839    
840     is_ok = context.TryLink(conopt_test_text,".c")
841     context.Result(is_ok)
842    
843     keep.restore(context)
844    
845     return is_ok
846    
847     #----------------
848 johnpye 405 # Tcl test
849 johnpye 404
850 johnpye 561 # TCL and TK required version 8.1, 8.2, 8.3, or 8.4:
851     tcltk_minor_newest_acceptable = 4
852     tcltk_major_required = 8
853    
854 johnpye 404 tcl_check_text = r"""
855     #include <tcl.h>
856     #include <stdio.h>
857     int main(void){
858     printf("%s",TCL_PATCH_LEVEL);
859     return 0;
860     }
861     """
862    
863     def CheckTcl(context):
864 johnpye 521 return CheckExtLib(context,'tcl',tcl_check_text,static=env['STATIC_TCLTK'])
865 johnpye 405
866     def CheckTclVersion(context):
867 johnpye 521 keep = KeepContext(context,'TCL',static=env['STATIC_TCLTK'])
868 johnpye 405 context.Message("Checking Tcl version... ")
869     (is_ok,output) = context.TryRun(tcl_check_text,'.c')
870 johnpye 404 keep.restore(context)
871     if not is_ok:
872 johnpye 405 context.Result("failed to run check")
873 johnpye 404 return 0
874 johnpye 405
875 wangym 511 major,minor,patch = tuple([int(i) for i in output.split(".")])
876 johnpye 561 if major != tcltk_major_required or minor > tcltk_minor_newest_acceptable:
877 johnpye 428 context.Result(output+" (bad version)")
878 johnpye 405 # bad version
879     return 0
880    
881     # good version
882 johnpye 552 context.Result(output+", good")
883 johnpye 404 return 1
884    
885 johnpye 405 #----------------
886 johnpye 463 # Tk test
887 johnpye 405
888     tk_check_text = r"""
889     #include <tk.h>
890     #include <stdio.h>
891     int main(void){
892     printf("%s",TK_PATCH_LEVEL);
893     return 0;
894     }
895     """
896     def CheckTk(context):
897 johnpye 673 return CheckExtLib(context,'tk',tk_check_text,static=env['STATIC_TCLTK'])
898 johnpye 405
899 johnpye 428
900 johnpye 405 def CheckTkVersion(context):
901 johnpye 521 keep = KeepContext(context,'TK',static=context.env['STATIC_TCLTK'])
902 johnpye 405 context.Message("Checking Tk version... ")
903 johnpye 521 #print "LINKFLAGS =",context.env['LINKFLAGS']
904 johnpye 405 (is_ok,output) = context.TryRun(tk_check_text,'.c')
905 johnpye 404 keep.restore(context)
906     if not is_ok:
907     context.Result("failed to run check")
908     return 0
909    
910 wangym 511 major,minor,patch = tuple([int(i) for i in output.split(".")])
911 johnpye 561 if major != tcltk_major_required or minor > tcltk_minor_newest_acceptable:
912 johnpye 404 # bad version
913 johnpye 561 context.Result(output+" (bad version)")
914 johnpye 404 return 0
915 johnpye 400
916 johnpye 404 # good version
917 johnpye 561 context.Result(output+" (good)")
918 johnpye 404 return 1
919 johnpye 485
920     #----------------
921 johnpye 521 # Tktable test
922    
923     tktable_check_text = r"""
924     #include <tkTable.h>
925     #include <stdio.h>
926     int main(void){
927     Table mytable;
928     return 0;
929     }
930     """
931    
932     def CheckTkTable(context):
933     return CheckExtLib(context,'tktable',tktable_check_text,static=env['STATIC_TCLTK'])
934    
935     #---------------
936     # X11 test
937    
938     x11_check_text = r"""
939     #include <X11/Xlib.h>
940     #include <X11/IntrinsicP.h>
941     #include <X11/Intrinsic.h>
942     #include <X11/ObjectP.h>
943     #include <X11/Object.h>
944     int main(void){
945     Object mything;
946     return 0;
947     }
948     """
949    
950     def CheckX11(context):
951     return CheckExtLib(context,'X11',x11_check_text)
952    
953     #----------------
954 johnpye 485 # GCC Version sniffing
955    
956     # TODO FIXME
957    
958     gcc_version4 = False
959    
960 johnpye 398 #------------------------------------------------------
961 johnpye 385 # CONFIGURATION
962    
963     conf = Configure(env
964     , custom_tests = {
965 johnpye 673 'CheckMath' : CheckMath
966     , 'CheckSwigVersion' : CheckSwigVersion
967 johnpye 400 , 'CheckCUnit' : CheckCUnit
968 johnpye 404 , 'CheckTcl' : CheckTcl
969     , 'CheckTclVersion' : CheckTclVersion
970 johnpye 405 , 'CheckTk' : CheckTk
971     , 'CheckTkVersion' : CheckTkVersion
972 johnpye 502 , 'CheckGcc' : CheckGcc
973 johnpye 500 , 'CheckGccVisibility' : CheckGccVisibility
974 johnpye 502 , 'CheckYacc' : CheckYacc
975 johnpye 521 , 'CheckTkTable' : CheckTkTable
976     , 'CheckX11' : CheckX11
977 johnpye 673 , 'CheckIDA' : CheckIDA
978 johnpye 783 , 'CheckCONOPT' : CheckCONOPT
979 johnpye 400 # , 'CheckIsNan' : CheckIsNan
980     # , 'CheckCppUnitConfig' : CheckCppUnitConfig
981 johnpye 385 }
982 johnpye 459 # , config_h = "config.h"
983 johnpye 385 )
984    
985 johnpye 740 # stdio -- just to check that compiler is behaving
986 johnpye 398
987 johnpye 740 if not conf.CheckHeader('stdio.h'):
988     print "Did not find 'stdio.h'! Check your compiler configuration."
989     Exit(1)
990    
991 johnpye 385 # Math library
992    
993 johnpye 673 if need_libm:
994     if not conf.CheckMath():
995     print 'Did not find math library, exiting!'
996     Exit(1)
997     #pass
998 johnpye 427
999 johnpye 385 # Where is 'isnan'?
1000    
1001 johnpye 740 if not conf.CheckFunc('isnan') and not conf.CheckFunc('_isnan'):
1002 johnpye 385 print "Didn't find isnan"
1003 johnpye 414 # Exit(1)
1004 johnpye 385
1005 johnpye 500 # GCC visibility
1006    
1007 johnpye 502 if conf.CheckGcc():
1008     conf.env['HAVE_GCC']=True;
1009 johnpye 526 if env['WITH_GCCVISIBILITY'] and conf.CheckGccVisibility():
1010 johnpye 509 conf.env['HAVE_GCCVISIBILITY']=True;
1011     conf.env.Append(CCFLAGS=['-fvisibility=hidden'])
1012     conf.env.Append(CPPDEFINES=['HAVE_GCCVISIBILITY'])
1013 johnpye 709 conf.env.Append(CCFLAGS=['-Wall'])
1014 johnpye 500
1015 johnpye 502 # YACC
1016    
1017 johnpye 506 if not conf.CheckYacc():
1018     print "YACC NOT FOUND OR NOT WORKING"
1019     else:
1020 johnpye 502 conf.env['HAVE_YACC']=True
1021    
1022     conf.env['HAVE_LEX']=True
1023    
1024 johnpye 387 # Tcl/Tk
1025 johnpye 386
1026 johnpye 586 if with_tcltk:
1027     if conf.CheckTcl():
1028     if conf.CheckTclVersion():
1029     if conf.CheckTk():
1030     if with_tcltk and conf.CheckTkVersion():
1031     if env['STATIC_TCLTK']:
1032     if conf.CheckTkTable():
1033     pass
1034     else:
1035     without_tcltk_reason = "TkTable not found"
1036     with_tcltk = False
1037     else:
1038     without_tcltk_reason = "Require Tk version <= 8.4. See 'scons -h'"
1039     with_tcltk = False
1040 johnpye 521 else:
1041 johnpye 586 without_tcltk_reason = "Tk not found."
1042 johnpye 551 with_tcltk = False
1043 johnpye 428 else:
1044 johnpye 586 without_tcltk_reason = "Require Tcl <= 8.4 Tcl."
1045 johnpye 551 with_tcltk = False
1046 johnpye 586
1047 johnpye 428 else:
1048 johnpye 586 without_tcltk_reason = "Tcl not found."
1049 johnpye 551 with_tcltk = False
1050 johnpye 386
1051 johnpye 521 if env['STATIC_TCLTK']:
1052     conf.CheckX11()
1053    
1054 johnpye 395 # Python... obviously we're already running python, so we just need to
1055     # check that we can link to the python library OK:
1056    
1057 johnpye 391 if platform.system()=="Windows":
1058 johnpye 395 python_lib='python24'
1059 johnpye 391 else:
1060 johnpye 395 python_lib='python2.4'
1061 johnpye 391
1062 johnpye 395 # SWIG version
1063    
1064 johnpye 413 if not conf.CheckSwigVersion():
1065     without_python_reason = 'SWIG >= 1.3.24 is required'
1066     with_python = False
1067    
1068 johnpye 400 # CUnit
1069    
1070 johnpye 593 if with_cunit:
1071 johnpye 404 if not conf.CheckCUnit():
1072 johnpye 427 without_cunit_reason = 'CUnit not found'
1073 johnpye 665 with_cunit = False
1074 johnpye 705 #print "CUNIT NOT FOUND, LIBS=",conf.env.get('LIBS')
1075 johnpye 427
1076 johnpye 673 # IDA
1077    
1078     if not with_ida:
1079     without_ida_reason = "Not selected (see config option WITH_SOLVERS)"
1080     elif not conf.CheckIDA():
1081     with_ida = False
1082     without_ida_reason = "IDA not found"
1083    
1084 johnpye 783 # IDA
1085    
1086     if not with_conopt:
1087     without_conopt_reason = "Not selected (see config option WITH_SOLVERS)"
1088     elif not conf.CheckCONOPT():
1089     with_ida = False
1090     without_ida_reason = "CONOPT not found"
1091    
1092 johnpye 427 # BLAS
1093    
1094 johnpye 459 need_blas=False
1095 johnpye 673
1096     if with_lsode:
1097     need_fortran = True
1098 johnpye 459 need_blas=True
1099 johnpye 673
1100 johnpye 459 if need_blas:
1101     if conf.CheckLib('blas'):
1102     with_local_blas = False
1103     without_local_blas_reason = "Found BLAS installed on system"
1104     else:
1105     with_local_blas = True
1106     need_fortran = True
1107 johnpye 673 else:
1108     with_local_blas= False;
1109     without_local_blas_reason = "BLAS not required"
1110 johnpye 427
1111     # FORTRAN
1112    
1113     if need_fortran:
1114 johnpye 629 conf.env.Tool('fortran')
1115     detect_fortran = conf.env.Detect(['g77','f77','gfortran'])
1116 johnpye 427 if detect_fortran:
1117     # For some reason, g77 doesn't get detected properly on MinGW
1118 johnpye 673 if not env.has_key('F77') and not env.has_key('FORTRAN'):
1119 johnpye 427 conf.env.Replace(F77=detect_fortran)
1120     conf.env.Replace(F77COM='$F77 $F77FLAGS -c -o $TARGET $SOURCE')
1121     conf.env.Replace(F77FLAGS='')
1122 johnpye 428 #print "F77:",conf.env['F77']
1123     #print "F77COM:",conf.env['F77COM']
1124     #print "F77FLAGS:",conf.env['F77FLAGS']
1125 johnpye 427 fortran_builder = Builder(
1126     action='$F77COM'
1127     , suffix='.o'
1128     , src_suffix='.f'
1129     )
1130     conf.env.Append(BUILDERS={'Fortran':fortran_builder})
1131     else:
1132 johnpye 673 with_lsode=False;
1133     without_lsode_reason="FORTRAN-77 required but not found"
1134 johnpye 629
1135 johnpye 464 #else:
1136     # print "FORTRAN not required"
1137 johnpye 400
1138 johnpye 673 # F2C
1139    
1140     if need_fortran:
1141     if platform.system()=="Windows":
1142     conf.env.Append(LIBPATH='c:\mingw\lib')
1143    
1144    
1145 johnpye 385 # TODO: -D_HPUX_SOURCE is needed
1146    
1147     # TODO: check size of void*
1148    
1149 johnpye 393 # TODO: detect if dynamic libraries are possible or not
1150    
1151 johnpye 427 if platform.system()=="Windows" and env.has_key('MSVS'):
1152 johnpye 740 _found_windows_h = conf.CheckHeader('Windows.h')
1153    
1154     if not _found_windows_h:
1155 johnpye 741 print "Could not locate 'Windows.h' in CPPPATH. Check your configuration."
1156 johnpye 740 Exit(1)
1157 johnpye 741
1158 johnpye 534 if with_python and not conf.CheckHeader(['basetsd.h','BaseTsd.h']):
1159 johnpye 427 with_python = 0;
1160     without_python_reason = "Header file 'basetsd.h' not found. Install the MS Platform SDK."
1161    
1162     conf.env.Append(CPPDEFINES=env['PACKAGE_LINKING'])
1163    
1164 johnpye 395 conf.Finish()
1165    
1166     env.Append(PYTHON_LIBPATH=[distutils.sysconfig.PREFIX+"/libs"])
1167     env.Append(PYTHON_LIB=[python_lib])
1168     env.Append(PYTHON_CPPPATH=[distutils.sysconfig.get_python_inc()])
1169    
1170 johnpye 507 #---------------------------------------
1171     # SUBSTITUTION DICTIONARY for .in files
1172    
1173 johnpye 658 release = env.get('RELEASE')
1174     if release=="0.":
1175     release="0"
1176    
1177 johnpye 507 subst_dict = {
1178     '@DEFAULT_ASCENDLIBRARY@':env['DEFAULT_ASCENDLIBRARY']
1179     , '@GLADE_FILE@':'ascend.glade'
1180     , '@HELP_ROOT@':''
1181     , '@ICON_EXTENSION@':icon_extension
1182 johnpye 628 , '@INSTALL_ASCDATA@':env['INSTALL_ASCDATA']
1183 johnpye 507 , '@INSTALL_BIN@':env['INSTALL_BIN']
1184     , '@INSTALL_INCLUDE@':env['INSTALL_INCLUDE']
1185 johnpye 683 , '@INSTALL_LIB@':env['INSTALL_LIB']
1186 johnpye 721 , '@INSTALL_MODELS@':env['INSTALL_MODELS']
1187 johnpye 507 , '@PYGTK_ASSETS@':env['PYGTK_ASSETS']
1188     , '@VERSION@':version
1189 johnpye 658 , '@RELEASE@':release
1190 johnpye 563 , '@DISTTAR_NAME@':env['DISTTAR_NAME']
1191 johnpye 507 , '@WEBHELPROOT@':'http://pye.dyndns.org/ascend/manual/'
1192 johnpye 508 , '@ASC_SHLIBSUFFIX@':env['SHLIBSUFFIX']
1193     , '@ASC_SHLIBPREFIX@':env['SHLIBPREFIX']
1194 johnpye 589 , '@ASC_ENV_TK_DEFAULT@' : '$$ASCENDDIST/tcltk'
1195 johnpye 627 , '@ASC_DISTDIR_REL_BIN@' : default_rel_distdir
1196 johnpye 683 , '@PYTHON@' : python_exe
1197 johnpye 507 }
1198    
1199 johnpye 594 if env.get('WITH_LOCAL_HELP'):
1200 johnpye 507 print "WITH_LOCAL_HELP:",env['WITH_LOCAL_HELP']
1201     subst_dict['@HELP_ROOT@']=env['WITH_LOCAL_HELP']
1202    
1203 johnpye 597 # bool options...
1204 johnpye 673 for k,v in {
1205     'ABSOLUTE_PATHS' : 'ASC_ABSOLUTE_PATHS'
1206     ,'WITH_XTERM_COLORS' : 'ASC_XTERM_COLORS'
1207     ,'MALLOC_DEBUG' : 'MALLOC_DEBUG'
1208 johnpye 605 }.iteritems():
1209 johnpye 597 if env.get(k):
1210 johnpye 673 # subst_dict['@'+v+'@']='1'
1211     subst_dict["/\\* #define "+v+' @'+v+"@ \\*/"]='# define '+v+' 1 '
1212 johnpye 594
1213 johnpye 673 if with_ida:
1214     subst_dict["/\\* #define ASC_WITH_IDA @ASC_WITH_IDA@ \\*/"]='#define ASC_WITH_IDA '
1215    
1216 johnpye 783 if with_conopt:
1217     subst_dict["/\\* #define ASC_WITH_CONOPT @ASC_WITH_CONOPT@ \\*/"]='#define ASC_WITH_CONOPT '
1218    
1219 johnpye 673 if with_lsode:
1220     subst_dict["/\\* #define ASC_WITH_LSODE @ASC_WITH_LSODE@ \\*/"]='#define ASC_WITH_LSODE '
1221    
1222 johnpye 507 if with_python:
1223     subst_dict['@ASCXX_USE_PYTHON@']="1"
1224 johnpye 673 env['WITH_PYTHON']=1;
1225 johnpye 507
1226     if env.has_key('HAVE_GCCVISIBILITY'):
1227     subst_dict['@HAVE_GCCVISIBILITY@'] = "1"
1228    
1229     env.Append(SUBST_DICT=subst_dict)
1230    
1231 johnpye 385 #------------------------------------------------------
1232 johnpye 558 # RECIPE: SWIG scanner
1233    
1234     import SCons.Script
1235    
1236     SWIGScanner = SCons.Scanner.ClassicCPP(
1237     "SWIGScan"
1238     , ".i"
1239     , "CPPPATH"
1240     , '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")'
1241     )
1242    
1243     env.Append(SCANNERS=[SWIGScanner])
1244    
1245     #------------------------------------------------------
1246 johnpye 393 # RECIPE: 'SubstInFile', used in pygtk SConscript
1247    
1248     import re
1249 johnpye 395 from SCons.Script import * # the usual scons stuff you get in a SConscript
1250 johnpye 393
1251 johnpye 395 def TOOL_SUBST(env):
1252     """Adds SubstInFile builder, which substitutes the keys->values of SUBST_DICT
1253     from the source to the target.
1254     The values of SUBST_DICT first have any construction variables expanded
1255     (its keys are not expanded).
1256     If a value of SUBST_DICT is a python callable function, it is called and
1257     the result is expanded as the value.
1258     If there's more than one source and more than one target, each target gets
1259     substituted from the corresponding source.
1260 johnpye 393 """
1261 johnpye 395 env.Append(TOOLS = 'SUBST')
1262     def do_subst_in_file(targetfile, sourcefile, dict):
1263     """Replace all instances of the keys of dict with their values.
1264     For example, if dict is {'%VERSION%': '1.2345', '%BASE%': 'MyProg'},
1265     then all instances of %VERSION% in the file will be replaced with 1.2345 etc.
1266     """
1267     try:
1268     f = open(sourcefile, 'rb')
1269     contents = f.read()
1270     f.close()
1271     except:
1272     raise SCons.Errors.UserError, "Can't read source file %s"%sourcefile
1273     for (k,v) in dict.items():
1274     contents = re.sub(k, v, contents)
1275     try:
1276     f = open(targetfile, 'wb')
1277     f.write(contents)
1278     f.close()
1279     except:
1280     raise SCons.Errors.UserError, "Can't write target file %s"%targetfile
1281     return 0 # success
1282 johnpye 393
1283 johnpye 395 def subst_in_file(target, source, env):
1284     if not env.has_key('SUBST_DICT'):
1285     raise SCons.Errors.UserError, "SubstInFile requires SUBST_DICT to be set."
1286     d = dict(env['SUBST_DICT']) # copy it
1287     for (k,v) in d.items():
1288     if callable(v):
1289     d[k] = env.subst(v())
1290     elif SCons.Util.is_String(v):
1291     d[k]=env.subst(v)
1292     else:
1293     raise SCons.Errors.UserError, "SubstInFile: key %s: %s must be a string or callable"%(k, repr(v))
1294     for (t,s) in zip(target, source):
1295     return do_subst_in_file(str(t), str(s), d)
1296 johnpye 393
1297 johnpye 395 def subst_in_file_string(target, source, env):
1298     """This is what gets printed on the console."""
1299     return '\n'.join(['Substituting vars from %s into %s'%(str(s), str(t))
1300     for (t,s) in zip(target, source)])
1301 johnpye 393
1302 johnpye 395 def subst_emitter(target, source, env):
1303     """Add dependency from substituted SUBST_DICT to target.
1304     Returns original target, source tuple unchanged.
1305     """
1306     d = env['SUBST_DICT'].copy() # copy it
1307     for (k,v) in d.items():
1308     if callable(v):
1309     d[k] = env.subst(v())
1310     elif SCons.Util.is_String(v):
1311     d[k]=env.subst(v)
1312     Depends(target, SCons.Node.Python.Value(d))
1313     return target, source
1314 johnpye 393
1315 johnpye 395 subst_action=SCons.Action.Action(subst_in_file, subst_in_file_string)
1316     env['BUILDERS']['SubstInFile'] = Builder(action=subst_action, emitter=subst_emitter)
1317    
1318     TOOL_SUBST(env)
1319    
1320 johnpye 393 #------------------------------------------------------
1321 johnpye 463 # Recipe for 'CHMOD' ACTION
1322 johnpye 439
1323     import SCons
1324     from SCons.Script.SConscript import SConsEnvironment
1325     SConsEnvironment.Chmod = SCons.Action.ActionFactory(os.chmod,
1326     lambda dest, mode: 'Chmod("%s", 0%o)' % (dest, mode))
1327    
1328     def InstallPerm(env, dest, files, perm):
1329     obj = env.Install(dest, files)
1330     for i in obj:
1331     env.AddPostAction(i, env.Chmod(str(i), perm))
1332    
1333     SConsEnvironment.InstallPerm = InstallPerm
1334    
1335     # define wrappers
1336     SConsEnvironment.InstallProgram = lambda env, dest, files: InstallPerm(env, dest, files, 0755)
1337 johnpye 578 SConsEnvironment.InstallHeader = lambda env, dest, files: InstallPerm(env, dest, files, 0644)
1338 johnpye 629 SConsEnvironment.InstallShared = lambda env, dest, files: InstallPerm(env, dest, files, 0644)
1339 johnpye 463
1340 johnpye 439 #------------------------------------------------------
1341 johnpye 463 # BUILD...
1342 johnpye 385
1343 johnpye 463 # so that #include <modulename/headername.h> works across all modules...
1344 johnpye 743 env.AppendUnique(CPPPATH=['#base/generic'])
1345 johnpye 385
1346 johnpye 508 if env['DEBUG']:
1347     env.Append(CCFLAGS=['-g'])
1348    
1349 johnpye 591 if env['GCOV']:
1350     env.Append(
1351     CPPFLAGS=['-g','-fprofile-arcs','-ftest-coverage']
1352     , LIBS=['gcov']
1353     , LINKFLAGS=['-fprofile-arcs','-ftest-coverage']
1354     )
1355    
1356 johnpye 673 if with_ida:
1357     env.Append(WITH_IDA=1)
1358    
1359 johnpye 783 if with_conopt:
1360     env.Append(WITH_CONOPT=1)
1361    
1362 johnpye 463 #-------------
1363     # TCL/TK GUI
1364 johnpye 385
1365 johnpye 551 if with_tcltk:
1366 johnpye 569 env.SConscript(['tcltk/generic/interface/SConscript'],'env')
1367 johnpye 391 else:
1368 johnpye 405 print "Skipping... Tcl/Tk GUI isn't being built:",without_tcltk_reason
1369 johnpye 386
1370 johnpye 463 #-------------
1371     # PYTHON INTERFACE
1372    
1373 johnpye 387 if with_python:
1374 johnpye 532 env.SConscript(['pygtk/SConscript'],'env')
1375 johnpye 391 else:
1376 johnpye 413 print "Skipping... Python GUI isn't being built:",without_python_reason
1377 johnpye 400
1378 johnpye 463 #------------
1379     # BASE/GENERIC SUBDIRECTORIES
1380    
1381 johnpye 673 libascend_env = env.Copy()
1382    
1383 johnpye 463 dirs = ['general','utilities','compiler','solver','packages']
1384    
1385     srcs = []
1386     for d in dirs:
1387 johnpye 673 heresrcs = libascend_env.SConscript('base/generic/'+d+'/SConscript','libascend_env')
1388 johnpye 463 srcs += heresrcs
1389    
1390     #-------------
1391 johnpye 673 # IMPORTED CODE: LSODE, BLAS, etc
1392    
1393     if with_lsode:
1394     srcs += env.SConscript(['lsod/SConscript'],'env')
1395     srcs += env.SConscript(['linpack/SConscript'],'env')
1396     else:
1397     print "Skipping... LSODE won't be built:", without_lsode_reason
1398    
1399     if with_local_blas:
1400     srcs += env.SConscript(['blas/SConscript'],'env')
1401     else:
1402     print "Skipping... BLAS won't be built:", without_local_blas_reason
1403    
1404     if not with_ida:
1405     print "Skipping... IDA won't be built:", without_ida_reason
1406    
1407     #-------------
1408 johnpye 463 # LIBASCEND -- all base/generic functionality
1409    
1410 johnpye 673 libascend = libascend_env.SharedLibrary('ascend',srcs)
1411 johnpye 463
1412 johnpye 673 env.Alias('libascend',libascend)
1413    
1414 johnpye 463 #-------------
1415 johnpye 761 # UNIT TESTS (C CODE)
1416 johnpye 463
1417 johnpye 593 if with_cunit:
1418 johnpye 400 testdirs = ['general','solver','utilities']
1419 johnpye 593 testsrcs = []
1420 johnpye 400 for testdir in testdirs:
1421     path = 'base/generic/'+testdir+'/test/'
1422     env.SConscript([path+'SConscript'],'env')
1423 johnpye 593 testsrcs += [i.path for i in env['TESTSRCS_'+testdir.upper()]]
1424    
1425     #print "TESTSRCS =",testsrcs
1426    
1427 johnpye 400 env.SConscript(['test/SConscript'],'env')
1428     env.SConscript(['base/generic/test/SConscript'],'env')
1429 johnpye 593
1430     env.Alias('test',[env.Dir('test'),env.Dir('base/generic/test')])
1431 johnpye 400
1432     else:
1433 johnpye 427 print "Skipping... CUnit tests aren't being built:",without_cunit_reason
1434 johnpye 400
1435 johnpye 761 #-------------
1436     # EXTERNAL FUNCTIONS
1437    
1438     extfns = []
1439     if with_extfns:
1440     testdirs = ['johnpye/extfn']
1441     for testdir in testdirs:
1442     path = 'models/'+testdir+"/SConscript"
1443     extfns += env.SConscript(path,'env')
1444     else:
1445     print "Skipping... External modules aren't being built:",without_extfns_reason
1446    
1447     env.Alias('extfns',extfns)
1448    
1449 johnpye 463 #------------------------------------------------------
1450 johnpye 683 # CREATE ASCEND-CONFIG scriptlet
1451    
1452     ascendconfig = env.SubstInFile('ascend-config.in')
1453    
1454     #------------------------------------------------------
1455 johnpye 463 # INSTALLATION
1456 johnpye 427
1457 johnpye 552 if env.get('CAN_INSTALL'):
1458 johnpye 463 # the models directory only needs to be processed for installation, no other processing required.
1459     env.SConscript(['models/SConscript'],'env')
1460 johnpye 427
1461 johnpye 721 dirs = ['INSTALL_BIN','INSTALL_ASCDATA','INSTALL_LIB', 'INSTALL_INCLUDE']
1462 johnpye 463 install_dirs = [env['INSTALL_ROOT']+env[d] for d in dirs]
1463 johnpye 449
1464 johnpye 463 # TODO: add install options
1465     env.Alias('install',install_dirs)
1466 johnpye 400
1467 johnpye 629 env.InstallShared(env['INSTALL_ROOT']+env['INSTALL_LIB'],libascend)
1468 johnpye 435
1469 johnpye 683 env.InstallProgram(env['INSTALL_ROOT']+env['INSTALL_BIN'],ascendconfig)
1470    
1471 johnpye 438 #------------------------------------------------------
1472 johnpye 631 # WINDOWS INSTALLER
1473     # For the windows installer, please see pygtk/SConscript
1474    
1475     if with_installer:
1476     pass
1477     else:
1478     print "Skipping... Windows installer isn't being built:",without_installer_reason
1479    
1480     #------------------------------------------------------
1481 johnpye 673 # PROJECT FILE for MSVC
1482    
1483     env.SConscript(['base/msvc/SConscript'],['env','libascend']);
1484    
1485     #------------------------------------------------------
1486 johnpye 438 # CREATE the SPEC file for generation of RPM packages
1487    
1488 johnpye 463 if platform.system()=="Linux":
1489     env.SubstInFile('ascend.spec.in')
1490 johnpye 552
1491     #------------------------------------------------------
1492     # DISTRIBUTION TAR FILE
1493    
1494 johnpye 554 env['DISTTAR_FORMAT']='bz2'
1495 johnpye 556 env.Append(
1496 johnpye 566 DISTTAR_EXCLUDEEXTS=['.o','.os','.so','.a','.dll','.cc','.cache','.pyc','.cvsignore','.dblite','.log','.pl']
1497 johnpye 561 , DISTTAR_EXCLUDEDIRS=['CVS','.svn','.sconf_temp', 'dist']
1498 johnpye 556 )
1499 johnpye 554
1500 johnpye 563 tar = env.DistTar("dist/"+env['DISTTAR_NAME']
1501 johnpye 556 , [env.Dir('#')]
1502 johnpye 554 )
1503    
1504 johnpye 680 env.Depends(tar,'ascend.spec')
1505    
1506 johnpye 554 #------------------------------------------------------
1507 johnpye 766 # LIBASCEND DOXYGEN DOCUMENTATION
1508    
1509     env.SConscript('base/doc/SConscript',['env'])
1510    
1511     #------------------------------------------------------
1512 johnpye 554 # RPM BUILD
1513    
1514 johnpye 766 # for RPM builds, 'scons dist' then 'rpmbuild -ta dist/ascend-*.tar.bz2'
1515     # (check * for the version number used to create the tarball)
1516 johnpye 554
1517     #------------------------------------------------------
1518     # DEFAULT TARGETS
1519    
1520 johnpye 673 default_targets =['libascend']
1521 johnpye 629 if with_tcltk:
1522     default_targets.append('tcltk')
1523     if with_python:
1524     default_targets.append('pygtk')
1525 johnpye 631 if with_installer:
1526     default_targets.append('installer')
1527 johnpye 761 if with_extfns:
1528     default_targets.append('extfns')
1529 johnpye 554
1530 johnpye 629 env.Default(default_targets)
1531    
1532     print "Building targets:"," ".join([str(i) for i in BUILD_TARGETS])
1533    
1534 johnpye 705 # vim: set syntax=python:
1535    

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