/[ascend]/trunk/SConstruct
ViewVC logotype

Annotation of /trunk/SConstruct

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1339 - (hide annotations) (download)
Sat Mar 10 13:57:01 2007 UTC (13 years, 1 month ago) by jpye
File size: 51339 byte(s)
Removed ASC_IDA_NEW_ANALYSE condition from the codebase.
Cleaned up some debug output.
1 johnpye 955 import sys, os, commands, platform, distutils.sysconfig, os.path, re
2 johnpye 385
3 johnpye 1260 version = "0.9.5.107"
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 johnpye 800 default_conopt_prefix = "c:\\Program Files\\CONOPT"
33     default_conopt_libpath="$CONOPT_PREFIX"
34     default_conopt_cpppath="$CONOPT_PREFIX"
35     default_conopt_lib="conopt3"
36     default_conopt_envvar="CONOPT_PATH"
37 johnpye 935
38 johnpye 938 default_prefix="c:\\MinGW"
39     default_libpath="$DEFAULT_PREFIX\\lib"
40     default_cpppath="$DEFAULT_PREFIX\\include"
41 johnpye 800
42 johnpye 783 if not os.path.exists(default_conopt_prefix):
43     default_conopt_prefix = None
44 johnpye 739
45 johnpye 673 need_libm = False
46 johnpye 683 python_exe = "c:\\Python24\\python.exe"
47 johnpye 816 default_with_scrollkeeper=False
48 johnpye 464 else:
49 johnpye 673 default_tcl_lib = "tcl8.4"
50     default_tk_lib = "tk8.4"
51 johnpye 464 default_tktable_lib = "Tktable2.8"
52 johnpye 628 default_install_assets = "$INSTALL_ASCDATA/glade/"
53 johnpye 499 icon_extension = '.svg'
54 johnpye 684 default_tcl = '/usr'
55 johnpye 541 default_tcl_libpath = "$TCL/lib"
56 johnpye 627 default_rel_distdir = '../share/ascend'
57 johnpye 628 default_absolute_paths = True
58 johnpye 673 default_ida_prefix="/usr/local"
59 johnpye 783 default_conopt_prefix="/usr"
60 johnpye 800 default_conopt_libpath="$CONOPT_PREFIX/lib"
61     default_conopt_cpppath="$CONOPT_PREFIX/include"
62     default_conopt_lib="consub3"
63 johnpye 804 default_conopt_envvar="CONOPT_PATH"
64 johnpye 800
65 johnpye 938 default_prefix="/usr"
66     default_libpath="$DEFAULT_PREFIX/lib"
67     default_cpppath="$DEFAULT_PREFIX/include"
68    
69 johnpye 673 need_libm = True
70 johnpye 551 if not os.path.isdir(default_tcl):
71     default_tcl = '/usr'
72 johnpye 683 python_exe = distutils.sysconfig.EXEC_PREFIX+"/bin/python"
73 johnpye 816 default_with_scrollkeeper=False
74 johnpye 551
75 johnpye 562 opts.Add(
76     'CC'
77     ,'C Compiler command'
78     ,None
79     )
80    
81     opts.Add(
82     'CXX'
83     ,'C++ Compiler command'
84     ,None
85     )
86    
87 johnpye 591 opts.Add(BoolOption(
88     'GCOV'
89 johnpye 593 , 'Whether to enable coverage testing in object code'
90     , False
91 johnpye 591 ))
92    
93 johnpye 385 # Package linking option
94 johnpye 386 opts.Add(EnumOption(
95     'PACKAGE_LINKING'
96 johnpye 385 , 'Style of linking for external libraries'
97     , 'DYNAMIC_PACKAGES'
98 johnpye 386 , ['DYNAMIC_PACKAGES', 'STATIC_PACKAGES', 'NO_PACKAGES']
99     ))
100 johnpye 385
101 johnpye 526 opts.Add(BoolOption(
102     'WITH_GCCVISIBILITY'
103     ,"Whether to use GCC Visibility features (only applicable if available)"
104     ,True
105     ))
106    
107 johnpye 1142 opts.Add(BoolOption(
108     'WITH_SIGNALS'
109     ,"Whether to permit use of signals for flow control in the C-level code"
110 johnpye 1234 ,True
111 johnpye 1142 ))
112    
113 johnpye 392 # You can turn off building of Tcl/Tk interface
114 johnpye 386 opts.Add(BoolOption(
115 johnpye 542 'WITH_TCLTK'
116 johnpye 673 ,"Set to False if you don't want to build the original Tcl/Tk GUI."
117 johnpye 542 , True
118 johnpye 386 ))
119    
120 johnpye 392 # You can turn off the building of the Python interface
121 johnpye 387 opts.Add(BoolOption(
122 johnpye 542 'WITH_PYTHON'
123 johnpye 673 ,"Set to False if you don't want to build Python wrappers."
124 johnpye 542 , True
125 johnpye 387 ))
126    
127 johnpye 392 # Which solvers will we allow?
128     opts.Add(ListOption(
129     'WITH_SOLVERS'
130 johnpye 393 ,"List of the solvers you want to build. The default is the minimum that"
131     +" works."
132 johnpye 784 ,["QRSLV","CMSLV","LSOD","IDA","CONOPT","LRSLV"]
133 johnpye 392 ,['QRSLV','MPS','SLV','OPTSQP'
134     ,'NGSLV','CMSLV','LRSLV','MINOS','CONOPT'
135 johnpye 673 ,'LSOD','OPTSQP',"IDA"
136 johnpye 392 ]
137     ))
138    
139 johnpye 393 # Where will the local copy of the help files be kept?
140     opts.Add(PackageOption(
141     'WITH_LOCAL_HELP'
142     , "Directory containing the local copy of the help files (optional)"
143     , "no"
144     ))
145    
146     # Will bintoken support be enabled?
147     opts.Add(BoolOption(
148     'WITH_BINTOKEN'
149     ,"Enable bintoken support? This means compiling models as C-code before"
150     +" running them, to increase solving speed for large models."
151     ,False
152     ))
153    
154 johnpye 398 # What should the default ASCENDLIBRARY path be?
155     # Note: users can change it by editing their ~/.ascend.ini
156 johnpye 393 opts.Add(
157     'DEFAULT_ASCENDLIBRARY'
158     ,"Set the default value of the ASCENDLIBRARY -- the location where"
159     +" ASCEND will look for models when running ASCEND"
160 johnpye 628 ,"$INSTALL_ASCDATA/models"
161 johnpye 393 )
162    
163 johnpye 398 # Where is SWIG?
164     opts.Add(
165     'SWIG'
166     ,"SWIG location, probably only required for MinGW and MSVC users."
167     +" Enter the location as a Windows-style path, for example"
168 johnpye 404 +" 'c:\\msys\\1.0\\home\\john\\swigwin-1.3.29\\swig.exe'."
169 johnpye 398 )
170    
171 johnpye 400 # Build the test suite?
172     opts.Add(BoolOption(
173 johnpye 593 'WITH_CUNIT'
174 johnpye 665 ,"You can disable CUnit tests with this option. This will basically stop"
175     +" SCons from parsing the SConscript files relating to the 'test'"
176     +" target, which just might make things marginally faster. Probably"
177     +" you can just ignore this option though. SCons will sniff for Cunit"
178     +" but build the tests only if you specify the 'test' target."
179     ,True
180 johnpye 400 ))
181 johnpye 393
182 johnpye 993 # Build with MMIO matrix export support?
183     opts.Add(BoolOption(
184     'WITH_MMIO'
185     ,"Include support for exporting matrices in Matrix Market format"
186     ,True
187     ))
188    
189 johnpye 938 #----- default paths -----
190     opts.Add(PackageOption(
191     'DEFAULT_PREFIX'
192     ,"Where are most of the shared libraries located on your system?"
193     ,default_prefix
194     ))
195    
196 johnpye 957 #------ install location for python extensions ------
197    
198     # (removed for the moment)
199    
200 johnpye 938 #------ cunit --------
201 johnpye 935 # Where was CUNIT installed?
202     opts.Add(PackageOption(
203     'CUNIT_PREFIX'
204     ,"Where are your CUnit files?"
205 johnpye 938 ,"$DEFAULT_PREFIX"
206 johnpye 935 ))
207    
208 johnpye 400 # Where are the CUnit includes?
209     opts.Add(PackageOption(
210     'CUNIT_CPPPATH'
211     ,"Where are your CUnit include files?"
212 johnpye 938 ,"$CUNIT_PREFIX/include"
213 johnpye 400 ))
214 johnpye 392
215 johnpye 404 # Where are the CUnit libraries?
216 johnpye 400 opts.Add(PackageOption(
217     'CUNIT_LIBPATH'
218 johnpye 404 ,"Where are your CUnit libraries?"
219 johnpye 938 ,"$CUNIT_PREFIX/lib"
220 johnpye 400 ))
221    
222 johnpye 938 #-------- ida -------
223    
224 johnpye 673 opts.Add(PackageOption(
225     "IDA_PREFIX"
226     ,"Prefix for your IDA install (IDA ./configure --prefix)"
227     ,default_ida_prefix
228     ))
229 johnpye 521
230 johnpye 534 opts.Add(
231 johnpye 782 "IDA_LIB"
232     ,"Libraries linked to for IDA"
233 johnpye 922 ,['sundials_nvecserial','sundials_ida','m']
234 johnpye 782 )
235    
236     opts.Add(
237 johnpye 673 'IDA_CPPPATH'
238     ,"Where is your ida.h?"
239     ,"$IDA_PREFIX/include"
240     )
241    
242     opts.Add(
243     'IDA_LIBPATH'
244     ,"Where are your SUNDIALS libraries installed?"
245     ,"$IDA_PREFIX/lib"
246     )
247    
248 johnpye 938 # ----- conopt-----
249 johnpye 783
250     opts.Add(PackageOption(
251     "CONOPT_PREFIX"
252     ,"Prefix for your CONOPT install (CONOPT ./configure --prefix)"
253 johnpye 800 ,default_conopt_prefix
254 johnpye 783 ))
255    
256 johnpye 673 opts.Add(
257 johnpye 783 "CONOPT_LIB"
258     ,"Library linked to for CONOPT"
259 johnpye 800 ,default_conopt_lib
260 johnpye 783 )
261    
262     opts.Add(
263     'CONOPT_CPPPATH'
264     ,"Where is your conopt.h?"
265 johnpye 800 ,default_conopt_cpppath
266 johnpye 783 )
267    
268     opts.Add(
269     'CONOPT_LIBPATH'
270     ,"Where is your CONOPT libraries installed?"
271 johnpye 800 ,default_conopt_libpath
272 johnpye 783 )
273    
274     opts.Add(
275 johnpye 800 'CONOPT_ENVVAR'
276     ,"What environment variable should be used at runtime to override the default search location for CONOPT DLL/SO?"
277     ,default_conopt_envvar
278     )
279    
280 johnpye 938 #-------- f2c ------
281    
282 johnpye 800 opts.Add(
283 johnpye 673 "F2C_LIB"
284     ,"F2C library (eg. g2c, gfortran, f2c)"
285     ,"g2c"
286     )
287    
288     opts.Add(PackageOption(
289     "F2C_LIBPATH"
290     ,"Directory containing F2C library (i.e. g2c, gfortran, f2c, etc.), if not already accessible"
291     ,"off"
292     ))
293    
294 johnpye 938 #------- tcl/tk --------
295    
296 johnpye 673 opts.Add(
297 johnpye 521 'TCL'
298     ,'Base of Tcl distribution'
299     ,default_tcl
300 johnpye 534 )
301 johnpye 521
302 johnpye 404 # Where are the Tcl includes?
303 johnpye 534 opts.Add(
304 johnpye 404 'TCL_CPPPATH'
305     ,"Where are your Tcl include files?"
306 johnpye 521 ,"$TCL/include"
307 johnpye 534 )
308 johnpye 404
309     # Where are the Tcl libs?
310 johnpye 534 opts.Add(
311 johnpye 404 'TCL_LIBPATH'
312     ,"Where are your Tcl libraries?"
313 johnpye 541 ,default_tcl_libpath
314 johnpye 534 )
315 johnpye 404
316 johnpye 428 # What is the name of the Tcl lib?
317     opts.Add(
318     'TCL_LIB'
319 johnpye 561 ,"Name of Tcl lib (eg 'tcl' or 'tcl83'), for full path to static library (if STATIC_TCLTK is set)"
320 johnpye 464 ,default_tcl_lib
321 johnpye 428 )
322    
323 johnpye 405 # Where are the Tk includes?
324 johnpye 534 opts.Add(
325 johnpye 405 'TK_CPPPATH'
326     ,"Where are your Tk include files?"
327 johnpye 464 ,'$TCL_CPPPATH'
328 johnpye 534 )
329 johnpye 404
330 johnpye 405 # Where are the Tk libs?
331 johnpye 534 opts.Add(
332 johnpye 405 'TK_LIBPATH'
333     ,"Where are your Tk libraries?"
334 johnpye 464 ,'$TCL_LIBPATH'
335 johnpye 534 )
336 johnpye 405
337 johnpye 428 # What is the name of the Tk lib?
338     opts.Add(
339     'TK_LIB'
340 johnpye 521 ,"Name of Tk lib (eg 'tk' or 'tk83'), or full path to static library"
341 johnpye 464 ,default_tk_lib
342 johnpye 435 )
343    
344 johnpye 460 # Static linking to TkTable
345    
346     opts.Add(BoolOption(
347 johnpye 521 'STATIC_TCLTK'
348 johnpye 554 ,'Set true for static linking for Tcl/Tk and TkTable. EXPERIMENTAL'
349 johnpye 460 ,False
350     ))
351    
352 johnpye 464 opts.Add(
353 johnpye 460 'TKTABLE_LIBPATH'
354     ,'Location of TkTable static library'
355 johnpye 464 ,'$TCL_LIBPATH/Tktable2.8'
356     )
357 johnpye 460
358 johnpye 435 opts.Add(
359 johnpye 460 'TKTABLE_LIB'
360 johnpye 521 ,'Stem name of TkTable (eg tktable2.8, no ".so" or "lib") shared library, or full path of static tktable (/usr/lib/...)'
361 johnpye 464 ,default_tktable_lib
362 johnpye 460 )
363    
364     opts.Add(
365 johnpye 521 'TKTABLE_CPPPATH'
366     ,'Location of TkTable header file'
367     ,'$TCL_CPPPATH'
368     )
369    
370     opts.Add(
371     'X11'
372 johnpye 554 ,'Base X11 directory. Only used when STATIC_TCLTK is turned on. EXPERIMENTAL'
373 johnpye 521 ,'/usr/X11R6'
374     )
375    
376     opts.Add(
377     'X11_LIBPATH'
378 johnpye 554 ,'Location of X11 lib. EXPERIMENTAL'
379 johnpye 521 ,'$X11/lib'
380     )
381    
382     opts.Add(
383     'X11_CPPPATH'
384 johnpye 554 ,'Location of X11 includes. EXPERIMENTAL'
385 johnpye 521 ,'$X11/include'
386     )
387    
388     opts.Add(
389     'X11_LIB'
390 johnpye 554 ,'Name of X11 lib. EXPERIMENTAL'
391 johnpye 521 ,'X11'
392     )
393    
394 johnpye 938 #----- installed file locations (for 'scons install') -----
395    
396 johnpye 521 opts.Add(
397 johnpye 435 'INSTALL_PREFIX'
398     ,'Root location for installed files'
399 johnpye 449 ,'/usr/local'
400 johnpye 428 )
401    
402 johnpye 435 opts.Add(
403     'INSTALL_BIN'
404     ,'Location to put binaries during installation'
405     ,"$INSTALL_PREFIX/bin"
406     )
407    
408     opts.Add(
409 johnpye 463 'INSTALL_LIB'
410 johnpye 683 ,'Location to put libraries during installation'
411 johnpye 463 ,"$INSTALL_PREFIX/lib"
412     )
413    
414     opts.Add(
415 ben.allan 624 'INSTALL_SHARE'
416 johnpye 628 ,'Common shared-file location on this system'
417     ,"$INSTALL_PREFIX/share"
418 johnpye 435 )
419    
420 johnpye 816 opts.Add(
421 johnpye 628 'INSTALL_ASCDATA'
422     ,"Location of ASCEND shared data (TK, python, models etc)"
423     ,"$INSTALL_SHARE/ascend"
424     )
425    
426     opts.Add(
427 johnpye 435 'INSTALL_INCLUDE'
428     ,'Location to put header files during installation'
429     ,"$INSTALL_PREFIX/include"
430     )
431    
432 johnpye 938
433 johnpye 448 opts.Add(
434 johnpye 938 'INSTALL_ROOT'
435     ,'For use by RPM only: location of %{buildroot} during rpmbuild'
436     ,""
437     )
438    
439     #----------------------
440    
441     opts.Add(
442 johnpye 455 'PYGTK_ASSETS'
443 johnpye 532 ,'Default location for Glade assets (placed in pygtk/config.py)'
444 johnpye 455 ,default_install_assets
445     )
446    
447 johnpye 508 opts.Add(BoolOption(
448     'DEBUG'
449     ,"Compile source with debugger symbols, eg for use with 'gdb'"
450     ,False
451     ))
452    
453 johnpye 597 opts.Add(BoolOption(
454     'MALLOC_DEBUG'
455     ,"Compile with debugging version of MALLOC. Required for full CUnit testing"
456     ,False
457     ))
458    
459 johnpye 938 #------ dmalloc --------
460     opts.Add(PackageOption(
461     'DMALLOC_PREFIX'
462     ,"Where are your dmalloc files?"
463     ,default_prefix
464     ))
465 johnpye 448
466 johnpye 938 opts.Add(PackageOption(
467     'DMALLOC_CPPPATH'
468     ,"Where are your dmalloc include files?"
469     ,default_cpppath
470     ))
471    
472     opts.Add(PackageOption(
473     'DMALLOC_LIBPATH'
474     ,"Where are your dmalloc libraries?"
475     ,default_libpath
476     ))
477    
478     opts.Add(BoolOption(
479     'WITH_DMALLOC'
480     ,"Link to the DMALLOC library (if available) for debugging of memory usage."
481     ,False
482     ))
483    
484 jpye 1326 #------ f --------
485 johnpye 1109 opts.Add(PackageOption(
486     'MFGRAPH_PREFIX'
487     ,"Where are your MFGRAPH files?"
488     ,default_prefix
489     ))
490    
491     opts.Add(PackageOption(
492     'MFGRAPH_CPPPATH'
493     ,"Where are your MFGRAPH include files?"
494     ,default_cpppath
495     ))
496    
497     opts.Add(PackageOption(
498     'MFGRAPH_LIBPATH'
499     ,"Where are your MFGRAPH libraries?"
500     ,default_libpath
501     ))
502    
503     opts.Add(BoolOption(
504     'WITH_MFGRAPH'
505 jpye 1326 ,"Link to the MFGRAPH library (if available, for generating incidence graphs)"
506 johnpye 1109 ,True
507     ))
508    
509 jpye 1326
510     #------ ufsparse --------
511     opts.Add(PackageOption(
512     'UFSPARSE_PREFIX'
513     ,"Where are your UFSPARSE files?"
514     ,default_prefix
515     ))
516    
517     opts.Add(PackageOption(
518     'UFSPARSE_CPPPATH'
519     ,"Where are your UFSPARSE include files?"
520     ,default_cpppath
521     ))
522    
523     opts.Add(PackageOption(
524     'UFSPARSE_LIBPATH'
525     ,"Where are your UFSPARSE libraries?"
526     ,default_libpath
527     ))
528    
529     opts.Add(BoolOption(
530     'WITH_UFSPARSE'
531     ,"Link to the UFSPARSE library (if available, for additional sparse matrix routines)"
532     ,True
533     ))
534    
535 johnpye 938 #-----------------------
536    
537 johnpye 563 opts.Add(
538     'DISTTAR_NAME'
539     ,"Stem name of the tarball created by 'scons dist'. So for 'ascend-aaa.tar.bz2', set this to 'ascend-aaa'."
540     ,"ascend-"+version
541     )
542    
543 johnpye 656 opts.Add(
544     'RELEASE'
545     ,"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."
546     ,"0"
547     )
548    
549 johnpye 605 opts.Add(BoolOption(
550 johnpye 628 'ABSOLUTE_PATHS'
551 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."
552 johnpye 628 ,default_absolute_paths
553 johnpye 605 ))
554    
555 johnpye 578 opts.Add(
556     'WIN_INSTALLER_NAME'
557     ,"Name of the installer .exe to create under Windows (minus the '.exe')"
558     ,"ascend-"+version
559     )
560    
561 johnpye 594 opts.Add(BoolOption(
562     'WITH_XTERM_COLORS'
563     ,"Set to 0 if you don't want xterm colour codes in the console output"
564     ,True
565     ))
566    
567 johnpye 761 opts.Add(BoolOption(
568     'WITH_EXTFNS'
569     ,"Set to 0 if you don't want to attempt to build external modules bundled"
570     + " with ASCEND."
571     ,True
572     ))
573    
574 johnpye 816 opts.Add(BoolOption(
575     'WITH_SCROLLKEEPER'
576     ,"Set to to 1 if you want to install an OMF file that can be read by scrollkeeper (eg Yelp on GNOME)"
577     ,default_with_scrollkeeper
578     ))
579    
580 johnpye 546 if platform.system()!="Windows":
581     opts.Add(BoolOption(
582     'WITH_GCCVISIBILITY'
583     , 'Whether to use GCC Visibility extensions when building with GCC 4.0'
584     , True
585     ))
586    
587 johnpye 832
588    
589 johnpye 392 # TODO: OTHER OPTIONS?
590     # TODO: flags for optimisation
591 johnpye 393 # TODO: turning on/off bintoken functionality
592 johnpye 427 # TODO: Where will the 'Makefile.bt' file be installed?
593 johnpye 393
594 johnpye 498 # Import the outside environment
595    
596 johnpye 800 def c_escape(str):
597     return re.sub("\\\\","/",str)
598    
599     envadditional={}
600 johnpye 740
601 johnpye 832 if platform.system()=="Windows":
602 johnpye 1078 if os.environ.get('OSTYPE')=='msys' or os.environ.get('MSYSTEM'):
603 johnpye 832 envenv = os.environ;
604 johnpye 922 tools = ['mingw','lex','yacc','fortran','swig','disttar','nsis']
605     #TODO removed 'doxygen' for SCons 0.96.93
606 johnpye 832 envadditional['IS_MINGW']=True
607     else:
608 johnpye 1082 print "Assuming VC++ build environment (Note: MinGW is preferred)"
609 johnpye 832 envenv = {
610     'PATH':os.environ['PATH']
611     ,'INCLUDE':os.environ['INCLUDE']
612     ,'LIB':os.environ['LIB']
613     ,'MSVS_IGNORE_IDE_PATHS':1
614     }
615 johnpye 922 tools=['default','lex','yacc','fortran','swig','disttar','nsis']
616     #TODO removed 'doxygen' for SCons 0.96.93
617 johnpye 832 envadditional['CPPDEFINES']=['_CRT_SECURE_NO_DEPRECATE']
618 johnpye 498 else:
619 johnpye 832 if os.environ.get('TARGET')=='mingw':
620     envenv = os.environ
621     tools=['crossmingw','lex','yacc','disttar','nsis','doxygen']
622     envadditional['CPPPATH']=['/usr/local/lib/gcc/i386-mingw32/3.4.5/include','/usr/include']
623     else:
624     envenv = os.environ
625 johnpye 922 tools=['default','lex','yacc','fortran','swig','disttar','nsis']
626     #TODO removed 'doxygen' for SCons 0.96.93
627 johnpye 800
628 johnpye 832
629 johnpye 800 env = Environment(
630     ENV=envenv
631     , toolpath=['scons']
632     , tools=tools
633     , **envadditional
634     )
635 johnpye 498
636 johnpye 385 opts.Update(env)
637     opts.Save('options.cache',env)
638    
639     Help(opts.GenerateHelpText(env))
640    
641 johnpye 551 with_tcltk = env.get('WITH_TCLTK')
642 johnpye 427 without_tcltk_reason = "disabled by options/config.py"
643 johnpye 386
644 johnpye 551 with_python = env.get('WITH_PYTHON')
645 johnpye 427 without_python_reason = "disabled by options/config.py"
646 johnpye 387
647 johnpye 593 with_cunit = env.get('WITH_CUNIT')
648 johnpye 427 without_cunit_reason = "not requested"
649 johnpye 400
650 johnpye 761 with_extfns = env.get('WITH_EXTFNS')
651     without_extfn_reason = "disabled by options/config.py"
652    
653 johnpye 816 with_scrollkeeper = env.get('WITH_SCROLLKEEPER')
654     without_scrollkeeper_reason = "disabled by options/config.py"
655    
656 johnpye 938 with_dmalloc = env.get('WITH_DMALLOC')
657     without_dmalloc_reason = "disabled by options/config.py"
658    
659 johnpye 1109 with_mfgraph = env.get('WITH_MFGRAPH')
660     without_mfgraph_reason = "disabled by options/config.py"
661    
662 jpye 1326 with_ufsparse = env.get('WITH_UFSPARSE')
663     without_ufsparse_reason = "disabled by options/config.py"
664    
665 johnpye 993 with_mmio = env.get('WITH_MMIO')
666     without_mmio_reason = "disabled by options/config.py"
667    
668 johnpye 1142 with_signals = env.get('WITH_SIGNALS')
669     without_signals_reason = "disabled by options/config.py"
670    
671 johnpye 631 if platform.system()=="Windows":
672     with_installer=1
673     else:
674     with_installer=0
675     without_installer_reason = "only possible under Windows"
676    
677 johnpye 673 if 'LSOD' in env['WITH_SOLVERS']:
678     with_lsode=True
679     else:
680     with_lsode=False
681     without_lsode_reason = "not requested (WITH_SOLVERS)"
682    
683     if 'IDA' in env['WITH_SOLVERS']:
684     with_ida=True
685     else:
686     with_ida=False
687     without_ida_reason = "not requested (WITH_SOLVERS)"
688    
689    
690 johnpye 783 if 'CONOPT' in env['WITH_SOLVERS']:
691     with_conopt=True
692     else:
693     with_conopt=False
694     without_conopt_reason = "not requested (WITH_SOLVERS)"
695    
696    
697 johnpye 464 #print "SOLVERS:",env['WITH_SOLVERS']
698     #print "WITH_BINTOKEN:",env['WITH_BINTOKEN']
699     #print "DEFAULT_ASCENDLIBRARY:",env['DEFAULT_ASCENDLIBRARY']
700 johnpye 393
701 johnpye 463 can_install = True
702     if platform.system()=='Windows':
703     can_install = False
704    
705     env['CAN_INSTALL']=can_install
706 johnpye 721 env['INSTALL_MODELS']=env['INSTALL_ASCDATA']+"/models/"
707    
708 johnpye 521 print "TCL_CPPPATH =",env['TCL_CPPPATH']
709     print "TCL_LIBPATH =",env['TCL_LIBPATH']
710     print "TCL_LIB =",env['TCL_LIB']
711 johnpye 562 print "CC =",env['CC']
712     print "CXX =",env['CXX']
713 johnpye 673 print "FORTRAN=",env.get('FORTRAN')
714 johnpye 393
715 johnpye 628 print "ABSOLUTE PATHS =",env['ABSOLUTE_PATHS']
716 johnpye 385 #------------------------------------------------------
717 johnpye 398 # SPECIAL CONFIGURATION TESTS
718    
719 johnpye 463 need_fortran = False
720    
721 johnpye 400 #----------------
722     # SWIG
723    
724 johnpye 398 import os,re
725    
726 johnpye 413 def get_swig_version(env):
727 johnpye 403 cmd = env['SWIG']+' -version'
728 johnpye 427 (cin,coutcerr) = os.popen4(cmd)
729 johnpye 403 output = coutcerr.read()
730 johnpye 398
731 johnpye 403 restr = "SWIG\\s+Version\\s+(?P<maj>[0-9]+)\\.(?P<min>[0-9]+)\\.(?P<pat>[0-9]+)\\s*$"
732     expr = re.compile(restr,re.M);
733 johnpye 398 m = expr.search(output);
734     if not m:
735 johnpye 413 return None
736 johnpye 398 maj = int(m.group('maj'))
737     min = int(m.group('min'))
738     pat = int(m.group('pat'))
739 johnpye 413
740     return (maj,min,pat)
741 johnpye 398
742 johnpye 413
743     def CheckSwigVersion(context):
744    
745     try:
746     context.Message("Checking version of SWIG... ")
747     maj,min,pat = get_swig_version(context.env)
748     except:
749     context.Result("Failed to detect version, or failed to run SWIG")
750     return 0;
751    
752 johnpye 478 context.env['SWIGVERSION']=tuple([maj,min,pat])
753    
754 johnpye 398 if maj == 1 and (
755 johnpye 400 min > 3
756     or (min == 3 and pat >= 24)
757 johnpye 398 ):
758     context.Result("ok, %d.%d.%d" % (maj,min,pat))
759     return 1;
760 johnpye 401 else:
761     context.Result("too old, %d.%d.%d" % (maj,min,pat))
762     return 0;
763 johnpye 398
764 johnpye 400 #----------------
765 johnpye 816 # Scrollkeeper (Linux documentation system)
766    
767     def get_scrollkeeper_omfdir(env):
768     cmd = 'scrollkeeper-config --omfdir'
769     (cin,coutcerr) = os.popen4(cmd)
770     output = coutcerr.read()
771     return output.strip()
772    
773     def CheckScrollkeeperConfig(context):
774     try:
775     context.Message("Checking for scrollkeeper...")
776     dir=get_scrollkeeper_omfdir(context.env)
777     except:
778     context.Result("Failed to run 'scrollkeeper-config'")
779     return 0
780     context.env['OMFDIR']=dir
781     context.Result("OK, %s" % dir)
782     return 1
783    
784     #----------------
785 johnpye 400 # General purpose library-and-header test
786    
787 johnpye 404 class KeepContext:
788 johnpye 521 def __init__(self,context,varprefix,static=False):
789 johnpye 404 self.keep = {}
790 johnpye 521 for k in ['LIBS','LIBPATH','CPPPATH','LINKFLAGS']:
791 johnpye 705 #print "Keeping env %s = %s" % (k,context.env.get(k))
792     self.keep[k]=context.env.get(k)
793 johnpye 404
794     if context.env.has_key(varprefix+'_CPPPATH'):
795 johnpye 743 context.env.AppendUnique(CPPPATH=[env[varprefix+'_CPPPATH']])
796 johnpye 800 #print "Adding '"+str(env[varprefix+'_CPPPATH'])+"' to cpp path"
797 johnpye 428
798 johnpye 521 if static:
799     staticlib=env[varprefix+'_LIB']
800     #print "STATIC LIB = ",staticlib
801     context.env.Append(
802     LINKFLAGS=[staticlib]
803     )
804     else:
805     if context.env.has_key(varprefix+'_LIBPATH'):
806     context.env.Append(LIBPATH=[env[varprefix+'_LIBPATH']])
807 johnpye 800 #print "Adding '"+str(env[varprefix+'_LIBPATH'])+"' to lib path"
808 johnpye 428
809 johnpye 521 if context.env.has_key(varprefix+'_LIB'):
810     context.env.Append(LIBS=[env[varprefix+'_LIB']])
811 johnpye 705 #print "Adding '"+str(env[varprefix+'_LIB'])+"' to libs"
812 johnpye 404
813     def restore(self,context):
814 johnpye 464 #print "RESTORING CONTEXT"
815     #print self.keep
816     #print "..."
817 johnpye 404 for k in self.keep:
818 johnpye 463 if self.keep[k]==None:
819 johnpye 521 if context.env.has_key(k):
820     #print "Clearing "+str(k)
821     del context.env[k];
822 johnpye 463 else:
823 johnpye 705 #print "Restoring %s to '%s'" %(k,self.keep.get(k))
824 johnpye 463 context.env[k]=self.keep[k];
825 johnpye 404
826 johnpye 521 def CheckExtLib(context,libname,text,ext='.c',varprefix=None,static=False):
827 johnpye 400 """This method will check for variables LIBNAME_LIBPATH
828     and LIBNAME_CPPPATH and try to compile and link the
829     file with the provided text, linking with the
830     library libname."""
831    
832 johnpye 521 if static:
833     context.Message( 'Checking for static '+libname+'... ' )
834     else:
835     context.Message( 'Checking for '+libname+'... ' )
836    
837 johnpye 400 if varprefix==None:
838     varprefix = libname.upper()
839    
840 johnpye 705 #print "LIBS is currently:",context.env.get('LIBS')
841 johnpye 521 keep = KeepContext(context,varprefix,static)
842 johnpye 400
843 johnpye 428 if not context.env.has_key(varprefix+'_LIB'):
844 johnpye 463 # if varprefix_LIB were in env, KeepContext would
845     # have appended it already
846 johnpye 705 context.env.Append(LIBS=[libname])
847 johnpye 428
848 johnpye 404 is_ok = context.TryLink(text,ext)
849 johnpye 428
850 johnpye 521 #print "Link success? ",(is_ok != 0)
851 johnpye 400
852 johnpye 405 keep.restore(context)
853 johnpye 400
854 johnpye 428 # print "Restored CPPPATH="+str(context.env['CPPPATH'])
855 johnpye 705 # print "Restored LIBS="+str(context.env['LIBS'])
856 johnpye 428 # print "Restored LIBPATH="+str(context.env['LIBPATH'])
857    
858 johnpye 404 context.Result(is_ok)
859     return is_ok
860    
861     #----------------
862 johnpye 502 # GCC
863    
864     gcc_test_text = """
865     #ifndef __GNUC__
866     # error "Not using GCC"
867     #endif
868    
869     int main(void){
870     return __GNUC__;
871     }
872     """
873    
874     def CheckGcc(context):
875     context.Message("Checking for GCC... ")
876     is_ok = context.TryCompile(gcc_test_text,".c")
877     context.Result(is_ok)
878     return is_ok
879    
880     #----------------
881 johnpye 500 # GCC VISIBILITY feature
882    
883     gccvisibility_test_text = """
884     #if __GNUC__ < 4
885     # error "Require GCC version 4 or newer"
886     #endif
887    
888     __attribute__ ((visibility("default"))) int x;
889    
890     int main(void){
891     extern int x;
892     x = 4;
893     }
894     """
895    
896     def CheckGccVisibility(context):
897     context.Message("Checking for GCC 'visibility' capability... ")
898 johnpye 546 if not context.env.has_key('WITH_GCCVISIBILITY') or not env['WITH_GCCVISIBILITY']:
899     context.Result("disabled")
900     return 0
901 johnpye 500 is_ok = context.TryCompile(gccvisibility_test_text,".c")
902     context.Result(is_ok)
903     return is_ok
904 johnpye 502
905 johnpye 500 #----------------
906 johnpye 502 # YACC
907    
908     yacc_test_text = """
909 johnpye 646 %{
910     #include <stdio.h>
911 johnpye 741
912     /* MSVC++ needs this before it can swallow Bison output */
913     #ifdef _MSC_VER
914     # define __STDC__
915     #endif
916 johnpye 646 %}
917     %token MSG
918 johnpye 502 %start ROOT
919 johnpye 646 %%
920     ROOT:
921     MSG { printf("HELLO"); }
922     ;
923     %%
924 johnpye 502 """
925    
926     def CheckYacc(context):
927 johnpye 644 context.Message("Checking for Yacc ('%s')... " % context.env.get('YACC'))
928 johnpye 502 is_ok = context.TryCompile(yacc_test_text,".y")
929     context.Result(is_ok)
930     return is_ok
931    
932     #----------------
933 johnpye 1025 # LEX
934    
935     lex_test_text = """
936     %{
937     #include <stdio.h>
938     %}
939     DIGIT [0-9]
940     ID [a-z][a-z0-9]*
941     %%
942     {DIGIT}+ {
943     printf("A digit: %s\\n",yytext);
944     }
945    
946     [ \\t\\n]+ /* ignore */
947    
948     . {
949     printf("Unrecognized guff");
950     }
951     %%
952     main(){
953     yylex();
954     }
955     """
956    
957     def CheckLex(context):
958     context.Message("Checking for Lex ('%s')... " % context.env.get('LEX'))
959     is_ok = context.TryCompile(lex_test_text,".l")
960     context.Result(is_ok)
961     return is_ok
962    
963     #----------------
964 johnpye 404 # CUnit test
965    
966 johnpye 400 cunit_test_text = """
967 johnpye 451 #include <CUnit/CUnit.h>
968 johnpye 400 int maxi(int i1, int i2){
969     return (i1 > i2) ? i1 : i2;
970     }
971    
972     void test_maxi(void){
973     CU_ASSERT(maxi(0,2) == 2);
974     CU_ASSERT(maxi(0,-2) == 0);
975     CU_ASSERT(maxi(2,2) == 2);
976    
977     }
978     int main(void){
979     /* CU_initialize_registry() */
980 johnpye 404 return 0;
981 johnpye 400 }
982     """
983    
984     def CheckCUnit(context):
985 johnpye 451 return CheckExtLib(context,'cunit',cunit_test_text)
986 johnpye 400
987 johnpye 404 #----------------
988 johnpye 938 # dmalloc test
989    
990     dmalloc_test_text = """
991     #include <stdlib.h>
992     #include <dmalloc.h>
993    
994     int main(void){
995     char *c;
996     c = malloc(100*sizeof(char));
997     free(c);
998     return 0;
999     }
1000     """
1001    
1002     def CheckDMalloc(context):
1003     return CheckExtLib(context,'dmalloc',dmalloc_test_text)
1004    
1005     #----------------
1006 johnpye 1109 # mfgraph test
1007    
1008     mfgraph_test_text = """
1009     #include <mfgraph/mfg_draw_graph.h>
1010     int main(void){
1011     using namespace mfg;
1012     DrawGraph g;
1013     return 0;
1014     }
1015     """
1016    
1017     def CheckMFGraph(context):
1018     return CheckExtLib(context,'mfgraph',mfgraph_test_text,ext=".cpp")
1019    
1020     #----------------
1021 jpye 1326 # ufsparse test
1022    
1023     ufsparse_test_text = """
1024     #include <ufsparse/cs.h>
1025     int main(void){
1026     cs *A,*B,*C;
1027     C = cs_multiply(A,B);
1028     return 0;
1029     }
1030     """
1031    
1032     def CheckUFSparse(context):
1033     return CheckExtLib(context
1034     ,libname='cxsparse'
1035     ,varprefix='ufsparse'
1036     ,text=ufsparse_test_text
1037     ,ext=".c"
1038     )
1039    
1040     #----------------
1041 johnpye 673 # MATH test
1042    
1043     math_test_text = """
1044 johnpye 705 #ifndef _ALL_SOURCE
1045     # define _ALL_SOURCE
1046     #endif
1047     #ifndef _XOPEN_SOURCE
1048     # define _XOPEN_SOURCE
1049     #endif
1050     #ifndef _XOPEN_SOURCE_EXTENDED
1051     # define _XOPEN_SOURCE_EXTENDED 1
1052     #endif
1053 johnpye 673 #include <math.h>
1054     int main(void){
1055 johnpye 705 double x = 1.0; double y = 1.0; int i = 1;
1056     acosh(x); asinh(x); atanh(x); cbrt(x); expm1(x); erf(x); erfc(x); isnan(x);
1057     j0(x); j1(x); jn(i,x); ilogb(x); logb(x); log1p(x); rint(x);
1058     y0(x); y1(x); yn(i,x);
1059     #ifdef _THREAD_SAFE
1060     gamma_r(x,&i);
1061     lgamma_r(x,&i);
1062     #else
1063     gamma(x);
1064     lgamma(x);
1065     #endif
1066     hypot(x,y); nextafter(x,y); remainder(x,y); scalb(x,y);
1067 johnpye 673 return 0;
1068     }
1069     """
1070    
1071     def CheckMath(context):
1072 johnpye 832 context.Message('Checking for IEEE math library... ')
1073 johnpye 705 libsave=context.env.get('LIBS');
1074     context.env.AppendUnique(LIBS=['m'])
1075     is_ok=context.TryLink(math_test_text,".c")
1076     context.Result(is_ok)
1077     if not is_ok:
1078     context.env['LIBS']=libsave
1079     return is_ok
1080    
1081 johnpye 673 #----------------
1082 johnpye 957 # libpython test
1083    
1084     libpython_test_text = """
1085     #include <Python.h>
1086     int main(void){
1087     PyObject *p;
1088     p = Py_None;
1089     return 0;
1090     }
1091     """
1092    
1093     def CheckPythonLib(context):
1094     context.Message('Checking for libpython... ')
1095    
1096     if platform.system()=="Windows":
1097     python_lib='python%d%d'
1098     else:
1099     python_lib='python%d.%d'
1100 johnpye 958 python_libs = [python_lib % (sys.version_info[0],sys.version_info[1])]
1101 johnpye 957
1102     python_cpppath = [distutils.sysconfig.get_python_inc()]
1103     cfig = distutils.sysconfig.get_config_vars()
1104    
1105     lastLIBS = context.env.get('LIBS')
1106     lastLIBPATH = context.env.get('LIBPATH')
1107     lastCPPPATH = context.env.get('CPPPATH')
1108 johnpye 959 lastLINKFLAGS = context.env.get('LINKFLAGS')
1109 johnpye 957
1110     python_libpath = []
1111 johnpye 959 python_linkflags = []
1112 johnpye 965 if platform.system()=="Windows":
1113 johnpye 980 python_libpath+=[cfig['prefix']]
1114 johnpye 965 else:
1115     # checked on Linux and SunOS
1116     if cfig['LDLIBRARY']==cfig['LIBRARY']:
1117     sys.stdout.write("(static)")
1118     python_libpath += [cfig['LIBPL']]
1119     python_linkflags += cfig['LIBS'].split(' ')
1120 johnpye 957
1121 johnpye 958 context.env.AppendUnique(LIBS=python_libs)
1122 johnpye 957 context.env.AppendUnique(LIBPATH=python_libpath)
1123     context.env.AppendUnique(CPPPATH=python_cpppath)
1124 johnpye 959 context.env.AppendUnique(LINKFLAGS=python_linkflags)
1125 johnpye 957 result = context.TryLink(libpython_test_text,".c");
1126    
1127 johnpye 958 context.Result(result)
1128 johnpye 957
1129     if(result):
1130 johnpye 958 context.env['PYTHON_LIBPATH']=python_libpath
1131     context.env['PYTHON_LIB']=python_libs
1132     context.env['PYTHON_CPPPATH']=python_cpppath
1133 johnpye 959 context.env['PYTHON_LINKFLAGS']=python_linkflags
1134 johnpye 957
1135     context.env['LIBS'] = lastLIBS
1136     context.env['LIBPATH'] = lastLIBPATH
1137     context.env['CPPPATH'] = lastCPPPATH
1138 johnpye 959 context.env['LINKFLAGS'] = lastLINKFLAGS
1139 johnpye 957
1140     return result
1141    
1142     #----------------
1143 johnpye 673 # IDA test
1144    
1145 johnpye 913 sundials_version_major_required = 2
1146     sundials_version_minor_min = 2
1147     sundials_version_minor_max = 3
1148    
1149     sundials_version_text = """
1150     #include <sundials/sundials_config.h>
1151     #include <stdio.h>
1152     int main(){
1153     printf("%s",SUNDIALS_PACKAGE_VERSION);
1154     return 0;
1155     }
1156     """
1157    
1158 johnpye 673 ida_test_text = """
1159 johnpye 907 # include <ida/ida.h>
1160     # include <nvector/nvector_serial.h>
1161     # include <ida/ida_spgmr.h>
1162 johnpye 673 int main(){
1163     void *ida_mem;
1164     ida_mem = IDACreate();
1165 johnpye 782 return 0;
1166 johnpye 673 }
1167     """
1168    
1169     def CheckIDA(context):
1170     context.Message( 'Checking for IDA (SUNDIALS)... ' )
1171    
1172     keep = KeepContext(context,"IDA")
1173    
1174     is_ok = context.TryLink(ida_test_text,".c")
1175     context.Result(is_ok)
1176    
1177     keep.restore(context)
1178 johnpye 782
1179 johnpye 673 return is_ok
1180    
1181 johnpye 913 # slightly changed calling convention (IDACalcID) in newer versions of SUNDIALS,
1182     # so detect the version and act accordingly.
1183     def CheckIDAVersion(context):
1184     keep = KeepContext(context,'IDA')
1185     context.Message("Checking SUNDIALS version... ")
1186     (is_ok,output) = context.TryRun(sundials_version_text,'.c')
1187     keep.restore(context)
1188     if not is_ok:
1189     context.Result("failed to run check")
1190     return 0
1191    
1192     major,minor,patch = tuple([int(i) for i in output.split(".")])
1193     context.env['SUNDIALS_VERSION_MAJOR'] = major
1194     context.env['SUNDIALS_VERSION_MINOR'] = minor
1195     if major != sundials_version_major_required \
1196     or minor < sundials_version_minor_min \
1197     or minor > sundials_version_minor_max:
1198     context.Result(output+" (bad version)")
1199     # bad version
1200     return 0
1201    
1202     # good version
1203 johnpye 1086 context.Result("%d.%d.%d, good" % (major,minor,patch))
1204 johnpye 913 return 1
1205    
1206 johnpye 673 #----------------
1207 johnpye 783 # CONOPT test
1208    
1209     conopt_test_text = """
1210 johnpye 800 #if !defined(_WIN32)
1211     # define FNAME_LCASE_DECOR
1212     #endif
1213    
1214 johnpye 783 #include <conopt.h>
1215     #include <stdlib.h>
1216     int main(){
1217     int s, *v, e;
1218     s = COIDEF_Size();
1219     v = (int *)malloc(s*sizeof(int));
1220     e = COIDEF_Ini(v);
1221     return e;
1222     }
1223     """
1224    
1225     def CheckCONOPT(context):
1226     context.Message( 'Checking for CONOPT... ' )
1227    
1228     keep = KeepContext(context,"CONOPT")
1229    
1230     is_ok = context.TryLink(conopt_test_text,".c")
1231     context.Result(is_ok)
1232    
1233     keep.restore(context)
1234    
1235     return is_ok
1236    
1237     #----------------
1238 johnpye 405 # Tcl test
1239 johnpye 404
1240 johnpye 561 # TCL and TK required version 8.1, 8.2, 8.3, or 8.4:
1241     tcltk_minor_newest_acceptable = 4
1242     tcltk_major_required = 8
1243    
1244 johnpye 404 tcl_check_text = r"""
1245     #include <tcl.h>
1246     #include <stdio.h>
1247     int main(void){
1248     printf("%s",TCL_PATCH_LEVEL);
1249     return 0;
1250     }
1251     """
1252    
1253     def CheckTcl(context):
1254 johnpye 521 return CheckExtLib(context,'tcl',tcl_check_text,static=env['STATIC_TCLTK'])
1255 johnpye 405
1256     def CheckTclVersion(context):
1257 johnpye 521 keep = KeepContext(context,'TCL',static=env['STATIC_TCLTK'])
1258 johnpye 405 context.Message("Checking Tcl version... ")
1259     (is_ok,output) = context.TryRun(tcl_check_text,'.c')
1260 johnpye 404 keep.restore(context)
1261     if not is_ok:
1262 johnpye 405 context.Result("failed to run check")
1263 johnpye 404 return 0
1264 johnpye 405
1265 wangym 511 major,minor,patch = tuple([int(i) for i in output.split(".")])
1266 johnpye 561 if major != tcltk_major_required or minor > tcltk_minor_newest_acceptable:
1267 johnpye 428 context.Result(output+" (bad version)")
1268 johnpye 405 # bad version
1269     return 0
1270    
1271     # good version
1272 johnpye 552 context.Result(output+", good")
1273 johnpye 404 return 1
1274    
1275 johnpye 405 #----------------
1276 johnpye 463 # Tk test
1277 johnpye 405
1278     tk_check_text = r"""
1279     #include <tk.h>
1280     #include <stdio.h>
1281     int main(void){
1282     printf("%s",TK_PATCH_LEVEL);
1283     return 0;
1284     }
1285     """
1286     def CheckTk(context):
1287 johnpye 673 return CheckExtLib(context,'tk',tk_check_text,static=env['STATIC_TCLTK'])
1288 johnpye 405
1289 johnpye 428
1290 johnpye 405 def CheckTkVersion(context):
1291 johnpye 521 keep = KeepContext(context,'TK',static=context.env['STATIC_TCLTK'])
1292 johnpye 405 context.Message("Checking Tk version... ")
1293 johnpye 521 #print "LINKFLAGS =",context.env['LINKFLAGS']
1294 johnpye 405 (is_ok,output) = context.TryRun(tk_check_text,'.c')
1295 johnpye 404 keep.restore(context)
1296     if not is_ok:
1297     context.Result("failed to run check")
1298     return 0
1299    
1300 wangym 511 major,minor,patch = tuple([int(i) for i in output.split(".")])
1301 johnpye 561 if major != tcltk_major_required or minor > tcltk_minor_newest_acceptable:
1302 johnpye 404 # bad version
1303 johnpye 561 context.Result(output+" (bad version)")
1304 johnpye 404 return 0
1305 johnpye 400
1306 johnpye 404 # good version
1307 johnpye 561 context.Result(output+" (good)")
1308 johnpye 404 return 1
1309 johnpye 485
1310     #----------------
1311 johnpye 521 # Tktable test
1312    
1313     tktable_check_text = r"""
1314     #include <tkTable.h>
1315     #include <stdio.h>
1316     int main(void){
1317     Table mytable;
1318     return 0;
1319     }
1320     """
1321    
1322     def CheckTkTable(context):
1323     return CheckExtLib(context,'tktable',tktable_check_text,static=env['STATIC_TCLTK'])
1324    
1325     #---------------
1326     # X11 test
1327    
1328     x11_check_text = r"""
1329     #include <X11/Xlib.h>
1330     #include <X11/IntrinsicP.h>
1331     #include <X11/Intrinsic.h>
1332     #include <X11/ObjectP.h>
1333     #include <X11/Object.h>
1334     int main(void){
1335     Object mything;
1336     return 0;
1337     }
1338     """
1339    
1340     def CheckX11(context):
1341     return CheckExtLib(context,'X11',x11_check_text)
1342    
1343     #----------------
1344 johnpye 968 # Check that we can raise and catch sigint
1345    
1346     sigint_test_text = r"""
1347     #include <signal.h>
1348     #include <setjmp.h>
1349     #include <stdlib.h>
1350     static jmp_buf g_jmpenv;
1351     void sighandler(int sig){
1352     longjmp(g_jmpenv,sig);
1353     }
1354     void testsigint(){
1355     raise(SIGINT);
1356     }
1357     int main(void){
1358     signal(SIGINT,&sighandler);
1359     switch(setjmp(g_jmpenv)){
1360     case 0:
1361     testsigint();
1362     exit(1);
1363     case SIGINT:
1364     exit(0);
1365     default:
1366     exit(2);
1367     }
1368     }
1369     """
1370    
1371     def CheckSIGINT(context):
1372     context.Message("Checking SIGINT is catchable... ")
1373     (is_ok,output)=context.TryRun(sigint_test_text,".c")
1374     context.Result(is_ok)
1375     return is_ok
1376    
1377     #----------------
1378 johnpye 953 # Check that we're able to catch floating point errors
1379    
1380     sigfpe_test_text = r"""
1381     #include <signal.h>
1382     #include <setjmp.h>
1383     #include <stdlib.h>
1384     #include <fenv.h>
1385     static jmp_buf g_jmpenv;
1386     void fpehandler(int sig){
1387     longjmp(g_jmpenv,sig);
1388     }
1389     int main(void){
1390     fenv_t myfenv;
1391     fegetenv(&myfenv);
1392     fesetenv(&myfenv);
1393     feenableexcept(FE_ALL_EXCEPT);
1394     signal(SIGFPE,&fpehandler);
1395     double x;
1396     switch(setjmp(g_jmpenv)){
1397     case 0:
1398     x = 1.0 / 0.0;
1399     /* failed to catch */
1400     exit(1);
1401     case SIGFPE:
1402     exit(0);
1403     }
1404     }
1405     """
1406    
1407     def CheckFPE(context):
1408 johnpye 968 context.Message("Checking C99 FPE behaviour... ")
1409 johnpye 953 (is_ok,output) = context.TryRun(sigfpe_test_text,'.c')
1410     context.Result(is_ok)
1411     return is_ok
1412    
1413     #----------------
1414 johnpye 968 # signal reset needed?
1415    
1416     sigreset_test_text = r"""
1417     #include <signal.h>
1418     #include <setjmp.h>
1419     #include <stdlib.h>
1420     #include <stdio.h>
1421     typedef void SigHandlerFn(int);
1422     static jmp_buf g_jmpenv;
1423     void sighandler(int sig){
1424     longjmp(g_jmpenv,sig);
1425     }
1426     void testsigint(){
1427 johnpye 1002 /* fprintf(stderr,"Raising SIGINT\n"); */
1428 johnpye 968 raise(SIGINT);
1429     }
1430     int main(void){
1431     SigHandlerFn *last,*saved;
1432     saved = signal(SIGINT,&sighandler);
1433     if(saved!=SIG_DFL){
1434 johnpye 1002 fprintf(stderr,"Default handler (%p) was not correctly set\n",SIG_DFL);
1435 johnpye 968 exit(3);
1436     }
1437     switch(setjmp(g_jmpenv)){
1438     case 0:
1439     testsigint();
1440     fprintf(stderr,"Back from SIGINT\n");
1441     exit(1);
1442     case SIGINT:
1443     break;
1444     default:
1445     exit(2);
1446     };
1447 johnpye 1002 last = signal(SIGINT,SIG_DFL);
1448 johnpye 968 if(last!=&sighandler){
1449     printf("1");
1450     exit(0);
1451     }
1452     printf("0");
1453     exit(0);
1454     }
1455     """
1456    
1457     def CheckSigReset(context):
1458     context.Message("Checking signal handler reset... ")
1459     (is_ok,output) = context.TryRun(sigreset_test_text,'.c')
1460     if not is_ok:
1461     context.Result("ERROR")
1462 johnpye 1260 return False
1463 johnpye 1002 if int(output)==1:
1464 johnpye 968 context.Result("required");
1465     context.env['ASC_RESETNEEDED'] = True
1466     else:
1467     context.Result("not required");
1468     context.env['ASC_RESETNEEDED'] = False
1469     return is_ok
1470    
1471     #----------------
1472 johnpye 485 # GCC Version sniffing
1473    
1474     # TODO FIXME
1475    
1476     gcc_version4 = False
1477    
1478 johnpye 398 #------------------------------------------------------
1479 johnpye 385 # CONFIGURATION
1480    
1481     conf = Configure(env
1482     , custom_tests = {
1483 johnpye 673 'CheckMath' : CheckMath
1484     , 'CheckSwigVersion' : CheckSwigVersion
1485 johnpye 957 , 'CheckPythonLib' : CheckPythonLib
1486 johnpye 400 , 'CheckCUnit' : CheckCUnit
1487 johnpye 938 , 'CheckDMalloc' : CheckDMalloc
1488 johnpye 1109 , 'CheckMFGraph' : CheckMFGraph
1489 jpye 1326 , 'CheckUFSparse' : CheckUFSparse
1490 johnpye 404 , 'CheckTcl' : CheckTcl
1491     , 'CheckTclVersion' : CheckTclVersion
1492 johnpye 405 , 'CheckTk' : CheckTk
1493     , 'CheckTkVersion' : CheckTkVersion
1494 johnpye 502 , 'CheckGcc' : CheckGcc
1495 johnpye 500 , 'CheckGccVisibility' : CheckGccVisibility
1496 johnpye 502 , 'CheckYacc' : CheckYacc
1497 johnpye 1025 , 'CheckLex' : CheckLex
1498 johnpye 521 , 'CheckTkTable' : CheckTkTable
1499     , 'CheckX11' : CheckX11
1500 johnpye 673 , 'CheckIDA' : CheckIDA
1501 johnpye 913 , 'CheckIDAVersion' : CheckIDAVersion
1502 johnpye 783 , 'CheckCONOPT' : CheckCONOPT
1503 johnpye 816 , 'CheckScrollkeeperConfig' : CheckScrollkeeperConfig
1504 johnpye 953 , 'CheckFPE' : CheckFPE
1505 johnpye 968 , 'CheckSIGINT' : CheckSIGINT
1506     , 'CheckSigReset' : CheckSigReset
1507 johnpye 400 # , 'CheckIsNan' : CheckIsNan
1508     # , 'CheckCppUnitConfig' : CheckCppUnitConfig
1509 johnpye 385 }
1510 johnpye 459 # , config_h = "config.h"
1511 johnpye 385 )
1512    
1513 johnpye 740 # stdio -- just to check that compiler is behaving
1514 johnpye 398
1515 johnpye 740 if not conf.CheckHeader('stdio.h'):
1516 johnpye 832 print "CPPPATH =",env.get('CPPPATH')
1517 johnpye 740 print "Did not find 'stdio.h'! Check your compiler configuration."
1518 johnpye 1080 print ""
1519     print "You environment is printed here:"
1520     for k,v in os.environ.iteritems():
1521     print "%-30s%s" % ("%s :" % k, v)
1522 johnpye 740 Exit(1)
1523    
1524 johnpye 1228 if not conf.CheckFunc('snprintf'):
1525     print "Didn't find snprintf";
1526     exit(1)
1527    
1528 johnpye 385 # Math library
1529    
1530 johnpye 1262 conf.env['HAVE_IEEE']=True
1531    
1532     if need_libm and not conf.CheckMath():
1533 johnpye 1232 conf.env['HAVE_IEEE']=False
1534 johnpye 1262 print 'Did not find math library, exiting!'
1535     Exit(1)
1536 johnpye 427
1537 johnpye 385 # Where is 'isnan'?
1538    
1539 johnpye 740 if not conf.CheckFunc('isnan') and not conf.CheckFunc('_isnan'):
1540 johnpye 385 print "Didn't find isnan"
1541 johnpye 414 # Exit(1)
1542 johnpye 385
1543 johnpye 500 # GCC visibility
1544    
1545 johnpye 502 if conf.CheckGcc():
1546     conf.env['HAVE_GCC']=True;
1547 johnpye 526 if env['WITH_GCCVISIBILITY'] and conf.CheckGccVisibility():
1548 johnpye 509 conf.env['HAVE_GCCVISIBILITY']=True;
1549     conf.env.Append(CCFLAGS=['-fvisibility=hidden'])
1550     conf.env.Append(CPPDEFINES=['HAVE_GCCVISIBILITY'])
1551 johnpye 709 conf.env.Append(CCFLAGS=['-Wall'])
1552 johnpye 500
1553 johnpye 968 # Catching SIGINT
1554    
1555 johnpye 1142 if env['WITH_SIGNALS']:
1556     if not conf.CheckSIGINT():
1557     with_signals = False
1558     without_signals_reason = "SIGINT uncatchable"
1559 johnpye 968
1560 johnpye 953 # Catching SIGFPE
1561    
1562     if conf.CheckFPE():
1563 johnpye 968 conf.env['HAVE_C99FPE']=True
1564 johnpye 953 else:
1565 johnpye 968 conf.env['HAVE_C99FPE']=False
1566 johnpye 953
1567 johnpye 968 # Checking for signal reset requirement
1568    
1569     if not conf.CheckSigReset():
1570     print "Unable to determine if signal reset is required"
1571 johnpye 1260 Exit(1)
1572 johnpye 968
1573 johnpye 502 # YACC
1574    
1575 johnpye 506 if not conf.CheckYacc():
1576     print "YACC NOT FOUND OR NOT WORKING"
1577     else:
1578 johnpye 502 conf.env['HAVE_YACC']=True
1579    
1580 johnpye 1025 if not conf.CheckLex():
1581     print "YACC NOT FOUND OR NOT WORKING"
1582     else:
1583     conf.env['HAVE_LEX']=True
1584 johnpye 502
1585 johnpye 387 # Tcl/Tk
1586 johnpye 386
1587 johnpye 586 if with_tcltk:
1588     if conf.CheckTcl():
1589     if conf.CheckTclVersion():
1590     if conf.CheckTk():
1591     if with_tcltk and conf.CheckTkVersion():
1592     if env['STATIC_TCLTK']:
1593     if conf.CheckTkTable():
1594     pass
1595     else:
1596     without_tcltk_reason = "TkTable not found"
1597     with_tcltk = False
1598     else:
1599     without_tcltk_reason = "Require Tk version <= 8.4. See 'scons -h'"
1600     with_tcltk = False
1601 johnpye 521 else:
1602 johnpye 586 without_tcltk_reason = "Tk not found."
1603 johnpye 551 with_tcltk = False
1604 johnpye 428 else:
1605 johnpye 586 without_tcltk_reason = "Require Tcl <= 8.4 Tcl."
1606 johnpye 551 with_tcltk = False
1607 johnpye 586
1608 johnpye 428 else:
1609 johnpye 586 without_tcltk_reason = "Tcl not found."
1610 johnpye 551 with_tcltk = False
1611 johnpye 386
1612 johnpye 521 if env['STATIC_TCLTK']:
1613     conf.CheckX11()
1614    
1615 johnpye 395 # Python... obviously we're already running python, so we just need to
1616     # check that we can link to the python library OK:
1617    
1618 johnpye 957 if not conf.CheckPythonLib():
1619     without_python_reason = 'libpython2.x not found or not linkable'
1620     with_python = False
1621 johnpye 982 env['WITH_PYTHON']=False
1622 johnpye 391
1623 johnpye 395 # SWIG version
1624    
1625 johnpye 957 if with_python and not conf.CheckSwigVersion():
1626 johnpye 413 without_python_reason = 'SWIG >= 1.3.24 is required'
1627     with_python = False
1628 johnpye 982 env['WITH_PYTHON']=False
1629 johnpye 413
1630 johnpye 400 # CUnit
1631    
1632 johnpye 593 if with_cunit:
1633 johnpye 404 if not conf.CheckCUnit():
1634 johnpye 427 without_cunit_reason = 'CUnit not found'
1635 johnpye 665 with_cunit = False
1636 johnpye 705 #print "CUNIT NOT FOUND, LIBS=",conf.env.get('LIBS')
1637 johnpye 427
1638 johnpye 938 # DMALLOC
1639    
1640     if with_dmalloc:
1641     if not conf.CheckDMalloc():
1642     without_dmalloc_reason = 'dmalloc not found'
1643     with_dmalloc = False
1644    
1645 jpye 1326 # MFGRAPH
1646 johnpye 1109
1647     if with_mfgraph:
1648     if not conf.CheckMFGraph():
1649     without_mfgraph_reason = 'mfgraph not found'
1650 johnpye 1113 with_mfgraph = False
1651 johnpye 1114 env['WITH_MFGRAPH'] = False
1652 johnpye 1109
1653 jpye 1326 # UFSPARSE
1654    
1655     if with_ufsparse:
1656     if not conf.CheckUFSparse():
1657     without_ufsparse_reason = 'mfgraph not found'
1658     with_ufsparse = False
1659     env['WITH_UFSPARSE'] = False
1660    
1661 johnpye 673 # IDA
1662    
1663     if not with_ida:
1664     without_ida_reason = "Not selected (see config option WITH_SOLVERS)"
1665     elif not conf.CheckIDA():
1666     with_ida = False
1667     without_ida_reason = "IDA not found"
1668 johnpye 913 elif not conf.CheckIDAVersion():
1669     with_ida = False
1670     without_ida_reason = "Unsupported (or undetected) SUNDIALS version"
1671 johnpye 673
1672 johnpye 797 # CONOPT
1673 johnpye 783
1674     if not with_conopt:
1675     without_conopt_reason = "Not selected (see config option WITH_SOLVERS)"
1676     elif not conf.CheckCONOPT():
1677 johnpye 797 with_conopt = False
1678     without_conpt_reason = "CONOPT not found"
1679 johnpye 783
1680 johnpye 427 # BLAS
1681    
1682 johnpye 459 need_blas=False
1683 johnpye 673
1684     if with_lsode:
1685     need_fortran = True
1686 johnpye 459 need_blas=True
1687 johnpye 673
1688 johnpye 459 if need_blas:
1689     if conf.CheckLib('blas'):
1690     with_local_blas = False
1691     without_local_blas_reason = "Found BLAS installed on system"
1692     else:
1693     with_local_blas = True
1694     need_fortran = True
1695 johnpye 673 else:
1696     with_local_blas= False;
1697     without_local_blas_reason = "BLAS not required"
1698 johnpye 427
1699     # FORTRAN
1700    
1701     if need_fortran:
1702 johnpye 629 conf.env.Tool('fortran')
1703     detect_fortran = conf.env.Detect(['g77','f77','gfortran'])
1704 johnpye 427 if detect_fortran:
1705     # For some reason, g77 doesn't get detected properly on MinGW
1706 johnpye 673 if not env.has_key('F77') and not env.has_key('FORTRAN'):
1707 johnpye 427 conf.env.Replace(F77=detect_fortran)
1708     conf.env.Replace(F77COM='$F77 $F77FLAGS -c -o $TARGET $SOURCE')
1709     conf.env.Replace(F77FLAGS='')
1710 johnpye 428 #print "F77:",conf.env['F77']
1711     #print "F77COM:",conf.env['F77COM']
1712     #print "F77FLAGS:",conf.env['F77FLAGS']
1713 johnpye 427 fortran_builder = Builder(
1714     action='$F77COM'
1715     , suffix='.o'
1716     , src_suffix='.f'
1717     )
1718     conf.env.Append(BUILDERS={'Fortran':fortran_builder})
1719 johnpye 1284 if platform.system()=="Linux":
1720     conf.env.Append(SHFORTRANFLAGS=['-fPIC'])
1721 johnpye 427 else:
1722 johnpye 673 with_lsode=False;
1723     without_lsode_reason="FORTRAN-77 required but not found"
1724 johnpye 629
1725 johnpye 464 #else:
1726     # print "FORTRAN not required"
1727 johnpye 400
1728 johnpye 673 # F2C
1729    
1730     if need_fortran:
1731     if platform.system()=="Windows":
1732     conf.env.Append(LIBPATH='c:\mingw\lib')
1733    
1734 johnpye 816 # scrollkeeper
1735 johnpye 673
1736 johnpye 816 if with_scrollkeeper:
1737     if not conf.CheckScrollkeeperConfig():
1738     with_scrollkeeper=False
1739     without_scrollkeeper_reason="unable to detect scrollkeeper-config"
1740    
1741 johnpye 385 # TODO: -D_HPUX_SOURCE is needed
1742    
1743     # TODO: check size of void*
1744    
1745 johnpye 393 # TODO: detect if dynamic libraries are possible or not
1746    
1747 johnpye 427 if platform.system()=="Windows" and env.has_key('MSVS'):
1748 johnpye 740 _found_windows_h = conf.CheckHeader('Windows.h')
1749    
1750     if not _found_windows_h:
1751 johnpye 741 print "Could not locate 'Windows.h' in CPPPATH. Check your configuration."
1752 johnpye 740 Exit(1)
1753 johnpye 741
1754 johnpye 534 if with_python and not conf.CheckHeader(['basetsd.h','BaseTsd.h']):
1755 johnpye 427 with_python = 0;
1756     without_python_reason = "Header file 'basetsd.h' not found. Install the MS Platform SDK."
1757    
1758     conf.env.Append(CPPDEFINES=env['PACKAGE_LINKING'])
1759    
1760 johnpye 395 conf.Finish()
1761    
1762 johnpye 507 #---------------------------------------
1763     # SUBSTITUTION DICTIONARY for .in files
1764    
1765 johnpye 658 release = env.get('RELEASE')
1766     if release=="0.":
1767     release="0"
1768    
1769 johnpye 800 #print "SUBSTITUTED CONOPT_LIBPATH:",c_escape(env.subst("$CONOPT_LIBPATH"))
1770    
1771 johnpye 507 subst_dict = {
1772     '@DEFAULT_ASCENDLIBRARY@':env['DEFAULT_ASCENDLIBRARY']
1773     , '@GLADE_FILE@':'ascend.glade'
1774     , '@HELP_ROOT@':''
1775     , '@ICON_EXTENSION@':icon_extension
1776 johnpye 628 , '@INSTALL_ASCDATA@':env['INSTALL_ASCDATA']
1777 johnpye 507 , '@INSTALL_BIN@':env['INSTALL_BIN']
1778     , '@INSTALL_INCLUDE@':env['INSTALL_INCLUDE']
1779 johnpye 683 , '@INSTALL_LIB@':env['INSTALL_LIB']
1780 johnpye 721 , '@INSTALL_MODELS@':env['INSTALL_MODELS']
1781 johnpye 507 , '@PYGTK_ASSETS@':env['PYGTK_ASSETS']
1782     , '@VERSION@':version
1783 johnpye 658 , '@RELEASE@':release
1784 johnpye 563 , '@DISTTAR_NAME@':env['DISTTAR_NAME']
1785 johnpye 507 , '@WEBHELPROOT@':'http://pye.dyndns.org/ascend/manual/'
1786 johnpye 1228 , '@SHLIBSUFFIX@':env['SHLIBSUFFIX']
1787     , '@SHLIBPREFIX@':env['SHLIBPREFIX']
1788 johnpye 589 , '@ASC_ENV_TK_DEFAULT@' : '$$ASCENDDIST/tcltk'
1789 johnpye 627 , '@ASC_DISTDIR_REL_BIN@' : default_rel_distdir
1790 johnpye 683 , '@PYTHON@' : python_exe
1791 johnpye 800 , '@ASC_CONOPT_LIB@':env.get('CONOPT_LIB')
1792     , '@ASC_CONOPT_ENVVAR@':env.get('CONOPT_ENVVAR')
1793     , '@ASC_CONOPT_DLPATH@':c_escape(env.subst("$CONOPT_LIBPATH"))
1794 johnpye 1174 , '@SOURCE_ROOT@':c_escape(os.path.abspath(str(env.Dir("#"))))
1795 johnpye 507 }
1796    
1797 johnpye 594 if env.get('WITH_LOCAL_HELP'):
1798 johnpye 507 print "WITH_LOCAL_HELP:",env['WITH_LOCAL_HELP']
1799     subst_dict['@HELP_ROOT@']=env['WITH_LOCAL_HELP']
1800    
1801 johnpye 597 # bool options...
1802 johnpye 673 for k,v in {
1803 johnpye 1142 'ASC_WITH_IDA':with_ida
1804     ,'ASC_WITH_DMALLOC':with_dmalloc
1805     ,'ASC_WITH_MFGRAPH':with_mfgraph
1806 jpye 1326 ,'ASC_WITH_UFSPARSE':with_ufsparse
1807 johnpye 1142 ,'ASC_WITH_CONOPT':with_conopt
1808     ,'ASC_WITH_LSODE':with_lsode
1809     ,'ASC_WITH_MMIO':with_mmio
1810     ,'ASC_SIGNAL_TRAPS':with_signals
1811     ,'ASC_RESETNEEDED':env.get('ASC_RESETNEEDED')
1812     ,'HAVE_C99FPE':env.get('HAVE_C99FPE')
1813 johnpye 1261 ,'HAVE_IEEE':env.get('HAVE_IEEE')
1814 johnpye 1142 ,'ASC_ABSOLUTE_PATHS':env.get('ASC_ABSOLUTE_PATHS')
1815     ,'ASC_XTERM_COLORS':env.get('WITH_XTERM_COLORS')
1816     ,'MALLOC_DEBUG':env.get('MALLOC_DEBUG')
1817     }.iteritems():
1818    
1819     if v: subst_dict["/\\* #define %s @%s@ \\*/" % (k,k)]='# define %s 1 ' % k
1820 johnpye 594
1821 johnpye 507 if with_python:
1822     subst_dict['@ASCXX_USE_PYTHON@']="1"
1823 johnpye 673 env['WITH_PYTHON']=1;
1824 johnpye 507
1825     if env.has_key('HAVE_GCCVISIBILITY'):
1826     subst_dict['@HAVE_GCCVISIBILITY@'] = "1"
1827    
1828     env.Append(SUBST_DICT=subst_dict)
1829    
1830 johnpye 1142 #for k,v in subst_dict.iteritems():
1831     # print "%-50s%s" % ("'%s'"%k,v)
1832 johnpye 829
1833 johnpye 1142 # REMOVED: long command-line support on Win2k
1834 johnpye 829
1835     #------------------------------------------------------
1836 johnpye 558 # RECIPE: SWIG scanner
1837    
1838     import SCons.Script
1839    
1840     SWIGScanner = SCons.Scanner.ClassicCPP(
1841     "SWIGScan"
1842     , ".i"
1843     , "CPPPATH"
1844     , '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")'
1845     )
1846    
1847     env.Append(SCANNERS=[SWIGScanner])
1848    
1849     #------------------------------------------------------
1850 johnpye 393 # RECIPE: 'SubstInFile', used in pygtk SConscript
1851    
1852     import re
1853 johnpye 395 from SCons.Script import * # the usual scons stuff you get in a SConscript
1854 johnpye 393
1855 johnpye 395 def TOOL_SUBST(env):
1856     """Adds SubstInFile builder, which substitutes the keys->values of SUBST_DICT
1857     from the source to the target.
1858     The values of SUBST_DICT first have any construction variables expanded
1859     (its keys are not expanded).
1860     If a value of SUBST_DICT is a python callable function, it is called and
1861     the result is expanded as the value.
1862     If there's more than one source and more than one target, each target gets
1863     substituted from the corresponding source.
1864 johnpye 393 """
1865 johnpye 395 env.Append(TOOLS = 'SUBST')
1866     def do_subst_in_file(targetfile, sourcefile, dict):
1867     """Replace all instances of the keys of dict with their values.
1868     For example, if dict is {'%VERSION%': '1.2345', '%BASE%': 'MyProg'},
1869     then all instances of %VERSION% in the file will be replaced with 1.2345 etc.
1870     """
1871     try:
1872     f = open(sourcefile, 'rb')
1873     contents = f.read()
1874     f.close()
1875     except:
1876     raise SCons.Errors.UserError, "Can't read source file %s"%sourcefile
1877     for (k,v) in dict.items():
1878 johnpye 1088 try:
1879 johnpye 1090 #print "%s ---> %s" % (k,v)
1880 johnpye 1088 contents = re.sub(k, v, contents)
1881     except Exception,e:
1882     sys.stderr.write("Failed to substute '%s' with '%s': %s\n" % (k,v,e))
1883    
1884 johnpye 395 try:
1885     f = open(targetfile, 'wb')
1886     f.write(contents)
1887     f.close()
1888     except:
1889     raise SCons.Errors.UserError, "Can't write target file %s"%targetfile
1890     return 0 # success
1891 johnpye 393
1892 johnpye 395 def subst_in_file(target, source, env):
1893     if not env.has_key('SUBST_DICT'):
1894     raise SCons.Errors.UserError, "SubstInFile requires SUBST_DICT to be set."
1895     d = dict(env['SUBST_DICT']) # copy it
1896     for (k,v) in d.items():
1897     if callable(v):
1898     d[k] = env.subst(v())
1899     elif SCons.Util.is_String(v):
1900     d[k]=env.subst(v)
1901     else:
1902     raise SCons.Errors.UserError, "SubstInFile: key %s: %s must be a string or callable"%(k, repr(v))
1903     for (t,s) in zip(target, source):
1904     return do_subst_in_file(str(t), str(s), d)
1905 johnpye 393
1906 johnpye 395 def subst_in_file_string(target, source, env):
1907     """This is what gets printed on the console."""
1908     return '\n'.join(['Substituting vars from %s into %s'%(str(s), str(t))
1909     for (t,s) in zip(target, source)])
1910 johnpye 393
1911 johnpye 395 def subst_emitter(target, source, env):
1912     """Add dependency from substituted SUBST_DICT to target.
1913     Returns original target, source tuple unchanged.
1914     """
1915     d = env['SUBST_DICT'].copy() # copy it
1916     for (k,v) in d.items():
1917     if callable(v):
1918     d[k] = env.subst(v())
1919     elif SCons.Util.is_String(v):
1920     d[k]=env.subst(v)
1921     Depends(target, SCons.Node.Python.Value(d))
1922     return target, source
1923 johnpye 393
1924 johnpye 395 subst_action=SCons.Action.Action(subst_in_file, subst_in_file_string)
1925     env['BUILDERS']['SubstInFile'] = Builder(action=subst_action, emitter=subst_emitter)
1926    
1927     TOOL_SUBST(env)
1928    
1929 johnpye 393 #------------------------------------------------------
1930 johnpye 463 # Recipe for 'CHMOD' ACTION
1931 johnpye 439
1932     import SCons
1933     from SCons.Script.SConscript import SConsEnvironment
1934     SConsEnvironment.Chmod = SCons.Action.ActionFactory(os.chmod,
1935     lambda dest, mode: 'Chmod("%s", 0%o)' % (dest, mode))
1936    
1937     def InstallPerm(env, dest, files, perm):
1938     obj = env.Install(dest, files)
1939     for i in obj:
1940     env.AddPostAction(i, env.Chmod(str(i), perm))
1941    
1942     SConsEnvironment.InstallPerm = InstallPerm
1943    
1944     # define wrappers
1945     SConsEnvironment.InstallProgram = lambda env, dest, files: InstallPerm(env, dest, files, 0755)
1946 johnpye 578 SConsEnvironment.InstallHeader = lambda env, dest, files: InstallPerm(env, dest, files, 0644)
1947 johnpye 629 SConsEnvironment.InstallShared = lambda env, dest, files: InstallPerm(env, dest, files, 0644)
1948 johnpye 463
1949 johnpye 439 #------------------------------------------------------
1950 johnpye 463 # BUILD...
1951 johnpye 385
1952 johnpye 463 # so that #include <modulename/headername.h> works across all modules...
1953 johnpye 743 env.AppendUnique(CPPPATH=['#base/generic'])
1954 johnpye 385
1955 johnpye 508 if env['DEBUG']:
1956     env.Append(CCFLAGS=['-g'])
1957    
1958 johnpye 591 if env['GCOV']:
1959     env.Append(
1960     CPPFLAGS=['-g','-fprofile-arcs','-ftest-coverage']
1961     , LIBS=['gcov']
1962     , LINKFLAGS=['-fprofile-arcs','-ftest-coverage']
1963     )
1964    
1965 johnpye 673 if with_ida:
1966     env.Append(WITH_IDA=1)
1967    
1968 johnpye 783 if with_conopt:
1969     env.Append(WITH_CONOPT=1)
1970    
1971 johnpye 463 #-------------
1972     # TCL/TK GUI
1973 johnpye 385
1974 johnpye 551 if with_tcltk:
1975 johnpye 569 env.SConscript(['tcltk/generic/interface/SConscript'],'env')
1976 johnpye 391 else:
1977 johnpye 982 print "Skipping... Tcl/Tk bindings aren't being built:",without_tcltk_reason
1978 johnpye 386
1979 johnpye 463 #-------------
1980     # PYTHON INTERFACE
1981    
1982 johnpye 387 if with_python:
1983 johnpye 532 env.SConscript(['pygtk/SConscript'],'env')
1984 johnpye 391 else:
1985 johnpye 982 print "Skipping... Python bindings aren't being built:",without_python_reason
1986 johnpye 400
1987 johnpye 463 #------------
1988     # BASE/GENERIC SUBDIRECTORIES
1989    
1990 johnpye 673 libascend_env = env.Copy()
1991    
1992 johnpye 1316 dirs = ['general','utilities','compiler','system','solver','integrator','packages','linear']
1993 johnpye 463
1994     srcs = []
1995     for d in dirs:
1996 johnpye 673 heresrcs = libascend_env.SConscript('base/generic/'+d+'/SConscript','libascend_env')
1997 johnpye 463 srcs += heresrcs
1998    
1999     #-------------
2000 johnpye 673 # IMPORTED CODE: LSODE, BLAS, etc
2001    
2002     if with_lsode:
2003     srcs += env.SConscript(['lsod/SConscript'],'env')
2004     srcs += env.SConscript(['linpack/SConscript'],'env')
2005     else:
2006     print "Skipping... LSODE won't be built:", without_lsode_reason
2007    
2008     if with_local_blas:
2009     srcs += env.SConscript(['blas/SConscript'],'env')
2010     else:
2011     print "Skipping... BLAS won't be built:", without_local_blas_reason
2012    
2013     if not with_ida:
2014     print "Skipping... IDA won't be built:", without_ida_reason
2015    
2016 johnpye 993 if with_mmio:
2017     srcs += env.SConscript(['mmio/SConscript'],'env')
2018     else:
2019     print "Skipping... MMIO export won't be built:", without_mmio_reason
2020 johnpye 673 #-------------
2021 johnpye 463 # LIBASCEND -- all base/generic functionality
2022    
2023 johnpye 938 if with_dmalloc:
2024     libascend_env.Append(LIBS=['dmalloc'])
2025    
2026 jpye 1326 if with_ufsparse:
2027     libascend_env.Append(LIBS=['cxsparse'])
2028    
2029 johnpye 673 libascend = libascend_env.SharedLibrary('ascend',srcs)
2030 johnpye 463
2031 johnpye 673 env.Alias('libascend',libascend)
2032    
2033 johnpye 463 #-------------
2034 johnpye 761 # UNIT TESTS (C CODE)
2035 johnpye 463
2036 johnpye 593 if with_cunit:
2037 jpye 1319 testdirs = ['general','solver','utilities','linear']
2038 johnpye 593 testsrcs = []
2039 johnpye 400 for testdir in testdirs:
2040     path = 'base/generic/'+testdir+'/test/'
2041     env.SConscript([path+'SConscript'],'env')
2042 johnpye 593 testsrcs += [i.path for i in env['TESTSRCS_'+testdir.upper()]]
2043    
2044     #print "TESTSRCS =",testsrcs
2045    
2046 johnpye 400 env.SConscript(['test/SConscript'],'env')
2047     env.SConscript(['base/generic/test/SConscript'],'env')
2048 johnpye 593
2049     env.Alias('test',[env.Dir('test'),env.Dir('base/generic/test')])
2050 johnpye 400
2051     else:
2052 johnpye 427 print "Skipping... CUnit tests aren't being built:",without_cunit_reason
2053 johnpye 400
2054 johnpye 761 #-------------
2055     # EXTERNAL FUNCTIONS
2056    
2057 johnpye 811 env['extfns']=[]
2058     modeldirs = env.SConscript(['models/SConscript'],'env')
2059    
2060     if not with_extfns:
2061 johnpye 761 print "Skipping... External modules aren't being built:",without_extfns_reason
2062    
2063 johnpye 811 env.Alias('extfns',env['extfns'])
2064 johnpye 761
2065 johnpye 463 #------------------------------------------------------
2066 johnpye 683 # CREATE ASCEND-CONFIG scriptlet
2067    
2068     ascendconfig = env.SubstInFile('ascend-config.in')
2069    
2070     #------------------------------------------------------
2071 johnpye 463 # INSTALLATION
2072 johnpye 427
2073 johnpye 552 if env.get('CAN_INSTALL'):
2074 johnpye 427
2075 jpye 1335 dirs = ['INSTALL_BIN','INSTALL_ASCDATA','INSTALL_LIB', 'INSTALL_INCLUDE']
2076 johnpye 884 install_dirs = [env.Entry(env['INSTALL_ROOT']+env[d]) for d in dirs]
2077 johnpye 811 install_dirs += modeldirs
2078 johnpye 449
2079 johnpye 463 # TODO: add install options
2080     env.Alias('install',install_dirs)
2081 johnpye 400
2082 johnpye 629 env.InstallShared(env['INSTALL_ROOT']+env['INSTALL_LIB'],libascend)
2083 johnpye 435
2084 johnpye 683 env.InstallProgram(env['INSTALL_ROOT']+env['INSTALL_BIN'],ascendconfig)
2085    
2086 johnpye 438 #------------------------------------------------------
2087 johnpye 631 # WINDOWS INSTALLER
2088     # For the windows installer, please see pygtk/SConscript
2089    
2090     if with_installer:
2091     pass
2092     else:
2093     print "Skipping... Windows installer isn't being built:",without_installer_reason
2094    
2095     #------------------------------------------------------
2096 johnpye 673 # PROJECT FILE for MSVC
2097    
2098     env.SConscript(['base/msvc/SConscript'],['env','libascend']);
2099    
2100     #------------------------------------------------------
2101 johnpye 438 # CREATE the SPEC file for generation of RPM packages
2102    
2103 johnpye 463 if platform.system()=="Linux":
2104     env.SubstInFile('ascend.spec.in')
2105 johnpye 552
2106     #------------------------------------------------------
2107 johnpye 816 # CREATE OMF FILE FOR USE WITH SCROLLKEEPER
2108    
2109     if with_scrollkeeper:
2110     env.SubstInFile('#/pygtk/gnome/ascend.omf.in')
2111     env.InstallShared(env['INSTALL_ROOT']+env['OMFDIR'],"#/pygtk/gnome/ascend.omf")
2112    
2113     #------------------------------------------------------
2114 johnpye 552 # DISTRIBUTION TAR FILE
2115    
2116 johnpye 554 env['DISTTAR_FORMAT']='bz2'
2117 johnpye 556 env.Append(
2118 johnpye 862 DISTTAR_EXCLUDEEXTS=['.o','.os','.so','.a','.dll','.cc','.cache','.pyc','.cvsignore','.dblite','.log','.pl','.out']
2119 johnpye 561 , DISTTAR_EXCLUDEDIRS=['CVS','.svn','.sconf_temp', 'dist']
2120 johnpye 556 )
2121 johnpye 554
2122 johnpye 563 tar = env.DistTar("dist/"+env['DISTTAR_NAME']
2123 johnpye 556 , [env.Dir('#')]
2124 johnpye 554 )
2125    
2126 johnpye 680 env.Depends(tar,'ascend.spec')
2127    
2128 johnpye 862 Alias('dist',tar)
2129    
2130 johnpye 554 #------------------------------------------------------
2131 johnpye 816 # USER'S MANUAL
2132    
2133     env.SConscript('doc/SConscript',['env'])
2134    
2135     #------------------------------------------------------
2136 johnpye 766 # LIBASCEND DOXYGEN DOCUMENTATION
2137    
2138     env.SConscript('base/doc/SConscript',['env'])
2139    
2140     #------------------------------------------------------
2141 johnpye 554 # RPM BUILD
2142    
2143 johnpye 766 # for RPM builds, 'scons dist' then 'rpmbuild -ta dist/ascend-*.tar.bz2'
2144     # (check * for the version number used to create the tarball)
2145 johnpye 554
2146     #------------------------------------------------------
2147     # DEFAULT TARGETS
2148    
2149 johnpye 673 default_targets =['libascend']
2150 johnpye 629 if with_tcltk:
2151     default_targets.append('tcltk')
2152     if with_python:
2153     default_targets.append('pygtk')
2154 johnpye 631 if with_installer:
2155     default_targets.append('installer')
2156 johnpye 761 if with_extfns:
2157     default_targets.append('extfns')
2158 johnpye 554
2159 johnpye 629 env.Default(default_targets)
2160    
2161     print "Building targets:"," ".join([str(i) for i in BUILD_TARGETS])
2162    
2163 johnpye 705 # vim: set syntax=python:
2164    

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