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