-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSConstruct
198 lines (181 loc) · 7.32 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
from __future__ import print_function
import site
#### May need to edit this section ####
# These may be overridden using "debug=" and "release=" command-line arguments
debug = 1
release = 0
# Locations of 64-bit files appear first,
# since they don't exist on 32-bit machines
includePath = Split('/opt/local/include /sw/include /usr/include ./MultiNest_v2.7')
libPath = Split('/opt/local/lib /usr/lib64 /sw/lib /usr/lib /usr/X11R6/lib64 /usr/X11R6/lib ./MultiNest_v2.7')
# Path to Sun F95 (if installed); used to auto-set compiler switches
sun_f95 = '/opt/SUNWspro/bin/f95'
# Path to NAGWare F95 (if installed); used to auto-set compiler switches
nagw_f95 = '/usr/local/nag/bin_amd64/f95'
#nagw_f95 = '/opt/NAGWare/bin/f95'
# Fortran 90/95 compilers to search for, in preferred order
f95List = ['g95', 'gfortran', sun_f95, nagw_f95, 'f95', 'f90']
####### End of editable section #######
# Inherit complete environment, including PATH
import os
env = Environment(ENV = os.environ)
conf = Configure(env)
# Parse command-line arguments
debug = int(ARGUMENTS.get('debug', debug))
release = int(ARGUMENTS.get('release', release))
user_f95 = ARGUMENTS.get('f95', None)
# Find fortran compiler and set command-line switches to use for it
if user_f95 is not None:
f95 = user_f95
else:
f95 = env.Detect(f95List)
if f95 is None:
print("No f90/f95 compiler found in %s" % env['ENV']['PATH'])
Exit(1)
print("Building on '%s' using %s" % (Platform(), f95))
print("debug=%s release=%s" % (debug, release))
env.Replace(FORTRAN=f95, LINK=f95)
env.Replace(FORTRANFLAGS=[])
env.Replace(LINKFLAGS=[])
if debug:
# most compilers understand -g
env.Append(FORTRANFLAGS=['-g'])
if f95 == 'g95':
print("Configuring for G95")
env.Append(FORTRANFLAGS=['-fno-second-underscore'])
f2kcli = 'f2kcli.f90'
elif f95 == 'gfortran':
print("Configuring for gfortran")
env.Append(FORTRANFLAGS=['-Wall'])
if release:
env.Append(FORTRANFLAGS=['-O3'])
f2kcli = 'f2kcli.f90'
elif f95 == sun_f95:
print("Configuring for Sun WorkShop Fortran 95")
env.Append(FORTRANFLAGS=['-dalign'])
if release:
env.Append(FORTRANFLAGS=['-fast'])
env.Append(LINKFLAGS=['-fast'])
if debug:
env.Append(FORTRANFLAGS=['-C'])
env.Append(LINKFLAGS=['-dalign'])
env.Append(LIBS=['f77compat'])
f2kcli = 'f2kcli.f90'
elif f95 == nagw_f95:
print("Configuring for NAGWare Fortran 95")
env.Append(FORTRANFLAGS=['-mismatch'])
if release:
env.Append(FORTRANFLAGS=['-O'])
env.Append(LINKFLAGS=['-O'])
if debug:
env.Append(FORTRANFLAGS=['-C'])
# Prevent 'undefined symbol' errors when linking to libraries built with
# Sun fortran compiler
env.Append(LIBPATH=['/opt/SUNWspro/lib'])
if conf.CheckLib('F77'):
# NB CheckLib() appends to env['LIBS'] if found
env.Append(LIBS=['M77']) # need both F77 and M77
# need different f2kcli for this compiler
f2kcli = 'f2kcli_nagw.f90'
# Ignores LD_RUN_PATH, so pass "-rpath <path>" to ld
if env['PLATFORM'] in ['linux','posix']:
# f95 runs gcc which runs linux ld
env.Append(LINKFLAGS=['-Wl,-Xlinker', '-Wl,-rpath',
'-Wl,-Xlinker', '-Wl,%s' % ':'.join(libPath)])
elif env['PLATFORM'] == 'sunos':
# f95 runs cc or gcc (specified at purchase) which runs sunos ld
# Fortunately cc understands -R directly
env.Append(LINKFLAGS=['-Wl,-R%s' % ':'.join(libPath)])
else:
print("Configuring for generic Fortran 9x compiler")
f2kcli = 'f2kcli.f90'
# Work around inconsistent behaviour between scons versions
env.Replace(F90FLAGS=env['FORTRANFLAGS'])
env.Replace(F90=f95)
# Prepend to include/library paths from variables above
env.Prepend(FORTRANPATH=includePath)
# FORTRANPATH seems not to be used for .f90
env.Prepend(F90PATH=includePath)
env.Prepend(LIBPATH=libPath)
if env['PLATFORM'] != 'win32':
libUnixPath = ':'.join(env['LIBPATH'])
env.Append(ENV={'LD_RUN_PATH' : libUnixPath})
# Configure libraries to link in
baseLibs = env.get('LIBS', [])
pgLibs = ['pgplot', 'X11']
fitsioLibs = ['cfitsio']
if conf.CheckLib('socket'):
fitsioLibs += ['nsl', 'socket']
fftwLibs = ['fftw3']
if Platform() == 'sunos':
fftwLibs += ['m']
if conf.CheckLib('nag'):
conf.env.Append(CPPDEFINES='HAVE_NAG=1')
nagLibs = ['nag']
else:
nagLibs = []
nestLibs = ['nest3', 'lapack']
env = conf.Finish()
# Define targets and dependencies...
sources = {}
sources['mfit'] = ['main.f90',
'maths.f90', 'search.f90', 'fit.f90', 'visibility.f90', 'inout.f90',
'plot.f90', 'postplot.f90', 'model.f90',
'gamma.f', 'rjbesl.f', 'maths_pda.f', 'fit_pda.f', 'pda_xermsg.f',
'gmst.f', 'dranrm.f',
'marginalise.F90', 'wrap.f90', 'bayes.f90']
sources['clfit'] = ['clfit.f90',
'maths.f90', 'search.f90', 'fit.f90', 'visibility.f90', 'inout.f90',
'plot.f90', 'postplot.f90', 'model.f90',
'gamma.f', 'rjbesl.f', 'maths_pda.f', 'fit_pda.f', 'pda_xermsg.f',
'gmst.f', 'dranrm.f',
'marginalise.F90', 'wrap.f90', 'bayes.f90'] + [f2kcli]
sources['clnest'] = ['clnest.f90', 'nestwrap.f90', 'readmc.f90',
'maths.f90', 'search.f90', 'visibility.f90', 'inout.f90',
'model.f90', 'gamma.f', 'rjbesl.f', 'maths_pda.f',
'wrap.f90', 'bayes.f90'] + [f2kcli]
sources['binnest'] = ['binnest.f90', 'nestwrap.f90', 'readmc.f90',
'wrap.f90', 'model.f90', 'bayes.f90', 'visibility.f90',
'maths.f90', 'search.f90', 'rjbesl.f', 'maths_pda.f'] + [f2kcli]
sources['mplot'] = ['modelplot.f90', 'model.f90', 'search.f90',
'gamma.f', 'rjbesl.f', 'fitsimage.f90', 'inout.f90']
sources['calc'] = ['calc.f90',
'maths.f90', 'gamma.f', 'rjbesl.f', 'maths_pda.f']
libs = {}
libs['mfit'] = baseLibs + pgLibs + fitsioLibs + fftwLibs + nagLibs
libs['clfit'] = baseLibs + pgLibs + fitsioLibs + fftwLibs + nagLibs
libs['clnest'] = baseLibs + fitsioLibs + fftwLibs + nestLibs
libs['binnest'] = baseLibs + nestLibs + fftwLibs
libs['mplot'] = baseLibs + pgLibs + fitsioLibs + fftwLibs
libs['calc'] = baseLibs
objects = {}
# ...object files
for key in sources.keys():
allobjs = env.Object(sources[key])
# filter out mod files
objects[key] = list(filter(lambda o: str(o)[-4:] != '.mod', allobjs))
# ...executables
for key in objects.keys():
prog = env.Program(key, objects[key], LIBS=libs[key])
if key not in ['clnest', 'binnest']:
Default(prog)
env.Install('/usr/local/bin', prog)
env.Alias('install', '/usr/local/bin')
# ...install fitgui python code
sitedir = site.getsitepackages()[0] # e.g. /usr/local/lib/python3.8/dist-packages
env.Install('/usr/local/bin', Split('fitgui fitgui_dev'))
env.Install(sitedir, 'fitgui.py')
env.Alias('install', sitedir)
# ...targets for distribution of mfit
import glob
env.Replace(TARFLAGS = '-c -z')
distFiles = Split('README NEWS TODO documentation f2kcli.txt readme.specfun')
distFiles += Split('SConstruct fitgui fitgui_dev')
distFiles += Split('test.oifits test.model')
# don't distribute makefile.coast
for pattern in ['*.f90', '*.F90', '*.f', '*.py']:
distFiles += glob.glob(pattern)
env.Tar('mfit.tar.gz', distFiles)
# Local Variables:
# mode: python
# End: