/[ascend]/trunk/SConstruct
ViewVC logotype

Annotation of /trunk/SConstruct

Parent Directory Parent Directory | Revision Log Revision Log


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

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