This repository has been archived by the owner on Apr 14, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSConstruct
278 lines (212 loc) · 6.87 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
# Setup
import os
env = Environment(ENV = os.environ)
try:
env.Tool('config', toolpath = [os.environ.get('CBANG_HOME')])
except Exception, e:
raise Exception, 'CBANG_HOME not set?\n' + str(e)
import sys
from urlparse import urlparse
import urllib2
import tarfile
import shutil
import subprocess
import stat
version = '4.5.4'
package = 'gromacs-%s.tar.gz' % version
url = 'ftp://ftp.gromacs.org/pub/gromacs/' + package
patches = ['gromacs-4.5.4-fah.patch']
# Setup
env.CBLoadTools('compiler fah-gromacs')
try:
env.CBLoadTools('libfah')
except: pass
conf = env.CBConfigure()
env.__setitem__('strict', 0) # Force not strict
def CheckPipes(context):
env = context.env
context.Message('Checking for Pipes... ')
source = """
#include <stdio.h>
int main() {return popen("/tmp/xyz", "r") != 0;}
"""
if context.TryCompile(source.strip(), '.cpp'):
env.AppendUnique(CPPDEFINES = ['HAVE_PIPES'])
context.Result(True)
return True
context.Result(False)
return False
def do_tar(package, extract):
f = None
tar = None
try:
f = open(package, 'rb') # Work around for Windows
tar = tarfile.open(package, fileobj = f)
if extract:
sys.stdout.write('Extracting ' + package + '...')
sys.stdout.flush()
tar.extractall()
sys.stdout.write('ok\n')
sys.stdout.flush()
return tar.getnames()[0]
finally:
if tar is not None: tar.close()
if f is not None: f.close()
def extract(package):
return do_tar(package, True)
def get_tar_root(package):
return do_tar(package, False)
def patch(root, patches):
for patch in patches:
sys.stdout.write('Applying patch ' + patch + '...')
sys.stdout.flush()
ret = subprocess.Popen(['python', 'patch.py', '-q', patch]).wait()
if ret: raise Exception, 'Failed to apply patch ' + patch
sys.stdout.write('ok\n')
sys.stdout.flush()
def process_package(package, patches):
extract(package)
root = get_tar_root(package)
patch(root, patches)
os.utime(root, None)
def remove(path):
if os.path.exists(path):
if os.path.isdir(path): shutil.rmtree(path)
else: os.unlink(path)
def flatten(l, ltypes = (list, tuple)):
ltype = type(l)
l = list(l)
i = 0
while i < len(l):
while isinstance(l[i], ltypes):
if not l[i]:
l.pop(i)
i -= 1
break
else: l[i:i + 1] = l[i]
i += 1
return ltype(l)
# Download and unpack Gromacs package
clean_gromacs = False
if not os.path.exists(package):
env.CBDownload(package, url)
clean_gromacs = True
try:
package_root = None
package_root = get_tar_root(package)
# Check for patch updates
if os.path.exists(package_root):
package_time = os.stat(package_root)[stat.ST_MTIME]
for file in patches:
if package_time < os.stat(file)[stat.ST_MTIME]:
clean_gromacs = True
break
if clean_gromacs:
remove(package_root)
remove('gromacs')
if not os.path.exists(package_root):
process_package(package, patches)
except:
# Redownload and try again
remove(package)
if package_root is not None: remove(package_root)
remove('gromacs')
env.CBDownload(package, url)
process_package(package, patches)
# Copy Gromacs headers
if not os.path.exists('gromacs'):
shutil.copytree(package_root + '/include', 'gromacs')
# Configure
if not env.GetOption('clean'):
# Configure compiler
if env['PLATFORM'] == 'win32': cstd = 'c99'
else: cstd = 'gnu99'
conf.CBConfig('compiler', cstd = cstd)
functions = [
'_aligned_malloc', '_commit', 'fileno', '_fileno', '_fseeki64',
'fseeko', 'fsync', 'gettimeofday', 'memalign', 'posix_memalign',
'strdup', 'swap', 'sysconf',
]
headers = [
'altivec', 'direct', 'dirent', 'regex', 'sys/time', 'sys/types',
'sched', 'unistd', 'pthread', 'pwd', 'io', 'inttypes',
]
if int(env.get('cross_mingw', 0)): headers.remove('dirent')
# Headers
for hdr in headers:
if conf.CBCheckCHeader(hdr + '.h'):
env.CBDefine('HAVE_' + hdr.replace('/', '_').upper() + '_H')
# Functions
for func in functions:
if conf.CheckFunc(func):
env.CBDefine('HAVE_' + func.upper())
# Other dependencies
conf.CBConfig('fah-gromacs-deps')
# Defines
import socket
import getpass
import platform
from datetime import datetime
env.CBDefine([
'VERSION="\\"%s\\""' % version,
'GMXLIBDIR="\\"invalid\\""',
'BUILD_TIME="\\"%s\\""' % 'undefined', #datetime.now().isoformat(),
'BUILD_USER="\\"%s@%s\\""' % (getpass.getuser(),
socket.gethostname()),
'BUILD_MACHINE="\\"%s\\""' % platform.platform(),
'GMX_DOUBLE', 'GMX_NO_NICE'
])
# Remove DEBUG define (Causes Gromacs compile failure in 4.5.4+)
defines = env['CPPDEFINES']
defines = filter(lambda d: not d.startswith('DEBUG'), flatten(defines))
env.Replace(CPPDEFINES = defines)
if env['PLATFORM'] == 'win32' or int(env.get('cross_mingw', 0)):
env.CBDefine('RETSIGTYPE=int')
else: env.CBDefine('RETSIGTYPE=void')
# XDR
if not conf.CBCheckCHeader('rpc/xdr.h'):
env.CBDefine('GMX_INTERNAL_XDR')
# libfah
if env.get('fah', 0): conf.CBConfig('libfah')
# Pipes
conf.AddTest('CheckPipes', CheckPipes)
conf.CheckPipes()
# Windows
if env['PLATFORM'] == 'win32' or int(env.get('cross_mingw', 0)):
env.CBDefine('uid_t=int')
# Local includes
env.Append(CPPPATH = [package_root + '/include'])
# Build libs
libs = {
'gmx': ['', 'selection', 'trajana', 'statistics', 'nonbonded',
'nonbonded/nb_kernel_c'],
'md': [''],
}
for name, subdirs in libs.items():
# Gather source
src = []
for dir in subdirs:
src += Glob(package_root + '/src/%slib/%s/*.c' % (name, dir))
src = map(str, src)
# Filter out tests
src = filter(lambda filename: filename.find('test') == -1, src)
# Build
Default(env.Library(name + '_d', src))
# Find FAH source files
if env.get('fah', 0):
fahSrc = []
nonFAHSrc = []
for path in src:
f = None
try:
f = open(path)
if f.read().find('GMX_FAHCORE') != -1: fahSrc += [path]
else: nonFAHSrc += [path]
finally:
if f is not None: f.close()
# Build FAH lib
fahObjs = []
for path in fahSrc:
fahObjs += [env.StaticObject(path, OBJPREFIX = 'fah-',
CCFLAGS = '$CFLAGS -DGMX_FAHCORE=2')]
Default(env.Library(name + '-fah', nonFAHSrc + fahObjs))