[pypy-commit] cffi default: Fix setup.py for cross-compilation (thanks Sarvi).

arigo noreply at buildbot.pypy.org
Sat Aug 25 01:25:15 CEST 2012


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r894:58766b1bee00
Date: 2012-08-25 01:24 +0200
http://bitbucket.org/cffi/cffi/changeset/58766b1bee00/

Log:	Fix setup.py for cross-compilation (thanks Sarvi).

diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -13,9 +13,10 @@
 extra_link_args = []
 
 
-def _ask_pkg_config(resultlist, option, result_prefix=''):
+def _ask_pkg_config(resultlist, option, result_prefix='', sysroot=False):
+    pkg_config = os.environ.get('PKG_CONFIG','pkg-config')
     try:
-        p = subprocess.Popen(['pkg-config', option, 'libffi'],
+        p = subprocess.Popen([pkg_config, option, 'libffi'],
                              stdout=subprocess.PIPE)
     except OSError as e:
         if e.errno != errno.ENOENT:
@@ -29,12 +30,21 @@
                 assert x.startswith(result_prefix)
             res = [x[len(result_prefix):] for x in res]
             #print 'PKG_CONFIG:', option, res
+            #
+            sysroot = sysroot and os.environ.get('PKG_CONFIG_SYSROOT_DIR', '')
+            if sysroot:
+                # old versions of pkg-config don't support this env var,
+                # so here we emulate its effect if needed
+                res = [path if path.startswith(sysroot)
+                            else sysroot + path
+                         for path in res]
+            #
             resultlist[:] = res
 
 def use_pkg_config():
-    _ask_pkg_config(include_dirs,       '--cflags-only-I', '-I')
+    _ask_pkg_config(include_dirs,       '--cflags-only-I', '-I', sysroot=True)
     _ask_pkg_config(extra_compile_args, '--cflags-only-other')
-    _ask_pkg_config(library_dirs,       '--libs-only-L', '-L')
+    _ask_pkg_config(library_dirs,       '--libs-only-L', '-L', sysroot=True)
     _ask_pkg_config(extra_link_args,    '--libs-only-other')
     _ask_pkg_config(libraries,          '--libs-only-l', '-l')
 


More information about the pypy-commit mailing list