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

Contents of /branches/prepy3/SConstruct

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3665 - (show annotations)
Tue Nov 15 07:12:49 2011 UTC (7 years, 4 months ago) by jfenwick
File size: 37724 byte(s)
We can now compile using a version of python other than the one
scons is running under

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

  ViewVC Help
Powered by ViewVC 1.1.26