/[escript]/branches/scons_revamp_from_3210/SConstruct
ViewVC logotype

Contents of /branches/scons_revamp_from_3210/SConstruct

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3212 - (show annotations)
Tue Sep 28 01:06:07 2010 UTC (10 years, 6 months ago) by caltinay
File size: 32746 byte(s)
First iteration:
- cleanup of main SConstruct file
- new template options file with commented options
- moved our extensions to the "proper" place according to scons docs
- fixed a regex issue in wrapper script
- this version works on guineapig and shake75

1 ########################################################
2 #
3 # Copyright (c) 2003-2010 by University of Queensland
4 # Earth Systems Science Computational Center (ESSCC)
5 # http://www.uq.edu.au/esscc
6 #
7 # Primary Business: Queensland, Australia
8 # Licensed under the Open Software License version 3.0
9 # http://www.opensource.org/licenses/osl-3.0.php
10 #
11 ########################################################
12
13 EnsureSConsVersion(0,96,91)
14 EnsurePythonVersion(2,5)
15
16 import sys, os, platform, re
17 from distutils import sysconfig
18
19 # Version number to check for in options file. Increment when new features are
20 # added or existing options changed.
21 REQUIRED_OPTS_VERSION=200
22
23 # MS Windows support, many thanks to PH
24 IS_WINDOWS = (os.name == 'nt')
25
26 ########################## Determine options file ############################
27 # 1. command line
28 # 2. scons/<hostname>_options.py
29 # 3. name as part of a cluster
30 options_file=ARGUMENTS.get('options_file', None)
31 if not options_file:
32 ext_dir = os.path.join(os.getcwd(), 'scons')
33 hostname = platform.node().split('.')[0]
34 for name in hostname, effectiveName(hostname):
35 mangledhostname = re.sub('[^0-9a-zA-Z]', '_', hostname)
36 options_file = os.path.join(ext_dir, mangledhostname+'_options.py')
37 if os.path.isfile(options_file): break
38
39 if not os.path.isfile(options_file):
40 print("\nWARNING:\nOptions file %s" % options_file)
41 print("not found! Default options will be used which is most likely suboptimal.")
42 print("It is recommended that you copy one of the TEMPLATE files in the scons/")
43 print("subdirectory and customize it to your needs.\n")
44 options_file = None
45
46 ######################## SCons compatibility stuff ###########################
47
48 # Call additional SConscript
49 # scons < 0.98: build_dir, BuildDir()
50 # scons >= 0.98: variant_dir, VariantDir()
51 import SCons
52 scons_ver=SCons.__version__.split('.')
53 cantusevariantdir=float(scons_ver[0]+'.'+scons_ver[1])<0.98
54
55 def CallSConscript(obj, **kw):
56 if cantusevariantdir:
57 if 'variant_dir' in kw:
58 kw['build_dir']=kw['variant_dir']
59 del kw['variant_dir']
60 obj.SConscript(**kw)
61
62 # Make a copy of an environment
63 # scons <= 0.98: env.Copy()
64 # scons > 0.98: env.Clone()
65 def clone_env(env):
66 if 'Clone' in dir(env):
67 return env.Clone()
68 else:
69 return env.Copy()
70
71 # Prepare user-settable variables
72 # scons <= 0.98.0: Options
73 # scons >= 0.98.1: Variables
74 unknown_vars=None
75 try:
76 vars = Variables(options_file, ARGUMENTS)
77 adder = vars.AddVariables
78 unknown_vars = vars.UnknownVariables
79 except:
80 vars = Options(options_file, ARGUMENTS)
81 adder = vars.AddOptions
82 if 'UnknownOptions' in dir(vars):
83 unknown_vars = vars.UnknownOptions
84 BoolVariable = BoolOption
85 EnumVariable = EnumOption
86 PackageVariable = PackageOption
87 PathVariable = PathOption
88
89 ############################### build options ################################
90
91 default_prefix='/usr'
92 mpi_flavours=('none', 'MPT', 'MPICH', 'MPICH2', 'OPENMPI', 'INTELMPI')
93 lapack_flavours=('none', 'clapack', 'mkl')
94
95 adder(
96 PathVariable('options_file', 'Path to options file', options_file, PathVariable.PathIsFile),
97 PathVariable('prefix', 'Installation prefix', Dir('#.').abspath, PathVariable.PathIsDirCreate),
98 BoolVariable('verbose', 'Output full compile/link lines', False),
99 # Compiler/Linker options
100 ('cc', 'Path to C compiler', 'default'),
101 ('cxx', 'Path to C++ compiler', 'default'),
102 ('cc_flags', 'Base C/C++ compiler flags', 'default'),
103 ('cc_optim', 'Additional C/C++ flags for a non-debug build', 'default'),
104 ('cc_debug', 'Additional C/C++ flags for a debug build', 'default'),
105 ('cc_extra', 'Extra C compiler flags', ''),
106 ('cxx_extra', 'Extra C++ compiler flags', ''),
107 ('ld_extra', 'Extra linker flags', ''),
108 BoolVariable('werror','Treat compiler warnings as errors', True),
109 BoolVariable('debug', 'Compile with debug flags', False),
110 BoolVariable('openmp', 'Compile parallel version using OpenMP', False),
111 ('omp_flags', 'OpenMP compiler flags', 'default'),
112 ('omp_ldflags', 'OpenMP linker flags', 'default'),
113 # Mandatory libraries
114 EnumVariable('mpi', 'Compile parallel version using MPI flavour', 'none', allowed_values=mpi_flavours),
115 ('mpi_prefix', 'Prefix/Paths of MPI installation', default_prefix),
116 ('mpi_libs', 'MPI shared libraries to link with', ['mpi']),
117 ('boost_prefix', 'Prefix/Paths of boost installation', default_prefix),
118 ('boost_libs', 'Boost libraries to link with', ['boost_python']),
119 # Optional libraries
120 BoolVariable('netcdf', 'Enable netCDF file support', True),
121 ('netcdf_prefix', 'Prefix/Paths of netCDF installation', default_prefix),
122 ('netcdf_libs', 'netCDF libraries to link with', ['netcdf_c++', 'netcdf']),
123 BoolVariable('parmetis', 'Enable ParMETIS (requires MPI)', False),
124 ('parmetis_prefix', 'Prefix/Paths of ParMETIS installation', default_prefix),
125 ('parmetis_libs', 'ParMETIS libraries to link with', ['parmetis', 'metis']),
126 BoolVariable('papi', 'Enable PAPI', False),
127 ('papi_prefix', 'Prefix/Paths to PAPI installation', default_prefix),
128 ('papi_libs', 'PAPI libraries to link with', ['papi']),
129 BoolVariable('papi_instrument_solver', 'Use PAPI to instrument each iteration of the solver', False),
130 BoolVariable('mkl', 'Enable the Math Kernel Library', False),
131 ('mkl_prefix', 'Prefix/Paths to MKL installation', default_prefix),
132 ('mkl_libs', 'MKL libraries to link with', ['mkl_solver','mkl_em64t','guide','pthread']),
133 BoolVariable('umfpack', 'Enable UMFPACK', False),
134 ('umfpack_prefix', 'Prefix/Paths to UMFPACK installation', default_prefix),
135 ('umfpack_libs', 'UMFPACK libraries to link with', ['umfpack']),
136 EnumVariable('lapack', 'Set LAPACK flavour', 'none', allowed_values=lapack_flavours),
137 ('lapack_prefix', 'Prefix/Paths to LAPACK installation', default_prefix),
138 ('lapack_libs', 'LAPACK libraries to link with', []),
139 BoolVariable('silo', 'Enable the Silo file format in weipa', False),
140 ('silo_prefix', 'Prefix/Paths to Silo installation', default_prefix),
141 ('silo_libs', 'Silo libraries to link with', ['siloh5', 'hdf5']),
142 BoolVariable('visit', 'Enable the VisIt simulation interface', False),
143 ('visit_prefix', 'Prefix/Paths to VisIt installation', default_prefix),
144 ('visit_libs', 'VisIt libraries to link with', ['simV2']),
145 BoolVariable('pyvisi', 'Enable pyvisi (deprecated, requires VTK module)', False),
146 # Advanced settings
147 # To enable passing function pointers through python
148 BoolVariable('iknowwhatimdoing', 'Allow non-standard C', False),
149 # An option for specifying the compiler tools (see windows branch)
150 ('tools_names', 'Compiler tools to use', ['default']),
151 ('env_export', 'Environment variables to be passed to tools',[]),
152 EnumVariable('forcelazy', 'For testing use only - set the default value for autolazy', 'leave_alone', allowed_values=('leave_alone', 'on', 'off')),
153 EnumVariable('forcecollres', 'For testing use only - set the default value for force resolving collective ops', 'leave_alone', allowed_values=('leave_alone', 'on', 'off')),
154 # finer control over library building, intel aggressive global optimisation
155 # works with dynamic libraries on windows.
156 ('share_esysutils', 'Build a dynamic esysUtils library', False),
157 ('share_paso', 'Build a dynamic paso library', False),
158 ('sys_libs', 'Extra libraries to link with', []),
159 ('escript_opts_version', 'Version of options file (do not specify on command line)'),
160 )
161
162 ##################### Create environment and help text #######################
163
164 # Intel's compiler uses regular expressions improperly and emits a warning
165 # about failing to find the compilers. This warning can be safely ignored.
166
167 if ARGUMENTS.get('tools_names', 'default') == 'default':
168 env = Environment(tools = ['default'], options = vars)
169 else:
170 env = Environment(tools = ['default']+env['tools_names'], options = vars)
171
172 if options_file:
173 opts_valid=False
174 if 'escript_opts_version' in env.Dictionary() and \
175 int(env['escript_opts_version']) >= REQUIRED_OPTS_VERSION:
176 opts_valid=True
177 if opts_valid:
178 print("Using options in %s." % options_file)
179 else:
180 print("\nOptions file %s" % options_file)
181 print("is outdated! Please update the file by examining one of the TEMPLATE")
182 print("files in the scons/ subdirectory and setting escript_opts_version to %d.\n"%REQUIRED_OPTS_VERSION)
183 Exit(1)
184
185 # Generate help text (scons -h)
186 Help(vars.GenerateHelpText(env))
187
188 # Check for superfluous options if scons supports it
189 if unknown_vars:
190 for k in unknown_vars():
191 print("WARNING: Ignoring unknown option '%s'" % k)
192
193 #################### Make sure install directories exist #####################
194
195 prefix=Dir(env['prefix']).abspath
196 env['incinstall'] = os.path.join(prefix, 'include')
197 env['bininstall'] = os.path.join(prefix, 'bin')
198 env['libinstall'] = os.path.join(prefix, 'lib')
199 env['pyinstall'] = os.path.join(prefix, 'esys')
200 if not os.path.isdir(env['bininstall']):
201 os.makedirs(env['bininstall'])
202 if not os.path.isdir(env['libinstall']):
203 os.makedirs(env['libinstall'])
204 if not os.path.isdir(env['pyinstall']):
205 os.makedirs(env['pyinstall'])
206
207 env.Append(CPPPATH = [env['incinstall']])
208 env.Append(LIBPATH = [env['libinstall']])
209
210 ################# Fill in compiler options if not set above ##################
211
212 if env['cc'] != 'default': env['CC']=env['cc']
213 if env['cxx'] != 'default': env['CXX']=env['cxx']
214
215 # version >=9 of intel C++ compiler requires use of icpc to link in C++
216 # runtimes (icc does not)
217 if not IS_WINDOWS and os.uname()[4]=='ia64' and env['CXX']=='icpc':
218 env['LINK'] = env['CXX']
219
220 # default compiler/linker options
221 cc_flags = ''
222 cc_optim = ''
223 cc_debug = ''
224 omp_flags = ''
225 omp_ldflags = ''
226 fatalwarning = '' # switch to turn warnings into errors
227 sysheaderopt = '' # how to indicate that a header is a system header
228
229 # env['CC'] might be a full path
230 cc_name=os.path.basename(env['CC'])
231
232 if cc_name == 'icc':
233 # Intel compiler
234 cc_flags = "-std=c99 -fPIC -wd161 -w1 -vec-report0 -DBLOCKTIMER -DCORE_ID1"
235 cc_optim = "-O3 -ftz -IPF_ftlacc- -IPF_fma -fno-alias -ip"
236 cc_debug = "-g -O0 -DDOASSERT -DDOPROF -DBOUNDS_CHECK"
237 omp_flags = "-openmp -openmp_report0"
238 omp_ldflags = "-openmp -openmp_report0 -lguide -lpthread"
239 elif cc_name[:3] == 'gcc':
240 # GNU C on any system
241 cc_flags = "-pedantic -Wall -fPIC -ffast-math -Wno-unknown-pragmas -DBLOCKTIMER -Wno-sign-compare -Wno-system-headers -Wno-long-long -Wno-strict-aliasing -finline-functions"
242 cc_optim = "-O3"
243 cc_debug = "-g -O0 -DDOASSERT -DDOPROF -DBOUNDS_CHECK"
244 omp_flags = "-fopenmp"
245 omp_ldflags = "-fopenmp"
246 fatalwarning = "-Werror"
247 sysheaderopt = "-isystem"
248 elif cc_name == 'cl':
249 # Microsoft Visual C on Windows
250 cc_flags = "/EHsc /GR /MD /wd4068 -D_USE_MATH_DEFINES -DDLL_NETCDF"
251 cc_optim = "/O2 /Op /MT /W3"
252 cc_debug = "/Od /RTCcsu /MTd /ZI -DBOUNDS_CHECK"
253 fatalwarning = "/WX"
254 elif cc_name == 'icl':
255 # Intel C on Windows
256 cc_flags = '/EHsc /GR /MD'
257 cc_optim = '/fast /Oi /W3 /Qssp /Qinline-factor- /Qinline-min-size=0 /Qunroll'
258 cc_debug = '/Od /RTCcsu /Zi /Y- /debug:all /Qtrapuv'
259 omp_flags = '/Qvec-report0 /Qopenmp /Qopenmp-report0 /Qparallel'
260 omp_ldflags = '/Qvec-report0 /Qopenmp /Qopenmp-report0 /Qparallel'
261
262 # set defaults if not otherwise specified
263 if env['cc_flags'] == 'default': env['cc_flags'] = cc_flags
264 if env['cc_optim'] == 'default': env['cc_optim'] = cc_optim
265 if env['cc_debug'] == 'default': env['cc_debug'] = cc_debug
266 if env['omp_flags'] == 'default': env['omp_flags'] = omp_flags
267 if env['omp_ldflags'] == 'default': env['omp_ldflags'] = omp_ldflags
268 if env['cc_extra'] != '': env.Append(CFLAGS = env['cc_extra'])
269 if env['cxx_extra'] != '': env.Append(CXXFLAGS = env['cxx_extra'])
270 if env['ld_extra'] != '': env.Append(LINKFLAGS = env['ld_extra'])
271
272 # set up the autolazy values
273 if env['forcelazy'] == 'on':
274 env.Append(CPPDEFINES=['FAUTOLAZYON'])
275 elif env['forcelazy'] == 'off':
276 env.Append(CPPDEFINES=['FAUTOLAZYOFF'])
277
278 # set up the collective resolve values
279 if env['forcecollres'] == 'on':
280 env.Append(CPPDEFINES=['FRESCOLLECTON'])
281 elif env['forcecollres'] == 'off':
282 env.Append(CPPDEFINES=['FRESCOLLECTOFF'])
283
284 # allow non-standard C if requested
285 if env['iknowwhatimdoing']:
286 env.Append(CPPDEFINES=['IKNOWWHATIMDOING'])
287
288 # Disable OpenMP if no flags provided
289 if env['openmp'] and env['omp_flags'] == '':
290 print("OpenMP requested but no flags provided - disabling OpenMP!")
291 env['openmp'] = False
292
293 if env['openmp']:
294 env.Append(CCFLAGS = env['omp_flags'])
295 if env['omp_ldflags'] != '': env.Append(LINKFLAGS = env['omp_ldflags'])
296 else:
297 env['omp_flags']=''
298 env['omp_ldflags']=''
299
300 # add debug/non-debug compiler flags
301 if env['debug']:
302 env.Append(CCFLAGS = env['cc_debug'])
303 else:
304 env.Append(CCFLAGS = env['cc_optim'])
305
306 # always add cc_flags
307 env.Append(CCFLAGS = env['cc_flags'])
308
309 # Get the global Subversion revision number for the getVersion() method
310 try:
311 global_revision = os.popen('svnversion -n .').read()
312 global_revision = re.sub(':.*', '', global_revision)
313 global_revision = re.sub('[^0-9]', '', global_revision)
314 if global_revision == '': global_revision='-2'
315 except:
316 global_revision = '-1'
317 env.Append(CPPDEFINES=['SVN_VERSION='+global_revision])
318
319 if IS_WINDOWS:
320 if not env['share_esysutils']:
321 env.Append(CPPDEFINES = ['ESYSUTILS_STATIC_LIB'])
322 if not env['share_paso']:
323 env.Append(CPPDEFINES = ['PASO_STATIC_LIB'])
324
325 ###################### Copy required environment vars ########################
326
327 # Windows doesn't use LD_LIBRARY_PATH but PATH instead
328 if IS_WINDOWS:
329 LD_LIBRARY_PATH_KEY='PATH'
330 env['ENV']['LD_LIBRARY_PATH']=''
331 else:
332 LD_LIBRARY_PATH_KEY='LD_LIBRARY_PATH'
333
334 # the following env variables are exported for the unit tests
335
336 for key in 'OMP_NUM_THREADS', 'ESCRIPT_NUM_PROCS', 'ESCRIPT_NUM_NODES':
337 try:
338 env['ENV'][key] = os.environ[key]
339 except KeyError:
340 env['ENV'][key] = 1
341
342 env_export=env['env_export']
343 env_export.extend(['ESCRIPT_NUM_THREADS','ESCRIPT_HOSTFILE','DISPLAY','XAUTHORITY'])
344
345 for key in set(env_export):
346 try:
347 env['ENV'][key] = os.environ[key]
348 except KeyError:
349 pass
350
351 try:
352 env.PrependENVPath(LD_LIBRARY_PATH_KEY, os.environ[LD_LIBRARY_PATH_KEY])
353 except KeyError:
354 pass
355
356 #for key in 'PATH','C_INCLUDE_PATH','CPLUS_INCLUDE_PATH','LIBRARY_PATH':
357 # try:
358 # env['ENV'][key] = os.environ[key]
359 # except KeyError:
360 # pass
361 #
362 try:
363 env['ENV']['PYTHONPATH'] = os.environ['PYTHONPATH']
364 except KeyError:
365 pass
366
367 ######################## Add some custom builders ############################
368
369 py_builder = Builder(action = build_py, suffix = '.pyc', src_suffix = '.py', single_source=True)
370 env.Append(BUILDERS = {'PyCompile' : py_builder});
371
372 runUnitTest_builder = Builder(action = runUnitTest, suffix = '.passed', src_suffix=env['PROGSUFFIX'], single_source=True)
373 env.Append(BUILDERS = {'RunUnitTest' : runUnitTest_builder});
374
375 runPyUnitTest_builder = Builder(action = runPyUnitTest, suffix = '.passed', src_suffic='.py', single_source=True)
376 env.Append(BUILDERS = {'RunPyUnitTest' : runPyUnitTest_builder});
377
378 epstopdfbuilder = Builder(action = eps2pdf, suffix='.pdf', src_suffix='.eps', single_source=True)
379 env.Append(BUILDERS = {'EpsToPDF' : epstopdfbuilder});
380
381 ############################ Dependency checks ###############################
382
383 # Create a Configure() environment to check for compilers and python
384 conf = Configure(env)
385
386 ######## Test that the compilers work
387
388 if 'CheckCC' in dir(conf): # exists since scons 1.1.0
389 if not conf.CheckCC():
390 print("Cannot run C compiler '%s' (check config.log)" % (env['CC']))
391 Exit(1)
392 if not conf.CheckCXX():
393 print("Cannot run C++ compiler '%s' (check config.log)" % (env['CXX']))
394 Exit(1)
395 else:
396 if not conf.CheckFunc('printf', language='c'):
397 print("Cannot run C compiler '%s' (check config.log)" % (env['CC']))
398 Exit(1)
399 if not conf.CheckFunc('printf', language='c++'):
400 print("Cannot run C++ compiler '%s' (check config.log)" % (env['CXX']))
401 Exit(1)
402
403 if conf.CheckFunc('gethostname'):
404 conf.env.Append(CPPDEFINES = ['HAVE_GETHOSTNAME'])
405
406 ######## Python headers & library (required)
407
408 python_inc_path=sysconfig.get_python_inc()
409 python_lib_path=sysconfig.get_config_var('LIBDIR')
410 python_libs=[sysconfig.get_config_var('LDLIBRARY')]
411
412 if sysheaderopt == '':
413 conf.env.AppendUnique(CPPPATH = [python_inc_path])
414 else:
415 conf.env.Append(CCFLAGS = [sysheaderopt, python_inc_path])
416
417 conf.env.AppendUnique(LIBPATH = [python_lib_path])
418 conf.env.AppendUnique(LIBS = python_libs)
419 # The wrapper script needs to find the libs
420 conf.env.PrependENVPath(LD_LIBRARY_PATH_KEY, python_lib_path)
421
422 if not conf.CheckCHeader('Python.h'):
423 print("Cannot find python include files (tried 'Python.h' in directory %s)" % (python_inc_path))
424 Exit(1)
425 if not conf.CheckFunc('Py_Exit'):
426 print("Cannot find python library method Py_Main (tried %s in directory %s)" % (python_libs, python_lib_path))
427 Exit(1)
428
429 # Commit changes to environment
430 env = conf.Finish()
431
432 ######## boost (required)
433
434 boost_inc_path,boost_lib_path=findLibWithHeader(env, env['boost_libs'], 'boost/python.hpp', env['boost_prefix'], lang='c++')
435 if sysheaderopt == '':
436 env.AppendUnique(CPPPATH = [boost_inc_path])
437 else:
438 # This is required because we can't -isystem /usr/include since it breaks
439 # std includes
440 if os.path.normpath(boost_inc_path) == '/usr/include':
441 conf.env.Append(CCFLAGS=[sysheaderopt, os.path.join(boost_inc_path,'boost')])
442 else:
443 env.Append(CCFLAGS=[sysheaderopt, boost_inc_path])
444
445 env.AppendUnique(LIBPATH = [boost_lib_path])
446 env.AppendUnique(LIBS = env['boost_libs'])
447 env.PrependENVPath(LD_LIBRARY_PATH_KEY, boost_lib_path)
448
449 ######## numpy (required)
450
451 try:
452 from numpy import identity
453 except ImportError:
454 print("Cannot import numpy, you need to set your PYTHONPATH and probably %s"%LD_LIBRARY_PATH_KEY)
455 Exit(1)
456
457 ######## VTK (optional)
458
459 if env['pyvisi']:
460 try:
461 import vtk
462 env['pyvisi'] = True
463 except ImportError:
464 env['pyvisi'] = False
465
466 ######## netCDF (optional)
467
468 netcdf_inc_path=''
469 netcdf_lib_path=''
470 if env['netcdf']:
471 netcdf_inc_path,netcdf_lib_path=findLibWithHeader(env, env['netcdf_libs'], 'netcdf.h', env['netcdf_prefix'], lang='c++')
472 env.AppendUnique(CPPPATH = [netcdf_inc_path])
473 env.AppendUnique(LIBPATH = [netcdf_lib_path])
474 env.AppendUnique(LIBS = env['netcdf_libs'])
475 env.PrependENVPath(LD_LIBRARY_PATH_KEY, netcdf_lib_path)
476 env.Append(CPPDEFINES = ['USE_NETCDF'])
477
478 ######## PAPI (optional)
479
480 papi_inc_path=''
481 papi_lib_path=''
482 if env['papi']:
483 papi_inc_path,papi_lib_path=findLibWithHeader(env, env['papi_libs'], 'papi.h', env['papi_prefix'], lang='c')
484 env.AppendUnique(CPPPATH = [papi_inc_path])
485 env.AppendUnique(LIBPATH = [papi_lib_path])
486 env.AppendUnique(LIBS = env['papi_libs'])
487 env.PrependENVPath(LD_LIBRARY_PATH_KEY, papi_lib_path)
488 env.Append(CPPDEFINES = ['BLOCKPAPI'])
489
490 ######## MKL (optional)
491
492 mkl_inc_path=''
493 mkl_lib_path=''
494 if env['mkl']:
495 mkl_inc_path,mkl_lib_path=findLibWithHeader(env, env['mkl_libs'], 'mkl_solver.h', env['mkl_prefix'], lang='c')
496 env.AppendUnique(CPPPATH = [mkl_inc_path])
497 env.AppendUnique(LIBPATH = [mkl_lib_path])
498 env.AppendUnique(LIBS = env['mkl_libs'])
499 env.PrependENVPath(LD_LIBRARY_PATH_KEY, mkl_lib_path)
500 env.Append(CPPDEFINES = ['MKL'])
501
502 ######## UMFPACK (optional)
503
504 umfpack_inc_path=''
505 umfpack_lib_path=''
506 if env['umfpack']:
507 umfpack_inc_path,umfpack_lib_path=findLibWithHeader(env, env['umfpack_libs'], 'umfpack.h', env['umfpack_prefix'], lang='c')
508 env.AppendUnique(CPPPATH = [umfpack_inc_path])
509 env.AppendUnique(LIBPATH = [umfpack_lib_path])
510 env.AppendUnique(LIBS = env['umfpack_libs'])
511 env.PrependENVPath(LD_LIBRARY_PATH_KEY, umfpack_lib_path)
512 env.Append(CPPDEFINES = ['UMFPACK'])
513
514 ######## LAPACK (optional)
515
516 if env['lapack']=='mkl' and not env['mkl']:
517 print("mkl_lapack requires MKL!")
518 Exit(1)
519
520 env['uselapack'] = env['lapack']!='none'
521 lapack_inc_path=''
522 lapack_lib_path=''
523 if env['uselapack']:
524 header='clapack.h'
525 if env['lapack']=='mkl':
526 env.AppendUnique(CPPDEFINES = ['MKL_LAPACK'])
527 header='mkl_lapack.h'
528 lapack_inc_path,lapack_lib_path=findLibWithHeader(env, env['lapack_libs'], header, env['lapack_prefix'], lang='c')
529 env.AppendUnique(CPPPATH = [lapack_inc_path])
530 env.AppendUnique(LIBPATH = [lapack_lib_path])
531 env.AppendUnique(LIBS = env['lapack_libs'])
532 env.Append(CPPDEFINES = ['USE_LAPACK'])
533
534 ######## Silo (optional)
535
536 silo_inc_path=''
537 silo_lib_path=''
538 if env['silo']:
539 silo_inc_path,silo_lib_path=findLibWithHeader(env, env['silo_libs'], 'silo.h', env['silo_prefix'], lang='c')
540 env.AppendUnique(CPPPATH = [silo_inc_path])
541 env.AppendUnique(LIBPATH = [silo_lib_path])
542 # Note that we do not add the libs since they are only needed for the
543 # weipa library and tools.
544 #env.AppendUnique(LIBS = [env['silo_libs']])
545
546 ######## VisIt (optional)
547
548 visit_inc_path=''
549 visit_lib_path=''
550 if env['visit']:
551 visit_inc_path,visit_lib_path=findLibWithHeader(env, env['visit_libs'], 'VisItControlInterface_V2.h', env['visit_prefix'], lang='c')
552 env.AppendUnique(CPPPATH = [visit_inc_path])
553 env.AppendUnique(LIBPATH = [visit_lib_path])
554
555 ######## MPI (optional)
556
557 env['usempi'] = env['mpi']!='none'
558
559 # Create a modified environment for MPI programs (identical to env if mpi=none)
560 env_mpi = clone_env(env)
561
562 mpi_inc_path=''
563 mpi_lib_path=''
564 if env_mpi['usempi']:
565 mpi_inc_path,mpi_lib_path=findLibWithHeader(env_mpi, env['mpi_libs'], 'mpi.h', env['mpi_prefix'], lang='c')
566 env_mpi.AppendUnique(CPPPATH = [mpi_inc_path])
567 env_mpi.AppendUnique(LIBPATH = [mpi_lib_path])
568 env_mpi.AppendUnique(LIBS = env['mpi_libs'])
569 env_mpi.PrependENVPath(LD_LIBRARY_PATH_KEY, mpi_lib_path)
570 env_mpi.Append(CPPDEFINES = ['PASO_MPI', 'MPI_NO_CPPBIND', 'MPICH_IGNORE_CXX_SEEK'])
571 # NetCDF 4.1 defines MPI_Comm et al. if MPI_INCLUDED is not defined!
572 # On the other hand MPT and OpenMPI don't define the latter so we have to
573 # do that here
574 if env['netcdf'] and env_mpi['mpi'] in ['MPT','OPENMPI']:
575 env_mpi.Append(CPPDEFINES = ['MPI_INCLUDED'])
576
577
578 ######## ParMETIS (optional)
579
580 if not env_mpi['usempi']: env_mpi['parmetis'] = False
581
582 parmetis_inc_path=''
583 parmetis_lib_path=''
584 if env_mpi['parmetis']:
585 parmetis_inc_path,parmetis_lib_path=findLibWithHeader(env_mpi, env['parmetis_libs'], 'parmetis.h', env['parmetis_prefix'], lang='c')
586 env_mpi.AppendUnique(CPPPATH = [parmetis_inc_path])
587 env_mpi.AppendUnique(LIBPATH = [parmetis_lib_path])
588 env_mpi.AppendUnique(LIBS = env_mpi['parmetis_libs'])
589 env_mpi.PrependENVPath(LD_LIBRARY_PATH_KEY, parmetis_lib_path)
590 env_mpi.Append(CPPDEFINES = ['USE_PARMETIS'])
591
592 env['parmetis'] = env_mpi['parmetis']
593
594 ######################## Summarize our environment ###########################
595
596 # keep some of our install paths first in the list for the unit tests
597 env.PrependENVPath(LD_LIBRARY_PATH_KEY, env['libinstall'])
598 env.PrependENVPath('PYTHONPATH', prefix)
599 env['ENV']['ESCRIPT_ROOT'] = prefix
600
601 if not env['verbose']:
602 for e in env, env_mpi:
603 e['CCCOMSTR'] = "Compiling $TARGET"
604 e['CXXCOMSTR'] = "Compiling $TARGET"
605 e['SHCCCOMSTR'] = "Compiling $TARGET"
606 e['SHCXXCOMSTR'] = "Compiling $TARGET"
607 e['ARCOMSTR'] = "Linking $TARGET"
608 e['LINKCOMSTR'] = "Linking $TARGET"
609 e['SHLINKCOMSTR'] = "Linking $TARGET"
610 #Progress(['Checking -\r', 'Checking \\\r', 'Checking |\r', 'Checking /\r'], interval=17)
611
612 print("")
613 print("*** Config Summary (see config.log and lib/buildvars for details) ***")
614 print("Escript/Finley revision %s"%global_revision)
615 print(" Install prefix: %s"%env['prefix'])
616 print(" Python: %s"%sysconfig.PREFIX)
617 print(" boost: %s"%env['boost_prefix'])
618 print(" numpy: YES")
619 if env['usempi']:
620 print(" MPI: YES (flavour: %s)"%env['mpi'])
621 else:
622 print(" MPI: DISABLED")
623 if env['uselapack']:
624 print(" LAPACK: YES (flavour: %s)"%env['lapack'])
625 else:
626 print(" LAPACK: DISABLED")
627 d_list=[]
628 e_list=[]
629 for i in 'debug','openmp','netcdf','parmetis','papi','mkl','umfpack','silo','visit','pyvisi':
630 if env[i]: e_list.append(i)
631 else: d_list.append(i)
632 for i in e_list:
633 print("%16s: YES"%i)
634 for i in d_list:
635 print("%16s: DISABLED"%i)
636 if ((fatalwarning != '') and (env['werror'])):
637 print(" Treating warnings as errors")
638 else:
639 print(" NOT treating warnings as errors")
640 print("")
641
642 ####################### Configure the subdirectories #########################
643
644 from grouptest import *
645
646 TestGroups=[]
647
648 # keep an environment without warnings-as-errors
649 dodgy_env=clone_env(env_mpi)
650
651 # now add warnings-as-errors flags. This needs to be done after configuration
652 # because the scons test files have warnings in them
653 if ((fatalwarning != '') and (env['werror'])):
654 env.Append(CCFLAGS = fatalwarning)
655 env_mpi.Append(CCFLAGS = fatalwarning)
656
657 Export(
658 ['env',
659 'env_mpi',
660 'clone_env',
661 'dodgy_env',
662 'IS_WINDOWS',
663 'TestGroups',
664 'CallSConscript',
665 'cantusevariantdir'
666 ]
667 )
668
669 CallSConscript(env, dirs = ['tools/CppUnitTest/src'], variant_dir='build/$PLATFORM/tools/CppUnitTest', duplicate=0)
670 CallSConscript(env, dirs = ['tools/escriptconvert'], variant_dir='build/$PLATFORM/tools/escriptconvert', duplicate=0)
671 CallSConscript(env, dirs = ['paso/src'], variant_dir='build/$PLATFORM/paso', duplicate=0)
672 CallSConscript(env, dirs = ['weipa/src'], variant_dir='build/$PLATFORM/weipa', duplicate=0)
673 CallSConscript(env, dirs = ['escript/src'], variant_dir='build/$PLATFORM/escript', duplicate=0)
674 CallSConscript(env, dirs = ['esysUtils/src'], variant_dir='build/$PLATFORM/esysUtils', duplicate=0)
675 CallSConscript(env, dirs = ['finley/src'], variant_dir='build/$PLATFORM/finley', duplicate=0)
676 CallSConscript(env, dirs = ['modellib/py_src'], variant_dir='build/$PLATFORM/modellib', duplicate=0)
677 CallSConscript(env, dirs = ['doc'], variant_dir='build/$PLATFORM/doc', duplicate=0)
678 CallSConscript(env, dirs = ['pyvisi/py_src'], variant_dir='build/$PLATFORM/pyvisi', duplicate=0)
679 CallSConscript(env, dirs = ['pycad/py_src'], variant_dir='build/$PLATFORM/pycad', duplicate=0)
680 CallSConscript(env, dirs = ['pythonMPI/src'], variant_dir='build/$PLATFORM/pythonMPI', duplicate=0)
681 CallSConscript(env, dirs = ['scripts'], variant_dir='build/$PLATFORM/scripts', duplicate=0)
682 CallSConscript(env, dirs = ['paso/profiling'], variant_dir='build/$PLATFORM/paso/profiling', duplicate=0)
683
684 ######################## Populate the buildvars file #########################
685
686 # remove obsolete file
687 if not env['usempi']:
688 Execute(Delete(os.path.join(env['libinstall'], 'pythonMPI')))
689 Execute(Delete(os.path.join(env['libinstall'], 'pythonMPIredirect')))
690
691 # Try to extract the boost version from version.hpp
692 boosthpp=open(os.path.join(boost_inc_path, 'boost', 'version.hpp'))
693 boostversion='unknown'
694 try:
695 for line in boosthpp:
696 ver=re.match(r'#define BOOST_VERSION (\d+)',line)
697 if ver:
698 boostversion=ver.group(1)
699 except StopIteration:
700 pass
701 boosthpp.close()
702
703 buildvars=open(os.path.join(env['libinstall'], 'buildvars'), 'w')
704 buildvars.write("svn_revision="+str(global_revision)+"\n")
705 buildvars.write("prefix="+prefix+"\n")
706 buildvars.write("cc="+env['CC']+"\n")
707 buildvars.write("cxx="+env['CXX']+"\n")
708 buildvars.write("python="+sys.executable+"\n")
709 buildvars.write("python_version="+str(sys.version_info[0])+"."+str(sys.version_info[1])+"."+str(sys.version_info[2])+"\n")
710 buildvars.write("boost_inc_path="+boost_inc_path+"\n")
711 buildvars.write("boost_lib_path="+boost_lib_path+"\n")
712 buildvars.write("boost_version="+boostversion+"\n")
713 buildvars.write("debug=%d\n"%int(env['debug']))
714 buildvars.write("openmp=%d\n"%int(env['openmp']))
715 buildvars.write("mpi=%s\n"%env['mpi'])
716 buildvars.write("mpi_inc_path=%s\n"%mpi_inc_path)
717 buildvars.write("mpi_lib_path=%s\n"%mpi_lib_path)
718 buildvars.write("lapack=%s\n"%env['lapack'])
719 buildvars.write("pyvisi=%d\n"%env['pyvisi'])
720 for i in 'netcdf','parmetis','papi','mkl','umfpack','silo','visit':
721 buildvars.write("%s=%d\n"%(i, int(env[i])))
722 if env[i]:
723 buildvars.write("%s_inc_path=%s\n"%(i, eval(i+'_inc_path')))
724 buildvars.write("%s_lib_path=%s\n"%(i, eval(i+'_lib_path')))
725 buildvars.close()
726
727 ################### Targets to build and install libraries ###################
728
729 target_init = env.Command(env['pyinstall']+'/__init__.py', None, Touch('$TARGET'))
730 env.Alias('target_init', [target_init])
731
732 # The headers have to be installed prior to build in order to satisfy
733 # #include <paso/Common.h>
734 env.Alias('build_esysUtils', ['target_install_esysUtils_headers', 'target_esysUtils_a'])
735 env.Alias('install_esysUtils', ['build_esysUtils', 'target_install_esysUtils_a'])
736
737 env.Alias('build_paso', ['target_install_paso_headers', 'target_paso_a'])
738 env.Alias('install_paso', ['build_paso', 'target_install_paso_a'])
739
740 env.Alias('build_escript', ['target_install_escript_headers', 'target_escript_so', 'target_escriptcpp_so'])
741 env.Alias('install_escript', ['build_escript', 'target_install_escript_so', 'target_install_escriptcpp_so', 'target_install_escript_py'])
742
743 env.Alias('build_finley', ['target_install_finley_headers', 'target_finley_so', 'target_finleycpp_so'])
744 env.Alias('install_finley', ['build_finley', 'target_install_finley_so', 'target_install_finleycpp_so', 'target_install_finley_py'])
745
746 env.Alias('build_weipa', ['target_install_weipa_headers', 'target_weipa_so', 'target_weipacpp_so'])
747 env.Alias('install_weipa', ['build_weipa', 'target_install_weipa_so', 'target_install_weipacpp_so', 'target_install_weipa_py'])
748
749 env.Alias('build_escriptreader', ['target_install_weipa_headers', 'target_escriptreader_a'])
750 env.Alias('install_escriptreader', ['build_escriptreader', 'target_install_escriptreader_a'])
751
752 # Now gather all the above into some easy targets: build_all and install_all
753 build_all_list = []
754 build_all_list += ['build_esysUtils']
755 build_all_list += ['build_paso']
756 build_all_list += ['build_escript']
757 build_all_list += ['build_finley']
758 build_all_list += ['build_weipa']
759 build_all_list += ['build_escriptreader']
760 if env['usempi']: build_all_list += ['target_pythonMPI_exe']
761 build_all_list += ['target_escriptconvert']
762 env.Alias('build_all', build_all_list)
763
764 install_all_list = []
765 install_all_list += ['target_init']
766 install_all_list += ['install_esysUtils']
767 install_all_list += ['install_paso']
768 install_all_list += ['install_escript']
769 install_all_list += ['install_finley']
770 install_all_list += ['install_weipa']
771 install_all_list += ['install_escriptreader']
772 install_all_list += ['target_install_pyvisi_py']
773 install_all_list += ['target_install_modellib_py']
774 install_all_list += ['target_install_pycad_py']
775 if env['usempi']: install_all_list += ['target_install_pythonMPI_exe']
776 install_all_list += ['target_install_escriptconvert']
777 env.Alias('install_all', install_all_list)
778
779 # Default target is install
780 env.Default('install_all')
781
782 ################## Targets to build and run the test suite ###################
783
784 env.Alias('build_cppunittest', ['target_install_cppunittest_headers', 'target_cppunittest_a'])
785 env.Alias('install_cppunittest', ['build_cppunittest', 'target_install_cppunittest_a'])
786 env.Alias('run_tests', ['install_all', 'target_install_cppunittest_a'])
787 env.Alias('all_tests', ['install_all', 'target_install_cppunittest_a', 'run_tests', 'py_tests'])
788 env.Alias('build_full',['install_all','build_tests','build_py_tests'])
789 env.Alias('build_PasoTests','build/$PLATFORM/paso/profiling/PasoTests')
790
791 ##################### Targets to build the documentation #####################
792
793 env.Alias('api_epydoc','install_all')
794 env.Alias('docs', ['examples_tarfile', 'examples_zipfile', 'api_epydoc', 'api_doxygen', 'guide_pdf', 'guide_html','install_pdf', 'cookbook_pdf'])
795 env.Alias('release_prep', ['docs', 'install_all'])
796
797 if not IS_WINDOWS:
798 try:
799 utest=open('utest.sh','w')
800 utest.write(GroupTest.makeHeader(env['PLATFORM']))
801 for tests in TestGroups:
802 utest.write(tests.makeString())
803 utest.close()
804 Chmod('utest.sh', 0755)
805 print("Generated utest.sh.")
806 except IOError:
807 print("Error attempting to write unittests file.")
808 Exit(1)
809
810 # Make sure that the escript wrapper is in place
811 if not os.path.isfile(os.path.join(env['bininstall'], 'escript')):
812 print("Copying escript wrapper.")
813 Execute(Copy(os.path.join(env['bininstall'],'escript'), 'bin/escript'))
814

  ViewVC Help
Powered by ViewVC 1.1.26