diff options
-rw-r--r-- | setup.py | 42 | ||||
-rw-r--r-- | setup_base.py | 4 |
2 files changed, 35 insertions, 11 deletions
@@ -7,6 +7,36 @@ sources = ['c/_cffi_backend.c'] 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 @@ if COMPILE_LIBFFI: 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 index 549d327..7582535 100644 --- a/setup_base.py +++ b/setup_base.py @@ -2,6 +2,7 @@ import sys, os 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 @@ if __name__ == '__main__': sources=sources, libraries=libraries, define_macros=define_macros, + library_dirs=library_dirs, + extra_compile_args=extra_compile_args, + extra_link_args=extra_link_args, )]) |