-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsconstruct
693 lines (523 loc) · 27.2 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
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
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
#! /usr/bin/python
# That line was just so programs like gvim or emacs will understand that this is Python code! Don't
# make this file executable.
###############################################################################
# #
# Copyright (C) 2006-2014 Edward d'Auvergne #
# Copyright (C) 2014 Troels E. Linnet #
# #
# This file is part of the program relax (http://www.nmr-relax.com). #
# #
# This program 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, either version 3 of the License, or #
# (at your option) any later version. #
# #
# This program 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 relax; if not, write to the Free Software #
# #
###############################################################################
# Import statements.
from os import F_OK, access, getcwd, path, remove, rmdir, sep, walk, environ
import platform
from re import search
from shutil import rmtree
from subprocess import PIPE, Popen
import sys
from tempfile import mkdtemp
# Scons modules.
from scons.distrib import package, gpg_sign
from scons.install import install, uninstall
from scons.manuals import clean_manual_files, compile_api_manual_html, compile_user_manual_html, compile_user_manual_pdf, fetch_docstrings, version_file
from SCons.Script import ARGUMENTS
import SCons.Util
# relax version file.
from version import version
########################
# Paths and file names #
########################
# The operating system.
SYSTEM = platform.uname()[0]
# The machine type.
MACH = platform.uname()[4]
# Symbolic link flag.
SYMLINK_FLAG = 1
# GNU/Linux.
if SYSTEM == 'Linux':
# System specific string.
SYS = 'GNU-Linux'
# Linux installation path.
INSTALL_PATH = '/usr/local'
# MS Windows.
elif SYSTEM == 'Windows' or SYSTEM == 'Microsoft':
# Set the system to 'Windows' no matter what.
SYSTEM = 'Windows'
# Architecture.
arch = platform.architecture()[0]
# 32 bit.
if arch == '32bit':
SYS = 'Win32'
# 64 bit.
elif arch == '64bit':
SYS = 'Win64'
# Unknown.
else:
SYS = 'Win'
# Windows installation path.
INSTALL_PATH = 'C:\\'
# No symlinks!
SYMLINK_FLAG = 0
# Mac OS X.
elif SYSTEM == 'Darwin':
# System specific string.
SYS = SYSTEM
# Mac OS X installation path.
INSTALL_PATH = sys.prefix + sep + 'local'
# All other operating systems.
else:
# System specific string.
SYS = SYSTEM
# Installation path.
INSTALL_PATH = sys.prefix + sep + 'local'
# Installation.
###############
# Relax installation directory.
RELAX_PATH = INSTALL_PATH + sep + 'relax'
# Installation path for binaries.
BIN_PATH = INSTALL_PATH + sep + 'bin'
# Symbolic link installation path.
SYMLINK = BIN_PATH + sep + 'relax'
# The distribution files.
#########################
if SYSTEM == 'Windows':
BIN_FILE = 'relax-' + version + '.' + SYS
SRC_FILE = 'relax-' + version + '.src'
DIST_TYPE = 'zip'
elif SYSTEM == 'Darwin':
BIN_FILE = 'relax-' + version + '.' + SYS
SRC_FILE = 'relax-' + version + '.src'
DIST_TYPE = 'dmg'
else:
BIN_FILE = 'relax-' + version + '.' + SYS + '.' + MACH
SRC_FILE = 'relax-' + version + '.src'
DIST_TYPE = 'tar'
# GPG key.
##########
GPG_KEY = ARGUMENTS.get('key')
# Documentation.
################
# Documentation directory.
DOCS_DIR = 'docs' + sep
# LaTeX directory.
LATEX_DIR = 'docs' + sep + 'latex' + sep
class Main:
def __init__(self):
"""Initialise the main building targets.
This function sets up the Scons build Environments, sets custom Builders, sets the build
targets, and sets the build dependancies.
"""
# Initialisation.
#################
# Set the help message.
self.help()
# C module compilation.
#######################
# Setup the rules for building the relaxation curve fitting C modules (and set it as the default).
self.relax_fit()
Default(self.relax_fit_object)
# Program installation.
#######################
# Install target.
install_env = Environment(BUILDERS={'install' : Builder(action=install)},
BIN_PATH=BIN_PATH,
INSTALL_PATH=INSTALL_PATH,
RELAX_PATH=RELAX_PATH,
SYMLINK=SYMLINK,
SYMLINK_FLAG=SYMLINK_FLAG)
install_env.install(target='install', source=None)
# Uninstall target.
uninstall_env = Environment(BUILDERS={'uninstall' : Builder(action=uninstall)},
BIN_PATH=BIN_PATH,
INSTALL_PATH=INSTALL_PATH,
RELAX_PATH=RELAX_PATH,
SYMLINK=SYMLINK,
SYMLINK_FLAG=SYMLINK_FLAG)
uninstall_env.uninstall(target='uninstall', source=None)
# Distribution packages.
########################
# Target for creating the binary distribution file.
binary_dist_env = Environment(BUILDERS={'dummy' : Builder(action=self.dummy)})
binary_dist_env.dummy(target='binary_dist', source=None)
binary_dist_env.Depends('binary_dist', 'version_check') # First check the program version number.
binary_dist_env.Depends('binary_dist', self.relax_fit_object) # Compile the C code.
binary_dist_env.Depends('binary_dist', 'manual_clean_nodeps') # Clean up the temporary manual files.
binary_dist_env.Depends('binary_dist', 'clean') # Then clean up all other temporary files.
binary_dist_env.Depends('binary_dist', 'package_bin') # Package the binary distribution.
binary_dist_env.Depends('binary_dist', 'gpg_bin') # GPG sign the binary distribution file.
# Target for creating the source distribution file.
source_dist_env = Environment(BUILDERS={'dummy' : Builder(action=self.dummy)})
source_dist_env.dummy(target='source_dist', source=None)
source_dist_env.Depends('source_dist', 'version_check') # First check the program version number.
source_dist_env.Depends('source_dist', 'manual_clean_nodeps') # Clean up the temporary manual files.
source_dist_env.Depends('source_dist', 'clean_all') # Then clean up the sources.
source_dist_env.Depends('source_dist', 'package_src') # Package the source distribution.
source_dist_env.Depends('source_dist', 'gpg_src') # GPG sign the source distribution file.
# Target for packaging the binary distribution.
package_bin_env = Environment(BUILDERS={'archive' : Builder(action=package)},
DIST_FILE=BIN_FILE,
DIST_TYPE=DIST_TYPE)
package_bin_env.archive(target='package_bin', source=None)
package_bin_env.Depends('package_bin', 'version_check') # Check the program version number first.
# Target for packaging the source distribution.
package_src_env = Environment(BUILDERS={'archive' : Builder(action=package)},
DIST_FILE=SRC_FILE,
DIST_TYPE='ALL')
package_src_env.archive(target='package_src', source=None)
package_src_env.Depends('package_src', 'version_check') # Check the program version number first.
# Target for creating a GPG signature of the binary distribution file.
gpg_bin_env = Environment(BUILDERS={'sign' : Builder(action=gpg_sign)},
DIST_FILE=BIN_FILE,
DIST_TYPE=DIST_TYPE,
GPG_KEY=GPG_KEY)
gpg_bin_env.sign(target='gpg_bin', source=None)
gpg_bin_env.Depends('gpg_bin', 'version_check') # Check the program version number before signing.
# Target for creating a GPG signature of the source distribution file.
gpg_src_env = Environment(BUILDERS={'sign' : Builder(action=gpg_sign)},
DIST_FILE=SRC_FILE,
DIST_TYPE='ALL',
GPG_KEY=GPG_KEY)
gpg_src_env.sign(target='gpg_src', source=None)
gpg_src_env.Depends('gpg_src', 'version_check') # Check the program version number before signing.
# relax version checking.
#########################
# relax version number checking target.
version_check_env = Environment(BUILDERS={'check' : Builder(action=self.test_version)})
version_check_env.check(target='version_check', source=None)
# Cleaning up.
##############
# Clean target.
clean_all_env = Environment(BUILDERS={'clean' : Builder(action=self.clean_all_files)})
clean_all_env.clean(target='clean_all', source=None)
clean_all_env.Depends('clean_all', 'clean') # Run the 'clean' target.
clean_all_env.Depends('clean_all', 'manual_clean') # Run the 'manual_clean' target.
# Target for removing temporary files.
clean_env = Environment(BUILDERS={'clean' : Builder(action=self.clean_files)})
clean_env.Depends('clean', 'manual_clean')
clean_env.clean(target='clean', source=None)
# relax manuals.
################
# Create the manual build environment.
manual_env = Environment(DOCS_DIR=DOCS_DIR,
LATEX_DIR=LATEX_DIR,
SYSTEM=SYSTEM)
# Set up the builder for the standard manual targets (using the self.dummy function).
manual_env.Append(BUILDERS={'Manual' : Builder(action=self.dummy)})
# Target for creating the user manual (PDF version).
manual_env.Manual(target='user_manual_pdf', source=None)
manual_env.Depends('user_manual_pdf', 'manual_clean')
manual_env.Depends('user_manual_pdf', 'manual_version_file')
manual_env.Depends('user_manual_pdf', 'fetch_docstrings')
manual_env.Depends('user_manual_pdf', 'compile_user_manual_pdf')
# Target for creating the user manual (PDF version, without fetching the docstrings).
manual_env.Manual(target='user_manual_pdf_nofetch', source=None)
manual_env.Depends('user_manual_pdf_nofetch', 'manual_clean')
manual_env.Depends('user_manual_pdf_nofetch', 'manual_version_file')
manual_env.Depends('user_manual_pdf_nofetch', 'compile_user_manual_pdf')
# Target for creating the user manual (HTML version).
manual_env.Manual(target='user_manual_html', source=None)
manual_env.Depends('user_manual_html', 'manual_clean')
manual_env.Depends('user_manual_html', 'manual_version_file')
manual_env.Depends('user_manual_html', 'fetch_docstrings')
manual_env.Depends('user_manual_html', 'compile_user_manual_html')
# Target for creating the user manual (HTML version, without fetching the docstrings).
manual_env.Manual(target='user_manual_html_nofetch', source=None)
manual_env.Depends('user_manual_html_nofetch', 'manual_clean')
manual_env.Depends('user_manual_html_nofetch', 'manual_version_file')
manual_env.Depends('user_manual_html_nofetch', 'compile_user_manual_html')
# Target for creating the API documentation manual (HTML version).
manual_env.Manual(target='api_manual_html', source=None)
manual_env.Depends('api_manual_html', 'manual_clean')
manual_env.Depends('api_manual_html', 'compile_api_manual_html')
# Target for creating relax version number LaTeX file.
manual_env.Append(BUILDERS={'Version' : Builder(action=version_file)})
manual_env.Version(target='manual_version_file', source=None)
# Target for fetching the docstrings.
manual_env.Append(BUILDERS={'Fetch' : Builder(action=fetch_docstrings)})
manual_env.Fetch(target='fetch_docstrings', source=None)
# Target for compiling the PDF version of the user manual from the LaTeX sources.
manual_env.Append(BUILDERS={'CompileUserManualPDF' : Builder(action=compile_user_manual_pdf)})
manual_env.CompileUserManualPDF(target='compile_user_manual_pdf', source=None)
# Target for compiling the HTML version of the user manual from the LaTeX sources.
manual_env.Append(BUILDERS={'CompileUserManualHTML' : Builder(action=compile_user_manual_html)})
manual_env.CompileUserManualHTML(target='compile_user_manual_html', source=None)
# Target for compiling the HTML version of the API documentation manual using Epydoc.
manual_env.Append(BUILDERS={'CompileAPIManualHTML' : Builder(action=compile_api_manual_html)})
manual_env.CompileAPIManualHTML(target='compile_api_manual_html', source=None)
# Clean target.
manual_env.Append(BUILDERS={'Clean' : Builder(action=clean_manual_files)})
manual_env.Clean(target='manual_clean', source=None)
# Clean target (with no manual environments dependent on it).
manual_env.Append(BUILDERS={'Clean' : Builder(action=clean_manual_files)})
manual_env.Clean(target='manual_clean_nodeps', source=None)
def clean_all_files(self, target, source, env):
"""Builder action for cleaning up."""
# Print out.
print
print("#########################")
print("# Cleaning up all files #")
print("#########################\n\n")
# Extensions of files to remove.
temp_extns = ['so', 'sconsign', 'dll', 'pyd']
# Print out.
print("\nRemoving the files ending in " + `temp_extns` + ".\n")
# Walk through the directories.
for root, dirs, files in walk(getcwd()):
# Loop over the files in the current directory.
for file in files:
# Loop over the extensions.
for ext in temp_extns:
if search('\.' + ext + '$', file):
remove(path.join(root, file))
# Remove build directories.
if path.isdir('build'):
print("Removing the build directory 'build' used to create a Mac OS X app.")
rmtree('build')
if path.isdir('dist'):
print("Removing the distribution directory 'dist' used to create a Mac OS X app.")
rmtree('dist')
# Final printout.
print("\n\n\n")
def clean_files(self, target, source, env):
"""Builder action for removing temporary files."""
# Print out.
print
print("###############################")
print("# Cleaning up temporary files #")
print("###############################\n\n")
# Extensions of temporary files.
temp_extns = ['pyc', 'pyo', 'bak', 'o', 'os', 'obj', 'exp', 'lib']
# Print out.
print("\nRemoving the files ending in " + `temp_extns` + ".\n")
# Walk through the directories.
for root, dirs, files in walk(getcwd()):
# Loop over the files in the current directory.
for file in files:
# Loop over the extensions.
for ext in temp_extns:
if search('\.' + ext + '$', file):
remove(path.join(root, file))
# Remove relax save state files.
print("Removing temporary relax save state files (of the form relax_state_xxxxxxxx_xxxxxx.bz2).\n")
for root, dirs, files in walk(getcwd()):
# Loop over the files in the current directory.
for file in files:
if search('^relax_state_.*.bz2', file):
remove(path.join(root, file))
# Remove the Python 3 __pycache__ directories.
print("Removing the Python 3 __pycache__ directories.\n")
for root, dirs, files in walk(getcwd()):
# Loop over the directories.
for dir in dirs:
if search('__pycache__', dir):
rmdir(path.join(root, dir))
# Final printout.
print("\n\n\n")
def det_arch(self):
"""Determine which architectures are supported for cross-compilation on Mac OS X.
@return: The list of CPU architects to cross-compile.
@rtype: list of str
"""
# Printout.
print("\nDetermining which architectures can be cross compiled for.")
# Create a temporary directory for compilation tests.
tempdir = mkdtemp()
# The list of archectures to try.
archs = ['i386', 'ppc', 'x86_64', 'ppc64']
allowed = []
# Safely loop over each arch and test it.
try:
for arch in archs:
# Create a C file to compile.
base_name = tempdir + sep + 'test'
file = open(base_name + '.c', 'w')
file.write("#include<stdio.h>\n\n")
file.write("main() {\n")
file.write(" printf(\"Compilation with arch '%s' successful.\\n\");\n" % arch)
file.write("}\n")
file.close()
# Run gcc.
arch_test = ''
for name in allowed:
arch_test += '-arch %s ' % name
pipe = Popen('gcc %s -arch %s %s.c -o %s' % (arch_test, arch, base_name, base_name), shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=False)
for line in pipe.stdout.readlines():
pass
# Execute the file.
pipe = Popen('%s' % base_name, shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=False)
# Check the output.
for line in pipe.stdout.readlines():
# Printout.
print(" %s" % line[:-1])
# Successful arch.
if search("successful", line):
allowed.append(arch)
# Delete the compiled file, if it exists.
if access(base_name, F_OK):
remove(base_name)
# Clean up.
finally:
rmtree(tempdir)
# Return the list.
print("\n")
return allowed
def dummy(self, target, source, env):
"""Dummy function which returns zero."""
return 0
def help(self):
"""The help message."""
# Intro.
string = '\nHelp for using Scons to build the various components of relax.\n\n'
# Usage message.
string = string + 'usage: scons [target]\n'
# No target.
string = string + '\nNo target:\n'
string = string + ' %-25s\n' % ('compile the C modules')
# Standard targets.
string = string + '\nStandard targets:\n'
string = string + ' %-25s%-40s\n' % ('install', 'install relax')
string = string + ' %-25s%-40s\n' % ('uninstall', 'uninstall relax')
string = string + ' %-25s%-40s\n' % ('binary_dist', 'create the binary distribution packages')
string = string + ' %-25s%-40s\n' % ('source_dist', 'create the source distribution packages')
string = string + ' %-25s%-40s\n' % ('clean', 'remove the temporary files')
string = string + ' %-25s%-40s\n' % ('clean_all', 'remove the compiled and temporary files')
string = string + ' %-25s%-40s\n' % ('user_manual_pdf', 'create the user manual (PDF version)')
string = string + ' %-25s%-40s\n' % ('user_manual_pdf_nofetch', 'create the user manual (PDF version, without fetching the docstrings)')
string = string + ' %-25s%-40s\n' % ('user_manual_html', 'create the user manual (HTML version)')
string = string + ' %-25s%-40s\n' % ('user_manual_html_nofetch', 'create the user manual (HTML version, without fetching the docstrings)')
string = string + ' %-25s%-40s\n' % ('api_manual_html', 'create the API documentation manual (HTML version)')
# Specific targets.
string = string + '\nSpecific targets:\n'
string = string + ' %-25s%-40s\n' % ('package_bin', 'package the binary distribution')
string = string + ' %-25s%-40s\n' % ('package_src', 'package the source distribution')
string = string + ' %-25s%-40s\n' % ('gpg_bin', 'GPG sign the binary distribution file')
string = string + ' %-25s%-40s\n' % ('gpg_src', 'GPG sign the source distribution file')
string = string + ' %-25s%-40s\n' % ('version_check', 'check the relax version number')
string = string + ' %-25s%-40s\n' % ('manual_version_file', 'create the relax version number LaTeX file')
string = string + ' %-25s%-40s\n' % ('fetch_docstrings', 'fetch and LaTeX format the docstrings')
string = string + ' %-25s%-40s\n' % ('compile_user_manual_pdf', 'compile the PDF version of the user manual from the LaTeX sources')
string = string + ' %-25s%-40s\n' % ('compile_user_manual_html', 'compile the HTML version of the user manual from the LaTeX sources')
string = string + ' %-25s%-40s\n' % ('compile_api_manual_html', 'compile the HTML version of the API documentation manual using Epydoc')
string = string + ' %-25s%-40s\n' % ('manual_clean', 'remove the temporary manual files')
string = string + ' %-25s%-40s\n' % ('manual_clean_nodeps', 'remove the temporary manual files (with no manual environments dependent on it)')
# Set the help message.
Help(string)
def relax_fit(self):
"""Function for setting up scons for building the relaxation curve fitting C modules."""
# The directory.
dir = 'target_functions'
# File names.
files = ['c_chi2.c',
'exponential.c',
'exponential_inv.c',
'exponential_sat.c',
'relax_fit.c']
# Construct the python include path (for Python.h).
py_include_minpath = sys.prefix + path.sep + 'include'
py_include_fullpath = py_include_minpath + path.sep + 'python' + `sys.version_info[0]` + '.' + `sys.version_info[1]`
# Test if Python.h resides here.
f_name_pyth = py_include_fullpath + path.sep + 'Python.h'
if not access(f_name_pyth, F_OK):
# Test if 'PYTHON_INCLUDE_DIR' has been set to system environment.
if 'PYTHON_INCLUDE_DIR' in environ:
# Test if Python.h is here.
f_name_pyth = environ['PYTHON_INCLUDE_DIR'] + path.sep + 'Python.h'
if access(f_name_pyth, F_OK):
py_include_fullpath = environ['PYTHON_INCLUDE_DIR']
# Construct the python bin path.
py_bin_minpath = sys.prefix + path.sep + 'bin'
py_bin_fullpath = py_bin_minpath + path.sep + 'python' + `sys.version_info[0]` + '.' + `sys.version_info[1]`
# Relaxation curve fitting build environment.
env = Environment()
# Determine the cross-compilation architectures for Mac systems.
if env['PLATFORM'] == 'darwin':
archs = self.det_arch()
# C flags.
if SYSTEM == 'Windows':
cflags = '/nologo /I\"' + py_include_minpath + '\"'
else:
cflags = '-I' + py_include_fullpath
if env['PLATFORM'] == 'darwin':
for arch in archs:
cflags += ' -arch %s' % arch
# Python library path.
libpath = ''
if SYSTEM == 'Windows':
libpath = sys.prefix + path.sep + 'libs'
# Add the python library path to the environment.
env.Append(LIBPATH = libpath)
# Catch Mac OS X and send the correct command line options to the linker (these may become redundant as SCons improves).
if env['PLATFORM'] == 'darwin':
# The flags.
lnflags = [
'-bundle',
'-bundle_loader', py_bin_fullpath,
'-dynamic',
'-undefined', 'dynamic_lookup'
]
# Force all architectures.
for arch in archs:
lnflags.append('-arch')
lnflags.append(arch)
# Set up the environment.
env.Append(LINKFLAGS = lnflags)
env['SHLINKFLAGS'] = SCons.Util.CLVar('$LINKFLAGS')
# Shared library prefix and suffix.
prefix = ''
suffix = '.so'
if SYSTEM == 'Windows':
suffix = '.pyd'
# Loop over the relaxation curve fitting files.
nodes = []
for file in files:
nodes.append(env.SharedObject(dir + path.sep + file, CCFLAGS=cflags))
# Respect the user environment, specifically compiler, compiler- and linkerflags.
if 'LDFLAGS' in environ:
env.Append(LINKFLAGS = environ['LDFLAGS'])
if 'CFLAGS' in environ:
env.Append(CFLAGS = environ['CFLAGS'])
if 'CC' in environ:
env.Replace(CC = environ['CC'])
# Build the relaxation curve fitting module.
self.relax_fit_object = env.SharedLibrary(target=dir + path.sep + 'relax_fit', source=nodes, SHLIBPREFIX=prefix, SHLIBSUFFIX=suffix)
# Print out string returning function.
def print_string(target, source, env):
string = "\n\n\n\n"
string = string + "###########################\n"
string = string + "# Compiling the C modules #\n"
string = string + "###########################\n\n\n"
string = string + "Building the relaxation curve fitting module " + `str(self.relax_fit_object[0])` + "\n"
return string
# Add the printout as an action to take before constructing the first object.
env.AddPreAction(nodes[0], Action(self.dummy, print_string))
def test_version(self, target, source, env):
"""Builder action for testing that the program version number has been set."""
# Print out.
print
print("#######################################")
print("# Checking the program version number #")
print("#######################################\n\n")
print("Version number: " + version + "\n")
# Test.
if version == "repository checkout":
sys.stderr.write("The program version number has not been set.\n\n")
sys.exit()
# Final printout.
print("\n\n\n")
# Execute the main class.
if __name__ in ['__main__', 'SCons.Script']:
Main()