/[ascend]/trunk/SConstruct
ViewVC logotype

Annotation of /trunk/SConstruct

Parent Directory Parent Directory | Revision Log Revision Log


Revision 800 - (hide annotations) (download)
Tue Aug 1 12:22:09 2006 UTC (14 years, 1 month ago) by johnpye
File size: 37866 byte(s)
Fixed for CONOPT under Windows.
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     default_conopt_envvar="LD_LIBRARY_PATH"
59    
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 #ifndef __MINGW32__
842     # error "where is mingw?"
843     #endif
844    
845     #if !defined(_WIN32)
846     # define FNAME_LCASE_DECOR
847     #endif
848    
849 johnpye 783 #include <conopt.h>
850     #include <stdlib.h>
851     int main(){
852     int s, *v, e;
853     s = COIDEF_Size();
854     v = (int *)malloc(s*sizeof(int));
855     e = COIDEF_Ini(v);
856     return e;
857     }
858     """
859    
860     def CheckCONOPT(context):
861     context.Message( 'Checking for CONOPT... ' )
862    
863     keep = KeepContext(context,"CONOPT")
864    
865     is_ok = context.TryLink(conopt_test_text,".c")
866     context.Result(is_ok)
867    
868     keep.restore(context)
869    
870     return is_ok
871    
872     #----------------
873 johnpye 405 # Tcl test
874 johnpye 404
875 johnpye 561 # TCL and TK required version 8.1, 8.2, 8.3, or 8.4:
876     tcltk_minor_newest_acceptable = 4
877     tcltk_major_required = 8
878    
879 johnpye 404 tcl_check_text = r"""
880     #include <tcl.h>
881     #include <stdio.h>
882     int main(void){
883     printf("%s",TCL_PATCH_LEVEL);
884     return 0;
885     }
886     """
887    
888     def CheckTcl(context):
889 johnpye 521 return CheckExtLib(context,'tcl',tcl_check_text,static=env['STATIC_TCLTK'])
890 johnpye 405
891     def CheckTclVersion(context):
892 johnpye 521 keep = KeepContext(context,'TCL',static=env['STATIC_TCLTK'])
893 johnpye 405 context.Message("Checking Tcl version... ")
894     (is_ok,output) = context.TryRun(tcl_check_text,'.c')
895 johnpye 404 keep.restore(context)
896     if not is_ok:
897 johnpye 405 context.Result("failed to run check")
898 johnpye 404 return 0
899 johnpye 405
900 wangym 511 major,minor,patch = tuple([int(i) for i in output.split(".")])
901 johnpye 561 if major != tcltk_major_required or minor > tcltk_minor_newest_acceptable:
902 johnpye 428 context.Result(output+" (bad version)")
903 johnpye 405 # bad version
904     return 0
905    
906     # good version
907 johnpye 552 context.Result(output+", good")
908 johnpye 404 return 1
909    
910 johnpye 405 #----------------
911 johnpye 463 # Tk test
912 johnpye 405
913     tk_check_text = r"""
914     #include <tk.h>
915     #include <stdio.h>
916     int main(void){
917     printf("%s",TK_PATCH_LEVEL);
918     return 0;
919     }
920     """
921     def CheckTk(context):
922 johnpye 673 return CheckExtLib(context,'tk',tk_check_text,static=env['STATIC_TCLTK'])
923 johnpye 405
924 johnpye 428
925 johnpye 405 def CheckTkVersion(context):
926 johnpye 521 keep = KeepContext(context,'TK',static=context.env['STATIC_TCLTK'])
927 johnpye 405 context.Message("Checking Tk version... ")
928 johnpye 521 #print "LINKFLAGS =",context.env['LINKFLAGS']
929 johnpye 405 (is_ok,output) = context.TryRun(tk_check_text,'.c')
930 johnpye 404 keep.restore(context)
931     if not is_ok:
932     context.Result("failed to run check")
933     return 0
934    
935 wangym 511 major,minor,patch = tuple([int(i) for i in output.split(".")])
936 johnpye 561 if major != tcltk_major_required or minor > tcltk_minor_newest_acceptable:
937 johnpye 404 # bad version
938 johnpye 561 context.Result(output+" (bad version)")
939 johnpye 404 return 0
940 johnpye 400
941 johnpye 404 # good version
942 johnpye 561 context.Result(output+" (good)")
943 johnpye 404 return 1
944 johnpye 485
945     #----------------
946 johnpye 521 # Tktable test
947    
948     tktable_check_text = r"""
949     #include <tkTable.h>
950     #include <stdio.h>
951     int main(void){
952     Table mytable;
953     return 0;
954     }
955     """
956    
957     def CheckTkTable(context):
958     return CheckExtLib(context,'tktable',tktable_check_text,static=env['STATIC_TCLTK'])
959    
960     #---------------
961     # X11 test
962    
963     x11_check_text = r"""
964     #include <X11/Xlib.h>
965     #include <X11/IntrinsicP.h>
966     #include <X11/Intrinsic.h>
967     #include <X11/ObjectP.h>
968     #include <X11/Object.h>
969     int main(void){
970     Object mything;
971     return 0;
972     }
973     """
974    
975     def CheckX11(context):
976     return CheckExtLib(context,'X11',x11_check_text)
977    
978     #----------------
979 johnpye 485 # GCC Version sniffing
980    
981     # TODO FIXME
982    
983     gcc_version4 = False
984    
985 johnpye 398 #------------------------------------------------------
986 johnpye 385 # CONFIGURATION
987    
988     conf = Configure(env
989     , custom_tests = {
990 johnpye 673 'CheckMath' : CheckMath
991     , 'CheckSwigVersion' : CheckSwigVersion
992 johnpye 400 , 'CheckCUnit' : CheckCUnit
993 johnpye 404 , 'CheckTcl' : CheckTcl
994     , 'CheckTclVersion' : CheckTclVersion
995 johnpye 405 , 'CheckTk' : CheckTk
996     , 'CheckTkVersion' : CheckTkVersion
997 johnpye 502 , 'CheckGcc' : CheckGcc
998 johnpye 500 , 'CheckGccVisibility' : CheckGccVisibility
999 johnpye 502 , 'CheckYacc' : CheckYacc
1000 johnpye 521 , 'CheckTkTable' : CheckTkTable
1001     , 'CheckX11' : CheckX11
1002 johnpye 673 , 'CheckIDA' : CheckIDA
1003 johnpye 783 , 'CheckCONOPT' : CheckCONOPT
1004 johnpye 400 # , 'CheckIsNan' : CheckIsNan
1005     # , 'CheckCppUnitConfig' : CheckCppUnitConfig
1006 johnpye 385 }
1007 johnpye 459 # , config_h = "config.h"
1008 johnpye 385 )
1009    
1010 johnpye 740 # stdio -- just to check that compiler is behaving
1011 johnpye 398
1012 johnpye 740 if not conf.CheckHeader('stdio.h'):
1013     print "Did not find 'stdio.h'! Check your compiler configuration."
1014     Exit(1)
1015    
1016 johnpye 385 # Math library
1017    
1018 johnpye 673 if need_libm:
1019     if not conf.CheckMath():
1020     print 'Did not find math library, exiting!'
1021     Exit(1)
1022     #pass
1023 johnpye 427
1024 johnpye 385 # Where is 'isnan'?
1025    
1026 johnpye 740 if not conf.CheckFunc('isnan') and not conf.CheckFunc('_isnan'):
1027 johnpye 385 print "Didn't find isnan"
1028 johnpye 414 # Exit(1)
1029 johnpye 385
1030 johnpye 500 # GCC visibility
1031    
1032 johnpye 502 if conf.CheckGcc():
1033     conf.env['HAVE_GCC']=True;
1034 johnpye 526 if env['WITH_GCCVISIBILITY'] and conf.CheckGccVisibility():
1035 johnpye 509 conf.env['HAVE_GCCVISIBILITY']=True;
1036     conf.env.Append(CCFLAGS=['-fvisibility=hidden'])
1037     conf.env.Append(CPPDEFINES=['HAVE_GCCVISIBILITY'])
1038 johnpye 709 conf.env.Append(CCFLAGS=['-Wall'])
1039 johnpye 500
1040 johnpye 502 # YACC
1041    
1042 johnpye 506 if not conf.CheckYacc():
1043     print "YACC NOT FOUND OR NOT WORKING"
1044     else:
1045 johnpye 502 conf.env['HAVE_YACC']=True
1046    
1047     conf.env['HAVE_LEX']=True
1048    
1049 johnpye 387 # Tcl/Tk
1050 johnpye 386
1051 johnpye 586 if with_tcltk:
1052     if conf.CheckTcl():
1053     if conf.CheckTclVersion():
1054     if conf.CheckTk():
1055     if with_tcltk and conf.CheckTkVersion():
1056     if env['STATIC_TCLTK']:
1057     if conf.CheckTkTable():
1058     pass
1059     else:
1060     without_tcltk_reason = "TkTable not found"
1061     with_tcltk = False
1062     else:
1063     without_tcltk_reason = "Require Tk version <= 8.4. See 'scons -h'"
1064     with_tcltk = False
1065 johnpye 521 else:
1066 johnpye 586 without_tcltk_reason = "Tk not found."
1067 johnpye 551 with_tcltk = False
1068 johnpye 428 else:
1069 johnpye 586 without_tcltk_reason = "Require Tcl <= 8.4 Tcl."
1070 johnpye 551 with_tcltk = False
1071 johnpye 586
1072 johnpye 428 else:
1073 johnpye 586 without_tcltk_reason = "Tcl not found."
1074 johnpye 551 with_tcltk = False
1075 johnpye 386
1076 johnpye 521 if env['STATIC_TCLTK']:
1077     conf.CheckX11()
1078    
1079 johnpye 395 # Python... obviously we're already running python, so we just need to
1080     # check that we can link to the python library OK:
1081    
1082 johnpye 391 if platform.system()=="Windows":
1083 johnpye 395 python_lib='python24'
1084 johnpye 391 else:
1085 johnpye 395 python_lib='python2.4'
1086 johnpye 391
1087 johnpye 395 # SWIG version
1088    
1089 johnpye 413 if not conf.CheckSwigVersion():
1090     without_python_reason = 'SWIG >= 1.3.24 is required'
1091     with_python = False
1092    
1093 johnpye 400 # CUnit
1094    
1095 johnpye 593 if with_cunit:
1096 johnpye 404 if not conf.CheckCUnit():
1097 johnpye 427 without_cunit_reason = 'CUnit not found'
1098 johnpye 665 with_cunit = False
1099 johnpye 705 #print "CUNIT NOT FOUND, LIBS=",conf.env.get('LIBS')
1100 johnpye 427
1101 johnpye 673 # IDA
1102    
1103     if not with_ida:
1104     without_ida_reason = "Not selected (see config option WITH_SOLVERS)"
1105     elif not conf.CheckIDA():
1106     with_ida = False
1107     without_ida_reason = "IDA not found"
1108    
1109 johnpye 797 # CONOPT
1110 johnpye 783
1111     if not with_conopt:
1112     without_conopt_reason = "Not selected (see config option WITH_SOLVERS)"
1113     elif not conf.CheckCONOPT():
1114 johnpye 797 with_conopt = False
1115     without_conpt_reason = "CONOPT not found"
1116 johnpye 783
1117 johnpye 427 # BLAS
1118    
1119 johnpye 459 need_blas=False
1120 johnpye 673
1121     if with_lsode:
1122     need_fortran = True
1123 johnpye 459 need_blas=True
1124 johnpye 673
1125 johnpye 459 if need_blas:
1126     if conf.CheckLib('blas'):
1127     with_local_blas = False
1128     without_local_blas_reason = "Found BLAS installed on system"
1129     else:
1130     with_local_blas = True
1131     need_fortran = True
1132 johnpye 673 else:
1133     with_local_blas= False;
1134     without_local_blas_reason = "BLAS not required"
1135 johnpye 427
1136     # FORTRAN
1137    
1138     if need_fortran:
1139 johnpye 629 conf.env.Tool('fortran')
1140     detect_fortran = conf.env.Detect(['g77','f77','gfortran'])
1141 johnpye 427 if detect_fortran:
1142     # For some reason, g77 doesn't get detected properly on MinGW
1143 johnpye 673 if not env.has_key('F77') and not env.has_key('FORTRAN'):
1144 johnpye 427 conf.env.Replace(F77=detect_fortran)
1145     conf.env.Replace(F77COM='$F77 $F77FLAGS -c -o $TARGET $SOURCE')
1146     conf.env.Replace(F77FLAGS='')
1147 johnpye 428 #print "F77:",conf.env['F77']
1148     #print "F77COM:",conf.env['F77COM']
1149     #print "F77FLAGS:",conf.env['F77FLAGS']
1150 johnpye 427 fortran_builder = Builder(
1151     action='$F77COM'
1152     , suffix='.o'
1153     , src_suffix='.f'
1154     )
1155     conf.env.Append(BUILDERS={'Fortran':fortran_builder})
1156     else:
1157 johnpye 673 with_lsode=False;
1158     without_lsode_reason="FORTRAN-77 required but not found"
1159 johnpye 629
1160 johnpye 464 #else:
1161     # print "FORTRAN not required"
1162 johnpye 400
1163 johnpye 673 # F2C
1164    
1165     if need_fortran:
1166     if platform.system()=="Windows":
1167     conf.env.Append(LIBPATH='c:\mingw\lib')
1168    
1169    
1170 johnpye 385 # TODO: -D_HPUX_SOURCE is needed
1171    
1172     # TODO: check size of void*
1173    
1174 johnpye 393 # TODO: detect if dynamic libraries are possible or not
1175    
1176 johnpye 427 if platform.system()=="Windows" and env.has_key('MSVS'):
1177 johnpye 740 _found_windows_h = conf.CheckHeader('Windows.h')
1178    
1179     if not _found_windows_h:
1180 johnpye 741 print "Could not locate 'Windows.h' in CPPPATH. Check your configuration."
1181 johnpye 740 Exit(1)
1182 johnpye 741
1183 johnpye 534 if with_python and not conf.CheckHeader(['basetsd.h','BaseTsd.h']):
1184 johnpye 427 with_python = 0;
1185     without_python_reason = "Header file 'basetsd.h' not found. Install the MS Platform SDK."
1186    
1187     conf.env.Append(CPPDEFINES=env['PACKAGE_LINKING'])
1188    
1189 johnpye 395 conf.Finish()
1190    
1191     env.Append(PYTHON_LIBPATH=[distutils.sysconfig.PREFIX+"/libs"])
1192     env.Append(PYTHON_LIB=[python_lib])
1193     env.Append(PYTHON_CPPPATH=[distutils.sysconfig.get_python_inc()])
1194    
1195 johnpye 507 #---------------------------------------
1196     # SUBSTITUTION DICTIONARY for .in files
1197    
1198 johnpye 658 release = env.get('RELEASE')
1199     if release=="0.":
1200     release="0"
1201    
1202 johnpye 800 #print "SUBSTITUTED CONOPT_LIBPATH:",c_escape(env.subst("$CONOPT_LIBPATH"))
1203    
1204 johnpye 507 subst_dict = {
1205     '@DEFAULT_ASCENDLIBRARY@':env['DEFAULT_ASCENDLIBRARY']
1206     , '@GLADE_FILE@':'ascend.glade'
1207     , '@HELP_ROOT@':''
1208     , '@ICON_EXTENSION@':icon_extension
1209 johnpye 628 , '@INSTALL_ASCDATA@':env['INSTALL_ASCDATA']
1210 johnpye 507 , '@INSTALL_BIN@':env['INSTALL_BIN']
1211     , '@INSTALL_INCLUDE@':env['INSTALL_INCLUDE']
1212 johnpye 683 , '@INSTALL_LIB@':env['INSTALL_LIB']
1213 johnpye 721 , '@INSTALL_MODELS@':env['INSTALL_MODELS']
1214 johnpye 507 , '@PYGTK_ASSETS@':env['PYGTK_ASSETS']
1215     , '@VERSION@':version
1216 johnpye 658 , '@RELEASE@':release
1217 johnpye 563 , '@DISTTAR_NAME@':env['DISTTAR_NAME']
1218 johnpye 507 , '@WEBHELPROOT@':'http://pye.dyndns.org/ascend/manual/'
1219 johnpye 508 , '@ASC_SHLIBSUFFIX@':env['SHLIBSUFFIX']
1220     , '@ASC_SHLIBPREFIX@':env['SHLIBPREFIX']
1221 johnpye 589 , '@ASC_ENV_TK_DEFAULT@' : '$$ASCENDDIST/tcltk'
1222 johnpye 627 , '@ASC_DISTDIR_REL_BIN@' : default_rel_distdir
1223 johnpye 683 , '@PYTHON@' : python_exe
1224 johnpye 800 , '@ASC_CONOPT_LIB@':env.get('CONOPT_LIB')
1225     , '@ASC_CONOPT_ENVVAR@':env.get('CONOPT_ENVVAR')
1226     , '@ASC_CONOPT_DLPATH@':c_escape(env.subst("$CONOPT_LIBPATH"))
1227 johnpye 507 }
1228    
1229 johnpye 594 if env.get('WITH_LOCAL_HELP'):
1230 johnpye 507 print "WITH_LOCAL_HELP:",env['WITH_LOCAL_HELP']
1231     subst_dict['@HELP_ROOT@']=env['WITH_LOCAL_HELP']
1232    
1233 johnpye 597 # bool options...
1234 johnpye 673 for k,v in {
1235     'ABSOLUTE_PATHS' : 'ASC_ABSOLUTE_PATHS'
1236     ,'WITH_XTERM_COLORS' : 'ASC_XTERM_COLORS'
1237     ,'MALLOC_DEBUG' : 'MALLOC_DEBUG'
1238 johnpye 605 }.iteritems():
1239 johnpye 597 if env.get(k):
1240 johnpye 673 # subst_dict['@'+v+'@']='1'
1241     subst_dict["/\\* #define "+v+' @'+v+"@ \\*/"]='# define '+v+' 1 '
1242 johnpye 594
1243 johnpye 673 if with_ida:
1244     subst_dict["/\\* #define ASC_WITH_IDA @ASC_WITH_IDA@ \\*/"]='#define ASC_WITH_IDA '
1245    
1246 johnpye 783 if with_conopt:
1247     subst_dict["/\\* #define ASC_WITH_CONOPT @ASC_WITH_CONOPT@ \\*/"]='#define ASC_WITH_CONOPT '
1248    
1249 johnpye 673 if with_lsode:
1250     subst_dict["/\\* #define ASC_WITH_LSODE @ASC_WITH_LSODE@ \\*/"]='#define ASC_WITH_LSODE '
1251    
1252 johnpye 507 if with_python:
1253     subst_dict['@ASCXX_USE_PYTHON@']="1"
1254 johnpye 673 env['WITH_PYTHON']=1;
1255 johnpye 507
1256     if env.has_key('HAVE_GCCVISIBILITY'):
1257     subst_dict['@HAVE_GCCVISIBILITY@'] = "1"
1258    
1259     env.Append(SUBST_DICT=subst_dict)
1260    
1261 johnpye 385 #------------------------------------------------------
1262 johnpye 558 # RECIPE: SWIG scanner
1263    
1264     import SCons.Script
1265    
1266     SWIGScanner = SCons.Scanner.ClassicCPP(
1267     "SWIGScan"
1268     , ".i"
1269     , "CPPPATH"
1270     , '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")'
1271     )
1272    
1273     env.Append(SCANNERS=[SWIGScanner])
1274    
1275     #------------------------------------------------------
1276 johnpye 393 # RECIPE: 'SubstInFile', used in pygtk SConscript
1277    
1278     import re
1279 johnpye 395 from SCons.Script import * # the usual scons stuff you get in a SConscript
1280 johnpye 393
1281 johnpye 395 def TOOL_SUBST(env):
1282     """Adds SubstInFile builder, which substitutes the keys->values of SUBST_DICT
1283     from the source to the target.
1284     The values of SUBST_DICT first have any construction variables expanded
1285     (its keys are not expanded).
1286     If a value of SUBST_DICT is a python callable function, it is called and
1287     the result is expanded as the value.
1288     If there's more than one source and more than one target, each target gets
1289     substituted from the corresponding source.
1290 johnpye 393 """
1291 johnpye 395 env.Append(TOOLS = 'SUBST')
1292     def do_subst_in_file(targetfile, sourcefile, dict):
1293     """Replace all instances of the keys of dict with their values.
1294     For example, if dict is {'%VERSION%': '1.2345', '%BASE%': 'MyProg'},
1295     then all instances of %VERSION% in the file will be replaced with 1.2345 etc.
1296     """
1297     try:
1298     f = open(sourcefile, 'rb')
1299     contents = f.read()
1300     f.close()
1301     except:
1302     raise SCons.Errors.UserError, "Can't read source file %s"%sourcefile
1303     for (k,v) in dict.items():
1304     contents = re.sub(k, v, contents)
1305     try:
1306     f = open(targetfile, 'wb')
1307     f.write(contents)
1308     f.close()
1309     except:
1310     raise SCons.Errors.UserError, "Can't write target file %s"%targetfile
1311     return 0 # success
1312 johnpye 393
1313 johnpye 395 def subst_in_file(target, source, env):
1314     if not env.has_key('SUBST_DICT'):
1315     raise SCons.Errors.UserError, "SubstInFile requires SUBST_DICT to be set."
1316     d = dict(env['SUBST_DICT']) # copy it
1317     for (k,v) in d.items():
1318     if callable(v):
1319     d[k] = env.subst(v())
1320     elif SCons.Util.is_String(v):
1321     d[k]=env.subst(v)
1322     else:
1323     raise SCons.Errors.UserError, "SubstInFile: key %s: %s must be a string or callable"%(k, repr(v))
1324     for (t,s) in zip(target, source):
1325     return do_subst_in_file(str(t), str(s), d)
1326 johnpye 393
1327 johnpye 395 def subst_in_file_string(target, source, env):
1328     """This is what gets printed on the console."""
1329     return '\n'.join(['Substituting vars from %s into %s'%(str(s), str(t))
1330     for (t,s) in zip(target, source)])
1331 johnpye 393
1332 johnpye 395 def subst_emitter(target, source, env):
1333     """Add dependency from substituted SUBST_DICT to target.
1334     Returns original target, source tuple unchanged.
1335     """
1336     d = env['SUBST_DICT'].copy() # copy it
1337     for (k,v) in d.items():
1338     if callable(v):
1339     d[k] = env.subst(v())
1340     elif SCons.Util.is_String(v):
1341     d[k]=env.subst(v)
1342     Depends(target, SCons.Node.Python.Value(d))
1343     return target, source
1344 johnpye 393
1345 johnpye 395 subst_action=SCons.Action.Action(subst_in_file, subst_in_file_string)
1346     env['BUILDERS']['SubstInFile'] = Builder(action=subst_action, emitter=subst_emitter)
1347    
1348     TOOL_SUBST(env)
1349    
1350 johnpye 393 #------------------------------------------------------
1351 johnpye 463 # Recipe for 'CHMOD' ACTION
1352 johnpye 439
1353     import SCons
1354     from SCons.Script.SConscript import SConsEnvironment
1355     SConsEnvironment.Chmod = SCons.Action.ActionFactory(os.chmod,
1356     lambda dest, mode: 'Chmod("%s", 0%o)' % (dest, mode))
1357    
1358     def InstallPerm(env, dest, files, perm):
1359     obj = env.Install(dest, files)
1360     for i in obj:
1361     env.AddPostAction(i, env.Chmod(str(i), perm))
1362    
1363     SConsEnvironment.InstallPerm = InstallPerm
1364    
1365     # define wrappers
1366     SConsEnvironment.InstallProgram = lambda env, dest, files: InstallPerm(env, dest, files, 0755)
1367 johnpye 578 SConsEnvironment.InstallHeader = lambda env, dest, files: InstallPerm(env, dest, files, 0644)
1368 johnpye 629 SConsEnvironment.InstallShared = lambda env, dest, files: InstallPerm(env, dest, files, 0644)
1369 johnpye 463
1370 johnpye 439 #------------------------------------------------------
1371 johnpye 463 # BUILD...
1372 johnpye 385
1373 johnpye 463 # so that #include <modulename/headername.h> works across all modules...
1374 johnpye 743 env.AppendUnique(CPPPATH=['#base/generic'])
1375 johnpye 385
1376 johnpye 508 if env['DEBUG']:
1377     env.Append(CCFLAGS=['-g'])
1378    
1379 johnpye 591 if env['GCOV']:
1380     env.Append(
1381     CPPFLAGS=['-g','-fprofile-arcs','-ftest-coverage']
1382     , LIBS=['gcov']
1383     , LINKFLAGS=['-fprofile-arcs','-ftest-coverage']
1384     )
1385    
1386 johnpye 673 if with_ida:
1387     env.Append(WITH_IDA=1)
1388    
1389 johnpye 783 if with_conopt:
1390     env.Append(WITH_CONOPT=1)
1391    
1392 johnpye 463 #-------------
1393     # TCL/TK GUI
1394 johnpye 385
1395 johnpye 551 if with_tcltk:
1396 johnpye 569 env.SConscript(['tcltk/generic/interface/SConscript'],'env')
1397 johnpye 391 else:
1398 johnpye 405 print "Skipping... Tcl/Tk GUI isn't being built:",without_tcltk_reason
1399 johnpye 386
1400 johnpye 463 #-------------
1401     # PYTHON INTERFACE
1402    
1403 johnpye 387 if with_python:
1404 johnpye 532 env.SConscript(['pygtk/SConscript'],'env')
1405 johnpye 391 else:
1406 johnpye 413 print "Skipping... Python GUI isn't being built:",without_python_reason
1407 johnpye 400
1408 johnpye 463 #------------
1409     # BASE/GENERIC SUBDIRECTORIES
1410    
1411 johnpye 673 libascend_env = env.Copy()
1412    
1413 johnpye 463 dirs = ['general','utilities','compiler','solver','packages']
1414    
1415     srcs = []
1416     for d in dirs:
1417 johnpye 673 heresrcs = libascend_env.SConscript('base/generic/'+d+'/SConscript','libascend_env')
1418 johnpye 463 srcs += heresrcs
1419    
1420     #-------------
1421 johnpye 673 # IMPORTED CODE: LSODE, BLAS, etc
1422    
1423     if with_lsode:
1424     srcs += env.SConscript(['lsod/SConscript'],'env')
1425     srcs += env.SConscript(['linpack/SConscript'],'env')
1426     else:
1427     print "Skipping... LSODE won't be built:", without_lsode_reason
1428    
1429     if with_local_blas:
1430     srcs += env.SConscript(['blas/SConscript'],'env')
1431     else:
1432     print "Skipping... BLAS won't be built:", without_local_blas_reason
1433    
1434     if not with_ida:
1435     print "Skipping... IDA won't be built:", without_ida_reason
1436    
1437     #-------------
1438 johnpye 463 # LIBASCEND -- all base/generic functionality
1439    
1440 johnpye 673 libascend = libascend_env.SharedLibrary('ascend',srcs)
1441 johnpye 463
1442 johnpye 673 env.Alias('libascend',libascend)
1443    
1444 johnpye 463 #-------------
1445 johnpye 761 # UNIT TESTS (C CODE)
1446 johnpye 463
1447 johnpye 593 if with_cunit:
1448 johnpye 400 testdirs = ['general','solver','utilities']
1449 johnpye 593 testsrcs = []
1450 johnpye 400 for testdir in testdirs:
1451     path = 'base/generic/'+testdir+'/test/'
1452     env.SConscript([path+'SConscript'],'env')
1453 johnpye 593 testsrcs += [i.path for i in env['TESTSRCS_'+testdir.upper()]]
1454    
1455     #print "TESTSRCS =",testsrcs
1456    
1457 johnpye 400 env.SConscript(['test/SConscript'],'env')
1458     env.SConscript(['base/generic/test/SConscript'],'env')
1459 johnpye 593
1460     env.Alias('test',[env.Dir('test'),env.Dir('base/generic/test')])
1461 johnpye 400
1462     else:
1463 johnpye 427 print "Skipping... CUnit tests aren't being built:",without_cunit_reason
1464 johnpye 400
1465 johnpye 761 #-------------
1466     # EXTERNAL FUNCTIONS
1467    
1468     extfns = []
1469     if with_extfns:
1470     testdirs = ['johnpye/extfn']
1471     for testdir in testdirs:
1472     path = 'models/'+testdir+"/SConscript"
1473     extfns += env.SConscript(path,'env')
1474     else:
1475     print "Skipping... External modules aren't being built:",without_extfns_reason
1476    
1477     env.Alias('extfns',extfns)
1478    
1479 johnpye 463 #------------------------------------------------------
1480 johnpye 683 # CREATE ASCEND-CONFIG scriptlet
1481    
1482     ascendconfig = env.SubstInFile('ascend-config.in')
1483    
1484     #------------------------------------------------------
1485 johnpye 463 # INSTALLATION
1486 johnpye 427
1487 johnpye 552 if env.get('CAN_INSTALL'):
1488 johnpye 463 # the models directory only needs to be processed for installation, no other processing required.
1489     env.SConscript(['models/SConscript'],'env')
1490 johnpye 427
1491 johnpye 721 dirs = ['INSTALL_BIN','INSTALL_ASCDATA','INSTALL_LIB', 'INSTALL_INCLUDE']
1492 johnpye 463 install_dirs = [env['INSTALL_ROOT']+env[d] for d in dirs]
1493 johnpye 449
1494 johnpye 463 # TODO: add install options
1495     env.Alias('install',install_dirs)
1496 johnpye 400
1497 johnpye 629 env.InstallShared(env['INSTALL_ROOT']+env['INSTALL_LIB'],libascend)
1498 johnpye 435
1499 johnpye 683 env.InstallProgram(env['INSTALL_ROOT']+env['INSTALL_BIN'],ascendconfig)
1500    
1501 johnpye 438 #------------------------------------------------------
1502 johnpye 631 # WINDOWS INSTALLER
1503     # For the windows installer, please see pygtk/SConscript
1504    
1505     if with_installer:
1506     pass
1507     else:
1508     print "Skipping... Windows installer isn't being built:",without_installer_reason
1509    
1510     #------------------------------------------------------
1511 johnpye 673 # PROJECT FILE for MSVC
1512    
1513     env.SConscript(['base/msvc/SConscript'],['env','libascend']);
1514    
1515     #------------------------------------------------------
1516 johnpye 438 # CREATE the SPEC file for generation of RPM packages
1517    
1518 johnpye 463 if platform.system()=="Linux":
1519     env.SubstInFile('ascend.spec.in')
1520 johnpye 552
1521     #------------------------------------------------------
1522     # DISTRIBUTION TAR FILE
1523    
1524 johnpye 554 env['DISTTAR_FORMAT']='bz2'
1525 johnpye 556 env.Append(
1526 johnpye 566 DISTTAR_EXCLUDEEXTS=['.o','.os','.so','.a','.dll','.cc','.cache','.pyc','.cvsignore','.dblite','.log','.pl']
1527 johnpye 561 , DISTTAR_EXCLUDEDIRS=['CVS','.svn','.sconf_temp', 'dist']
1528 johnpye 556 )
1529 johnpye 554
1530 johnpye 563 tar = env.DistTar("dist/"+env['DISTTAR_NAME']
1531 johnpye 556 , [env.Dir('#')]
1532 johnpye 554 )
1533    
1534 johnpye 680 env.Depends(tar,'ascend.spec')
1535    
1536 johnpye 554 #------------------------------------------------------
1537 johnpye 766 # LIBASCEND DOXYGEN DOCUMENTATION
1538    
1539     env.SConscript('base/doc/SConscript',['env'])
1540    
1541     #------------------------------------------------------
1542 johnpye 554 # RPM BUILD
1543    
1544 johnpye 766 # for RPM builds, 'scons dist' then 'rpmbuild -ta dist/ascend-*.tar.bz2'
1545     # (check * for the version number used to create the tarball)
1546 johnpye 554
1547     #------------------------------------------------------
1548     # DEFAULT TARGETS
1549    
1550 johnpye 673 default_targets =['libascend']
1551 johnpye 629 if with_tcltk:
1552     default_targets.append('tcltk')
1553     if with_python:
1554     default_targets.append('pygtk')
1555 johnpye 631 if with_installer:
1556     default_targets.append('installer')
1557 johnpye 761 if with_extfns:
1558     default_targets.append('extfns')
1559 johnpye 554
1560 johnpye 629 env.Default(default_targets)
1561    
1562     print "Building targets:"," ".join([str(i) for i in BUILD_TARGETS])
1563    
1564 johnpye 705 # vim: set syntax=python:
1565    

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