setup.py.in
7.48 KB
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
#############################################################################
# Disutils setup file for ctools Python extension module #
# ------------------------------------------------------------------------- #
# Copyright (C) 2011-2016 Juergen Knoedlseder #
# ------------------------------------------------------------------------- #
# #
# 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, see <http://www.gnu.org/licenses/>. #
# #
#############################################################################
from distutils.core import setup, Extension
from distutils import sysconfig
import glob
import os
import sys
# Define package name
pkg_name = 'ctools'
# Detect execution mode
is_build = True
if (len(sys.argv) >= 2):
if (sys.argv[1] == 'install'):
is_build = False
if is_build:
print('Python extension module building:')
else:
print('Python extension module installation:')
# Set prefix
prefix = '@prefix@'
if (len(sys.argv) >= 3):
if (sys.argv[2].find('--prefix') != -1):
start = sys.argv[2].find('=') + 1
prefix = sys.argv[2][start:]
# Darwin MacPorts kluge: Remove -L/opt/local/lib path from LDSHARED as this
# overrides the GammaLib settings. Otherwise, MacPorts libraries would be
# used instead of the libraries selected by GammaLib
if sys.platform.lower().startswith("darwin"):
# Get configuration variables
cvars = sysconfig.get_config_vars()
# Extract LDSHARED
ldshared_old = cvars.get('LDSHARED')
ldshared_new = ''
ldshared_rm = ''
for option in ldshared_old.split(' '):
if option.lstrip().find('-L/opt/local/lib') != 0:
ldshared_new += option + ' '
else:
ldshared_rm += option + ' '
if (len(ldshared_rm) > 0):
print('Removed following option(s) from LDSHARED: %s' % (ldshared_rm))
# Set LDSHARED
cvars['LDSHARED'] = ldshared_new
# Set default include directories and data files
include_dirs = [prefix+'/include/gammalib']
install_files = glob.glob('@top_srcdir@/pyext/*.i')
library_dirs = ['../src/.libs']
runtime_library_dirs = ['../src/.libs']
libraries = ['ctools','gamma']
# Add install directory to runtime library path
if os.path.exists(prefix+'/lib'):
library_dirs.append(prefix+'/lib')
runtime_library_dirs.append(prefix+'/lib')
# Add application include files. The method we use here is not very
# intelligent as it simple will add all names that start with 'ct'
# in the src directory. Once we added the ctools script we had to
# add an explicit filter to avoid appending those.
dirs = glob.glob('@top_srcdir@/src/ct*')
for dir in dirs:
if len(dir) > 0 and 'ctools' not in dir:
path = os.path.abspath(dir)
include_dirs.append(path)
include_dirs.append(os.path.abspath('@top_srcdir@/src/support'))
# Add extra libraries
extra_libs = ('@PYTHON_EXTRA_LIBS@').split(',')
for extra_lib in extra_libs:
if len(extra_lib) > 0:
libraries.append(extra_lib)
# Get extra library paths
extra_lib_paths = ('@LDFLAGS@').split(' ')
for extra_lib_path in extra_lib_paths:
if extra_lib_path.lstrip().find('-L') == 0:
dir = extra_lib_path.lstrip().lstrip('-L')
if len(dir) > 0:
library_dirs.append(dir)
runtime_library_dirs.append(dir)
# Get extra include directories
extra_include_dirs = ('@CPPFLAGS@').split(' ')
for extra_include_dir in extra_include_dirs:
if extra_include_dir.lstrip().find('-I') == 0:
dir = extra_include_dir.lstrip().lstrip('-I')
if len(dir) > 0:
include_dirs.append(dir)
# Set data files to install.
data_files=[(prefix+'/share/ctools/swig', install_files)]
# Optionally enable OpenMP
if '@OPENMP_TRUE@' != '#':
extra_compile_args = ['@OPENMP_CXXFLAGS@']
extra_link_args = ['@OPENMP_CXXFLAGS@']
else:
extra_compile_args = []
extra_link_args = []
# Append coverage CXXFLAGS
if len('@COVERAGE_CXXFLAGS@') > 0:
extra_compile_args.append('@COVERAGE_CXXFLAGS@')
extra_link_args.append('@COVERAGE_CXXFLAGS@')
# Optionally add link flag for El Capitan post-processing of modules
if '@IS_ELCAPITAN_TRUE@' != '#':
extra_link_args.append('-headerpad_max_install_names')
# If this is a build then we may need to copy over a bunch of files
if is_build:
# In case that wrappers were not built then copy the module wrapper files
# from the source to the build directory
if '@BUILD_WRAPPERS_FALSE@' != '#':
py_file = pkg_name+'/tools.py'
cpp_file = pkg_name+'/tools_wrap.cpp'
os.system('cp %s %s' % ('@top_srcdir@/pyext/'+cpp_file, '@top_builddir@/pyext/'+cpp_file))
os.system('cp %s %s' % ('@top_srcdir@/pyext/'+py_file, '@top_builddir@/pyext/'+py_file))
# In case that the build directory is different from the source directory
# then copy all cscripts and parfiles from the source directory to the
# build directory
if '@top_srcdir@' != '@top_builddir@':
os.system('cp %s/cscripts/*.py %s/cscripts' % ('@top_srcdir@', '@top_builddir@'))
os.system('cp %s/cscripts/*.par %s/cscripts' % ('@top_srcdir@', '@top_builddir@'))
# Setup
setup(name='@PACKAGE_NAME@',
version='@PACKAGE_VERSION@',
description='ctools Python module',
author='Juergen Knoedlseder',
author_email='@PACKAGE_BUGREPORT@',
url='http://cta.irap.omp.eu/ctools/',
ext_modules=[Extension('ctools._tools', ['ctools/tools_wrap.cpp'],
include_dirs=include_dirs,
library_dirs=library_dirs,
libraries=libraries,
runtime_library_dirs=runtime_library_dirs,
extra_compile_args=extra_compile_args,
extra_link_args=extra_link_args)],
py_modules=['ctools.tools'],
data_files=data_files,
license="GNU GPL v3",
long_description="CTA science analysis tools",
platforms=['Linux', 'Solaris', 'Mac OS-X', 'Unix', 'BSD'],
)
# Post-processing. A symbolic link is created to the directory containing the
# shared wrapper libraries so that we can add this directory to the PYTHONPATH
# for testing.
if is_build:
try:
os.chdir('build')
os.remove('ctools')
print('Removed symbolic link build/ctools.')
except:
pass
try:
path = glob.glob('lib.*')
os.symlink(path[0], 'ctools')
print('Created symbolic link build/ctools.')
except:
print('WARNING: Failed to create symbolic link build/ctools.')