forked from dftlibs/xcfun
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetup
More file actions
executable file
·352 lines (314 loc) · 11.6 KB
/
setup
File metadata and controls
executable file
·352 lines (314 loc) · 11.6 KB
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
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
#!/usr/bin/env python
# primitive frontend to cmake
# (c) Jonas Juselius <[email protected]> and Radovan Bast <[email protected]>
# licensed under the GNU Lesser General Public License
import os
import sys
import string
import subprocess
from optparse import OptionParser, OptionGroup
if sys.version < '2.4':
print 'setup requires python version >= 2.4'
sys.exit(1)
root_directory = os.path.realpath(__file__)[:-5]
default_path = root_directory + 'build/'
# define example usage
usage = '''
Example: ./%prog --fc=gfortran --cc=gcc'''
# initialize parser
parser = OptionParser(usage)
# define options
group = OptionGroup(parser, 'Basic options')
group.add_option('--auto',
action='store_true',
dest='auto',
default=False,
help='try to configure --fc, --cc, --cpp, and --math automatically [default: %default]')
group.add_option('--fc',
type='string',
action='store',
dest='fc',
default=None,
help='set the Fortran compiler [default: pick automatically or based on FC=...]',
metavar='STRING')
group.add_option('--cc',
type='string',
action='store',
dest='cc',
default=None,
help='set the C compiler [default: pick automatically or based on CC=...]',
metavar='STRING')
group.add_option('--cpp',
type='string',
action='store',
dest='cpp',
default=None,
help='set the C++ compiler [default: pick automatically or based on CXX=...]',
metavar='STRING')
group.add_option('--math-dir',
type='string',
action='store',
dest='mathdir',
default=None,
help='directory containing math libraries [default: pick automatically]',
metavar='PATH')
group.add_option('--internal-math',
action='store_true',
dest='nomath',
default=False,
help='force the use of internal math library [default: %default]')
group.add_option('--mpi',
action='store_true',
dest='mpi',
default=False,
help='build using MPI parallelization [default: %default]')
group.add_option('--int64',
action='store_true',
dest='int64',
default=False,
help='build for 64bit integers [default: %default]')
group.add_option('--python',
action='store_true',
dest='python',
default=False,
help='build Python interface [default: %default]')
group.add_option('--show',
action='store_true',
dest='show',
default=False,
help='show cmake command and exit [default: %default]')
parser.add_option_group(group)
group = OptionGroup(parser, 'Change default paths')
group.add_option('--build',
type='string',
action='store',
dest='build',
default=default_path,
help='set the build path (you can build several binaries with the same source) [default: %default]',
metavar='PATH')
group.add_option('--install',
type='string',
action='store',
dest='install',
default=None,
help='set the install path for make install [default: %default]',
metavar='PATH')
group.add_option('--cmake',
type='string',
action='store',
dest='alternative_cmake',
default=None,
help='give full path to alternative cmake binary (use this if default cmake is too old)',
metavar='PATH')
parser.add_option_group(group)
group = OptionGroup(parser, 'Advanced options')
group.add_option('--math',
type='string',
action='store',
dest='math',
default=None,
help='explicit linker specification for math library',
metavar='STRING')
group.add_option('--debug',
action='store_true',
dest='debug',
default=False,
help='build in debug mode (no optimization) [default: %default]')
group.add_option('--check',
action='store_true',
dest='check',
default=False,
help='enable bounds checking [default: %default]')
group.add_option('--coverage',
action='store_true',
dest='coverage',
default=False,
help='enable code coverage [default: %default]')
group.add_option('-D',
action="append",
dest='cmake',
default=[],
help='forward directly to cmake (example: -D ENABLE_THIS=1 -D ENABLE_THAT=1)',
metavar='STRING')
group.add_option('--host',
type='string',
action='store',
dest='host',
default=None,
help="use predefined defaults for 'host'",
metavar='STRING')
parser.add_option_group(group)
# process input
(options, args) = parser.parse_args()
def check_cmake_exists():
p = subprocess.Popen('cmake --version',
shell=True,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE)
if not ('cmake version' in p.communicate()[0]):
print ' This code is built using CMake'
print
print ' CMake is not found'
print ' get CMake at http://www.cmake.org/'
print ' on many clusters CMake is installed'
print ' but you have to load it first:'
print ' $ module load cmake'
sys.exit()
def gen_cmake_command():
# create cmake command from flags
command = ''
if not options.auto:
if options.fc:
command += ' FC=%s' % options.fc
if options.cc:
command += ' CC=%s' % options.cc
if options.cpp:
command += ' CXX=%s' % options.cpp
if options.alternative_cmake:
command += ' %s' % options.alternative_cmake
else:
command += ' cmake'
if options.nomath:
command += ' -DENABLE_INTERNAL_MATH=ON'
elif options.math:
command += ' -DUSERDEFINED_MATH="%s"' % options.math
elif options.mathdir:
if not os.path.exists(options.mathdir):
print "Specified MATH directory does not exist!"
sys.exit(1)
command += ' -DMATH_ROOT="%s"' % options.mathdir
# if fc starts with 'mpi' turn on MPI
if options.fc and (options.fc[:3] == 'mpi' or options.fc[:3] == 'MPI'):
options.mpi = True
if options.mpi:
command += ' -DENABLE_MPI=ON'
if options.python:
command += ' -DENABLE_PYTHON_INTERFACE=ON'
if options.int64:
command += ' -DENABLE_64BIT_INTEGERS=ON'
if options.check:
command += ' -DENABLE_BOUNDS_CHECK=ON'
if options.coverage:
command += ' -DENABLE_CODE_COVERAGE=ON'
if options.install:
command += ' -DCMAKE_INSTALL_PREFIX=' + options.install
if options.debug:
command += ' -DCMAKE_BUILD_TYPE=Debug'
else:
command += ' -DCMAKE_BUILD_TYPE=Release'
if options.cmake:
for definition in options.cmake:
command += ' -D%s' % definition
command += ' %s' % root_directory
print '%s\n' % command
if options.show:
sys.exit()
return command
def configure_host(host):
if host == 'stallo':
configure_stallo()
elif host == 'larry':
configure_larry()
elif host == 'titan':
configure_titan()
elif host == 'thor':
configure_thor()
else:
print "Unknown host/system: {0}".format(host)
sys.exit(1)
def print_build_help(build_path):
print ' configure step is done'
print ' now you need to compile the sources'
print
print ' to compile with configured parameters (recommended):'
print ' $ cd ' + build_path
print ' $ make'
print
print ' to modify configured parameters and then compile:'
print ' $ cd ' + build_path
print ' $ ccmake ' + root_directory
print ' $ make'
def gen_reconfigure_script(command, build_path):
file_name = os.path.join(build_path, 'reconfigure')
f = open(file_name, 'w')
f.write('#!/bin/sh \n')
f.write('%s' % command)
f.close()
os.system('chmod 700 %s' % file_name)
def save_setup_command(argv, build_path):
file_name = os.path.join(build_path, 'setup_command')
f = open(file_name, 'w')
f.write(" ".join(sys.argv[:]))
f.close()
def setup_build_path(build_path, only_show_command):
if os.path.isdir(build_path):
if not only_show_command:
print 'aborting setup - build directory %s exists already' % build_path
print 'please first remove it and then rerun setup'
sys.exit()
else:
os.makedirs(build_path, 0755)
def run_cmake(command, build_path):
topdir = os.getcwd()
os.chdir(build_path)
p = subprocess.Popen(command,
shell=True,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE)
s = p.communicate()[0]
print s
os.chdir(topdir)
return s
def main():
if len(sys.argv) == 1:
# user has given no arguments: print help and exit
print parser.format_help().strip()
sys.exit()
check_cmake_exists()
build_path = options.build
setup_build_path(build_path, options.show)
if options.host:
configure_host(options.host)
command = gen_cmake_command()
status = run_cmake(command, build_path)
if not 'Configuring incomplete' in status:
gen_reconfigure_script(command, build_path)
save_setup_command(sys.argv, build_path)
print_build_help(build_path)
# host/system specific configurations
def configure_stallo():
if not options.fc:
options.fc = 'ifort'
if not options.cc:
options.cc = 'icc'
if options.mpi:
options.fc = 'mpif90'
options.cc = 'mpicc'
def configure_titan():
if not options.fc:
options.fc = 'ifort'
if not options.cc:
options.cc = 'icc'
if not options.math:
options.math = '-L/site/Goto-library/AuthenticAMD-x86_64/ifort/ -lblas -L/site/Goto-library/AuthenticAMD-x86_64/ifort/ -llapack'
if options.mpi:
options.fc = 'mpif90'
options.cc = 'mpicc'
def configure_larry():
if not options.fc:
options.fc = 'ifort'
if not options.cc:
options.cc = 'icc'
if options.mpi:
options.fc = 'mpif90'
options.cc = 'mpicc'
def configure_thor():
if not options.fc:
options.fc = 'gfortran'
if not options.cc:
options.cc = 'gcc'
if options.mpi:
options.fc = 'mpif90'
options.cc = 'mpicc'
if __name__ == '__main__':
main()