~ubuntu-branches/ubuntu/wily/python-imaging/wily

« back to all changes in this revision

Viewing changes to debian/patches/toplevel-setup.py

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2013-01-31 20:49:20 UTC
  • mfrom: (1.1.4)
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130131204920-7tnuhqhlsqdza4c2
Rewrite build dependencies to allow cross builds.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
Index: b/setup.py
 
2
===================================================================
 
3
--- a/setup.py
 
4
+++ b/setup.py
 
5
@@ -7,7 +7,13 @@
 
6
 import sys
 
7
 
 
8
 from distutils.command.build_ext import build_ext
 
9
-from distutils import sysconfig
 
10
+try:
 
11
+    import sysconfig
 
12
+    host_platform = sysconfig.get_platform()
 
13
+except:
 
14
+    from distutils import sysconfig
 
15
+    host_platform = sys.platform
 
16
+
 
17
 from setuptools import Extension, setup, find_packages
 
18
 
 
19
 
 
20
@@ -68,6 +74,7 @@
 
21
     import _tkinter
 
22
 except ImportError:
 
23
     _tkinter = None
 
24
+    print('XXXXX _tkinter not found XXXXX')
 
25
 
 
26
 
 
27
 NAME = 'Pillow'
 
28
@@ -83,6 +90,38 @@
 
29
 
 
30
 class pil_build_ext(build_ext):
 
31
 
 
32
+    def add_gcc_paths(self):
 
33
+        gcc = sysconfig.get_config_var('CC')
 
34
+        tmpfile = os.path.join(self.build_temp, 'gccpaths')
 
35
+        if not os.path.exists(self.build_temp):
 
36
+            os.makedirs(self.build_temp)
 
37
+        ret = os.system('%s -E -v - </dev/null 2>%s 1>/dev/null' % (gcc, tmpfile))
 
38
+        is_gcc = False
 
39
+        in_incdirs = False
 
40
+        inc_dirs = []
 
41
+        lib_dirs = []
 
42
+        try:
 
43
+            if ret >> 8 == 0:
 
44
+                with open(tmpfile) as fp:
 
45
+                    for line in fp.readlines():
 
46
+                        if line.startswith("gcc version"):
 
47
+                            is_gcc = True
 
48
+                        elif line.startswith("#include <...>"):
 
49
+                            in_incdirs = True
 
50
+                        elif line.startswith("End of search list"):
 
51
+                            in_incdirs = False
 
52
+                        elif is_gcc and line.startswith("LIBRARY_PATH"):
 
53
+                            for d in line.strip().split("=")[1].split(":"):
 
54
+                                d = os.path.normpath(d)
 
55
+                                if '/gcc/' not in d:
 
56
+                                    _add_directory(self.compiler.library_dirs,
 
57
+                                                   d)
 
58
+                        elif is_gcc and in_incdirs and '/gcc/' not in line:
 
59
+                            _add_directory(self.compiler.include_dirs,
 
60
+                                           line.strip())
 
61
+        finally:
 
62
+            os.unlink(tmpfile)
 
63
+
 
64
     def build_extensions(self):
 
65
 
 
66
         global TCL_ROOT
 
67
@@ -107,12 +146,12 @@
 
68
         #
 
69
         # add platform directories
 
70
 
 
71
-        if sys.platform == "cygwin":
 
72
+        if host_platform == "cygwin":
 
73
             # pythonX.Y.dll.a is in the /usr/lib/pythonX.Y/config directory
 
74
             _add_directory(library_dirs, os.path.join(
 
75
                 "/usr/lib", "python%s" % sys.version[:3], "config"))
 
76
 
 
77
-        elif sys.platform == "darwin":
 
78
+        elif host_platform == "darwin":
 
79
             # attempt to make sure we pick freetype2 over other versions
 
80
             _add_directory(include_dirs, "/sw/include/freetype2")
 
81
             _add_directory(include_dirs, "/sw/lib/freetype2/include")
 
82
@@ -126,10 +165,8 @@
 
83
             _add_directory(library_dirs, "/usr/X11/lib")
 
84
             _add_directory(include_dirs, "/usr/X11/include")
 
85
 
 
86
-        elif sys.platform.startswith("linux"):
 
87
-            # XXX Kludge. Above /\ we brute force support multiarch. Here we
 
88
-            # try Barry's more general approach. Afterward, something should
 
89
-            # work ;-)
 
90
+        elif host_platform.startswith("linux"):
 
91
+            self.add_gcc_paths()
 
92
             self.add_multiarch_paths()
 
93
 
 
94
         _add_directory(library_dirs, "/usr/local/lib")
 
95
@@ -204,13 +241,13 @@
 
96
         if _find_include_file(self, "zlib.h"):
 
97
             if _find_library_file(self, "z"):
 
98
                 feature.zlib = "z"
 
99
-            elif sys.platform == "win32" and _find_library_file(self, "zlib"):
 
100
+            elif host_platform == "win32" and _find_library_file(self, "zlib"):
 
101
                 feature.zlib = "zlib"  # alternative name
 
102
 
 
103
         if _find_include_file(self, "jpeglib.h"):
 
104
             if _find_library_file(self, "jpeg"):
 
105
                 feature.jpeg = "jpeg"
 
106
-            elif sys.platform == "win32" and _find_library_file(self,
 
107
+            elif host_platform == "win32" and _find_library_file(self,
 
108
                     "libjpeg"):
 
109
                 feature.jpeg = "libjpeg"  # alternative name
 
110
 
 
111
@@ -271,7 +308,7 @@
 
112
         if feature.zlib:
 
113
             libs.append(feature.zlib)
 
114
             defs.append(("HAVE_LIBZ", None))
 
115
-        if sys.platform == "win32":
 
116
+        if host_platform == "win32":
 
117
             libs.extend(["kernel32", "user32", "gdi32"])
 
118
         if struct.unpack("h", "\0\1".encode('ascii'))[0] == 1:
 
119
             defs.append(("WORDS_BIGENDIAN", None))
 
120
@@ -296,12 +333,12 @@
 
121
 
 
122
         if os.path.isfile("_imagingcms.c") and feature.lcms:
 
123
             extra = []
 
124
-            if sys.platform == "win32":
 
125
+            if host_platform == "win32":
 
126
                 extra.extend(["user32", "gdi32"])
 
127
             exts.append(Extension(
 
128
                 "_imagingcms", ["_imagingcms.c"], libraries=["lcms"] + extra))
 
129
 
 
130
-        if sys.platform == "darwin":
 
131
+        if host_platform == "darwin":
 
132
             # locate Tcl/Tk frameworks
 
133
             frameworks = []
 
134
             framework_roots = [
 
135
@@ -351,7 +388,7 @@
 
136
         print("-" * 68)
 
137
         print("version      %s" % VERSION)
 
138
         v = sys.version.split("[")
 
139
-        print("platform     %s %s" % (sys.platform, v[0].strip()))
 
140
+        print("platform     %s %s" % (host_platform, v[0].strip()))
 
141
         for v in v[1:]:
 
142
             print("             [%s" % v.strip())
 
143
         print("-" * 68)