Commit 52314a98 authored by André Anjos's avatar André Anjos 💬

Add (uncommited changes for 0.1.5)

parent 2f8318b4
......@@ -11,7 +11,7 @@ from setuptools import setup, find_packages
setup(
name="xbob.extension",
version="0.1.4",
version="0.1.5",
description="Helps projects building Python/C++ extensions for Bob",
license="GPLv3",
author='Andre Anjos',
......
......@@ -6,8 +6,10 @@
"""A custom build class for Bob/Python extensions
"""
import os
import subprocess
from distutils.extension import Extension as ExtensionBase
from setuptools.command.build_ext import build_ext as build_ext_base
def pkgconfig(package):
......@@ -158,3 +160,48 @@ class Extension(ExtensionBase):
# Run the constructor for the base class
ExtensionBase.__init__(self, *args, **kwargs)
class build_ext(build_ext_base):
'''Customized extension to build bob.python bindings in the expected way'''
linker_is_smart = None
def __init__(self, *args, **kwargs):
build_ext_base.__init__(self, *args, **kwargs)
def build_extension(self, ext):
'''Concretely builds the extension given as input'''
def linker_can_remove_symbols(linker):
'''Tests if the `ld` linker can remove unused symbols from linked
libraries. In this case, use the --no-as-needed flag during link'''
import tempfile
f, name = tempfile.mkstemp()
del f
cmd = linker + ['-Wl,--no-as-needed', '-lm', '-o', name]
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
output = proc.communicate()[0]
if os.path.exists(name): os.unlink(name)
return True if proc.returncode == 0 else False
def ld_ok(opt):
'''Tells if a certain option is a go for the linker'''
if opt.find('-L') == 0: return False
return True
# Some clean-up on the linker which is screwed up...
self.compiler.linker_so = [k for k in self.compiler.linker_so if ld_ok(k)]
if self.linker_is_smart is None:
self.linker_is_smart = linker_can_remove_symbols(self.compiler.linker_so)
if self.linker_is_smart: self.compiler.linker_so += ['-Wl,--no-as-needed']
if hasattr(self.compiler, 'dll_libraries') and \
self.compiler.dll_libraries is None:
self.compiler.dll_libraries = []
build_ext_base.build_extension(self, ext)
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