-
Notifications
You must be signed in to change notification settings - Fork 49
/
sherpa_config.py
135 lines (113 loc) · 6.48 KB
/
sherpa_config.py
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
#
# Copyright (C) 2014, 2015, 2016, 2020 Smithsonian Astrophysical Observatory
#
#
# 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 this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
from .extensions import build_ext, build_lib_arrays
from .deps import build_deps
from distutils.cmd import Command
import os
import sys
version = '{}.{}'.format(sys.version_info[0], sys.version_info[1])
class sherpa_config(Command):
description = "Configure Sherpa build options. If in doubt, ignore this command and stick to defaults. See setup.cfg for more information."
user_options = [
('fftw', None, "Whether Sherpa should build the embedded fftw3 library, which is the default behavior: set to 'local' to make Sherpa link against existing libraries on the system.)"),
('fftw-include-dirs', None, "Where the fftw3 headers are located, if fftw is 'local'"),
('fftw-lib-dirs', None, "Where the fftw3 libraries are located, if fftw is 'local'"),
('fftw-libraries', None, "Name of the libraries that should be linked as fftw3"),
('region', None, "Whether Sherpa should build the embedded region library, which is the default behavior: set to 'local' to make Sherpa link against existing libraries on the system.)"),
('region-include-dirs', None, "Where the region headers are located, if region is 'local'"),
('region-lib-dirs', None, "Where the region libraries are located, if region is 'local'"),
('region-libraries', None, "Name of the libraries that should be linked as region"),
('wcs', None, "Whether Sherpa should build the embedded wcs library, which is the default behavior: set to 'local' to make Sherpa link against existing libraries on the system.)"),
('wcs-include-dirs', None, "Where the wcs subroutines headers are located"),
('wcs-lib-dirs', None, "Where the wcs subroutines libraries are located"),
('wcs-libraries', None, "Name of the libraries that should be linked as wcs"),
('group-location', None, "Location of the group python module"),
('disable-group', None, "Disable the group module install"),
('stk-location', None, "Location of the stack library python module"),
('disable-stk', None, "Disable the stack library module install"),
('install-dir', None, "Directory where external dependencies must be installed (--prefix)"),
('configure', None, "Additional configure flags for the external dependencies"),
('group-cflags', None, "Additional cflags for building the grouping library"),
]
def initialize_options(self):
self.install_dir=os.getcwd()+'/build'
self.fftw=None
self.fftw_include_dirs=None
self.fftw_lib_dirs=None
self.fftw_libraries='fftw3'
self.region=None
self.region_include_dirs=None
self.region_lib_dirs=None
self.region_libraries='region'
self.wcs=None
self.wcs_include_dirs=None
self.wcs_lib_dirs=None
self.wcs_libraries='wcssubs'
self.group_location=None
self.disable_group=False
self.configure='--disable-maintainer-mode --enable-stuberrorlib --disable-shared --enable-shared=libgrp,stklib'
self.group_cflags=None
self.stk_location=None
self.disable_stk=False
def finalize_options(self):
if self.fftw_include_dirs is None:
self.fftw_include_dirs=self.install_dir+'/include'
if self.fftw_lib_dirs is None:
self.fftw_lib_dirs=self.install_dir+'/lib'
if self.region_include_dirs is None:
self.region_include_dirs=self.install_dir+'/include'
if self.region_lib_dirs is None:
self.region_lib_dirs=self.install_dir+'/lib'
if self.wcs_include_dirs is None:
self.wcs_include_dirs=self.install_dir+'/include'
if self.wcs_lib_dirs is None:
self.wcs_lib_dirs=self.install_dir+'/lib'
if self.group_location is None:
self.group_location = '{}/lib/python{}/site-packages/{}'.format(self.install_dir, version, 'group.so')
if self.stk_location is None:
self.stk_location = '{}/lib/python{}/site-packages/{}'.format(self.install_dir, version, 'stk.so')
def build_configure(self):
configure = ['./configure', '--prefix='+self.install_dir, '--with-pic', '--enable-standalone']
if self.group_cflags is not None:
configure.append('GROUP_CFLAGS="'+self.group_cflags+'"')
if self.configure != 'None':
configure.extend(self.configure.split(' '))
if self.fftw != 'local':
configure.append('--enable-fftw')
self.distribution.ext_modules.append(build_ext('psf', *build_lib_arrays(self, 'fftw')))
self.distribution.ext_modules.append(build_ext('wcs', *build_lib_arrays(self, 'wcs')))
ld1, inc1, l1 = build_lib_arrays(self, 'wcs')
if self.region != 'local':
configure.append('--enable-region')
ld2, inc2, l2 = build_lib_arrays(self, 'region')
ld, inc, l = (ld1+ld2, inc1+inc2, l1+l2)
self.distribution.ext_modules.append(build_ext('region', ld, inc, l))
if not self.disable_group:
configure.append('--enable-group')
self.distribution.data_files.append(('', [self.group_location,]))
if not self.disable_stk:
configure.append('--enable-stk')
self.distribution.data_files.append(('', [self.stk_location,]))
if self.wcs != 'local':
configure.append('--enable-wcs')
self.warn('built configure string' + str(configure))
return configure
def run(self):
configure = self.build_configure()
build_deps(configure)