/[ascend]/trunk/SConstruct
ViewVC logotype

Annotation of /trunk/SConstruct

Parent Directory Parent Directory | Revision Log Revision Log


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

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