summaryrefslogtreecommitdiff
path: root/dev-python/pywcs/files/pywcs-1.11-wcslib.patch
blob: 14cd4e3dceab6777eac17b029a55af95ef22c936 (plain)
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
--- defsetup.py
+++ defsetup.py
@@ -78,73 +78,27 @@
 
 ######################################################################
 # WCSLIB
-WCSVERSION = "4.8.2"
-WCSLIB = "wcslib" # Path to wcslib
-WCSLIB_PATCHED = "wcslib"
-WCSLIBC = join(WCSLIB_PATCHED, "C") # Path to wcslib source files
-WCSFILES = [ # List of wcslib files to compile
-    'flexed/wcsbth.c',
-    'flexed/wcspih.c',
-    'flexed/wcsulex.c',
-    'flexed/wcsutrn.c',
-    'cel.c',
-    'lin.c',
-    'log.c',
-    'prj.c',
-    'spc.c',
-    'sph.c',
-    'spx.c',
-    'tab.c',
-    'wcs.c',
-    'wcserr.c',
-    'wcsfix.c',
-    'wcshdr.c',
-    'wcsprintf.c',
-    'wcsunits.c',
-    'wcsutil.c']
-WCSFILES = [join(WCSLIBC, x) for x in WCSFILES]
+from subprocess import Popen, PIPE
+from re import match
 
-######################################################################
-# WCSLIB CONFIGURATION
-
-# The only configuration parameter needed at compile-time is how to
-# specify a 64-bit signed integer.  Python's ctypes module can get us
-# that information, but it is only available in Python 2.5 or later.
-# If we can't be absolutely certain, we default to "long long int",
-# which is correct on most platforms (x86, x86_64).  If we find
-# platforms where this heuristic doesn't work, we may need to hardcode
-# for them.
-def determine_64_bit_int():
-    try:
-        try:
-            import ctypes
-        except ImportError:
-            raise ValueError()
-
-        if ctypes.sizeof(ctypes.c_longlong) == 8:
-            return "long long int"
-        elif ctypes.sizeof(ctypes.c_long) == 8:
-            return "long int"
-        elif ctypes.sizeof(ctypes.c_int) == 8:
-            return "int"
-        else:
-            raise ValueError()
-
-    except ValueError:
-        return "long long int"
+def pkgconfig(*packages, **kw):
+    flag_map = {'-I': 'include_dirs', '-L': 'library_dirs', '-l': 'libraries'}
+    arg = "--libs --cflags --modversion %s" % ' '.join(packages) 
+    for tok in Popen(["pkg-config "+ arg],stdout=PIPE, shell=True).communicate()[0].split():
+       token = tok.decode("utf-8")
+       if(match("[0-9]",token)):
+          kw.setdefault("version",[]).append(token)
+       else:
+          kw.setdefault(flag_map.get(token[:2]), []).append(token[2:])
+    return kw
 
-h_file = StringIO()
-h_file.write("""
-/* WCSLIB library version number. */
-#define WCSLIB_VERSION %s
-
-/* 64-bit integer data type. */
-#define WCSLIB_INT64 %s
-""" % (WCSVERSION, determine_64_bit_int()))
-write_if_different(join(srcroot, 'src', 'wcsconfig.h'), h_file.getvalue())
+WCSLIB = pkgconfig('wcslib')
+WCSVERSION = Popen(["pkg-config --modversion"],stdout=PIPE, shell=True).communicate()[0].split()
 
 ######################################################################
 # GENERATE DOCSTRINGS IN C
+
+######################################################################
 docstrings = {}
 with open(join(srcroot, 'doc', 'docstrings.py'), 'rb') as fd:
     docstrings_content = fd.read()
@@ -233,7 +186,8 @@
 
 ######################################################################
 # DISTUTILS SETUP
-libraries = []
+libraries = WCSLIB['libraries']
+include_dirs = [numpy_include, join(srcroot, "src")] + WCSLIB['include_dirs']
 define_macros = [('ECHO', None),
                  ('WCSTRIG_MACRO', None),
                  ('PYWCS_BUILD', None),
@@ -282,13 +236,8 @@
 
 PYWCS_EXTENSIONS = [
     Extension('pywcs._pywcs',
-              WCSFILES + PYWCS_SOURCES,
-              include_dirs =
-              [numpy_include,
-               join(srcroot, WCSLIBC),
-               WCSLIBC,
-               join(srcroot, "src")
-               ],
+              PYWCS_SOURCES,
+              include_dirs=include_dirs,
               define_macros=define_macros,
               undef_macros=undef_macros,
               extra_compile_args=extra_compile_args,
@@ -309,7 +258,6 @@
     'ext_modules' : PYWCS_EXTENSIONS,
     'data_files' : [
         ( 'pywcs/include', ['src/*.h']),
-        ( 'pywcs/include/wcslib', [ WCSLIBC + '/*.h'] ),
         ( 'pywcs/tests/maps', ['lib/pywcs/tests/maps/*.hdr']),
         ( 'pywcs/tests/spectra', ['lib/pywcs/tests/spectra/*.hdr']),
         ( 'pywcs/tests/data', ['lib/pywcs/tests/data/*.hdr'])