Commit cac8be21 authored by André Anjos's avatar André Anjos 💬

Automatically include HAVE and VERSION flags

parent 52314a98
......@@ -11,7 +11,7 @@ from setuptools import setup, find_packages
setup(
name="xbob.extension",
version="0.1.5",
version="0.1.6",
description="Helps projects building Python/C++ extensions for Bob",
license="GPLv3",
author='Andre Anjos',
......
......@@ -7,6 +7,7 @@
"""
import os
import string
import subprocess
from distutils.extension import Extension as ExtensionBase
from setuptools.command.build_ext import build_ext as build_ext_base
......@@ -29,6 +30,23 @@ def pkgconfig(package):
result.append(item)
return result
cmd = [
'pkg-config',
'--modversion',
package,
]
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
output = proc.communicate()[0]
if proc.returncode != 0:
raise RuntimeError, "PkgConfig did not find package %s. Output:\n%s" % \
(package, output.strip())
version = output.strip()
flag_map = {
'-I': 'include_dirs',
'-L': 'library_dirs',
......@@ -74,6 +92,13 @@ def pkgconfig(package):
for k, v in kw.iteritems(): # remove duplicated
kw[k] = uniq(v)
# adds version and HAVE flags
PACKAGE = package.upper().translate(string.maketrans(" -", "__"))
kw['define_macros'] = [
('HAVE_%s' % PACKAGE, '1'),
('%s_VERSION' % PACKAGE, '"%s"' % version),
]
return kw
def uniq(seq):
......@@ -125,6 +150,7 @@ class Extension(ExtensionBase):
'include_dirs': [],
'library_dirs': [],
'libraries': [],
'define_macros': [],
}
for m in modules:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment