1 |
import os, commands, platform, distutils.sysconfig, os.path, re |
2 |
|
3 |
version = "0.9.5.96" |
4 |
|
5 |
#------------------------------------------------------ |
6 |
# OPTIONS |
7 |
# |
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 |
|
11 |
opts = Options(['options.cache', 'config.py']) |
12 |
#print "PLATFORM = ",platform.system() |
13 |
|
14 |
if platform.system()=="Windows": |
15 |
default_tcl_lib = "tcl84" |
16 |
default_tk_lib = "tk84" |
17 |
default_tktable_lib = "Tktable28" |
18 |
default_install_assets = "glade/" |
19 |
icon_extension = '.png' |
20 |
default_tcl = "c:\\Tcl" |
21 |
if os.environ.get('MSYSTEM')=="MINGW32": |
22 |
default_tcl_libpath="$TCL\\bin" |
23 |
else: |
24 |
default_tcl_libpath="$TCL\\lib" |
25 |
default_rel_distdir = '.' |
26 |
default_absolute_paths = False |
27 |
|
28 |
default_ida_prefix = "c:\\MinGW" |
29 |
if not os.path.exists(default_ida_prefix): |
30 |
default_ida_prefix = None |
31 |
|
32 |
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 |
if not os.path.exists(default_conopt_prefix): |
39 |
default_conopt_prefix = None |
40 |
|
41 |
need_libm = False |
42 |
python_exe = "c:\\Python24\\python.exe" |
43 |
else: |
44 |
default_tcl_lib = "tcl8.4" |
45 |
default_tk_lib = "tk8.4" |
46 |
default_tktable_lib = "Tktable2.8" |
47 |
default_install_assets = "$INSTALL_ASCDATA/glade/" |
48 |
icon_extension = '.svg' |
49 |
default_tcl = '/usr' |
50 |
default_tcl_libpath = "$TCL/lib" |
51 |
default_rel_distdir = '../share/ascend' |
52 |
default_absolute_paths = True |
53 |
default_ida_prefix="/usr/local" |
54 |
default_conopt_prefix="/usr" |
55 |
default_conopt_libpath="$CONOPT_PREFIX/lib" |
56 |
default_conopt_cpppath="$CONOPT_PREFIX/include" |
57 |
default_conopt_lib="consub3" |
58 |
default_conopt_envvar="CONOPT_PATH" |
59 |
|
60 |
need_libm = True |
61 |
if not os.path.isdir(default_tcl): |
62 |
default_tcl = '/usr' |
63 |
python_exe = distutils.sysconfig.EXEC_PREFIX+"/bin/python" |
64 |
|
65 |
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 |
opts.Add(BoolOption( |
78 |
'GCOV' |
79 |
, 'Whether to enable coverage testing in object code' |
80 |
, False |
81 |
)) |
82 |
|
83 |
# Package linking option |
84 |
opts.Add(EnumOption( |
85 |
'PACKAGE_LINKING' |
86 |
, 'Style of linking for external libraries' |
87 |
, 'DYNAMIC_PACKAGES' |
88 |
, ['DYNAMIC_PACKAGES', 'STATIC_PACKAGES', 'NO_PACKAGES'] |
89 |
)) |
90 |
|
91 |
opts.Add(BoolOption( |
92 |
'WITH_GCCVISIBILITY' |
93 |
,"Whether to use GCC Visibility features (only applicable if available)" |
94 |
,True |
95 |
)) |
96 |
|
97 |
# You can turn off building of Tcl/Tk interface |
98 |
opts.Add(BoolOption( |
99 |
'WITH_TCLTK' |
100 |
,"Set to False if you don't want to build the original Tcl/Tk GUI." |
101 |
, True |
102 |
)) |
103 |
|
104 |
# You can turn off the building of the Python interface |
105 |
opts.Add(BoolOption( |
106 |
'WITH_PYTHON' |
107 |
,"Set to False if you don't want to build Python wrappers." |
108 |
, True |
109 |
)) |
110 |
|
111 |
# Which solvers will we allow? |
112 |
opts.Add(ListOption( |
113 |
'WITH_SOLVERS' |
114 |
,"List of the solvers you want to build. The default is the minimum that" |
115 |
+" works." |
116 |
,["QRSLV","CMSLV","LSOD","IDA","CONOPT","LRSLV"] |
117 |
,['QRSLV','MPS','SLV','OPTSQP' |
118 |
,'NGSLV','CMSLV','LRSLV','MINOS','CONOPT' |
119 |
,'LSOD','OPTSQP',"IDA" |
120 |
] |
121 |
)) |
122 |
|
123 |
# 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 |
# What should the default ASCENDLIBRARY path be? |
139 |
# Note: users can change it by editing their ~/.ascend.ini |
140 |
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 |
,"$INSTALL_ASCDATA/models" |
145 |
) |
146 |
|
147 |
# 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 |
+" 'c:\\msys\\1.0\\home\\john\\swigwin-1.3.29\\swig.exe'." |
153 |
) |
154 |
|
155 |
# Build the test suite? |
156 |
opts.Add(BoolOption( |
157 |
'WITH_CUNIT' |
158 |
,"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 |
)) |
165 |
|
166 |
# Where are the CUnit includes? |
167 |
opts.Add(PackageOption( |
168 |
'CUNIT_CPPPATH' |
169 |
,"Where are your CUnit include files?" |
170 |
,'off' |
171 |
)) |
172 |
|
173 |
# Where are the CUnit libraries? |
174 |
opts.Add(PackageOption( |
175 |
'CUNIT_LIBPATH' |
176 |
,"Where are your CUnit libraries?" |
177 |
,'off' |
178 |
)) |
179 |
|
180 |
opts.Add(PackageOption( |
181 |
"IDA_PREFIX" |
182 |
,"Prefix for your IDA install (IDA ./configure --prefix)" |
183 |
,default_ida_prefix |
184 |
)) |
185 |
|
186 |
opts.Add( |
187 |
"IDA_LIB" |
188 |
,"Libraries linked to for IDA" |
189 |
,['sundials_ida','sundials_nvecserial','m'] |
190 |
) |
191 |
|
192 |
opts.Add( |
193 |
'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 |
# conopt |
205 |
|
206 |
opts.Add(PackageOption( |
207 |
"CONOPT_PREFIX" |
208 |
,"Prefix for your CONOPT install (CONOPT ./configure --prefix)" |
209 |
,default_conopt_prefix |
210 |
)) |
211 |
|
212 |
opts.Add( |
213 |
"CONOPT_LIB" |
214 |
,"Library linked to for CONOPT" |
215 |
,default_conopt_lib |
216 |
) |
217 |
|
218 |
opts.Add( |
219 |
'CONOPT_CPPPATH' |
220 |
,"Where is your conopt.h?" |
221 |
,default_conopt_cpppath |
222 |
) |
223 |
|
224 |
opts.Add( |
225 |
'CONOPT_LIBPATH' |
226 |
,"Where is your CONOPT libraries installed?" |
227 |
,default_conopt_libpath |
228 |
) |
229 |
|
230 |
opts.Add( |
231 |
'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 |
"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 |
'TCL' |
250 |
,'Base of Tcl distribution' |
251 |
,default_tcl |
252 |
) |
253 |
|
254 |
# Where are the Tcl includes? |
255 |
opts.Add( |
256 |
'TCL_CPPPATH' |
257 |
,"Where are your Tcl include files?" |
258 |
,"$TCL/include" |
259 |
) |
260 |
|
261 |
# Where are the Tcl libs? |
262 |
opts.Add( |
263 |
'TCL_LIBPATH' |
264 |
,"Where are your Tcl libraries?" |
265 |
,default_tcl_libpath |
266 |
) |
267 |
|
268 |
# What is the name of the Tcl lib? |
269 |
opts.Add( |
270 |
'TCL_LIB' |
271 |
,"Name of Tcl lib (eg 'tcl' or 'tcl83'), for full path to static library (if STATIC_TCLTK is set)" |
272 |
,default_tcl_lib |
273 |
) |
274 |
|
275 |
# Where are the Tk includes? |
276 |
opts.Add( |
277 |
'TK_CPPPATH' |
278 |
,"Where are your Tk include files?" |
279 |
,'$TCL_CPPPATH' |
280 |
) |
281 |
|
282 |
# Where are the Tk libs? |
283 |
opts.Add( |
284 |
'TK_LIBPATH' |
285 |
,"Where are your Tk libraries?" |
286 |
,'$TCL_LIBPATH' |
287 |
) |
288 |
|
289 |
# What is the name of the Tk lib? |
290 |
opts.Add( |
291 |
'TK_LIB' |
292 |
,"Name of Tk lib (eg 'tk' or 'tk83'), or full path to static library" |
293 |
,default_tk_lib |
294 |
) |
295 |
|
296 |
# Static linking to TkTable |
297 |
|
298 |
opts.Add(BoolOption( |
299 |
'STATIC_TCLTK' |
300 |
,'Set true for static linking for Tcl/Tk and TkTable. EXPERIMENTAL' |
301 |
,False |
302 |
)) |
303 |
|
304 |
opts.Add( |
305 |
'TKTABLE_LIBPATH' |
306 |
,'Location of TkTable static library' |
307 |
,'$TCL_LIBPATH/Tktable2.8' |
308 |
) |
309 |
|
310 |
opts.Add( |
311 |
'TKTABLE_LIB' |
312 |
,'Stem name of TkTable (eg tktable2.8, no ".so" or "lib") shared library, or full path of static tktable (/usr/lib/...)' |
313 |
,default_tktable_lib |
314 |
) |
315 |
|
316 |
opts.Add( |
317 |
'TKTABLE_CPPPATH' |
318 |
,'Location of TkTable header file' |
319 |
,'$TCL_CPPPATH' |
320 |
) |
321 |
|
322 |
opts.Add( |
323 |
'X11' |
324 |
,'Base X11 directory. Only used when STATIC_TCLTK is turned on. EXPERIMENTAL' |
325 |
,'/usr/X11R6' |
326 |
) |
327 |
|
328 |
opts.Add( |
329 |
'X11_LIBPATH' |
330 |
,'Location of X11 lib. EXPERIMENTAL' |
331 |
,'$X11/lib' |
332 |
) |
333 |
|
334 |
opts.Add( |
335 |
'X11_CPPPATH' |
336 |
,'Location of X11 includes. EXPERIMENTAL' |
337 |
,'$X11/include' |
338 |
) |
339 |
|
340 |
opts.Add( |
341 |
'X11_LIB' |
342 |
,'Name of X11 lib. EXPERIMENTAL' |
343 |
,'X11' |
344 |
) |
345 |
|
346 |
opts.Add( |
347 |
'INSTALL_PREFIX' |
348 |
,'Root location for installed files' |
349 |
,'/usr/local' |
350 |
) |
351 |
|
352 |
opts.Add( |
353 |
'INSTALL_BIN' |
354 |
,'Location to put binaries during installation' |
355 |
,"$INSTALL_PREFIX/bin" |
356 |
) |
357 |
|
358 |
opts.Add( |
359 |
'INSTALL_LIB' |
360 |
,'Location to put libraries during installation' |
361 |
,"$INSTALL_PREFIX/lib" |
362 |
) |
363 |
|
364 |
opts.Add( |
365 |
'INSTALL_SHARE' |
366 |
,'Common shared-file location on this system' |
367 |
,"$INSTALL_PREFIX/share" |
368 |
) |
369 |
|
370 |
|
371 |
opts.Add( |
372 |
'INSTALL_ASCDATA' |
373 |
,"Location of ASCEND shared data (TK, python, models etc)" |
374 |
,"$INSTALL_SHARE/ascend" |
375 |
) |
376 |
|
377 |
opts.Add( |
378 |
'INSTALL_INCLUDE' |
379 |
,'Location to put header files during installation' |
380 |
,"$INSTALL_PREFIX/include" |
381 |
) |
382 |
|
383 |
opts.Add( |
384 |
'PYGTK_ASSETS' |
385 |
,'Default location for Glade assets (placed in pygtk/config.py)' |
386 |
,default_install_assets |
387 |
) |
388 |
|
389 |
opts.Add(BoolOption( |
390 |
'DEBUG' |
391 |
,"Compile source with debugger symbols, eg for use with 'gdb'" |
392 |
,False |
393 |
)) |
394 |
|
395 |
opts.Add(BoolOption( |
396 |
'MALLOC_DEBUG' |
397 |
,"Compile with debugging version of MALLOC. Required for full CUnit testing" |
398 |
,False |
399 |
)) |
400 |
|
401 |
opts.Add( |
402 |
'INSTALL_ROOT' |
403 |
,'For use by RPM only: location of %{buildroot} during rpmbuild' |
404 |
,"" |
405 |
) |
406 |
|
407 |
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 |
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 |
opts.Add(BoolOption( |
420 |
'ABSOLUTE_PATHS' |
421 |
,"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 |
,default_absolute_paths |
423 |
)) |
424 |
|
425 |
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 |
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 |
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 |
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 |
# TODO: OTHER OPTIONS? |
452 |
# TODO: flags for optimisation |
453 |
# TODO: turning on/off bintoken functionality |
454 |
# TODO: Where will the 'Makefile.bt' file be installed? |
455 |
|
456 |
# Import the outside environment |
457 |
|
458 |
def c_escape(str): |
459 |
return re.sub("\\\\","/",str) |
460 |
|
461 |
envadditional={} |
462 |
if os.environ.get('OSTYPE')=='msys': |
463 |
envenv = os.environ; |
464 |
tools = ['mingw','lex','yacc','fortran','swig','disttar','nsis','doxygen'] |
465 |
envadditional['IS_MINGW']=True |
466 |
|
467 |
elif platform.system()=="Windows": |
468 |
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 |
else: |
477 |
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 |
|
487 |
opts.Update(env) |
488 |
opts.Save('options.cache',env) |
489 |
|
490 |
Help(opts.GenerateHelpText(env)) |
491 |
|
492 |
with_tcltk = env.get('WITH_TCLTK') |
493 |
without_tcltk_reason = "disabled by options/config.py" |
494 |
|
495 |
with_python = env.get('WITH_PYTHON') |
496 |
without_python_reason = "disabled by options/config.py" |
497 |
|
498 |
with_cunit = env.get('WITH_CUNIT') |
499 |
without_cunit_reason = "not requested" |
500 |
|
501 |
with_extfns = env.get('WITH_EXTFNS') |
502 |
without_extfn_reason = "disabled by options/config.py" |
503 |
|
504 |
if platform.system()=="Windows": |
505 |
with_installer=1 |
506 |
else: |
507 |
with_installer=0 |
508 |
without_installer_reason = "only possible under Windows" |
509 |
|
510 |
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 |
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 |
#print "SOLVERS:",env['WITH_SOLVERS'] |
531 |
#print "WITH_BINTOKEN:",env['WITH_BINTOKEN'] |
532 |
#print "DEFAULT_ASCENDLIBRARY:",env['DEFAULT_ASCENDLIBRARY'] |
533 |
|
534 |
can_install = True |
535 |
if platform.system()=='Windows': |
536 |
can_install = False |
537 |
|
538 |
env['CAN_INSTALL']=can_install |
539 |
|
540 |
env['INSTALL_MODELS']=env['INSTALL_ASCDATA']+"/models/" |
541 |
|
542 |
print "TCL_CPPPATH =",env['TCL_CPPPATH'] |
543 |
print "TCL_LIBPATH =",env['TCL_LIBPATH'] |
544 |
print "TCL_LIB =",env['TCL_LIB'] |
545 |
print "CC =",env['CC'] |
546 |
print "CXX =",env['CXX'] |
547 |
print "FORTRAN=",env.get('FORTRAN') |
548 |
|
549 |
print "ABSOLUTE PATHS =",env['ABSOLUTE_PATHS'] |
550 |
#------------------------------------------------------ |
551 |
# SPECIAL CONFIGURATION TESTS |
552 |
|
553 |
need_fortran = False |
554 |
|
555 |
#---------------- |
556 |
# SWIG |
557 |
|
558 |
import os,re |
559 |
|
560 |
def get_swig_version(env): |
561 |
cmd = env['SWIG']+' -version' |
562 |
(cin,coutcerr) = os.popen4(cmd) |
563 |
output = coutcerr.read() |
564 |
|
565 |
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 |
m = expr.search(output); |
568 |
if not m: |
569 |
return None |
570 |
maj = int(m.group('maj')) |
571 |
min = int(m.group('min')) |
572 |
pat = int(m.group('pat')) |
573 |
|
574 |
return (maj,min,pat) |
575 |
|
576 |
|
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 |
context.env['SWIGVERSION']=tuple([maj,min,pat]) |
587 |
|
588 |
if maj == 1 and ( |
589 |
min > 3 |
590 |
or (min == 3 and pat >= 24) |
591 |
): |
592 |
context.Result("ok, %d.%d.%d" % (maj,min,pat)) |
593 |
return 1; |
594 |
else: |
595 |
context.Result("too old, %d.%d.%d" % (maj,min,pat)) |
596 |
return 0; |
597 |
|
598 |
#---------------- |
599 |
# General purpose library-and-header test |
600 |
|
601 |
class KeepContext: |
602 |
def __init__(self,context,varprefix,static=False): |
603 |
self.keep = {} |
604 |
for k in ['LIBS','LIBPATH','CPPPATH','LINKFLAGS']: |
605 |
#print "Keeping env %s = %s" % (k,context.env.get(k)) |
606 |
self.keep[k]=context.env.get(k) |
607 |
|
608 |
if context.env.has_key(varprefix+'_CPPPATH'): |
609 |
context.env.AppendUnique(CPPPATH=[env[varprefix+'_CPPPATH']]) |
610 |
#print "Adding '"+str(env[varprefix+'_CPPPATH'])+"' to cpp path" |
611 |
|
612 |
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 |
#print "Adding '"+str(env[varprefix+'_LIBPATH'])+"' to lib path" |
622 |
|
623 |
if context.env.has_key(varprefix+'_LIB'): |
624 |
context.env.Append(LIBS=[env[varprefix+'_LIB']]) |
625 |
#print "Adding '"+str(env[varprefix+'_LIB'])+"' to libs" |
626 |
|
627 |
def restore(self,context): |
628 |
#print "RESTORING CONTEXT" |
629 |
#print self.keep |
630 |
#print "..." |
631 |
for k in self.keep: |
632 |
if self.keep[k]==None: |
633 |
if context.env.has_key(k): |
634 |
#print "Clearing "+str(k) |
635 |
del context.env[k]; |
636 |
else: |
637 |
#print "Restoring %s to '%s'" %(k,self.keep.get(k)) |
638 |
context.env[k]=self.keep[k]; |
639 |
|
640 |
def CheckExtLib(context,libname,text,ext='.c',varprefix=None,static=False): |
641 |
"""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 |
if static: |
647 |
context.Message( 'Checking for static '+libname+'... ' ) |
648 |
else: |
649 |
context.Message( 'Checking for '+libname+'... ' ) |
650 |
|
651 |
if varprefix==None: |
652 |
varprefix = libname.upper() |
653 |
|
654 |
#print "LIBS is currently:",context.env.get('LIBS') |
655 |
keep = KeepContext(context,varprefix,static) |
656 |
|
657 |
if not context.env.has_key(varprefix+'_LIB'): |
658 |
# if varprefix_LIB were in env, KeepContext would |
659 |
# have appended it already |
660 |
context.env.Append(LIBS=[libname]) |
661 |
|
662 |
is_ok = context.TryLink(text,ext) |
663 |
|
664 |
#print "Link success? ",(is_ok != 0) |
665 |
|
666 |
keep.restore(context) |
667 |
|
668 |
# print "Restored CPPPATH="+str(context.env['CPPPATH']) |
669 |
# print "Restored LIBS="+str(context.env['LIBS']) |
670 |
# print "Restored LIBPATH="+str(context.env['LIBPATH']) |
671 |
|
672 |
context.Result(is_ok) |
673 |
return is_ok |
674 |
|
675 |
#---------------- |
676 |
# 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 |
# 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 |
if not context.env.has_key('WITH_GCCVISIBILITY') or not env['WITH_GCCVISIBILITY']: |
713 |
context.Result("disabled") |
714 |
return 0 |
715 |
is_ok = context.TryCompile(gccvisibility_test_text,".c") |
716 |
context.Result(is_ok) |
717 |
return is_ok |
718 |
|
719 |
#---------------- |
720 |
# YACC |
721 |
|
722 |
yacc_test_text = """ |
723 |
%{ |
724 |
#include <stdio.h> |
725 |
|
726 |
/* MSVC++ needs this before it can swallow Bison output */ |
727 |
#ifdef _MSC_VER |
728 |
# define __STDC__ |
729 |
#endif |
730 |
%} |
731 |
%token MSG |
732 |
%start ROOT |
733 |
%% |
734 |
ROOT: |
735 |
MSG { printf("HELLO"); } |
736 |
; |
737 |
%% |
738 |
""" |
739 |
|
740 |
def CheckYacc(context): |
741 |
context.Message("Checking for Yacc ('%s')... " % context.env.get('YACC')) |
742 |
is_ok = context.TryCompile(yacc_test_text,".y") |
743 |
context.Result(is_ok) |
744 |
return is_ok |
745 |
|
746 |
#---------------- |
747 |
# CUnit test |
748 |
|
749 |
cunit_test_text = """ |
750 |
#include <CUnit/CUnit.h> |
751 |
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 |
return 0; |
764 |
} |
765 |
""" |
766 |
|
767 |
def CheckCUnit(context): |
768 |
return CheckExtLib(context,'cunit',cunit_test_text) |
769 |
|
770 |
#---------------- |
771 |
# MATH test |
772 |
|
773 |
math_test_text = """ |
774 |
#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 |
#include <math.h> |
784 |
int main(void){ |
785 |
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 |
return 0; |
798 |
} |
799 |
""" |
800 |
|
801 |
def CheckMath(context): |
802 |
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 |
#---------------- |
812 |
# IDA test |
813 |
|
814 |
ida_test_text = """ |
815 |
#include <ida/ida.h> |
816 |
#include <nvector/nvector_serial.h> |
817 |
#include <ida/ida_spgmr.h> |
818 |
int main(){ |
819 |
void *ida_mem; |
820 |
ida_mem = IDACreate(); |
821 |
return 0; |
822 |
} |
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 |
|
835 |
return is_ok |
836 |
|
837 |
#---------------- |
838 |
# CONOPT test |
839 |
|
840 |
conopt_test_text = """ |
841 |
#if !defined(_WIN32) |
842 |
# define FNAME_LCASE_DECOR |
843 |
#endif |
844 |
|
845 |
#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 |
# Tcl test |
870 |
|
871 |
# 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 |
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 |
return CheckExtLib(context,'tcl',tcl_check_text,static=env['STATIC_TCLTK']) |
886 |
|
887 |
def CheckTclVersion(context): |
888 |
keep = KeepContext(context,'TCL',static=env['STATIC_TCLTK']) |
889 |
context.Message("Checking Tcl version... ") |
890 |
(is_ok,output) = context.TryRun(tcl_check_text,'.c') |
891 |
keep.restore(context) |
892 |
if not is_ok: |
893 |
context.Result("failed to run check") |
894 |
return 0 |
895 |
|
896 |
major,minor,patch = tuple([int(i) for i in output.split(".")]) |
897 |
if major != tcltk_major_required or minor > tcltk_minor_newest_acceptable: |
898 |
context.Result(output+" (bad version)") |
899 |
# bad version |
900 |
return 0 |
901 |
|
902 |
# good version |
903 |
context.Result(output+", good") |
904 |
return 1 |
905 |
|
906 |
#---------------- |
907 |
# Tk test |
908 |
|
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 |
return CheckExtLib(context,'tk',tk_check_text,static=env['STATIC_TCLTK']) |
919 |
|
920 |
|
921 |
def CheckTkVersion(context): |
922 |
keep = KeepContext(context,'TK',static=context.env['STATIC_TCLTK']) |
923 |
context.Message("Checking Tk version... ") |
924 |
#print "LINKFLAGS =",context.env['LINKFLAGS'] |
925 |
(is_ok,output) = context.TryRun(tk_check_text,'.c') |
926 |
keep.restore(context) |
927 |
if not is_ok: |
928 |
context.Result("failed to run check") |
929 |
return 0 |
930 |
|
931 |
major,minor,patch = tuple([int(i) for i in output.split(".")]) |
932 |
if major != tcltk_major_required or minor > tcltk_minor_newest_acceptable: |
933 |
# bad version |
934 |
context.Result(output+" (bad version)") |
935 |
return 0 |
936 |
|
937 |
# good version |
938 |
context.Result(output+" (good)") |
939 |
return 1 |
940 |
|
941 |
#---------------- |
942 |
# 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 |
# GCC Version sniffing |
976 |
|
977 |
# TODO FIXME |
978 |
|
979 |
gcc_version4 = False |
980 |
|
981 |
#------------------------------------------------------ |
982 |
# CONFIGURATION |
983 |
|
984 |
conf = Configure(env |
985 |
, custom_tests = { |
986 |
'CheckMath' : CheckMath |
987 |
, 'CheckSwigVersion' : CheckSwigVersion |
988 |
, 'CheckCUnit' : CheckCUnit |
989 |
, 'CheckTcl' : CheckTcl |
990 |
, 'CheckTclVersion' : CheckTclVersion |
991 |
, 'CheckTk' : CheckTk |
992 |
, 'CheckTkVersion' : CheckTkVersion |
993 |
, 'CheckGcc' : CheckGcc |
994 |
, 'CheckGccVisibility' : CheckGccVisibility |
995 |
, 'CheckYacc' : CheckYacc |
996 |
, 'CheckTkTable' : CheckTkTable |
997 |
, 'CheckX11' : CheckX11 |
998 |
, 'CheckIDA' : CheckIDA |
999 |
, 'CheckCONOPT' : CheckCONOPT |
1000 |
# , 'CheckIsNan' : CheckIsNan |
1001 |
# , 'CheckCppUnitConfig' : CheckCppUnitConfig |
1002 |
} |
1003 |
# , config_h = "config.h" |
1004 |
) |
1005 |
|
1006 |
# stdio -- just to check that compiler is behaving |
1007 |
|
1008 |
if not conf.CheckHeader('stdio.h'): |
1009 |
print "Did not find 'stdio.h'! Check your compiler configuration." |
1010 |
Exit(1) |
1011 |
|
1012 |
# Math library |
1013 |
|
1014 |
if need_libm: |
1015 |
if not conf.CheckMath(): |
1016 |
print 'Did not find math library, exiting!' |
1017 |
Exit(1) |
1018 |
#pass |
1019 |
|
1020 |
# Where is 'isnan'? |
1021 |
|
1022 |
if not conf.CheckFunc('isnan') and not conf.CheckFunc('_isnan'): |
1023 |
print "Didn't find isnan" |
1024 |
# Exit(1) |
1025 |
|
1026 |
# GCC visibility |
1027 |
|
1028 |
if conf.CheckGcc(): |
1029 |
conf.env['HAVE_GCC']=True; |
1030 |
if env['WITH_GCCVISIBILITY'] and conf.CheckGccVisibility(): |
1031 |
conf.env['HAVE_GCCVISIBILITY']=True; |
1032 |
conf.env.Append(CCFLAGS=['-fvisibility=hidden']) |
1033 |
conf.env.Append(CPPDEFINES=['HAVE_GCCVISIBILITY']) |
1034 |
conf.env.Append(CCFLAGS=['-Wall']) |
1035 |
|
1036 |
# YACC |
1037 |
|
1038 |
if not conf.CheckYacc(): |
1039 |
print "YACC NOT FOUND OR NOT WORKING" |
1040 |
else: |
1041 |
conf.env['HAVE_YACC']=True |
1042 |
|
1043 |
conf.env['HAVE_LEX']=True |
1044 |
|
1045 |
# Tcl/Tk |
1046 |
|
1047 |
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 |
else: |
1062 |
without_tcltk_reason = "Tk not found." |
1063 |
with_tcltk = False |
1064 |
else: |
1065 |
without_tcltk_reason = "Require Tcl <= 8.4 Tcl." |
1066 |
with_tcltk = False |
1067 |
|
1068 |
else: |
1069 |
without_tcltk_reason = "Tcl not found." |
1070 |
with_tcltk = False |
1071 |
|
1072 |
if env['STATIC_TCLTK']: |
1073 |
conf.CheckX11() |
1074 |
|
1075 |
# 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 |
if platform.system()=="Windows": |
1079 |
python_lib='python24' |
1080 |
else: |
1081 |
python_lib='python2.4' |
1082 |
|
1083 |
# SWIG version |
1084 |
|
1085 |
if not conf.CheckSwigVersion(): |
1086 |
without_python_reason = 'SWIG >= 1.3.24 is required' |
1087 |
with_python = False |
1088 |
|
1089 |
# CUnit |
1090 |
|
1091 |
if with_cunit: |
1092 |
if not conf.CheckCUnit(): |
1093 |
without_cunit_reason = 'CUnit not found' |
1094 |
with_cunit = False |
1095 |
#print "CUNIT NOT FOUND, LIBS=",conf.env.get('LIBS') |
1096 |
|
1097 |
# 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 |
# CONOPT |
1106 |
|
1107 |
if not with_conopt: |
1108 |
without_conopt_reason = "Not selected (see config option WITH_SOLVERS)" |
1109 |
elif not conf.CheckCONOPT(): |
1110 |
with_conopt = False |
1111 |
without_conpt_reason = "CONOPT not found" |
1112 |
|
1113 |
# BLAS |
1114 |
|
1115 |
need_blas=False |
1116 |
|
1117 |
if with_lsode: |
1118 |
need_fortran = True |
1119 |
need_blas=True |
1120 |
|
1121 |
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 |
else: |
1129 |
with_local_blas= False; |
1130 |
without_local_blas_reason = "BLAS not required" |
1131 |
|
1132 |
# FORTRAN |
1133 |
|
1134 |
if need_fortran: |
1135 |
conf.env.Tool('fortran') |
1136 |
detect_fortran = conf.env.Detect(['g77','f77','gfortran']) |
1137 |
if detect_fortran: |
1138 |
# For some reason, g77 doesn't get detected properly on MinGW |
1139 |
if not env.has_key('F77') and not env.has_key('FORTRAN'): |
1140 |
conf.env.Replace(F77=detect_fortran) |
1141 |
conf.env.Replace(F77COM='$F77 $F77FLAGS -c -o $TARGET $SOURCE') |
1142 |
conf.env.Replace(F77FLAGS='') |
1143 |
#print "F77:",conf.env['F77'] |
1144 |
#print "F77COM:",conf.env['F77COM'] |
1145 |
#print "F77FLAGS:",conf.env['F77FLAGS'] |
1146 |
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 |
with_lsode=False; |
1154 |
without_lsode_reason="FORTRAN-77 required but not found" |
1155 |
|
1156 |
#else: |
1157 |
# print "FORTRAN not required" |
1158 |
|
1159 |
# F2C |
1160 |
|
1161 |
if need_fortran: |
1162 |
if platform.system()=="Windows": |
1163 |
conf.env.Append(LIBPATH='c:\mingw\lib') |
1164 |
|
1165 |
|
1166 |
# TODO: -D_HPUX_SOURCE is needed |
1167 |
|
1168 |
# TODO: check size of void* |
1169 |
|
1170 |
# TODO: detect if dynamic libraries are possible or not |
1171 |
|
1172 |
if platform.system()=="Windows" and env.has_key('MSVS'): |
1173 |
_found_windows_h = conf.CheckHeader('Windows.h') |
1174 |
|
1175 |
if not _found_windows_h: |
1176 |
print "Could not locate 'Windows.h' in CPPPATH. Check your configuration." |
1177 |
Exit(1) |
1178 |
|
1179 |
if with_python and not conf.CheckHeader(['basetsd.h','BaseTsd.h']): |
1180 |
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 |
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 |
#--------------------------------------- |
1192 |
# SUBSTITUTION DICTIONARY for .in files |
1193 |
|
1194 |
release = env.get('RELEASE') |
1195 |
if release=="0.": |
1196 |
release="0" |
1197 |
|
1198 |
#print "SUBSTITUTED CONOPT_LIBPATH:",c_escape(env.subst("$CONOPT_LIBPATH")) |
1199 |
|
1200 |
subst_dict = { |
1201 |
'@DEFAULT_ASCENDLIBRARY@':env['DEFAULT_ASCENDLIBRARY'] |
1202 |
, '@GLADE_FILE@':'ascend.glade' |
1203 |
, '@HELP_ROOT@':'' |
1204 |
, '@ICON_EXTENSION@':icon_extension |
1205 |
, '@INSTALL_ASCDATA@':env['INSTALL_ASCDATA'] |
1206 |
, '@INSTALL_BIN@':env['INSTALL_BIN'] |
1207 |
, '@INSTALL_INCLUDE@':env['INSTALL_INCLUDE'] |
1208 |
, '@INSTALL_LIB@':env['INSTALL_LIB'] |
1209 |
, '@INSTALL_MODELS@':env['INSTALL_MODELS'] |
1210 |
, '@PYGTK_ASSETS@':env['PYGTK_ASSETS'] |
1211 |
, '@VERSION@':version |
1212 |
, '@RELEASE@':release |
1213 |
, '@DISTTAR_NAME@':env['DISTTAR_NAME'] |
1214 |
, '@WEBHELPROOT@':'http://pye.dyndns.org/ascend/manual/' |
1215 |
, '@ASC_SHLIBSUFFIX@':env['SHLIBSUFFIX'] |
1216 |
, '@ASC_SHLIBPREFIX@':env['SHLIBPREFIX'] |
1217 |
, '@ASC_ENV_TK_DEFAULT@' : '$$ASCENDDIST/tcltk' |
1218 |
, '@ASC_DISTDIR_REL_BIN@' : default_rel_distdir |
1219 |
, '@PYTHON@' : python_exe |
1220 |
, '@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 |
} |
1224 |
|
1225 |
if env.get('WITH_LOCAL_HELP'): |
1226 |
print "WITH_LOCAL_HELP:",env['WITH_LOCAL_HELP'] |
1227 |
subst_dict['@HELP_ROOT@']=env['WITH_LOCAL_HELP'] |
1228 |
|
1229 |
# bool options... |
1230 |
for k,v in { |
1231 |
'ABSOLUTE_PATHS' : 'ASC_ABSOLUTE_PATHS' |
1232 |
,'WITH_XTERM_COLORS' : 'ASC_XTERM_COLORS' |
1233 |
,'MALLOC_DEBUG' : 'MALLOC_DEBUG' |
1234 |
}.iteritems(): |
1235 |
if env.get(k): |
1236 |
# subst_dict['@'+v+'@']='1' |
1237 |
subst_dict["/\\* #define "+v+' @'+v+"@ \\*/"]='# define '+v+' 1 ' |
1238 |
|
1239 |
if with_ida: |
1240 |
subst_dict["/\\* #define ASC_WITH_IDA @ASC_WITH_IDA@ \\*/"]='#define ASC_WITH_IDA ' |
1241 |
|
1242 |
if with_conopt: |
1243 |
subst_dict["/\\* #define ASC_WITH_CONOPT @ASC_WITH_CONOPT@ \\*/"]='#define ASC_WITH_CONOPT ' |
1244 |
|
1245 |
if with_lsode: |
1246 |
subst_dict["/\\* #define ASC_WITH_LSODE @ASC_WITH_LSODE@ \\*/"]='#define ASC_WITH_LSODE ' |
1247 |
|
1248 |
if with_python: |
1249 |
subst_dict['@ASCXX_USE_PYTHON@']="1" |
1250 |
env['WITH_PYTHON']=1; |
1251 |
|
1252 |
if env.has_key('HAVE_GCCVISIBILITY'): |
1253 |
subst_dict['@HAVE_GCCVISIBILITY@'] = "1" |
1254 |
|
1255 |
env.Append(SUBST_DICT=subst_dict) |
1256 |
|
1257 |
#------------------------------------------------------ |
1258 |
# 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 |
# RECIPE: 'SubstInFile', used in pygtk SConscript |
1273 |
|
1274 |
import re |
1275 |
from SCons.Script import * # the usual scons stuff you get in a SConscript |
1276 |
|
1277 |
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 |
""" |
1287 |
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 |
|
1309 |
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 |
|
1323 |
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 |
|
1328 |
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 |
|
1341 |
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 |
#------------------------------------------------------ |
1347 |
# Recipe for 'CHMOD' ACTION |
1348 |
|
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 |
SConsEnvironment.InstallHeader = lambda env, dest, files: InstallPerm(env, dest, files, 0644) |
1364 |
SConsEnvironment.InstallShared = lambda env, dest, files: InstallPerm(env, dest, files, 0644) |
1365 |
|
1366 |
#------------------------------------------------------ |
1367 |
# BUILD... |
1368 |
|
1369 |
# so that #include <modulename/headername.h> works across all modules... |
1370 |
env.AppendUnique(CPPPATH=['#base/generic']) |
1371 |
|
1372 |
if env['DEBUG']: |
1373 |
env.Append(CCFLAGS=['-g']) |
1374 |
|
1375 |
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 |
if with_ida: |
1383 |
env.Append(WITH_IDA=1) |
1384 |
|
1385 |
if with_conopt: |
1386 |
env.Append(WITH_CONOPT=1) |
1387 |
|
1388 |
#------------- |
1389 |
# TCL/TK GUI |
1390 |
|
1391 |
if with_tcltk: |
1392 |
env.SConscript(['tcltk/generic/interface/SConscript'],'env') |
1393 |
else: |
1394 |
print "Skipping... Tcl/Tk GUI isn't being built:",without_tcltk_reason |
1395 |
|
1396 |
#------------- |
1397 |
# PYTHON INTERFACE |
1398 |
|
1399 |
if with_python: |
1400 |
env.SConscript(['pygtk/SConscript'],'env') |
1401 |
else: |
1402 |
print "Skipping... Python GUI isn't being built:",without_python_reason |
1403 |
|
1404 |
#------------ |
1405 |
# BASE/GENERIC SUBDIRECTORIES |
1406 |
|
1407 |
libascend_env = env.Copy() |
1408 |
|
1409 |
dirs = ['general','utilities','compiler','solver','packages'] |
1410 |
|
1411 |
srcs = [] |
1412 |
for d in dirs: |
1413 |
heresrcs = libascend_env.SConscript('base/generic/'+d+'/SConscript','libascend_env') |
1414 |
srcs += heresrcs |
1415 |
|
1416 |
#------------- |
1417 |
# 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 |
# LIBASCEND -- all base/generic functionality |
1435 |
|
1436 |
libascend = libascend_env.SharedLibrary('ascend',srcs) |
1437 |
|
1438 |
env.Alias('libascend',libascend) |
1439 |
|
1440 |
#------------- |
1441 |
# UNIT TESTS (C CODE) |
1442 |
|
1443 |
if with_cunit: |
1444 |
testdirs = ['general','solver','utilities'] |
1445 |
testsrcs = [] |
1446 |
for testdir in testdirs: |
1447 |
path = 'base/generic/'+testdir+'/test/' |
1448 |
env.SConscript([path+'SConscript'],'env') |
1449 |
testsrcs += [i.path for i in env['TESTSRCS_'+testdir.upper()]] |
1450 |
|
1451 |
#print "TESTSRCS =",testsrcs |
1452 |
|
1453 |
env.SConscript(['test/SConscript'],'env') |
1454 |
env.SConscript(['base/generic/test/SConscript'],'env') |
1455 |
|
1456 |
env.Alias('test',[env.Dir('test'),env.Dir('base/generic/test')]) |
1457 |
|
1458 |
else: |
1459 |
print "Skipping... CUnit tests aren't being built:",without_cunit_reason |
1460 |
|
1461 |
#------------- |
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 |
#------------------------------------------------------ |
1476 |
# CREATE ASCEND-CONFIG scriptlet |
1477 |
|
1478 |
ascendconfig = env.SubstInFile('ascend-config.in') |
1479 |
|
1480 |
#------------------------------------------------------ |
1481 |
# INSTALLATION |
1482 |
|
1483 |
if env.get('CAN_INSTALL'): |
1484 |
# the models directory only needs to be processed for installation, no other processing required. |
1485 |
env.SConscript(['models/SConscript'],'env') |
1486 |
|
1487 |
dirs = ['INSTALL_BIN','INSTALL_ASCDATA','INSTALL_LIB', 'INSTALL_INCLUDE'] |
1488 |
install_dirs = [env['INSTALL_ROOT']+env[d] for d in dirs] |
1489 |
|
1490 |
# TODO: add install options |
1491 |
env.Alias('install',install_dirs) |
1492 |
|
1493 |
env.InstallShared(env['INSTALL_ROOT']+env['INSTALL_LIB'],libascend) |
1494 |
|
1495 |
env.InstallProgram(env['INSTALL_ROOT']+env['INSTALL_BIN'],ascendconfig) |
1496 |
|
1497 |
#------------------------------------------------------ |
1498 |
# 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 |
# PROJECT FILE for MSVC |
1508 |
|
1509 |
env.SConscript(['base/msvc/SConscript'],['env','libascend']); |
1510 |
|
1511 |
#------------------------------------------------------ |
1512 |
# CREATE the SPEC file for generation of RPM packages |
1513 |
|
1514 |
if platform.system()=="Linux": |
1515 |
env.SubstInFile('ascend.spec.in') |
1516 |
|
1517 |
#------------------------------------------------------ |
1518 |
# DISTRIBUTION TAR FILE |
1519 |
|
1520 |
env['DISTTAR_FORMAT']='bz2' |
1521 |
env.Append( |
1522 |
DISTTAR_EXCLUDEEXTS=['.o','.os','.so','.a','.dll','.cc','.cache','.pyc','.cvsignore','.dblite','.log','.pl'] |
1523 |
, DISTTAR_EXCLUDEDIRS=['CVS','.svn','.sconf_temp', 'dist'] |
1524 |
) |
1525 |
|
1526 |
tar = env.DistTar("dist/"+env['DISTTAR_NAME'] |
1527 |
, [env.Dir('#')] |
1528 |
) |
1529 |
|
1530 |
env.Depends(tar,'ascend.spec') |
1531 |
|
1532 |
#------------------------------------------------------ |
1533 |
# LIBASCEND DOXYGEN DOCUMENTATION |
1534 |
|
1535 |
env.SConscript('base/doc/SConscript',['env']) |
1536 |
|
1537 |
#------------------------------------------------------ |
1538 |
# RPM BUILD |
1539 |
|
1540 |
# for RPM builds, 'scons dist' then 'rpmbuild -ta dist/ascend-*.tar.bz2' |
1541 |
# (check * for the version number used to create the tarball) |
1542 |
|
1543 |
#------------------------------------------------------ |
1544 |
# DEFAULT TARGETS |
1545 |
|
1546 |
default_targets =['libascend'] |
1547 |
if with_tcltk: |
1548 |
default_targets.append('tcltk') |
1549 |
if with_python: |
1550 |
default_targets.append('pygtk') |
1551 |
if with_installer: |
1552 |
default_targets.append('installer') |
1553 |
if with_extfns: |
1554 |
default_targets.append('extfns') |
1555 |
|
1556 |
env.Default(default_targets) |
1557 |
|
1558 |
print "Building targets:"," ".join([str(i) for i in BUILD_TARGETS]) |
1559 |
|
1560 |
# vim: set syntax=python: |
1561 |
|