From 507bd000843fb52445fdb8e6352400edacd5dd47 Mon Sep 17 00:00:00 2001 From: Ray Donnelly Date: Sat, 12 Mar 2016 18:48:46 +0000 Subject: [PATCH 5/5] Use pkg-config, add LIBALPM_STATIC env. var --- setup.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git setup.py setup.py index 44507a9..407057f 100644 --- setup.py +++ setup.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- import os from distutils.core import Extension, setup +import subprocess os.putenv('LC_CTYPE', 'en_US.UTF-8') @@ -12,11 +13,21 @@ cflags = ['-Wall', '-Wextra', cflags = ['-Wall', '-Wextra', '-Werror', '-Wno-unused-parameter', '-Wno-incompatible-pointer-types', - '-Wno-cast-function-type', '-std=c99', '-D_FILE_OFFSET_BITS=64'] + '-Wno-unused-function', '-Wno-strict-aliasing', '-std=c99', '-D_FILE_OFFSET_BITS=64', + '-DVERSION="%s"' % pyalpm_version] + +# From: http://code.activestate.com/recipes/502261-python-distutils-pkg-config/ +def pkg_config(*pkg_config_flags, **kw): + flag_map = {'-I': 'include_dirs', '-L': 'library_dirs', '-l': 'libraries'} + kw['extra_compile_args'] = cflags + for token in subprocess.check_output(("pkg-config --libs --cflags %s" % ' '.join(pkg_config_flags)).split()).decode('ascii').split(): + if token[:2] in flag_map: + kw.setdefault(flag_map.get(token[:2]), []).append(token[2:]) + else: + kw['extra_compile_args'].append(token) + return kw alpm = Extension('pyalpm', - libraries = ['alpm'], - extra_compile_args = cflags + ['-DVERSION="%s"' % pyalpm_version], language = 'C', sources = [ 'src/pyalpm.c', @@ -34,7 +45,9 @@ alpm = Extension('pyalpm', 'src/package.h', 'src/pyalpm.h', 'src/util.h', - ]) + ], + **pkg_config('libalpm', '--static' if os.getenv('LIBALPM_STATIC') else '') + ) setup(name = 'pyalpm', version = pyalpm_version, -- 2.7.1