1 |
import os, commands, platform, distutils.sysconfig, os.path |
2 |
|
3 |
version = "0.9.6rc0" |
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 |
# Import the outside environment |
15 |
env = Environment(ENV=os.environ) |
16 |
|
17 |
if platform.system()=='Windows' and env.has_key('MSVS'): |
18 |
print "INCLUDE =",env['ENV']['INCLUDE'] |
19 |
print "LIB =",env['ENV']['LIB'] |
20 |
print "LINK =",env['LINK'] |
21 |
print "LINKCOM =",env['LINKCOM'] |
22 |
print "AR =",env['AR'] |
23 |
print "ARCOM =",env['ARCOM'] |
24 |
#env['AR']='link /lib' |
25 |
env.Append(CPPPATH=env['ENV']['INCLUDE']) |
26 |
env.Append(LIBPATH=env['ENV']['LIB']) |
27 |
env.Append(CPPDEFINES=['_CRT_SECURE_NO_DEPRECATED','_CRT_SECURE_NO_DEPRECATE']) |
28 |
|
29 |
# Package linking option |
30 |
opts.Add(EnumOption( |
31 |
'PACKAGE_LINKING' |
32 |
, 'Style of linking for external libraries' |
33 |
, 'DYNAMIC_PACKAGES' |
34 |
, ['DYNAMIC_PACKAGES', 'STATIC_PACKAGES', 'NO_PACKAGES'] |
35 |
)) |
36 |
|
37 |
# You can turn off building of Tcl/Tk interface |
38 |
opts.Add(BoolOption( |
39 |
'WITHOUT_TCLTK_GUI' |
40 |
,"Set to True if you don't want to build the original Tcl/Tk GUI." |
41 |
, False |
42 |
)) |
43 |
|
44 |
# You can turn off the building of the Python interface |
45 |
opts.Add(BoolOption( |
46 |
'WITHOUT_PYTHON' |
47 |
,"Set to True if you don't want to build Python wrappers." |
48 |
, False |
49 |
)) |
50 |
|
51 |
# Which solvers will we allow? |
52 |
opts.Add(ListOption( |
53 |
'WITH_SOLVERS' |
54 |
,"List of the solvers you want to build. The default is the minimum that" |
55 |
+" works." |
56 |
,["QRSLV","CMSLV"] |
57 |
,['QRSLV','MPS','SLV','OPTSQP' |
58 |
,'NGSLV','CMSLV','LRSLV','MINOS','CONOPT' |
59 |
,'LSOD','OPTSQP' |
60 |
] |
61 |
)) |
62 |
|
63 |
# Where will the local copy of the help files be kept? |
64 |
opts.Add(PackageOption( |
65 |
'WITH_LOCAL_HELP' |
66 |
, "Directory containing the local copy of the help files (optional)" |
67 |
, "no" |
68 |
)) |
69 |
|
70 |
# Will bintoken support be enabled? |
71 |
opts.Add(BoolOption( |
72 |
'WITH_BINTOKEN' |
73 |
,"Enable bintoken support? This means compiling models as C-code before" |
74 |
+" running them, to increase solving speed for large models." |
75 |
,False |
76 |
)) |
77 |
|
78 |
# What should the default ASCENDLIBRARY path be? |
79 |
# Note: users can change it by editing their ~/.ascend.ini |
80 |
opts.Add( |
81 |
'DEFAULT_ASCENDLIBRARY' |
82 |
,"Set the default value of the ASCENDLIBRARY -- the location where" |
83 |
+" ASCEND will look for models when running ASCEND" |
84 |
,os.path.expanduser("~/src/ascend/trunk/models") |
85 |
) |
86 |
|
87 |
# Where is SWIG? |
88 |
opts.Add( |
89 |
'SWIG' |
90 |
,"SWIG location, probably only required for MinGW and MSVC users." |
91 |
+" Enter the location as a Windows-style path, for example" |
92 |
+" 'c:\\msys\\1.0\\home\\john\\swigwin-1.3.29\\swig.exe'." |
93 |
) |
94 |
|
95 |
# Build the test suite? |
96 |
opts.Add(BoolOption( |
97 |
'WITH_CUNIT_TESTS' |
98 |
,"Whether to build the CUnit tests. Default is off. If set to on," |
99 |
+" you must have CUnit installed somewhere that SCons can" |
100 |
+" find it." |
101 |
,False |
102 |
)) |
103 |
|
104 |
# Where are the CUnit includes? |
105 |
opts.Add(PackageOption( |
106 |
'CUNIT_CPPPATH' |
107 |
,"Where are your CUnit include files?" |
108 |
,"off" |
109 |
)) |
110 |
|
111 |
# Where are the CUnit libraries? |
112 |
opts.Add(PackageOption( |
113 |
'CUNIT_LIBPATH' |
114 |
,"Where are your CUnit libraries?" |
115 |
,"/usr/local/lib" |
116 |
)) |
117 |
|
118 |
# Where are the Tcl includes? |
119 |
opts.Add(PackageOption( |
120 |
'TCL_CPPPATH' |
121 |
,"Where are your Tcl include files?" |
122 |
,None |
123 |
)) |
124 |
|
125 |
# Where are the Tcl libs? |
126 |
opts.Add(PackageOption( |
127 |
'TCL_LIBPATH' |
128 |
,"Where are your Tcl libraries?" |
129 |
,None |
130 |
)) |
131 |
|
132 |
# What is the name of the Tcl lib? |
133 |
opts.Add( |
134 |
'TCL_LIB' |
135 |
,"Name of Tcl lib (eg 'tcl' or 'tcl83')" |
136 |
,'tcl' |
137 |
) |
138 |
|
139 |
# Where are the Tk includes? |
140 |
opts.Add(PackageOption( |
141 |
'TK_CPPPATH' |
142 |
,"Where are your Tk include files?" |
143 |
,None |
144 |
)) |
145 |
|
146 |
# Where are the Tk libs? |
147 |
opts.Add(PackageOption( |
148 |
'TK_LIBPATH' |
149 |
,"Where are your Tk libraries?" |
150 |
,None |
151 |
)) |
152 |
|
153 |
# What is the name of the Tk lib? |
154 |
opts.Add( |
155 |
'TK_LIB' |
156 |
,"Name of Tk lib (eg 'tk' or 'tk83')" |
157 |
,'tk' |
158 |
) |
159 |
|
160 |
opts.Add( |
161 |
'INSTALL_PREFIX' |
162 |
,'Root location for installed files' |
163 |
,'/usr/local' |
164 |
) |
165 |
|
166 |
opts.Add( |
167 |
'INSTALL_BIN' |
168 |
,'Location to put binaries during installation' |
169 |
,"$INSTALL_PREFIX/bin" |
170 |
) |
171 |
|
172 |
opts.Add( |
173 |
'INSTALL_DATA' |
174 |
,'Location to put data files during installation' |
175 |
,"$INSTALL_PREFIX/share" |
176 |
) |
177 |
|
178 |
opts.Add( |
179 |
'INSTALL_INCLUDE' |
180 |
,'Location to put header files during installation' |
181 |
,"$INSTALL_PREFIX/include" |
182 |
) |
183 |
|
184 |
opts.Add( |
185 |
'INSTALL_ROOT' |
186 |
,'For use by RPM only: location of %{buildroot} during rpmbuild' |
187 |
,"" |
188 |
) |
189 |
|
190 |
# TODO: OTHER OPTIONS? |
191 |
# TODO: flags for optimisation |
192 |
# TODO: turning on/off bintoken functionality |
193 |
# TODO: Where will the 'Makefile.bt' file be installed? |
194 |
|
195 |
opts.Update(env) |
196 |
opts.Save('options.cache',env) |
197 |
|
198 |
Help(opts.GenerateHelpText(env)) |
199 |
|
200 |
with_tcltk_gui = (env['WITHOUT_TCLTK_GUI']==False) |
201 |
without_tcltk_reason = "disabled by options/config.py" |
202 |
|
203 |
with_python = (env['WITHOUT_PYTHON']==False) |
204 |
without_python_reason = "disabled by options/config.py" |
205 |
|
206 |
with_cunit_tests = env['WITH_CUNIT_TESTS'] |
207 |
without_cunit_reason = "not requested" |
208 |
|
209 |
print "SOLVERS:",env['WITH_SOLVERS'] |
210 |
print "WITH_LOCAL_HELP:",env['WITH_LOCAL_HELP'] |
211 |
print "WITH_BINTOKEN:",env['WITH_BINTOKEN'] |
212 |
print "DEFAULT_ASCENDLIBRARY:",env['DEFAULT_ASCENDLIBRARY'] |
213 |
|
214 |
subst_dict = { |
215 |
'@WEBHELPROOT@':'http://pye.dyndns.org/ascend/manual/' |
216 |
, '@GLADE_FILE@':'ascend.glade' |
217 |
, '@DEFAULT_ASCENDLIBRARY@':env['DEFAULT_ASCENDLIBRARY'] |
218 |
, '@ASCEND_ICON@':'ascend.png' |
219 |
, '@HELP_ROOT@':'' |
220 |
, '@INSTALL_DATA@':env['INSTALL_DATA'] |
221 |
, '@INSTALL_BIN@':env['INSTALL_BIN'] |
222 |
, '@INSTALL_INCLUDE@':env['INSTALL_INCLUDE'] |
223 |
, '@VERSION@':version |
224 |
} |
225 |
|
226 |
if env['WITH_LOCAL_HELP']: |
227 |
subst_dict['@HELP_ROOT@']=env['WITH_LOCAL_HELP'] |
228 |
|
229 |
env.Append(SUBST_DICT=subst_dict) |
230 |
|
231 |
#------------------------------------------------------ |
232 |
# SPECIAL CONFIGURATION TESTS |
233 |
|
234 |
#---------------- |
235 |
# SWIG |
236 |
|
237 |
import os,re |
238 |
|
239 |
need_fortran = False |
240 |
|
241 |
def get_swig_version(env): |
242 |
cmd = env['SWIG']+' -version' |
243 |
(cin,coutcerr) = os.popen4(cmd) |
244 |
output = coutcerr.read() |
245 |
|
246 |
restr = "SWIG\\s+Version\\s+(?P<maj>[0-9]+)\\.(?P<min>[0-9]+)\\.(?P<pat>[0-9]+)\\s*$" |
247 |
expr = re.compile(restr,re.M); |
248 |
m = expr.search(output); |
249 |
if not m: |
250 |
return None |
251 |
maj = int(m.group('maj')) |
252 |
min = int(m.group('min')) |
253 |
pat = int(m.group('pat')) |
254 |
|
255 |
return (maj,min,pat) |
256 |
|
257 |
|
258 |
def CheckSwigVersion(context): |
259 |
|
260 |
try: |
261 |
context.Message("Checking version of SWIG... ") |
262 |
maj,min,pat = get_swig_version(context.env) |
263 |
except: |
264 |
context.Result("Failed to detect version, or failed to run SWIG") |
265 |
return 0; |
266 |
|
267 |
if maj == 1 and ( |
268 |
min > 3 |
269 |
or (min == 3 and pat >= 24) |
270 |
): |
271 |
context.Result("ok, %d.%d.%d" % (maj,min,pat)) |
272 |
return 1; |
273 |
else: |
274 |
context.Result("too old, %d.%d.%d" % (maj,min,pat)) |
275 |
return 0; |
276 |
|
277 |
#---------------- |
278 |
# General purpose library-and-header test |
279 |
|
280 |
class KeepContext: |
281 |
def __init__(self,context,varprefix): |
282 |
self.keep = {} |
283 |
for k in ['LIBS','LIBPATH','CPPPATH']: |
284 |
if context.env.has_key(k): |
285 |
self.keep[k] = context.env[k] |
286 |
|
287 |
libpath_add = [] |
288 |
if context.env.has_key(varprefix+'_LIBPATH'): |
289 |
libpath_add = [env[varprefix+'_LIBPATH']] |
290 |
#print "Adding '"+str(libpath_add)+"' to lib path" |
291 |
|
292 |
cpppath_add = [] |
293 |
if context.env.has_key(varprefix+'_CPPPATH'): |
294 |
cpppath_add = [env[varprefix+'_CPPPATH']] |
295 |
#print "Adding '"+str(cpppath_add)+"' to cpp path" |
296 |
|
297 |
libs_add = [] |
298 |
if context.env.has_key(varprefix+'_LIB'): |
299 |
libs_add = [env[varprefix+'_LIB']] |
300 |
#print "Adding '"+str(libs_add)+"' to libs" |
301 |
|
302 |
context.env.Append( |
303 |
LIBPATH = libpath_add |
304 |
, CPPPATH = cpppath_add |
305 |
, LIBS = libs_add |
306 |
) |
307 |
|
308 |
def restore(self,context): |
309 |
for k in self.keep: |
310 |
context.env[k]=self.keep[k]; |
311 |
|
312 |
def CheckExtLib(context,libname,text,ext='.c',varprefix=None): |
313 |
"""This method will check for variables LIBNAME_LIBPATH |
314 |
and LIBNAME_CPPPATH and try to compile and link the |
315 |
file with the provided text, linking with the |
316 |
library libname.""" |
317 |
|
318 |
context.Message( 'Checking for '+libname+'... ' ) |
319 |
|
320 |
if varprefix==None: |
321 |
varprefix = libname.upper() |
322 |
|
323 |
keep = KeepContext(context,varprefix) |
324 |
|
325 |
# print "TryLink with CPPPATH="+str(context.env['CPPPATH']) |
326 |
# print "TryLink with LIBS="+str(context.env['LIBS']) |
327 |
# print "TryLink with LIBPATH="+str(context.env['LIBPATH']) |
328 |
|
329 |
if not context.env.has_key(varprefix+'_LIB'): |
330 |
context.env.Append(LIBS=libname) |
331 |
|
332 |
is_ok = context.TryLink(text,ext) |
333 |
|
334 |
# print "Link success? ",(is_ok != 0) |
335 |
|
336 |
keep.restore(context) |
337 |
|
338 |
# print "Restored CPPPATH="+str(context.env['CPPPATH']) |
339 |
# print "Restored LIBS="+libname |
340 |
# print "Restored LIBPATH="+str(context.env['LIBPATH']) |
341 |
|
342 |
context.Result(is_ok) |
343 |
return is_ok |
344 |
|
345 |
#---------------- |
346 |
# CUnit test |
347 |
|
348 |
cunit_test_text = """ |
349 |
#include <CUnit/CUnit.h> |
350 |
int maxi(int i1, int i2){ |
351 |
return (i1 > i2) ? i1 : i2; |
352 |
} |
353 |
|
354 |
void test_maxi(void){ |
355 |
CU_ASSERT(maxi(0,2) == 2); |
356 |
CU_ASSERT(maxi(0,-2) == 0); |
357 |
CU_ASSERT(maxi(2,2) == 2); |
358 |
|
359 |
} |
360 |
int main(void){ |
361 |
/* CU_initialize_registry() */ |
362 |
return 0; |
363 |
} |
364 |
""" |
365 |
|
366 |
def CheckCUnit(context): |
367 |
return CheckExtLib(context,'cunit',cunit_test_text) |
368 |
|
369 |
#---------------- |
370 |
# Tcl test |
371 |
|
372 |
tcl_check_text = r""" |
373 |
#include <tcl.h> |
374 |
#include <stdio.h> |
375 |
int main(void){ |
376 |
printf("%s",TCL_PATCH_LEVEL); |
377 |
return 0; |
378 |
} |
379 |
""" |
380 |
|
381 |
def CheckTcl(context): |
382 |
return CheckExtLib(context,'tcl',tcl_check_text) |
383 |
|
384 |
def CheckTclVersion(context): |
385 |
keep = KeepContext(context,'TCL') |
386 |
context.Message("Checking Tcl version... ") |
387 |
(is_ok,output) = context.TryRun(tcl_check_text,'.c') |
388 |
keep.restore(context) |
389 |
if not is_ok: |
390 |
context.Result("failed to run check") |
391 |
return 0 |
392 |
|
393 |
major,minor,patch = tuple(int(i) for i in output.split(".")) |
394 |
if major != 8 or minor > 3: |
395 |
context.Result(output+" (bad version)") |
396 |
# bad version |
397 |
return 0 |
398 |
|
399 |
# good version |
400 |
context.Result(output+" (good)") |
401 |
return 1 |
402 |
|
403 |
#---------------- |
404 |
# Tcl test |
405 |
|
406 |
tk_check_text = r""" |
407 |
#include <tk.h> |
408 |
#include <stdio.h> |
409 |
int main(void){ |
410 |
printf("%s",TK_PATCH_LEVEL); |
411 |
return 0; |
412 |
} |
413 |
""" |
414 |
def CheckTk(context): |
415 |
return CheckExtLib(context,'tk',tcl_check_text) |
416 |
|
417 |
|
418 |
def CheckTkVersion(context): |
419 |
keep = KeepContext(context,'TK') |
420 |
context.Message("Checking Tk version... ") |
421 |
(is_ok,output) = context.TryRun(tk_check_text,'.c') |
422 |
keep.restore(context) |
423 |
if not is_ok: |
424 |
context.Result("failed to run check") |
425 |
return 0 |
426 |
context.Result(output) |
427 |
|
428 |
major,minor,patch = tuple(int(i) for i in output.split(".")) |
429 |
if major != 8 or minor > 3: |
430 |
# bad version |
431 |
return 0 |
432 |
|
433 |
# good version |
434 |
return 1 |
435 |
|
436 |
#------------------------------------------------------ |
437 |
# CONFIGURATION |
438 |
|
439 |
conf = Configure(env |
440 |
, custom_tests = { |
441 |
'CheckSwigVersion' : CheckSwigVersion |
442 |
, 'CheckCUnit' : CheckCUnit |
443 |
, 'CheckTcl' : CheckTcl |
444 |
, 'CheckTclVersion' : CheckTclVersion |
445 |
, 'CheckTk' : CheckTk |
446 |
, 'CheckTkVersion' : CheckTkVersion |
447 |
# , 'CheckIsNan' : CheckIsNan |
448 |
# , 'CheckCppUnitConfig' : CheckCppUnitConfig |
449 |
} |
450 |
, config_h = "config.h" |
451 |
) |
452 |
|
453 |
|
454 |
# Math library |
455 |
|
456 |
#if not conf.CheckFunc('sinh') and not conf.CheckLibWithHeader(['m','c','libc'], 'math.h', 'C'): |
457 |
# print 'Did not find math library, exiting!' |
458 |
# Exit(1) |
459 |
|
460 |
# Where is 'isnan'? |
461 |
|
462 |
if not conf.CheckFunc('isnan'): |
463 |
print "Didn't find isnan" |
464 |
# Exit(1) |
465 |
|
466 |
# Tcl/Tk |
467 |
|
468 |
if conf.CheckTcl(): |
469 |
if with_tcltk_gui and conf.CheckTclVersion(): |
470 |
if conf.CheckTk(): |
471 |
if with_tcltk_gui and not conf.CheckTkVersion(): |
472 |
without_tcltk_reason = "Require Tk version <= 8.3. See 'scons -h'" |
473 |
with_tcltk_gui = False |
474 |
else: |
475 |
without_tcltk_reason = "Tk not found." |
476 |
with_tcltk_gui = False |
477 |
else: |
478 |
without_tcltk_reason = "Require Tcl <= 8.3 Tcl." |
479 |
with_tcltk_gui = False |
480 |
|
481 |
else: |
482 |
without_tcltk_reason = "Tcl not found." |
483 |
with_tcltk_gui = False |
484 |
|
485 |
# Python... obviously we're already running python, so we just need to |
486 |
# check that we can link to the python library OK: |
487 |
|
488 |
if platform.system()=="Windows": |
489 |
python_lib='python24' |
490 |
else: |
491 |
python_lib='python2.4' |
492 |
|
493 |
# SWIG version |
494 |
|
495 |
if platform.system()=="Windows": |
496 |
env['ENV']['SWIGFEATURES']='-O' |
497 |
else: |
498 |
env['ENV']['SWIGFEATURES']='-O' |
499 |
|
500 |
|
501 |
if not conf.CheckSwigVersion(): |
502 |
without_python_reason = 'SWIG >= 1.3.24 is required' |
503 |
with_python = False |
504 |
|
505 |
# CUnit |
506 |
|
507 |
if with_cunit_tests: |
508 |
if not conf.CheckCUnit(): |
509 |
without_cunit_reason = 'CUnit not found' |
510 |
|
511 |
# BLAS |
512 |
|
513 |
if conf.CheckLib('blas'): |
514 |
print "FOUND BLAS" |
515 |
with_local_blas = False |
516 |
without_local_blas_reason = "Found BLAS installed on system" |
517 |
else: |
518 |
print "DIDN'T FIND BLAS" |
519 |
with_local_blas = True |
520 |
need_fortran = True |
521 |
|
522 |
# FORTRAN |
523 |
|
524 |
if need_fortran: |
525 |
conf.env.Tool('f77') |
526 |
detect_fortran = conf.env.Detect(['g77','f77']) |
527 |
if detect_fortran: |
528 |
# For some reason, g77 doesn't get detected properly on MinGW |
529 |
if not env.has_key('F77'): |
530 |
conf.env.Replace(F77=detect_fortran) |
531 |
conf.env.Replace(F77COM='$F77 $F77FLAGS -c -o $TARGET $SOURCE') |
532 |
conf.env.Replace(F77FLAGS='') |
533 |
#print "F77:",conf.env['F77'] |
534 |
#print "F77COM:",conf.env['F77COM'] |
535 |
#print "F77FLAGS:",conf.env['F77FLAGS'] |
536 |
fortran_builder = Builder( |
537 |
action='$F77COM' |
538 |
, suffix='.o' |
539 |
, src_suffix='.f' |
540 |
) |
541 |
conf.env.Append(BUILDERS={'Fortran':fortran_builder}) |
542 |
else: |
543 |
print "FORTRAN-77 required but not found" |
544 |
Exit(1) |
545 |
else: |
546 |
print "FORTRAN not required" |
547 |
|
548 |
# TODO: -D_HPUX_SOURCE is needed |
549 |
|
550 |
# TODO: check size of void* |
551 |
|
552 |
# TODO: detect if dynamic libraries are possible or not |
553 |
|
554 |
if platform.system()=="Windows" and env.has_key('MSVS'): |
555 |
if not conf.CheckHeader('windows.h') and env['PACKAGE_LINKING']=='DYNAMIC_PACKAGES': |
556 |
print "Reverting to STATIC_PACKAGES since windows.h is not available. Probably you "\ |
557 |
+"need to install the Microsoft Windows Server 2003 Platform SDK, or similar." |
558 |
env['PACKAGE_LINKING']='STATIC_PACKAGES' |
559 |
|
560 |
if with_python and not conf.CheckHeader('basetsd.h'): |
561 |
with_python = 0; |
562 |
without_python_reason = "Header file 'basetsd.h' not found. Install the MS Platform SDK." |
563 |
|
564 |
conf.env.Append(CPPDEFINES=env['PACKAGE_LINKING']) |
565 |
|
566 |
conf.Finish() |
567 |
|
568 |
env.Append(PYTHON_LIBPATH=[distutils.sysconfig.PREFIX+"/libs"]) |
569 |
env.Append(PYTHON_LIB=[python_lib]) |
570 |
env.Append(PYTHON_CPPPATH=[distutils.sysconfig.get_python_inc()]) |
571 |
|
572 |
#------------------------------------------------------ |
573 |
# RECIPE: 'SubstInFile', used in pygtk SConscript |
574 |
|
575 |
import re |
576 |
from SCons.Script import * # the usual scons stuff you get in a SConscript |
577 |
|
578 |
def TOOL_SUBST(env): |
579 |
"""Adds SubstInFile builder, which substitutes the keys->values of SUBST_DICT |
580 |
from the source to the target. |
581 |
The values of SUBST_DICT first have any construction variables expanded |
582 |
(its keys are not expanded). |
583 |
If a value of SUBST_DICT is a python callable function, it is called and |
584 |
the result is expanded as the value. |
585 |
If there's more than one source and more than one target, each target gets |
586 |
substituted from the corresponding source. |
587 |
""" |
588 |
env.Append(TOOLS = 'SUBST') |
589 |
def do_subst_in_file(targetfile, sourcefile, dict): |
590 |
"""Replace all instances of the keys of dict with their values. |
591 |
For example, if dict is {'%VERSION%': '1.2345', '%BASE%': 'MyProg'}, |
592 |
then all instances of %VERSION% in the file will be replaced with 1.2345 etc. |
593 |
""" |
594 |
try: |
595 |
f = open(sourcefile, 'rb') |
596 |
contents = f.read() |
597 |
f.close() |
598 |
except: |
599 |
raise SCons.Errors.UserError, "Can't read source file %s"%sourcefile |
600 |
for (k,v) in dict.items(): |
601 |
contents = re.sub(k, v, contents) |
602 |
try: |
603 |
f = open(targetfile, 'wb') |
604 |
f.write(contents) |
605 |
f.close() |
606 |
except: |
607 |
raise SCons.Errors.UserError, "Can't write target file %s"%targetfile |
608 |
return 0 # success |
609 |
|
610 |
def subst_in_file(target, source, env): |
611 |
if not env.has_key('SUBST_DICT'): |
612 |
raise SCons.Errors.UserError, "SubstInFile requires SUBST_DICT to be set." |
613 |
d = dict(env['SUBST_DICT']) # copy it |
614 |
for (k,v) in d.items(): |
615 |
if callable(v): |
616 |
d[k] = env.subst(v()) |
617 |
elif SCons.Util.is_String(v): |
618 |
d[k]=env.subst(v) |
619 |
else: |
620 |
raise SCons.Errors.UserError, "SubstInFile: key %s: %s must be a string or callable"%(k, repr(v)) |
621 |
for (t,s) in zip(target, source): |
622 |
return do_subst_in_file(str(t), str(s), d) |
623 |
|
624 |
def subst_in_file_string(target, source, env): |
625 |
"""This is what gets printed on the console.""" |
626 |
return '\n'.join(['Substituting vars from %s into %s'%(str(s), str(t)) |
627 |
for (t,s) in zip(target, source)]) |
628 |
|
629 |
def subst_emitter(target, source, env): |
630 |
"""Add dependency from substituted SUBST_DICT to target. |
631 |
Returns original target, source tuple unchanged. |
632 |
""" |
633 |
d = env['SUBST_DICT'].copy() # copy it |
634 |
for (k,v) in d.items(): |
635 |
if callable(v): |
636 |
d[k] = env.subst(v()) |
637 |
elif SCons.Util.is_String(v): |
638 |
d[k]=env.subst(v) |
639 |
Depends(target, SCons.Node.Python.Value(d)) |
640 |
return target, source |
641 |
|
642 |
subst_action=SCons.Action.Action(subst_in_file, subst_in_file_string) |
643 |
env['BUILDERS']['SubstInFile'] = Builder(action=subst_action, emitter=subst_emitter) |
644 |
|
645 |
TOOL_SUBST(env) |
646 |
|
647 |
#------------------------------------------------------ |
648 |
# Recipe for 'CHMOD' ACTION |
649 |
|
650 |
import SCons |
651 |
from SCons.Script.SConscript import SConsEnvironment |
652 |
SConsEnvironment.Chmod = SCons.Action.ActionFactory(os.chmod, |
653 |
lambda dest, mode: 'Chmod("%s", 0%o)' % (dest, mode)) |
654 |
|
655 |
def InstallPerm(env, dest, files, perm): |
656 |
obj = env.Install(dest, files) |
657 |
for i in obj: |
658 |
env.AddPostAction(i, env.Chmod(str(i), perm)) |
659 |
|
660 |
SConsEnvironment.InstallPerm = InstallPerm |
661 |
|
662 |
# define wrappers |
663 |
SConsEnvironment.InstallProgram = lambda env, dest, files: InstallPerm(env, dest, files, 0755) |
664 |
SConsEnvironment.InstallHeader = lambda env, dest, files: InstallPerm(env, dest, files, 0644) |
665 |
|
666 |
#------------------------------------------------------ |
667 |
# SUBDIRECTORIES.... |
668 |
|
669 |
|
670 |
env.Append(CPPPATH=['..']) |
671 |
|
672 |
env.SConscript(['base/generic/general/SConscript'],'env') |
673 |
|
674 |
env.SConscript(['base/generic/utilities/SConscript'],'env') |
675 |
|
676 |
env.SConscript(['base/generic/compiler/SConscript'],'env') |
677 |
|
678 |
env.SConscript(['base/generic/solver/SConscript'],'env') |
679 |
|
680 |
env.SConscript(['base/generic/packages/SConscript'],'env') |
681 |
|
682 |
if with_tcltk_gui: |
683 |
env.SConscript(['tcltk98/generic/interface/SConscript'],'env') |
684 |
else: |
685 |
print "Skipping... Tcl/Tk GUI isn't being built:",without_tcltk_reason |
686 |
|
687 |
if with_python: |
688 |
env.SConscript(['pygtk/interface/SConscript'],'env') |
689 |
else: |
690 |
print "Skipping... Python GUI isn't being built:",without_python_reason |
691 |
|
692 |
if with_cunit_tests: |
693 |
testdirs = ['general','solver','utilities'] |
694 |
for testdir in testdirs: |
695 |
path = 'base/generic/'+testdir+'/test/' |
696 |
env.SConscript([path+'SConscript'],'env') |
697 |
env.SConscript(['test/SConscript'],'env') |
698 |
env.SConscript(['base/generic/test/SConscript'],'env') |
699 |
|
700 |
|
701 |
else: |
702 |
print "Skipping... CUnit tests aren't being built:",without_cunit_reason |
703 |
|
704 |
if with_tcltk_gui: |
705 |
if with_local_blas: |
706 |
env.SConscript(['blas/SConscript'],'env') |
707 |
else: |
708 |
print "Skipping... BLAS won't be build:", without_local_blas_reason |
709 |
|
710 |
env.SConscript(['lsod/SConscript'],'env') |
711 |
|
712 |
env.SConscript(['linpack/SConscript'],'env') |
713 |
|
714 |
# the models directory only needs to be processed for installation |
715 |
env.SConscript(['models/SConscript'],'env') |
716 |
|
717 |
#------------------------------------------------------ |
718 |
# INSTALLATION |
719 |
|
720 |
install_dirs = [env['INSTALL_ROOT']+env['INSTALL_BIN']]+[env['INSTALL_ROOT']+env['INSTALL_DATA']] |
721 |
|
722 |
# TODO: add install options |
723 |
env.Alias('install',install_dirs) |
724 |
|
725 |
#------------------------------------------------------ |
726 |
# CREATE the SPEC file for generation of RPM packages |
727 |
|
728 |
env.SubstInFile('ascend.spec.in') |