/[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 3241 - (show annotations)
Tue Oct 5 05:59:37 2010 UTC (9 years, 3 months ago) by caltinay
File size: 31656 byte(s)
escriptreader is not available for Windoze.

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

  ViewVC Help
Powered by ViewVC 1.1.26