/[ascend]/trunk/SConstruct
ViewVC logotype

Annotation of /trunk/SConstruct

Parent Directory Parent Directory | Revision Log Revision Log


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

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