/[ascend]/trunk/SConstruct
ViewVC logotype

Annotation of /trunk/SConstruct

Parent Directory Parent Directory | Revision Log Revision Log


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

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