setup.py.in
4.4 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
from distutils.core import setup, Extension
from distutils import sysconfig
import glob
import os
import sys
# Removes list of bad prefixes from list
def remove_prefixes(optlist, bad_prefixes):
for bad_prefix in bad_prefixes:
for i, flag in enumerate(optlist):
if flag.startswith(bad_prefix):
optlist.pop(i)
break
return optlist
# Adjust compile options for darwin
if sys.platform.lower().startswith("darwin"):
# Remove some time consuming options
cvars = sysconfig.get_config_vars()
cflags = cvars.get('OPT')
if cflags:
cflags = remove_prefixes(cflags.split(),
['-g', '-O', '-Wstrict-prototypes', '-DNDEBUG'])
cvars['OPT'] = str.join(' ', cflags)
cvars['CFLAGS'] = cvars['BASECFLAGS'] + ' ' + cvars['OPT']
# Remove -arch flags. This prevents building a fat library
cvars['ARCHFLAGS'] = ''
# Signal darwin compiler adjustments
print 'Adjust default distutils compiler options for darwin.'
# Set GammaLib library name. If we're about to make the test build then
# create a symbolic link to the static library to enforce static linking.
# This is required on some system (such as Mac OS X) to avoid problems
# with finding the shared library during unit testing.
libgamma='gamma'
if (len(sys.argv) > 3):
if (sys.argv[3] == 'build'):
# Remove any existing symbolic link to libgamma.a. This will
# prevent any exception in creating the symbolic link due to
# an already existing link.
try:
os.remove('../src/.libs/libgamma_python.a')
print 'Removed ../src/.libs/libgamma_python.a'
except:
pass
# Now create a symbolic link and set the library name to this
# symbolic link
try:
os.symlink('libgamma.a', '../src/.libs/libgamma_python.a')
print 'Created ../src/.libs/libgamma_python.a'
libgamma='gamma_python'
except:
print 'WARNING: Failed to create symbolic link to static library. Link dynamically.'
# Set default include directories and data files
include_dirs = ['@top_srcdir@/include']
data_files = glob.glob('@top_srcdir@/pyext/*.i')
library_dirs = ['../src/.libs']
runtime_library_dirs = ['@libdir@']
libraries = [libgamma]
# Add cfitsio library only if available
if '@WITH_CFITSIO_TRUE@' != '#':
print "Link cfitsio into Python bindings."
libraries.append('cfitsio')
# Add readline library only if available
if '@WITH_READLINE_TRUE@' != '#':
print "Link readline into Python bindings."
libraries.append('readline')
libraries.append('ncurses')
# 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:
dir = extra_lib_path.lstrip('-L')
if len(dir) > 0:
library_dirs.append(extra_lib_path.lstrip('-L'))
runtime_library_dirs(extra_lib_path.lstrip('-L'))
# Get extra include directories
extra_inc_paths = ('@CPPFLAGS@').split(' ')
for extra_inc_path in extra_inc_paths:
dir = extra_inc_path.lstrip('-I')
if len(dir) > 0:
include_dirs.append(extra_inc_path.lstrip('-I'))
# Add instrument specific include directories and data files
if '@WITH_INST_MWL_TRUE@' != '#':
print "Include multi-wavelength interface in gammalib Python bindings."
include_dirs.append('@top_srcdir@/inst/mwl/include')
data_files.extend(glob.glob('@top_srcdir@/inst/mwl/pyext/*.i'))
if '@WITH_INST_CTA_TRUE@' != '#':
print "Include CTA instrument interface in gammalib Python bindings."
include_dirs.append('@top_srcdir@/inst/cta/include')
data_files.extend(glob.glob('@top_srcdir@/inst/cta/pyext/*.i'))
if '@WITH_INST_LAT_TRUE@' != '#':
print "Include Fermi/LAT instrument interface in gammalib Python bindings."
include_dirs.append('@top_srcdir@/inst/lat/include')
data_files.extend(glob.glob('@top_srcdir@/inst/lat/pyext/*.i'))
# Setup
setup(name='@PACKAGE_NAME@',
version='@PACKAGE_VERSION@',
description='gammalib Python bindings',
author='Jurgen Knodlseder',
author_email='@PACKAGE_BUGREPORT@',
url='http://gammalib.sourceforge.net/',
py_modules=['gammalib'],
ext_modules=[Extension('_gammalib', ['gammalib_wrap.cpp'],
include_dirs=include_dirs,
library_dirs=library_dirs,
libraries=libraries,
runtime_library_dirs=runtime_library_dirs)],
data_files=[('@prefix@/share/gammalib/swig', data_files)],
)