From e68a0036a4f987202665dced642ce182d78d73e5 Mon Sep 17 00:00:00 2001 From: John Szakmeister Date: Mon, 28 Feb 2011 05:21:12 -0500 Subject: [PATCH] Fix distutils to carry configure's LIBS through to extension modules. Port of r301 from Unladen Swallow. Had to add some filtering for it to work properly under py3k-jit. --- Lib/distutils/ccompiler.py | 16 ++++++++++++++-- Lib/distutils/command/build_ext.py | 3 ++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/Lib/distutils/ccompiler.py b/Lib/distutils/ccompiler.py index 1a4e8fb..685b95d 100644 --- a/Lib/distutils/ccompiler.py +++ b/Lib/distutils/ccompiler.py @@ -27,10 +27,11 @@ def customize_compiler(compiler): varies across Unices and is stored in Python's Makefile. """ if compiler.compiler_type == "unix": - (cc, cxx, opt, cflags, ccshared, ldshared, so_ext, ar, ar_flags) = \ + (cc, cxx, opt, cflags, ccshared, ldshared, so_ext, + ar, ar_flags, libs) = \ _sysconfig.get_config_vars('CC', 'CXX', 'OPT', 'CFLAGS', 'CCSHARED', 'LDSHARED', 'SO', 'AR', - 'ARFLAGS') + 'ARFLAGS', 'LIBS') if 'CC' in os.environ: cc = os.environ['CC'] @@ -57,6 +58,8 @@ def customize_compiler(compiler): archiver = ar + ' ' + os.environ['ARFLAGS'] else: archiver = ar + ' ' + ar_flags + if 'LIBS' in os.environ: + libs = os.environ['LIBS'] cc_cmd = cc + ' ' + cflags compiler.set_executables( @@ -70,6 +73,15 @@ def customize_compiler(compiler): compiler.shared_lib_extension = so_ext + for chunk in libs.split(" "): + if not chunk: + continue + if chunk.startswith("-l"): + chunk = chunk[2:] + elif chunk.startswith("-") or not chunk.endswith('.a'): + continue + compiler.libraries.append(chunk) + class CCompiler: """Abstract base class to define the interface that must be implemented by real compiler classes. Also has some utility methods used by diff --git a/Lib/distutils/command/build_ext.py b/Lib/distutils/command/build_ext.py index 8f41fac..7cd4bab 100644 --- a/Lib/distutils/command/build_ext.py +++ b/Lib/distutils/command/build_ext.py @@ -381,7 +381,8 @@ class build_ext(Command): for macro in self.undef: self.compiler_obj.undefine_macro(macro) if self.libraries is not None: - self.compiler_obj.set_libraries(self.libraries) + for lib in self.libraries: + self.compiler.add_library(lib) if self.library_dirs is not None: self.compiler_obj.set_library_dirs(self.library_dirs) if self.rpath is not None: -- 1.7.4.1