[pypy-commit] cffi default: Trying to use pkg-config to more systematically get installation

arigo noreply at buildbot.pypy.org
Sat Jul 21 23:29:49 CEST 2012


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r672:0e2a312b807b
Date: 2012-07-21 23:29 +0200
http://bitbucket.org/cffi/cffi/changeset/0e2a312b807b/

Log:	Trying to use pkg-config to more systematically get installation
	information about libffi.

diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -7,6 +7,36 @@
 libraries = ['ffi']
 include_dirs = []
 define_macros = []
+library_dirs = []
+extra_compile_args = []
+extra_link_args = []
+
+
+def _ask_pkg_config(option, result_prefix=''):
+    try:
+        p = subprocess.Popen(['pkg-config', option, 'libffi'],
+                             stdout=subprocess.PIPE, stderr=open('/dev/null', 'w'))
+    except OSError, e:
+        if e.errno != errno.ENOENT:
+            raise
+    else:
+        t = p.stdout.read().strip()
+        if p.wait() == 0:
+            res = t.split()
+            # '-I/usr/...' -> '/usr/...'
+            for x in res:
+                assert x.startswith(result_prefix)
+            res = [x[len(result_prefix):] for x in res]
+            #print 'PKG_CONFIG:', option, res
+            return res
+    return []
+
+def use_pkg_config():
+    include_dirs      .extend(_ask_pkg_config('--cflags-only-I', '-I'))
+    extra_compile_args.extend(_ask_pkg_config('--cflags-only-other'))
+    library_dirs      .extend(_ask_pkg_config('--libs-only-L', '-L'))
+    extra_link_args   .extend(_ask_pkg_config('--libs-only-other'))
+    libraries[:] = _ask_pkg_config('--libs-only-l', '-l') or libraries
 
 
 if sys.platform == 'win32':
@@ -33,17 +63,7 @@
                    for filename in _filenames)
     define_macros.append(('USE_C_LIBFFI_MSVC', '1'))
 else:
-    try:
-        p = subprocess.Popen(['pkg-config', '--cflags-only-I', 'libffi'],
-                             stdout=subprocess.PIPE, stderr=open('/dev/null', 'w'))
-    except OSError, e:
-        if e.errno != errno.ENOENT:
-            raise
-    else:
-        t = p.stdout.read().strip()
-        if p.wait() == 0 and t:
-            # '-I/usr/...' -> '/usr/...'
-            include_dirs.append(t[2:])
+    use_pkg_config()
 
 
 if __name__ == '__main__':
diff --git a/setup_base.py b/setup_base.py
--- a/setup_base.py
+++ b/setup_base.py
@@ -2,6 +2,7 @@
 
 
 from setup import include_dirs, sources, libraries, define_macros
+from setup import library_dirs, extra_compile_args, extra_link_args
 
 
 if __name__ == '__main__':
@@ -14,4 +15,7 @@
                                  sources=sources,
                                  libraries=libraries,
                                  define_macros=define_macros,
+                                 library_dirs=library_dirs,
+                                 extra_compile_args=extra_compile_args,
+                                 extra_link_args=extra_link_args,
                                  )])


More information about the pypy-commit mailing list