forked from samb8s/PsrPopPy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSConstruct
100 lines (73 loc) · 3.58 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
# Starter SConstruct for enscons
import sys
import os
import pytoml as toml
import enscons
# check if prefix is set
AddOption('--prefix', dest='prefix', type='string', nargs=1,
action='store', metavar='DIR', default='/usr/local',
help='Installation Prefix')
AddOption('--user', dest='user', action='store_true', default=False,
help='Install as pip-like "--user" (this overrides "--prefix")')
metadata = dict(toml.load(open('pyproject.toml')))['tool']['enscons']
# most specific binary, non-manylinux1 tag should be at the top of this list
import wheel.pep425tags
full_tag = '-'.join(next(tag for tag in wheel.pep425tags.get_supported() if not 'manylinux' in tag))
# full_tag = py2.py3-none-any # pure Python packages compatible with 2+3
env = Environment(tools=['default', 'packaging', enscons.generate],
PACKAGE_METADATA=metadata,
WHEEL_TAG=full_tag)
# set the compiler to gfortran
env['CC'] = 'gfortran'
py_source = Glob('psrpoppy/*.py')
libpath = os.path.join('psrpoppy', 'fortran')
# check whether installing on a Mac
if 'Darwin' in os.uname()[0]:
env.Append(CFLAGS=['-m 32'])
env.Append(CPPFLAGS=['-dynamiclib', '-O2', '-fPIC', '-fno-second-underscore', '-c', '-std=legacy'])
else:
env.Append(CPPFLAGS=['-O2', '-fPIC', '-fno-second-underscore', '-c', '-std=legacy'])
env.Append(CPPPATH=[libpath])
# dictionary of libraries and files needed for library
LIBDIC = {}
LIBDIC['libne2001'] = ['ne2001.f', 'dm.f', 'psr_ne.f', 'dist.f', 'calc_xyz.f', 'density.f', 'glun.f']
LIBDIC['libykarea'] = ['ykarea.f', 'psrran.f']
LIBDIC['libsla'] = ['galtfeq.f', 'sla.f']
LIBDIC['libvxyz'] = ['vxyz.f', 'rkqc.f', 'rk4.f']
LIBDIC['libgamma'] = ['gamma.f']
LIBDIC['libgetseed'] = ['getseed.f', 'clock.f']
libs = []
# compile libraries
for libname in LIBDIC:
lib = os.path.join(libpath, libname)
libsources = [os.path.join(libpath, srcfile) for srcfile in LIBDIC[libname]]
sharedlib = env.SharedLibrary(target=lib, source=libsources)
#staticlib = env.StaticLibrary(target=lib, source=libsources)
libs += sharedlib
# install prefix
if not GetOption('user'):
installprefix=GetOption('prefix')
else: # install in --user location
installprefix=os.path.join(os.environ['HOME'], '.local')
pyprefix='psrpoppy'
executables = ['dosurvey', 'evolve', 'populate']
# install executables
insbins = env.InstallAs(target=[os.path.join(installprefix, 'bin', ex) for ex in executables],
source=[os.path.join(pyprefix, ex+'.py') for ex in executables])
otherfiles = Glob('psrpoppy/fortran/*.so') + Glob('psrpoppy/fortran/lookuptables/*') + Glob('psrpoppy/models/*') + Glob('psrpoppy/surveys/*')
platlib = env.Whl('platlib', py_source + libs + otherfiles, root='')
whl = env.WhlFile(source=platlib)
# Add automatic source files, plus any other needed files.
sdist_source=list(set(FindSourceFiles() +
['PKG-INFO', 'setup.py'] +
Glob('psrpoppy/fortran/*.f') + Glob('psrpoppy/fortran/*.inc') + Glob('psrpoppy/fortran/lookuptables/*') + Glob('psrpoppy/models/*') + Glob('psrpoppy/surveys/*')))
sdist_source += py_source
sdist = env.SDist(source=sdist_source)
env.Alias('sdist', sdist)
if GetOption('user'):
install = env.Command("#DUMMY", whl, ' '.join([sys.executable, '-m', 'pip', 'install', '--no-deps', '--user', '$SOURCE']))
else:
install = env.Command("#DUMMY", whl, ' '.join(['PYTHONUSERBASE={}'.format(installprefix), sys.executable, '-m', 'pip', 'install', '--no-deps', '--user', '$SOURCE']))
env.Alias('install', install + insbins)
env.AlwaysBuild(install + insbins)
env.Default(sdist)