]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
python-lxc: search for lxc library and headers using pkg-config 1031/head
authorAleksandr Mezin <mezin.alexander@gmail.com>
Fri, 27 May 2016 11:58:15 +0000 (17:58 +0600)
committerAleksandr Mezin <mezin.alexander@gmail.com>
Fri, 27 May 2016 16:23:02 +0000 (22:23 +0600)
Signed-off-by: Aleksandr Mezin <mezin.alexander@gmail.com>
src/python-lxc/Makefile.am
src/python-lxc/setup.py

index cbb274721123ac7efb6667a751abcec3c16ad1a4..4a2b86e7b93cfa5dc593dd3c276f55489c8a3a67 100644 (file)
@@ -10,7 +10,7 @@ INSTALL_OPTS := install --prefix=$(prefix) --no-compile $(DISTSETUPOPTS)
 CALL_SETUP_PY := cd @srcdir@ && $(PYTHON) setup.py build -b @abs_builddir@/build
 
 all:
-       $(CALL_SETUP_PY) build_ext -I @abs_top_srcdir@/src -L @abs_top_builddir@/src/lxc
+       $(CALL_SETUP_PY) build_ext -I @abs_top_srcdir@/src -L @abs_top_builddir@/src/lxc --no-pkg-config
 
 install:
        if [ -z "$(DESTDIR)" ]; then \
index d8cb166a0eb3a8359f94b334394fff0b98ddfbd2..c9c201436792aee16caf8f5af7172f82f96b1ffc 100644 (file)
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301
 # USA
 
+import os
+import subprocess
+
 from distutils.core import setup, Extension
+from distutils.command.build_ext import build_ext as BuildExtCommand
+
+
+class LxcBuildExtCommand(BuildExtCommand):
+    user_options = BuildExtCommand.user_options + [
+        ('no-pkg-config', None,
+         "don't use pkg-config to detect include/library paths")
+    ]
+
+    def initialize_options(self):
+        super(LxcBuildExtCommand, self).initialize_options()
+        self.no_pkg_config = False
+
+    def build_extensions(self):
+        if not self.no_pkg_config:
+            pkg_config_executable = os.environ.get('PKG_CONFIG_EXECUTABLE',
+                                                   'pkg-config')
+
+            def get_pkg_config_var(name):
+                args = [pkg_config_executable, '--variable', name, 'lxc']
+                output = subprocess.check_output(args,
+                                                 universal_newlines=True)
+                return output.rstrip('\n')
+
+            try:
+                includedir = get_pkg_config_var('includedir')
+                libdir = get_pkg_config_var('libdir')
+
+                self.compiler.add_include_dir(includedir)
+                self.compiler.add_library_dir(libdir)
+
+            except subprocess.CalledProcessError:
+                pass
+
+        super(LxcBuildExtCommand, self).build_extensions()
 
 
 setup(name='_lxc',
@@ -31,4 +69,5 @@ setup(name='_lxc',
       packages=['lxc'],
       package_dir={'lxc': 'lxc'},
       ext_modules=[Extension('_lxc', sources=['lxc.c'], libraries=['lxc'])],
+      cmdclass={'build_ext': LxcBuildExtCommand},
       )