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