forked from GrossfieldLab/loos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SConstruct
319 lines (241 loc) · 10 KB
/
SConstruct
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
#!/usr/bin/env python3
# This file is part of LOOS.
#
# LOOS (Lightweight Object-Oriented Structure library)
# Copyright (c) 2008-2009, Tod D. Romo
# Department of Biochemistry and Biophysics
# School of Medicine & Dentistry, University of Rochester
#
# This package (LOOS) is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation under version 3 of the License.
#
# This package is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import sys
import os
import os.path
import glob
import platform
import re
import subprocess
from time import strftime
import shutil
import distutils.sysconfig
import distutils.spawn
from distutils.version import LooseVersion
from string import Template
import SCons
import loos_build_config
import scons_support
import platform
EnsureSConsVersion(2, 0)
# ----------------------------------------------------------------------------------------------
# Principal options...
opts = Variables('custom.py')
opts.Add('debug', 'Set to 1 to add -DDEBUG to build', 0)
opts.Add('profile', 'Set to 1 to build the code for profiling', 0)
opts.Add('release', 'Set to 1 to configure for release.', 1)
opts.Add('reparse', 'Set to 1 to regenerate parser-related files.', 0)
opts.Add('pyloos', 'Set to 0 to disable building PyLOOS.', 1)
opts.Add('threads', 'Set to 0 to disable using multithreaded libraries and code', 1)
#opts.Add('docs', 'Set to 0 to disable auto-generation of doxygen documentation', 1)
opts.Add(PathVariable('PREFIX', 'Where to install LOOS', '/opt/LOOS', PathVariable.PathAccept))
opts.Add('BOOST', 'Path to BOOST', '')
opts.Add('BOOST_INCLUDE', 'Path to BOOST Includes', '')
opts.Add('BOOST_LIBPATH', 'Path to BOOST Libraries', '')
opts.Add('BOOST_LIBS', 'Boost libraries to link with', '')
opts.Add('ATLAS_LIBPATH', 'Path to ATLAS Libraries', '')
opts.Add('ATLAS_LIBS', 'Atlas libraries to link with', '')
opts.Add('EIGEN', 'Path to eigen3', '')
opts.Add('NETCDF', 'Path to NetCDF', '')
opts.Add('NETCDF_INCLUDE', 'Path to NetCDF include files', '')
opts.Add('NETCDF_LIBPATH', 'Path to NetCDF libraries', '')
opts.Add('NETCDF_LIBS', 'NetCDF Libraries to link with', '')
opts.Add('PYTHON_PATH', 'Path to Python Modules', '')
opts.Add('PYTHON_INC', 'Include path for Python needed by PyLOOS (if not set, uses the same python as scons)', '')
opts.Add('INCLUDE_PATH', 'Add to include paths before any auto-config', '')
opts.Add('LIBRARY_PATH', 'Add to library paths before any auto-config', '')
scons_support.addDeprecatedOptions(opts)
# If we're using conda, we want to pull in the environment.
# Otherwise, we want the environment mostly cleaned out
if "CONDA_PREFIX" in os.environ:
env = Environment(ENV=os.environ,
options=opts,
toolpath='.',
SWIGFLAGS=['-c++', '-python', '-Wall', '-py3'],
SHLIBPREFIX=""
)
env["CONDA_PREFIX"]=os.environ["CONDA_PREFIX"]
env.USING_CONDA = True
else:
env = Environment(ENV={'PATH': os.environ['PATH']},
options=opts,
toolpath='.',
SWIGFLAGS=['-c++', '-python', '-Wall', '-py3'],
SHLIBPREFIX=""
)
env.USING_CONDA = False
Help(opts.GenerateHelpText(env))
scons_support.checkForDeprecatedOptions(env)
env.Decider('MD5-timestamp')
# Setup script-builder
script_builder = Builder(action=scons_support.script_builder_python)
env.Append(BUILDERS={'Scripts': script_builder})
# Get more info from environment
PREFIX = env['PREFIX']
# Inject paths (if present)
if 'INCLUDE_PATH' in env:
env.Append(CPPPATH=env['INCLUDE_PATH'].split(':'))
if 'LIBRARY_PATH' in env:
env.Append(LIBPATH=env['LIBRARY_PATH'].split(':'))
# ----------------------------------------------------------------------------------------------
cleaning = env.GetOption('clean')
# Autoconf
if env.USING_CONDA and platform.system() == "Darwin":
flag = "-rpath " + env["CONDA_PREFIX"] + "/lib"
env.Append(LINKFLAGS=flag)
scons_support.AutoConfiguration(env)
pyloos = int(env['pyloos'])
if not pyloos:
print('***Warning***')
print('PyLOOS will not be built. The OMG will not be installed.')
# Compile-flags
debug_opts = '-g -Wall -Wextra -fno-inline'
release_opts = '-O3 -DNDEBUG -Wall -Wno-deprecated'
profile_opts = '-O3 -DNDEBUG -Wall -g'
# Setup the general environment...
env.Prepend(CPPPATH=['#', '#src'])
env.Prepend(LIBPATH=['#', '#src'])
env.Append(LEXFLAGS=['-s'])
env.Append(CPPFLAGS=['-pthread'])
env.Append(LIBS=['pthread'])
# Platform specific build options...
if loos_build_config.host_type == 'Darwin':
release = platform.release().split('.')
if int(release[0]) >= 13: # MacOS 10.9 requires this flag for native compiler
# Hack to get swig to work with latest 10.9
env.Append(SWIGFLAGS='-DSWIG_NO_EXPORT_ITERATOR_METHODS')
env.Append(LINKFLAGS=' -llapack')
if not cleaning:
# Older version of BOOST will require this definition
# Note: the version of BOOST requiring this flag is just a guess...
if LooseVersion(loos_build_config.versions['boost']) < LooseVersion('1_58'):
env.Append(CCFLAGS='-DBOOST_SPIRIT_USE_PHOENIX_V3=1')
# This is for BOOST 1.44 and boost 1.45..force using Boost Filesystem v3
if LooseVersion(loos_build_config.versions['boost']) < LooseVersion('1_46') and LooseVersion(loos_build_config.versions['boost']) >= LooseVersion('1_44'):
env.Append(CCFLAGS='-DBOOST_FILESYSTEM_VERSION=3')
# Determine what kind of build...
release = int(env['release'])
debug = int(env['debug'])
profile = int(env['profile'])
#docsflag = int(env['docs'])
# If debug is requested, make sure there is no optimization...
if (debug > 0):
release=0
if int(release):
env.Append(CCFLAGS=release_opts)
else:
env.Append(CCFLAGS=debug_opts)
if (debug > 0):
env.Append(CCFLAGS=(" -DDEBUG=%d" % (debug)))
# Profiling is independent of release/debug status...
if int(profile):
env.Append(CCFLAGS=profile_opts)
env.Append(LINKFLAGS=profile_opts)
# Build a revision file to include with LOOS so all tools know what version
# of LOOS they were built with...
scons_support.setupRevision(env)
# Export for subsidiary SConscripts
Export('env')
# ---------------------------------------------------------------------------------------------
# Handle SConscripts and build targets
[loos, loos_python] = SConscript('src/SConscript')
loos_scripts = SConscript('SConscript')
Export('loos')
"""
Handle existing documentation
This is to permit source distributions that include pre-built documentation. If
a docs.prebuilt file is found in the top-level directory, then scons will not
include doxygen sources in the dependency tree (i.e. the docs will not be
rebuilt). They will also not be included in any cleaning targets.
If a tarball of the documentation is found, then this will be untar'd in place.
It should include a top-level docs.prebuilt file to avoid untar'ing every time.
Tarballs compressed with gzip and bzip2 are recognized, as well as uncompressed
tarballs.
If docs.prebuilt does NOT exist and no tarball is found, then scons will
automatically generate the documentation for most builds, and it will be
included in cleaning. In addition, install will generate the documentation
"""
"""
if os.path.exists('docs.prebuilt'):
existing_docs = True
print('Warning- existing documentation found and will NOT be rebuilt (or cleaned)!')
print(' Remove docs.prebuilt file to force rebuilding documentation.')
docs = ['Docs/html/index.html']
else:
doc_tarballs = glob.glob('loos-*-docs.tar*')
if doc_tarballs:
filename = doc_tarballs[0]
name, extension = os.path.splitext(doc_tarballs[0])
if extension == '.gz':
modifier = 'z'
elif extension == '.bz2':
modifier = 'j'
elif extension != '.tar':
print('Error- unknown compression extension for ', doc_tarballs[0])
sys.exit(-1)
print('Warning- existing documentation tarball found. To force rebuilding of')
print(' of documentation, remove the tarball and the docs.prebuilt file.')
if not cleaning:
print('Unpacking documentation...')
fnull = open(os.devnull, 'w')
subprocess.call(['tar', modifier + 'xvf', filename], stdout=fnull)
existing_docs = True
docs = ['Docs/html/index.html']
else:
existing_docs = False
docs = env.Doxygen('Doxyfile')
"""
loos_tools = SConscript('Tools/SConscript')
loos_core = loos + loos_scripts
# Automatically setup build targets based on package_list
# Note: excludes Python PyLOOS was not built...
loos_packages = []
for name in loos_build_config.package_list:
if name == 'Python' and not pyloos:
continue
pkg_sc = SConscript('Packages/' + loos_build_config.package_list[name] +
'/SConscript')
env.Alias(name, pkg_sc)
loos_packages = loos_packages + pkg_sc
# Always install documentation. Note: html version is hard-coded
"""
env.Command(PREFIX + '/docs/index.html', 'Docs/html/index.html', [
Delete(PREFIX + '/docs'),
Copy(PREFIX + '/docs', 'Docs/html'),
])
env.AlwaysBuild(PREFIX + '/docs/index.html')
"""
all = loos_tools + loos_scripts + loos_packages
if int(env['pyloos']):
loos_core = loos_core + loos_python
all = all + loos_python
loos_tools += loos_core
env.Alias('tools', loos_tools)
env.Alias('core', loos_core)
env.Alias('all', all)
env.Alias('install', PREFIX)
# To get a real "distclean", run "scons -c" and then "scons -c config"
env.Clean('config',
[
".sconsign.dblite",
".sconf_temp",
"config.log"
])
env.Default('all')