Greg Ward | e393ddb | 1999-08-14 23:57:49 +0000 | [diff] [blame] | 1 | """distutils.command.build_ext |
| 2 | |
| 3 | Implements the Distutils 'build_ext' command, for building extension |
Jeremy Hylton | a05e293 | 2000-06-28 14:48:01 +0000 | [diff] [blame] | 4 | modules (currently limited to C extensions, should accommodate C++ |
Greg Ward | e393ddb | 1999-08-14 23:57:49 +0000 | [diff] [blame] | 5 | extensions ASAP).""" |
| 6 | |
Neal Norwitz | 9d72bb4 | 2007-04-17 08:48:32 +0000 | [diff] [blame] | 7 | import sys, os, re |
Greg Ward | e393ddb | 1999-08-14 23:57:49 +0000 | [diff] [blame] | 8 | from distutils.core import Command |
Tarek Ziadé | edacea3 | 2010-01-29 11:41:03 +0000 | [diff] [blame] | 9 | from distutils.errors import * |
Tarek Ziadé | 3679727 | 2010-07-22 12:50:05 +0000 | [diff] [blame] | 10 | from distutils.sysconfig import customize_compiler, get_python_version |
Vinay Sajip | 8cffdd9 | 2012-07-16 18:30:03 +0100 | [diff] [blame] | 11 | from distutils.sysconfig import get_config_h_filename |
Greg Ward | 5213400 | 2000-05-26 01:31:53 +0000 | [diff] [blame] | 12 | from distutils.dep_util import newer_group |
Greg Ward | 5322f00 | 2000-05-31 01:09:52 +0000 | [diff] [blame] | 13 | from distutils.extension import Extension |
Tarek Ziadé | 3679727 | 2010-07-22 12:50:05 +0000 | [diff] [blame] | 14 | from distutils.util import get_platform |
Jeremy Hylton | cd8a114 | 2002-06-04 20:14:43 +0000 | [diff] [blame] | 15 | from distutils import log |
Greg Ward | e393ddb | 1999-08-14 23:57:49 +0000 | [diff] [blame] | 16 | |
Tarek Ziadé | 38e3d51 | 2009-02-27 12:58:56 +0000 | [diff] [blame] | 17 | # this keeps compatibility from 2.3 to 2.5 |
| 18 | if sys.version < "2.6": |
| 19 | USER_BASE = None |
| 20 | HAS_USER_SITE = False |
| 21 | else: |
| 22 | from site import USER_BASE |
| 23 | HAS_USER_SITE = True |
| 24 | |
Christian Heimes | cbf3b5c | 2007-12-03 21:02:03 +0000 | [diff] [blame] | 25 | if os.name == 'nt': |
| 26 | from distutils.msvccompiler import get_build_version |
| 27 | MSVC_VERSION = int(get_build_version()) |
| 28 | |
Greg Ward | dbb9625 | 1999-09-21 18:27:12 +0000 | [diff] [blame] | 29 | # An extension name is just a dot-separated list of Python NAMEs (ie. |
| 30 | # the same as a fully-qualified module name). |
| 31 | extension_name_re = re.compile \ |
| 32 | (r'^[a-zA-Z_][a-zA-Z_0-9]*(\.[a-zA-Z_][a-zA-Z_0-9]*)*$') |
Greg Ward | e393ddb | 1999-08-14 23:57:49 +0000 | [diff] [blame] | 33 | |
| 34 | |
Greg Ward | 3459381 | 2000-06-24 01:23:37 +0000 | [diff] [blame] | 35 | def show_compilers (): |
| 36 | from distutils.ccompiler import show_compilers |
| 37 | show_compilers() |
| 38 | |
| 39 | |
Collin Winter | 5b7e9d7 | 2007-08-30 03:52:21 +0000 | [diff] [blame] | 40 | class build_ext(Command): |
Fred Drake | 21d4535 | 2001-12-06 21:01:19 +0000 | [diff] [blame] | 41 | |
Greg Ward | 37bc815 | 2000-01-30 18:34:15 +0000 | [diff] [blame] | 42 | description = "build C/C++ extensions (compile/link to build directory)" |
| 43 | |
Greg Ward | e393ddb | 1999-08-14 23:57:49 +0000 | [diff] [blame] | 44 | # XXX thoughts on how to deal with complex command-line options like |
| 45 | # these, i.e. how to make it so fancy_getopt can suck them off the |
| 46 | # command line and make it look like setup.py defined the appropriate |
| 47 | # lists of tuples of what-have-you. |
| 48 | # - each command needs a callback to process its command-line options |
| 49 | # - Command.__init__() needs access to its share of the whole |
| 50 | # command line (must ultimately come from |
| 51 | # Distribution.parse_command_line()) |
| 52 | # - it then calls the current command class' option-parsing |
| 53 | # callback to deal with weird options like -D, which have to |
| 54 | # parse the option text and churn out some custom data |
| 55 | # structure |
| 56 | # - that data structure (in this case, a list of 2-tuples) |
| 57 | # will then be present in the command object by the time |
Greg Ward | e01149c | 2000-02-18 00:35:22 +0000 | [diff] [blame] | 58 | # we get to finalize_options() (i.e. the constructor |
Greg Ward | e393ddb | 1999-08-14 23:57:49 +0000 | [diff] [blame] | 59 | # takes care of both command-line and client options |
Greg Ward | e01149c | 2000-02-18 00:35:22 +0000 | [diff] [blame] | 60 | # in between initialize_options() and finalize_options()) |
Greg Ward | e393ddb | 1999-08-14 23:57:49 +0000 | [diff] [blame] | 61 | |
Greg Ward | 9ae7c3c | 2000-09-16 01:44:45 +0000 | [diff] [blame] | 62 | sep_by = " (separated by '%s')" % os.pathsep |
Greg Ward | bbeceea | 2000-02-18 00:25:39 +0000 | [diff] [blame] | 63 | user_options = [ |
Greg Ward | e51d69e | 2000-03-01 01:43:28 +0000 | [diff] [blame] | 64 | ('build-lib=', 'b', |
Greg Ward | bbeceea | 2000-02-18 00:25:39 +0000 | [diff] [blame] | 65 | "directory for compiled extension modules"), |
Greg Ward | e51d69e | 2000-03-01 01:43:28 +0000 | [diff] [blame] | 66 | ('build-temp=', 't', |
| 67 | "directory for temporary files (build by-products)"), |
Christian Heimes | 5e69685 | 2008-04-09 08:37:03 +0000 | [diff] [blame] | 68 | ('plat-name=', 'p', |
| 69 | "platform name to cross-compile for, if supported " |
| 70 | "(default: %s)" % get_platform()), |
Greg Ward | e51d69e | 2000-03-01 01:43:28 +0000 | [diff] [blame] | 71 | ('inplace', 'i', |
Greg Ward | 6a2035d | 2000-09-06 02:06:27 +0000 | [diff] [blame] | 72 | "ignore build-lib and put compiled extensions into the source " + |
Greg Ward | e51d69e | 2000-03-01 01:43:28 +0000 | [diff] [blame] | 73 | "directory alongside your pure Python modules"), |
Greg Ward | bbeceea | 2000-02-18 00:25:39 +0000 | [diff] [blame] | 74 | ('include-dirs=', 'I', |
Greg Ward | 9ae7c3c | 2000-09-16 01:44:45 +0000 | [diff] [blame] | 75 | "list of directories to search for header files" + sep_by), |
Greg Ward | bbeceea | 2000-02-18 00:25:39 +0000 | [diff] [blame] | 76 | ('define=', 'D', |
| 77 | "C preprocessor macros to define"), |
| 78 | ('undef=', 'U', |
| 79 | "C preprocessor macros to undefine"), |
Greg Ward | cdb20ba | 2000-03-26 21:45:14 +0000 | [diff] [blame] | 80 | ('libraries=', 'l', |
Greg Ward | bbeceea | 2000-02-18 00:25:39 +0000 | [diff] [blame] | 81 | "external C libraries to link with"), |
| 82 | ('library-dirs=', 'L', |
Greg Ward | 9ae7c3c | 2000-09-16 01:44:45 +0000 | [diff] [blame] | 83 | "directories to search for external C libraries" + sep_by), |
Greg Ward | bbeceea | 2000-02-18 00:25:39 +0000 | [diff] [blame] | 84 | ('rpath=', 'R', |
| 85 | "directories to search for shared C libraries at runtime"), |
| 86 | ('link-objects=', 'O', |
| 87 | "extra explicit link objects to include in the link"), |
| 88 | ('debug', 'g', |
| 89 | "compile/link with debugging information"), |
Greg Ward | c41d6b3 | 2000-04-10 00:19:42 +0000 | [diff] [blame] | 90 | ('force', 'f', |
Gregory P. Smith | 6cd0c43 | 2000-05-12 00:34:12 +0000 | [diff] [blame] | 91 | "forcibly build everything (ignore file timestamps)"), |
| 92 | ('compiler=', 'c', |
| 93 | "specify the compiler type"), |
Greg Ward | f3bd747 | 2000-06-27 01:37:10 +0000 | [diff] [blame] | 94 | ('swig-cpp', None, |
| 95 | "make SWIG create C++ files (default is C)"), |
Anthony Baxter | a024034 | 2004-10-14 10:02:08 +0000 | [diff] [blame] | 96 | ('swig-opts=', None, |
| 97 | "list of SWIG command line options"), |
| 98 | ('swig=', None, |
| 99 | "path to the SWIG executable"), |
Greg Ward | bbeceea | 2000-02-18 00:25:39 +0000 | [diff] [blame] | 100 | ] |
Greg Ward | 3459381 | 2000-06-24 01:23:37 +0000 | [diff] [blame] | 101 | |
Tarek Ziadé | 38e3d51 | 2009-02-27 12:58:56 +0000 | [diff] [blame] | 102 | boolean_options = ['inplace', 'debug', 'force', 'swig-cpp'] |
| 103 | |
| 104 | if HAS_USER_SITE: |
| 105 | user_options.append(('user', None, |
| 106 | "add user include, library and rpath")) |
| 107 | boolean_options.append('user') |
Greg Ward | 99b032e | 2000-09-25 01:41:15 +0000 | [diff] [blame] | 108 | |
Greg Ward | 9d17a7a | 2000-06-07 03:00:06 +0000 | [diff] [blame] | 109 | help_options = [ |
| 110 | ('help-compiler', None, |
Greg Ward | 3459381 | 2000-06-24 01:23:37 +0000 | [diff] [blame] | 111 | "list available compilers", show_compilers), |
Greg Ward | 0419a4f | 2000-08-01 23:54:29 +0000 | [diff] [blame] | 112 | ] |
Greg Ward | e393ddb | 1999-08-14 23:57:49 +0000 | [diff] [blame] | 113 | |
Collin Winter | 5b7e9d7 | 2007-08-30 03:52:21 +0000 | [diff] [blame] | 114 | def initialize_options(self): |
Greg Ward | 71eb864 | 1999-09-08 02:42:30 +0000 | [diff] [blame] | 115 | self.extensions = None |
Greg Ward | e51d69e | 2000-03-01 01:43:28 +0000 | [diff] [blame] | 116 | self.build_lib = None |
Christian Heimes | 5e69685 | 2008-04-09 08:37:03 +0000 | [diff] [blame] | 117 | self.plat_name = None |
Greg Ward | e51d69e | 2000-03-01 01:43:28 +0000 | [diff] [blame] | 118 | self.build_temp = None |
| 119 | self.inplace = 0 |
Greg Ward | 609a5c8 | 1999-09-13 13:55:34 +0000 | [diff] [blame] | 120 | self.package = None |
| 121 | |
Greg Ward | e393ddb | 1999-08-14 23:57:49 +0000 | [diff] [blame] | 122 | self.include_dirs = None |
| 123 | self.define = None |
| 124 | self.undef = None |
Greg Ward | cdb20ba | 2000-03-26 21:45:14 +0000 | [diff] [blame] | 125 | self.libraries = None |
Greg Ward | e393ddb | 1999-08-14 23:57:49 +0000 | [diff] [blame] | 126 | self.library_dirs = None |
| 127 | self.rpath = None |
| 128 | self.link_objects = None |
Greg Ward | e8c6ce4 | 2000-02-09 02:20:14 +0000 | [diff] [blame] | 129 | self.debug = None |
Greg Ward | c41d6b3 | 2000-04-10 00:19:42 +0000 | [diff] [blame] | 130 | self.force = None |
Gregory P. Smith | 6cd0c43 | 2000-05-12 00:34:12 +0000 | [diff] [blame] | 131 | self.compiler = None |
Anthony Baxter | a024034 | 2004-10-14 10:02:08 +0000 | [diff] [blame] | 132 | self.swig = None |
Greg Ward | f3bd747 | 2000-06-27 01:37:10 +0000 | [diff] [blame] | 133 | self.swig_cpp = None |
Anthony Baxter | a024034 | 2004-10-14 10:02:08 +0000 | [diff] [blame] | 134 | self.swig_opts = None |
Alexandre Vassalotti | 6461e10 | 2008-05-15 22:09:29 +0000 | [diff] [blame] | 135 | self.user = None |
Greg Ward | a6cb8ae | 1999-09-29 12:49:35 +0000 | [diff] [blame] | 136 | |
Collin Winter | 5b7e9d7 | 2007-08-30 03:52:21 +0000 | [diff] [blame] | 137 | def finalize_options(self): |
Tarek Ziadé | 3679727 | 2010-07-22 12:50:05 +0000 | [diff] [blame] | 138 | from distutils import sysconfig |
| 139 | |
Greg Ward | cb1f4c4 | 2000-09-30 18:27:54 +0000 | [diff] [blame] | 140 | self.set_undefined_options('build', |
| 141 | ('build_lib', 'build_lib'), |
| 142 | ('build_temp', 'build_temp'), |
| 143 | ('compiler', 'compiler'), |
| 144 | ('debug', 'debug'), |
Christian Heimes | 5e69685 | 2008-04-09 08:37:03 +0000 | [diff] [blame] | 145 | ('force', 'force'), |
| 146 | ('plat_name', 'plat_name'), |
| 147 | ) |
Greg Ward | e393ddb | 1999-08-14 23:57:49 +0000 | [diff] [blame] | 148 | |
Greg Ward | 609a5c8 | 1999-09-13 13:55:34 +0000 | [diff] [blame] | 149 | if self.package is None: |
Greg Ward | dbb9625 | 1999-09-21 18:27:12 +0000 | [diff] [blame] | 150 | self.package = self.distribution.ext_package |
| 151 | |
| 152 | self.extensions = self.distribution.ext_modules |
Fred Drake | 21d4535 | 2001-12-06 21:01:19 +0000 | [diff] [blame] | 153 | |
Martin v. Löwis | 4f1cd8b | 2001-07-26 13:41:06 +0000 | [diff] [blame] | 154 | # Make sure Python's include directories (for Python.h, pyconfig.h, |
Greg Ward | 1561ae1 | 2000-04-14 00:50:49 +0000 | [diff] [blame] | 155 | # etc.) are in the include search path. |
Tarek Ziadé | 3679727 | 2010-07-22 12:50:05 +0000 | [diff] [blame] | 156 | py_include = sysconfig.get_python_inc() |
| 157 | plat_py_include = sysconfig.get_python_inc(plat_specific=1) |
Greg Ward | e393ddb | 1999-08-14 23:57:49 +0000 | [diff] [blame] | 158 | if self.include_dirs is None: |
Greg Ward | dbb9625 | 1999-09-21 18:27:12 +0000 | [diff] [blame] | 159 | self.include_dirs = self.distribution.include_dirs or [] |
Guido van Rossum | 3172c5d | 2007-10-16 18:12:55 +0000 | [diff] [blame] | 160 | if isinstance(self.include_dirs, str): |
Neal Norwitz | 9d72bb4 | 2007-04-17 08:48:32 +0000 | [diff] [blame] | 161 | self.include_dirs = self.include_dirs.split(os.pathsep) |
Greg Ward | a6cb8ae | 1999-09-29 12:49:35 +0000 | [diff] [blame] | 162 | |
Vinay Sajip | e87acc1 | 2012-10-23 20:26:14 +0100 | [diff] [blame] | 163 | # If in a virtualenv, add its include directory |
| 164 | # Issue 16116 |
| 165 | if sys.exec_prefix != sys.base_exec_prefix: |
| 166 | self.include_dirs.append(os.path.join(sys.exec_prefix, 'include')) |
| 167 | |
Greg Ward | 1d16a9f | 2000-03-29 04:13:49 +0000 | [diff] [blame] | 168 | # Put the Python "system" include dir at the end, so that |
| 169 | # any local include dirs take precedence. |
Greg Ward | cb1f4c4 | 2000-09-30 18:27:54 +0000 | [diff] [blame] | 170 | self.include_dirs.append(py_include) |
Greg Ward | 1561ae1 | 2000-04-14 00:50:49 +0000 | [diff] [blame] | 171 | if plat_py_include != py_include: |
Greg Ward | cb1f4c4 | 2000-09-30 18:27:54 +0000 | [diff] [blame] | 172 | self.include_dirs.append(plat_py_include) |
Greg Ward | e393ddb | 1999-08-14 23:57:49 +0000 | [diff] [blame] | 173 | |
Éric Araujo | b2f5c0a | 2012-02-15 16:44:37 +0100 | [diff] [blame] | 174 | self.ensure_string_list('libraries') |
Greg Ward | dedd5b5 | 2000-03-18 15:21:03 +0000 | [diff] [blame] | 175 | |
Greg Ward | 8422964 | 2000-03-31 03:50:23 +0000 | [diff] [blame] | 176 | # Life is easier if we're not forever checking for None, so |
| 177 | # simplify these options to empty lists if unset |
| 178 | if self.libraries is None: |
| 179 | self.libraries = [] |
| 180 | if self.library_dirs is None: |
| 181 | self.library_dirs = [] |
Guido van Rossum | 3172c5d | 2007-10-16 18:12:55 +0000 | [diff] [blame] | 182 | elif isinstance(self.library_dirs, str): |
Neal Norwitz | 9d72bb4 | 2007-04-17 08:48:32 +0000 | [diff] [blame] | 183 | self.library_dirs = self.library_dirs.split(os.pathsep) |
Andrew M. Kuchling | 27eba5e | 2001-02-17 04:48:41 +0000 | [diff] [blame] | 184 | |
Greg Ward | 8422964 | 2000-03-31 03:50:23 +0000 | [diff] [blame] | 185 | if self.rpath is None: |
| 186 | self.rpath = [] |
Guido van Rossum | 3172c5d | 2007-10-16 18:12:55 +0000 | [diff] [blame] | 187 | elif isinstance(self.rpath, str): |
Neal Norwitz | 9d72bb4 | 2007-04-17 08:48:32 +0000 | [diff] [blame] | 188 | self.rpath = self.rpath.split(os.pathsep) |
Greg Ward | c185467 | 2000-02-05 02:23:16 +0000 | [diff] [blame] | 189 | |
Greg Ward | 8422964 | 2000-03-31 03:50:23 +0000 | [diff] [blame] | 190 | # for extensions under windows use different directories |
| 191 | # for Release and Debug builds. |
| 192 | # also Python's library directory must be appended to library_dirs |
| 193 | if os.name == 'nt': |
Christian Heimes | 5e69685 | 2008-04-09 08:37:03 +0000 | [diff] [blame] | 194 | # the 'libs' directory is for binary installs - we assume that |
| 195 | # must be the *native* platform. But we don't really support |
| 196 | # cross-compiling via a binary install anyway, so we let it go. |
Greg Ward | cb1f4c4 | 2000-09-30 18:27:54 +0000 | [diff] [blame] | 197 | self.library_dirs.append(os.path.join(sys.exec_prefix, 'libs')) |
Vinay Sajip | e87acc1 | 2012-10-23 20:26:14 +0100 | [diff] [blame] | 198 | if sys.base_exec_prefix != sys.prefix: # Issue 16116 |
| 199 | self.library_dirs.append(os.path.join(sys.base_exec_prefix, 'libs')) |
Greg Ward | 8422964 | 2000-03-31 03:50:23 +0000 | [diff] [blame] | 200 | if self.debug: |
Greg Ward | cb1f4c4 | 2000-09-30 18:27:54 +0000 | [diff] [blame] | 201 | self.build_temp = os.path.join(self.build_temp, "Debug") |
Greg Ward | 8422964 | 2000-03-31 03:50:23 +0000 | [diff] [blame] | 202 | else: |
Greg Ward | cb1f4c4 | 2000-09-30 18:27:54 +0000 | [diff] [blame] | 203 | self.build_temp = os.path.join(self.build_temp, "Release") |
Andrew M. Kuchling | 506f0b1 | 2001-01-24 15:43:09 +0000 | [diff] [blame] | 204 | |
Thomas Heller | 378498d | 2002-04-25 17:26:37 +0000 | [diff] [blame] | 205 | # Append the source distribution include and library directories, |
| 206 | # this allows distutils on windows to work in the source tree |
Vinay Sajip | 8cffdd9 | 2012-07-16 18:30:03 +0100 | [diff] [blame] | 207 | self.include_dirs.append(os.path.dirname(get_config_h_filename())) |
| 208 | _sys_home = getattr(sys, '_home', None) |
| 209 | if _sys_home: |
| 210 | self.library_dirs.append(_sys_home) |
Brian Curtin | 401f9f3 | 2012-05-13 11:19:23 -0500 | [diff] [blame] | 211 | if MSVC_VERSION >= 9: |
Christian Heimes | 5e69685 | 2008-04-09 08:37:03 +0000 | [diff] [blame] | 212 | # Use the .lib files for the correct architecture |
| 213 | if self.plat_name == 'win32': |
| 214 | suffix = '' |
| 215 | else: |
| 216 | # win-amd64 or win-ia64 |
| 217 | suffix = self.plat_name[4:] |
| 218 | new_lib = os.path.join(sys.exec_prefix, 'PCbuild') |
| 219 | if suffix: |
| 220 | new_lib = os.path.join(new_lib, suffix) |
| 221 | self.library_dirs.append(new_lib) |
| 222 | |
Christian Heimes | cbf3b5c | 2007-12-03 21:02:03 +0000 | [diff] [blame] | 223 | elif MSVC_VERSION == 8: |
| 224 | self.library_dirs.append(os.path.join(sys.exec_prefix, |
Éric Araujo | 60532bd | 2010-12-15 21:07:22 +0000 | [diff] [blame] | 225 | 'PC', 'VS8.0')) |
Hirokazu Yamamoto | 95b1cf6 | 2008-08-14 07:35:13 +0000 | [diff] [blame] | 226 | elif MSVC_VERSION == 7: |
Christian Heimes | cbf3b5c | 2007-12-03 21:02:03 +0000 | [diff] [blame] | 227 | self.library_dirs.append(os.path.join(sys.exec_prefix, |
Christian Heimes | 292d351 | 2008-02-03 16:51:08 +0000 | [diff] [blame] | 228 | 'PC', 'VS7.1')) |
Hirokazu Yamamoto | 95b1cf6 | 2008-08-14 07:35:13 +0000 | [diff] [blame] | 229 | else: |
| 230 | self.library_dirs.append(os.path.join(sys.exec_prefix, |
| 231 | 'PC', 'VC6')) |
Thomas Heller | 378498d | 2002-04-25 17:26:37 +0000 | [diff] [blame] | 232 | |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 233 | # OS/2 (EMX) doesn't support Debug vs Release builds, but has the |
Marc-André Lemburg | 2544f51 | 2002-01-31 18:56:00 +0000 | [diff] [blame] | 234 | # import libraries in its "Config" subdirectory |
| 235 | if os.name == 'os2': |
| 236 | self.library_dirs.append(os.path.join(sys.exec_prefix, 'Config')) |
| 237 | |
Tarek Ziadé | 3679727 | 2010-07-22 12:50:05 +0000 | [diff] [blame] | 238 | # for extensions under Cygwin and AtheOS Python's library directory must be |
Andrew M. Kuchling | 506f0b1 | 2001-01-24 15:43:09 +0000 | [diff] [blame] | 239 | # appended to library_dirs |
Tarek Ziadé | 3679727 | 2010-07-22 12:50:05 +0000 | [diff] [blame] | 240 | if sys.platform[:6] == 'cygwin' or sys.platform[:6] == 'atheos': |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 241 | if sys.executable.startswith(os.path.join(sys.exec_prefix, "bin")): |
Andrew M. Kuchling | 506f0b1 | 2001-01-24 15:43:09 +0000 | [diff] [blame] | 242 | # building third party extensions |
Thomas Heller | 378498d | 2002-04-25 17:26:37 +0000 | [diff] [blame] | 243 | self.library_dirs.append(os.path.join(sys.prefix, "lib", |
Tarek Ziadé | 3679727 | 2010-07-22 12:50:05 +0000 | [diff] [blame] | 244 | "python" + get_python_version(), |
Thomas Heller | 378498d | 2002-04-25 17:26:37 +0000 | [diff] [blame] | 245 | "config")) |
Andrew M. Kuchling | 506f0b1 | 2001-01-24 15:43:09 +0000 | [diff] [blame] | 246 | else: |
| 247 | # building python standard extensions |
| 248 | self.library_dirs.append('.') |
| 249 | |
Tarek Ziadé | 5874ef1 | 2009-02-05 22:56:14 +0000 | [diff] [blame] | 250 | # for extensions under Linux or Solaris with a shared Python library, |
Thomas Wouters | cf297e4 | 2007-02-23 15:07:44 +0000 | [diff] [blame] | 251 | # Python's library directory must be appended to library_dirs |
Tarek Ziadé | 3679727 | 2010-07-22 12:50:05 +0000 | [diff] [blame] | 252 | sysconfig.get_config_var('Py_ENABLE_SHARED') |
Victor Stinner | e674747 | 2011-08-21 00:39:18 +0200 | [diff] [blame] | 253 | if (sys.platform.startswith(('linux', 'gnu', 'sunos')) |
Tarek Ziadé | 3679727 | 2010-07-22 12:50:05 +0000 | [diff] [blame] | 254 | and sysconfig.get_config_var('Py_ENABLE_SHARED')): |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 255 | if sys.executable.startswith(os.path.join(sys.exec_prefix, "bin")): |
Thomas Wouters | cf297e4 | 2007-02-23 15:07:44 +0000 | [diff] [blame] | 256 | # building third party extensions |
Tarek Ziadé | 3679727 | 2010-07-22 12:50:05 +0000 | [diff] [blame] | 257 | self.library_dirs.append(sysconfig.get_config_var('LIBDIR')) |
Thomas Wouters | cf297e4 | 2007-02-23 15:07:44 +0000 | [diff] [blame] | 258 | else: |
| 259 | # building python standard extensions |
| 260 | self.library_dirs.append('.') |
| 261 | |
Andrew M. Kuchling | 7620bbd | 2001-03-17 20:15:41 +0000 | [diff] [blame] | 262 | # The argument parsing will result in self.define being a string, but |
| 263 | # it has to be a list of 2-tuples. All the preprocessor symbols |
| 264 | # specified by the 'define' option will be set to '1'. Multiple |
| 265 | # symbols can be separated with commas. |
Fred Drake | 21d4535 | 2001-12-06 21:01:19 +0000 | [diff] [blame] | 266 | |
Andrew M. Kuchling | 7620bbd | 2001-03-17 20:15:41 +0000 | [diff] [blame] | 267 | if self.define: |
Neal Norwitz | 9d72bb4 | 2007-04-17 08:48:32 +0000 | [diff] [blame] | 268 | defines = self.define.split(',') |
Amaury Forgeot d'Arc | 61cb087 | 2008-07-26 20:09:45 +0000 | [diff] [blame] | 269 | self.define = [(symbol, '1') for symbol in defines] |
Andrew M. Kuchling | 7620bbd | 2001-03-17 20:15:41 +0000 | [diff] [blame] | 270 | |
| 271 | # The option for macros to undefine is also a string from the |
| 272 | # option parsing, but has to be a list. Multiple symbols can also |
| 273 | # be separated with commas here. |
| 274 | if self.undef: |
Neal Norwitz | 9d72bb4 | 2007-04-17 08:48:32 +0000 | [diff] [blame] | 275 | self.undef = self.undef.split(',') |
Andrew M. Kuchling | 7620bbd | 2001-03-17 20:15:41 +0000 | [diff] [blame] | 276 | |
Anthony Baxter | a024034 | 2004-10-14 10:02:08 +0000 | [diff] [blame] | 277 | if self.swig_opts is None: |
| 278 | self.swig_opts = [] |
| 279 | else: |
| 280 | self.swig_opts = self.swig_opts.split(' ') |
| 281 | |
Alexandre Vassalotti | 6461e10 | 2008-05-15 22:09:29 +0000 | [diff] [blame] | 282 | # Finally add the user include and library directories if requested |
| 283 | if self.user: |
| 284 | user_include = os.path.join(USER_BASE, "include") |
| 285 | user_lib = os.path.join(USER_BASE, "lib") |
| 286 | if os.path.isdir(user_include): |
| 287 | self.include_dirs.append(user_include) |
| 288 | if os.path.isdir(user_lib): |
| 289 | self.library_dirs.append(user_lib) |
| 290 | self.rpath.append(user_lib) |
| 291 | |
Collin Winter | 5b7e9d7 | 2007-08-30 03:52:21 +0000 | [diff] [blame] | 292 | def run(self): |
Greg Ward | 37bc815 | 2000-01-30 18:34:15 +0000 | [diff] [blame] | 293 | from distutils.ccompiler import new_compiler |
| 294 | |
Greg Ward | 5322f00 | 2000-05-31 01:09:52 +0000 | [diff] [blame] | 295 | # 'self.extensions', as supplied by setup.py, is a list of |
| 296 | # Extension instances. See the documentation for Extension (in |
Greg Ward | b081e18 | 2000-06-17 23:04:31 +0000 | [diff] [blame] | 297 | # distutils.extension) for details. |
Fred Drake | 21d4535 | 2001-12-06 21:01:19 +0000 | [diff] [blame] | 298 | # |
Greg Ward | 5322f00 | 2000-05-31 01:09:52 +0000 | [diff] [blame] | 299 | # For backwards compatibility with Distutils 0.8.2 and earlier, we |
| 300 | # also allow the 'extensions' list to be a list of tuples: |
Greg Ward | e393ddb | 1999-08-14 23:57:49 +0000 | [diff] [blame] | 301 | # (ext_name, build_info) |
Greg Ward | 5322f00 | 2000-05-31 01:09:52 +0000 | [diff] [blame] | 302 | # where build_info is a dictionary containing everything that |
| 303 | # Extension instances do except the name, with a few things being |
| 304 | # differently named. We convert these 2-tuples to Extension |
| 305 | # instances as needed. |
Greg Ward | e393ddb | 1999-08-14 23:57:49 +0000 | [diff] [blame] | 306 | |
Greg Ward | 71eb864 | 1999-09-08 02:42:30 +0000 | [diff] [blame] | 307 | if not self.extensions: |
| 308 | return |
Greg Ward | e393ddb | 1999-08-14 23:57:49 +0000 | [diff] [blame] | 309 | |
Greg Ward | cdb20ba | 2000-03-26 21:45:14 +0000 | [diff] [blame] | 310 | # If we were asked to build any C/C++ libraries, make sure that the |
| 311 | # directory where we put them is in the library search path for |
| 312 | # linking extensions. |
Greg Ward | 4d16e0a | 2000-03-29 02:13:09 +0000 | [diff] [blame] | 313 | if self.distribution.has_c_libraries(): |
Greg Ward | cb1f4c4 | 2000-09-30 18:27:54 +0000 | [diff] [blame] | 314 | build_clib = self.get_finalized_command('build_clib') |
| 315 | self.libraries.extend(build_clib.get_library_names() or []) |
| 316 | self.library_dirs.append(build_clib.build_clib) |
Greg Ward | cdb20ba | 2000-03-26 21:45:14 +0000 | [diff] [blame] | 317 | |
Greg Ward | e393ddb | 1999-08-14 23:57:49 +0000 | [diff] [blame] | 318 | # Setup the CCompiler object that we'll use to do all the |
| 319 | # compiling and linking |
Tarek Ziadé | 3679727 | 2010-07-22 12:50:05 +0000 | [diff] [blame] | 320 | self.compiler = new_compiler(compiler=self.compiler, |
| 321 | verbose=self.verbose, |
| 322 | dry_run=self.dry_run, |
| 323 | force=self.force) |
| 324 | customize_compiler(self.compiler) |
Christian Heimes | 5e69685 | 2008-04-09 08:37:03 +0000 | [diff] [blame] | 325 | # If we are cross-compiling, init the compiler now (if we are not |
| 326 | # cross-compiling, init would not hurt, but people may rely on |
| 327 | # late initialization of compiler even if they shouldn't...) |
| 328 | if os.name == 'nt' and self.plat_name != get_platform(): |
Tarek Ziadé | 3679727 | 2010-07-22 12:50:05 +0000 | [diff] [blame] | 329 | self.compiler.initialize(self.plat_name) |
Greg Ward | cdb20ba | 2000-03-26 21:45:14 +0000 | [diff] [blame] | 330 | |
| 331 | # And make sure that any compile/link-related options (which might |
| 332 | # come from the command-line or from the setup script) are set in |
| 333 | # that CCompiler object -- that way, they automatically apply to |
| 334 | # all compiling and linking done here. |
Greg Ward | e393ddb | 1999-08-14 23:57:49 +0000 | [diff] [blame] | 335 | if self.include_dirs is not None: |
Tarek Ziadé | 3679727 | 2010-07-22 12:50:05 +0000 | [diff] [blame] | 336 | self.compiler.set_include_dirs(self.include_dirs) |
Greg Ward | e393ddb | 1999-08-14 23:57:49 +0000 | [diff] [blame] | 337 | if self.define is not None: |
| 338 | # 'define' option is a list of (name,value) tuples |
Tarek Ziadé | 06fbee1 | 2009-05-10 10:34:01 +0000 | [diff] [blame] | 339 | for (name, value) in self.define: |
Tarek Ziadé | 3679727 | 2010-07-22 12:50:05 +0000 | [diff] [blame] | 340 | self.compiler.define_macro(name, value) |
Greg Ward | e393ddb | 1999-08-14 23:57:49 +0000 | [diff] [blame] | 341 | if self.undef is not None: |
| 342 | for macro in self.undef: |
Tarek Ziadé | 3679727 | 2010-07-22 12:50:05 +0000 | [diff] [blame] | 343 | self.compiler.undefine_macro(macro) |
Greg Ward | cdb20ba | 2000-03-26 21:45:14 +0000 | [diff] [blame] | 344 | if self.libraries is not None: |
Tarek Ziadé | 3679727 | 2010-07-22 12:50:05 +0000 | [diff] [blame] | 345 | self.compiler.set_libraries(self.libraries) |
Greg Ward | e393ddb | 1999-08-14 23:57:49 +0000 | [diff] [blame] | 346 | if self.library_dirs is not None: |
Tarek Ziadé | 3679727 | 2010-07-22 12:50:05 +0000 | [diff] [blame] | 347 | self.compiler.set_library_dirs(self.library_dirs) |
Greg Ward | e393ddb | 1999-08-14 23:57:49 +0000 | [diff] [blame] | 348 | if self.rpath is not None: |
Tarek Ziadé | 3679727 | 2010-07-22 12:50:05 +0000 | [diff] [blame] | 349 | self.compiler.set_runtime_library_dirs(self.rpath) |
Greg Ward | e393ddb | 1999-08-14 23:57:49 +0000 | [diff] [blame] | 350 | if self.link_objects is not None: |
Tarek Ziadé | 3679727 | 2010-07-22 12:50:05 +0000 | [diff] [blame] | 351 | self.compiler.set_link_objects(self.link_objects) |
Greg Ward | 60f6433 | 2000-03-02 01:32:21 +0000 | [diff] [blame] | 352 | |
Greg Ward | cdb20ba | 2000-03-26 21:45:14 +0000 | [diff] [blame] | 353 | # Now actually compile and link everything. |
Greg Ward | cb1f4c4 | 2000-09-30 18:27:54 +0000 | [diff] [blame] | 354 | self.build_extensions() |
Greg Ward | e393ddb | 1999-08-14 23:57:49 +0000 | [diff] [blame] | 355 | |
Collin Winter | 5b7e9d7 | 2007-08-30 03:52:21 +0000 | [diff] [blame] | 356 | def check_extensions_list(self, extensions): |
Greg Ward | c185467 | 2000-02-05 02:23:16 +0000 | [diff] [blame] | 357 | """Ensure that the list of extensions (presumably provided as a |
Greg Ward | 5322f00 | 2000-05-31 01:09:52 +0000 | [diff] [blame] | 358 | command option 'extensions') is valid, i.e. it is a list of |
| 359 | Extension objects. We also support the old-style list of 2-tuples, |
| 360 | where the tuples are (ext_name, build_info), which are converted to |
| 361 | Extension instances here. |
Greg Ward | e393ddb | 1999-08-14 23:57:49 +0000 | [diff] [blame] | 362 | |
Greg Ward | 5322f00 | 2000-05-31 01:09:52 +0000 | [diff] [blame] | 363 | Raise DistutilsSetupError if the structure is invalid anywhere; |
| 364 | just returns otherwise. |
| 365 | """ |
Collin Winter | 5b7e9d7 | 2007-08-30 03:52:21 +0000 | [diff] [blame] | 366 | if not isinstance(extensions, list): |
| 367 | raise DistutilsSetupError( |
| 368 | "'ext_modules' option must be a list of Extension instances") |
Fred Drake | 21d4535 | 2001-12-06 21:01:19 +0000 | [diff] [blame] | 369 | |
Collin Winter | 5b7e9d7 | 2007-08-30 03:52:21 +0000 | [diff] [blame] | 370 | for i, ext in enumerate(extensions): |
Greg Ward | 5322f00 | 2000-05-31 01:09:52 +0000 | [diff] [blame] | 371 | if isinstance(ext, Extension): |
| 372 | continue # OK! (assume type-checking done |
| 373 | # by Extension constructor) |
Greg Ward | e393ddb | 1999-08-14 23:57:49 +0000 | [diff] [blame] | 374 | |
Tarek Ziadé | 06fbee1 | 2009-05-10 10:34:01 +0000 | [diff] [blame] | 375 | if not isinstance(ext, tuple) or len(ext) != 2: |
Collin Winter | 5b7e9d7 | 2007-08-30 03:52:21 +0000 | [diff] [blame] | 376 | raise DistutilsSetupError( |
| 377 | "each element of 'ext_modules' option must be an " |
Greg Ward | 5322f00 | 2000-05-31 01:09:52 +0000 | [diff] [blame] | 378 | "Extension instance or 2-tuple") |
Greg Ward | e393ddb | 1999-08-14 23:57:49 +0000 | [diff] [blame] | 379 | |
Tarek Ziadé | 06fbee1 | 2009-05-10 10:34:01 +0000 | [diff] [blame] | 380 | ext_name, build_info = ext |
| 381 | |
| 382 | log.warn(("old-style (ext_name, build_info) tuple found in " |
| 383 | "ext_modules for extension '%s'" |
| 384 | "-- please convert to Extension instance" % ext_name)) |
| 385 | |
Guido van Rossum | 3172c5d | 2007-10-16 18:12:55 +0000 | [diff] [blame] | 386 | if not (isinstance(ext_name, str) and |
Greg Ward | 5322f00 | 2000-05-31 01:09:52 +0000 | [diff] [blame] | 387 | extension_name_re.match(ext_name)): |
Collin Winter | 5b7e9d7 | 2007-08-30 03:52:21 +0000 | [diff] [blame] | 388 | raise DistutilsSetupError( |
| 389 | "first element of each tuple in 'ext_modules' " |
Greg Ward | 5322f00 | 2000-05-31 01:09:52 +0000 | [diff] [blame] | 390 | "must be the extension name (a string)") |
Greg Ward | e393ddb | 1999-08-14 23:57:49 +0000 | [diff] [blame] | 391 | |
Tarek Ziadé | 06fbee1 | 2009-05-10 10:34:01 +0000 | [diff] [blame] | 392 | if not isinstance(build_info, dict): |
Collin Winter | 5b7e9d7 | 2007-08-30 03:52:21 +0000 | [diff] [blame] | 393 | raise DistutilsSetupError( |
| 394 | "second element of each tuple in 'ext_modules' " |
Greg Ward | 5322f00 | 2000-05-31 01:09:52 +0000 | [diff] [blame] | 395 | "must be a dictionary (build info)") |
| 396 | |
| 397 | # OK, the (ext_name, build_info) dict is type-safe: convert it |
| 398 | # to an Extension instance. |
| 399 | ext = Extension(ext_name, build_info['sources']) |
| 400 | |
| 401 | # Easy stuff: one-to-one mapping from dict elements to |
| 402 | # instance attributes. |
Tarek Ziadé | 06fbee1 | 2009-05-10 10:34:01 +0000 | [diff] [blame] | 403 | for key in ('include_dirs', 'library_dirs', 'libraries', |
| 404 | 'extra_objects', 'extra_compile_args', |
Greg Ward | 5322f00 | 2000-05-31 01:09:52 +0000 | [diff] [blame] | 405 | 'extra_link_args'): |
Greg Ward | d8014e6 | 2000-08-26 02:21:55 +0000 | [diff] [blame] | 406 | val = build_info.get(key) |
| 407 | if val is not None: |
| 408 | setattr(ext, key, val) |
Greg Ward | 5322f00 | 2000-05-31 01:09:52 +0000 | [diff] [blame] | 409 | |
| 410 | # Medium-easy stuff: same syntax/semantics, different names. |
| 411 | ext.runtime_library_dirs = build_info.get('rpath') |
Guido van Rossum | e2b70bc | 2006-08-18 22:13:04 +0000 | [diff] [blame] | 412 | if 'def_file' in build_info: |
Jeremy Hylton | cd8a114 | 2002-06-04 20:14:43 +0000 | [diff] [blame] | 413 | log.warn("'def_file' element of build info dict " |
| 414 | "no longer supported") |
Greg Ward | 5322f00 | 2000-05-31 01:09:52 +0000 | [diff] [blame] | 415 | |
| 416 | # Non-trivial stuff: 'macros' split into 'define_macros' |
| 417 | # and 'undef_macros'. |
| 418 | macros = build_info.get('macros') |
| 419 | if macros: |
| 420 | ext.define_macros = [] |
| 421 | ext.undef_macros = [] |
| 422 | for macro in macros: |
Collin Winter | 5b7e9d7 | 2007-08-30 03:52:21 +0000 | [diff] [blame] | 423 | if not (isinstance(macro, tuple) and len(macro) in (1, 2)): |
| 424 | raise DistutilsSetupError( |
| 425 | "'macros' element of build info dict " |
| 426 | "must be 1- or 2-tuple") |
Greg Ward | 5322f00 | 2000-05-31 01:09:52 +0000 | [diff] [blame] | 427 | if len(macro) == 1: |
| 428 | ext.undef_macros.append(macro[0]) |
| 429 | elif len(macro) == 2: |
| 430 | ext.define_macros.append(macro) |
| 431 | |
| 432 | extensions[i] = ext |
| 433 | |
Collin Winter | 5b7e9d7 | 2007-08-30 03:52:21 +0000 | [diff] [blame] | 434 | def get_source_files(self): |
Andrew M. Kuchling | 23adc9f | 2000-07-14 13:35:07 +0000 | [diff] [blame] | 435 | self.check_extensions_list(self.extensions) |
Greg Ward | a6cb8ae | 1999-09-29 12:49:35 +0000 | [diff] [blame] | 436 | filenames = [] |
| 437 | |
| 438 | # Wouldn't it be neat if we knew the names of header files too... |
Greg Ward | 5322f00 | 2000-05-31 01:09:52 +0000 | [diff] [blame] | 439 | for ext in self.extensions: |
Greg Ward | cb1f4c4 | 2000-09-30 18:27:54 +0000 | [diff] [blame] | 440 | filenames.extend(ext.sources) |
Greg Ward | a6cb8ae | 1999-09-29 12:49:35 +0000 | [diff] [blame] | 441 | return filenames |
| 442 | |
Collin Winter | 5b7e9d7 | 2007-08-30 03:52:21 +0000 | [diff] [blame] | 443 | def get_outputs(self): |
Greg Ward | 4d16e0a | 2000-03-29 02:13:09 +0000 | [diff] [blame] | 444 | # Sanity check the 'extensions' list -- can't assume this is being |
| 445 | # done in the same run as a 'build_extensions()' call (in fact, we |
| 446 | # can probably assume that it *isn't*!). |
Greg Ward | cb1f4c4 | 2000-09-30 18:27:54 +0000 | [diff] [blame] | 447 | self.check_extensions_list(self.extensions) |
Greg Ward | 4d16e0a | 2000-03-29 02:13:09 +0000 | [diff] [blame] | 448 | |
| 449 | # And build the list of output (built) filenames. Note that this |
| 450 | # ignores the 'inplace' flag, and assumes everything goes in the |
| 451 | # "build" tree. |
| 452 | outputs = [] |
Greg Ward | 5322f00 | 2000-05-31 01:09:52 +0000 | [diff] [blame] | 453 | for ext in self.extensions: |
Tarek Ziadé | ff0e500 | 2009-05-12 17:14:01 +0000 | [diff] [blame] | 454 | outputs.append(self.get_ext_fullpath(ext.name)) |
Greg Ward | 4d16e0a | 2000-03-29 02:13:09 +0000 | [diff] [blame] | 455 | return outputs |
| 456 | |
Marc-André Lemburg | 49c9942 | 2001-01-26 18:00:48 +0000 | [diff] [blame] | 457 | def build_extensions(self): |
Greg Ward | 4d16e0a | 2000-03-29 02:13:09 +0000 | [diff] [blame] | 458 | # First, sanity-check the 'extensions' list |
Greg Ward | cb1f4c4 | 2000-09-30 18:27:54 +0000 | [diff] [blame] | 459 | self.check_extensions_list(self.extensions) |
Greg Ward | 4d16e0a | 2000-03-29 02:13:09 +0000 | [diff] [blame] | 460 | |
Greg Ward | 5322f00 | 2000-05-31 01:09:52 +0000 | [diff] [blame] | 461 | for ext in self.extensions: |
Tarek Ziadé | b2e36f1 | 2009-03-31 22:37:55 +0000 | [diff] [blame] | 462 | try: |
| 463 | self.build_extension(ext) |
Tarek Ziadé | 3091129 | 2009-03-31 22:50:54 +0000 | [diff] [blame] | 464 | except (CCompilerError, DistutilsError, CompileError) as e: |
Tarek Ziadé | b2e36f1 | 2009-03-31 22:37:55 +0000 | [diff] [blame] | 465 | if not ext.optional: |
| 466 | raise |
| 467 | self.warn('building extension "%s" failed: %s' % |
| 468 | (ext.name, e)) |
Greg Ward | a6cb8ae | 1999-09-29 12:49:35 +0000 | [diff] [blame] | 469 | |
Marc-André Lemburg | 49c9942 | 2001-01-26 18:00:48 +0000 | [diff] [blame] | 470 | def build_extension(self, ext): |
Marc-André Lemburg | 49c9942 | 2001-01-26 18:00:48 +0000 | [diff] [blame] | 471 | sources = ext.sources |
Collin Winter | 5b7e9d7 | 2007-08-30 03:52:21 +0000 | [diff] [blame] | 472 | if sources is None or not isinstance(sources, (list, tuple)): |
| 473 | raise DistutilsSetupError( |
| 474 | "in 'ext_modules' option (extension '%s'), " |
| 475 | "'sources' must be present and must be " |
| 476 | "a list of source filenames" % ext.name) |
Marc-André Lemburg | 49c9942 | 2001-01-26 18:00:48 +0000 | [diff] [blame] | 477 | sources = list(sources) |
Greg Ward | 5213400 | 2000-05-26 01:31:53 +0000 | [diff] [blame] | 478 | |
Tarek Ziadé | ff0e500 | 2009-05-12 17:14:01 +0000 | [diff] [blame] | 479 | ext_path = self.get_ext_fullpath(ext.name) |
Jeremy Hylton | 09e532b | 2002-06-12 20:08:56 +0000 | [diff] [blame] | 480 | depends = sources + ext.depends |
Tarek Ziadé | ff0e500 | 2009-05-12 17:14:01 +0000 | [diff] [blame] | 481 | if not (self.force or newer_group(depends, ext_path, 'newer')): |
Jeremy Hylton | cd8a114 | 2002-06-04 20:14:43 +0000 | [diff] [blame] | 482 | log.debug("skipping '%s' extension (up-to-date)", ext.name) |
Marc-André Lemburg | 49c9942 | 2001-01-26 18:00:48 +0000 | [diff] [blame] | 483 | return |
| 484 | else: |
Jeremy Hylton | cd8a114 | 2002-06-04 20:14:43 +0000 | [diff] [blame] | 485 | log.info("building '%s' extension", ext.name) |
Greg Ward | 5322f00 | 2000-05-31 01:09:52 +0000 | [diff] [blame] | 486 | |
Marc-André Lemburg | 49c9942 | 2001-01-26 18:00:48 +0000 | [diff] [blame] | 487 | # First, scan the sources for SWIG definition files (.i), run |
| 488 | # SWIG on 'em to create .c files, and modify the sources list |
| 489 | # accordingly. |
Anthony Baxter | a024034 | 2004-10-14 10:02:08 +0000 | [diff] [blame] | 490 | sources = self.swig_sources(sources, ext) |
Greg Ward | 5322f00 | 2000-05-31 01:09:52 +0000 | [diff] [blame] | 491 | |
Marc-André Lemburg | 49c9942 | 2001-01-26 18:00:48 +0000 | [diff] [blame] | 492 | # Next, compile the source code to object files. |
Greg Ward | 5322f00 | 2000-05-31 01:09:52 +0000 | [diff] [blame] | 493 | |
Marc-André Lemburg | 49c9942 | 2001-01-26 18:00:48 +0000 | [diff] [blame] | 494 | # XXX not honouring 'define_macros' or 'undef_macros' -- the |
| 495 | # CCompiler API needs to change to accommodate this, and I |
| 496 | # want to do one thing at a time! |
Greg Ward | df9e6b8 | 2000-09-17 00:54:58 +0000 | [diff] [blame] | 497 | |
Marc-André Lemburg | 49c9942 | 2001-01-26 18:00:48 +0000 | [diff] [blame] | 498 | # Two possible sources for extra compiler arguments: |
| 499 | # - 'extra_compile_args' in Extension object |
| 500 | # - CFLAGS environment variable (not particularly |
| 501 | # elegant, but people seem to expect it and I |
| 502 | # guess it's useful) |
| 503 | # The environment variable should take precedence, and |
| 504 | # any sensible compiler will give precedence to later |
| 505 | # command line args. Hence we combine them in order: |
| 506 | extra_args = ext.extra_compile_args or [] |
Greg Ward | 5322f00 | 2000-05-31 01:09:52 +0000 | [diff] [blame] | 507 | |
Marc-André Lemburg | 49c9942 | 2001-01-26 18:00:48 +0000 | [diff] [blame] | 508 | macros = ext.define_macros[:] |
| 509 | for undef in ext.undef_macros: |
| 510 | macros.append((undef,)) |
Greg Ward | e393ddb | 1999-08-14 23:57:49 +0000 | [diff] [blame] | 511 | |
Tarek Ziadé | 3679727 | 2010-07-22 12:50:05 +0000 | [diff] [blame] | 512 | objects = self.compiler.compile(sources, |
| 513 | output_dir=self.build_temp, |
| 514 | macros=macros, |
| 515 | include_dirs=ext.include_dirs, |
| 516 | debug=self.debug, |
| 517 | extra_postargs=extra_args, |
| 518 | depends=ext.depends) |
Marc-André Lemburg | 49c9942 | 2001-01-26 18:00:48 +0000 | [diff] [blame] | 519 | |
Fred Drake | 9028d0a | 2001-12-06 22:59:54 +0000 | [diff] [blame] | 520 | # XXX -- this is a Vile HACK! |
| 521 | # |
| 522 | # The setup.py script for Python on Unix needs to be able to |
| 523 | # get this list so it can perform all the clean up needed to |
| 524 | # avoid keeping object files around when cleaning out a failed |
| 525 | # build of an extension module. Since Distutils does not |
| 526 | # track dependencies, we have to get rid of intermediates to |
| 527 | # ensure all the intermediates will be properly re-built. |
| 528 | # |
| 529 | self._built_objects = objects[:] |
| 530 | |
Marc-André Lemburg | 49c9942 | 2001-01-26 18:00:48 +0000 | [diff] [blame] | 531 | # Now link the object files together into a "shared object" -- |
| 532 | # of course, first we have to figure out all the other things |
| 533 | # that go into the mix. |
| 534 | if ext.extra_objects: |
| 535 | objects.extend(ext.extra_objects) |
| 536 | extra_args = ext.extra_link_args or [] |
Greg Ward | 968d883 | 2000-02-10 02:17:06 +0000 | [diff] [blame] | 537 | |
Gustavo Niemeyer | 6b01685 | 2002-11-05 16:12:02 +0000 | [diff] [blame] | 538 | # Detect target language, if not provided |
Tarek Ziadé | 3679727 | 2010-07-22 12:50:05 +0000 | [diff] [blame] | 539 | language = ext.language or self.compiler.detect_language(sources) |
Gustavo Niemeyer | 6b01685 | 2002-11-05 16:12:02 +0000 | [diff] [blame] | 540 | |
Tarek Ziadé | 3679727 | 2010-07-22 12:50:05 +0000 | [diff] [blame] | 541 | self.compiler.link_shared_object( |
Tarek Ziadé | ff0e500 | 2009-05-12 17:14:01 +0000 | [diff] [blame] | 542 | objects, ext_path, |
Marc-André Lemburg | 49c9942 | 2001-01-26 18:00:48 +0000 | [diff] [blame] | 543 | libraries=self.get_libraries(ext), |
| 544 | library_dirs=ext.library_dirs, |
| 545 | runtime_library_dirs=ext.runtime_library_dirs, |
| 546 | extra_postargs=extra_args, |
Fred Drake | 21d4535 | 2001-12-06 21:01:19 +0000 | [diff] [blame] | 547 | export_symbols=self.get_export_symbols(ext), |
Marc-André Lemburg | 49c9942 | 2001-01-26 18:00:48 +0000 | [diff] [blame] | 548 | debug=self.debug, |
Gustavo Niemeyer | 6b01685 | 2002-11-05 16:12:02 +0000 | [diff] [blame] | 549 | build_temp=self.build_temp, |
| 550 | target_lang=language) |
Greg Ward | e393ddb | 1999-08-14 23:57:49 +0000 | [diff] [blame] | 551 | |
Collin Winter | 5b7e9d7 | 2007-08-30 03:52:21 +0000 | [diff] [blame] | 552 | def swig_sources(self, sources, extension): |
Greg Ward | ffcaf2d | 2000-06-24 00:19:35 +0000 | [diff] [blame] | 553 | """Walk the list of source files in 'sources', looking for SWIG |
| 554 | interface (.i) files. Run SWIG on all that are found, and |
| 555 | return a modified 'sources' list with SWIG source files replaced |
| 556 | by the generated C (or C++) files. |
| 557 | """ |
Greg Ward | ffcaf2d | 2000-06-24 00:19:35 +0000 | [diff] [blame] | 558 | new_sources = [] |
| 559 | swig_sources = [] |
| 560 | swig_targets = {} |
| 561 | |
Greg Ward | f3bd747 | 2000-06-27 01:37:10 +0000 | [diff] [blame] | 562 | # XXX this drops generated C/C++ files into the source tree, which |
Greg Ward | ffcaf2d | 2000-06-24 00:19:35 +0000 | [diff] [blame] | 563 | # is fine for developers who want to distribute the generated |
| 564 | # source -- but there should be an option to put SWIG output in |
| 565 | # the temp dir. |
| 566 | |
Greg Ward | f3bd747 | 2000-06-27 01:37:10 +0000 | [diff] [blame] | 567 | if self.swig_cpp: |
Anthony Baxter | a024034 | 2004-10-14 10:02:08 +0000 | [diff] [blame] | 568 | log.warn("--swig-cpp is deprecated - use --swig-opts=-c++") |
| 569 | |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 570 | if self.swig_cpp or ('-c++' in self.swig_opts) or \ |
| 571 | ('-c++' in extension.swig_opts): |
Greg Ward | f3bd747 | 2000-06-27 01:37:10 +0000 | [diff] [blame] | 572 | target_ext = '.cpp' |
| 573 | else: |
| 574 | target_ext = '.c' |
| 575 | |
Greg Ward | ffcaf2d | 2000-06-24 00:19:35 +0000 | [diff] [blame] | 576 | for source in sources: |
| 577 | (base, ext) = os.path.splitext(source) |
Greg Ward | 5ca84b8 | 2000-06-25 02:10:46 +0000 | [diff] [blame] | 578 | if ext == ".i": # SWIG interface file |
Thomas Heller | 5cba76d | 2002-01-18 20:30:53 +0000 | [diff] [blame] | 579 | new_sources.append(base + '_wrap' + target_ext) |
Greg Ward | 5ca84b8 | 2000-06-25 02:10:46 +0000 | [diff] [blame] | 580 | swig_sources.append(source) |
Greg Ward | ffcaf2d | 2000-06-24 00:19:35 +0000 | [diff] [blame] | 581 | swig_targets[source] = new_sources[-1] |
| 582 | else: |
| 583 | new_sources.append(source) |
| 584 | |
Greg Ward | 5ca84b8 | 2000-06-25 02:10:46 +0000 | [diff] [blame] | 585 | if not swig_sources: |
Greg Ward | ffcaf2d | 2000-06-24 00:19:35 +0000 | [diff] [blame] | 586 | return new_sources |
| 587 | |
Anthony Baxter | a024034 | 2004-10-14 10:02:08 +0000 | [diff] [blame] | 588 | swig = self.swig or self.find_swig() |
Thomas Heller | 5cba76d | 2002-01-18 20:30:53 +0000 | [diff] [blame] | 589 | swig_cmd = [swig, "-python"] |
Anthony Baxter | a024034 | 2004-10-14 10:02:08 +0000 | [diff] [blame] | 590 | swig_cmd.extend(self.swig_opts) |
Greg Ward | f3bd747 | 2000-06-27 01:37:10 +0000 | [diff] [blame] | 591 | if self.swig_cpp: |
Greg Ward | cb1f4c4 | 2000-09-30 18:27:54 +0000 | [diff] [blame] | 592 | swig_cmd.append("-c++") |
Greg Ward | ffcaf2d | 2000-06-24 00:19:35 +0000 | [diff] [blame] | 593 | |
Anthony Baxter | a024034 | 2004-10-14 10:02:08 +0000 | [diff] [blame] | 594 | # Do not override commandline arguments |
| 595 | if not self.swig_opts: |
| 596 | for o in extension.swig_opts: |
| 597 | swig_cmd.append(o) |
| 598 | |
Greg Ward | ffcaf2d | 2000-06-24 00:19:35 +0000 | [diff] [blame] | 599 | for source in swig_sources: |
Greg Ward | f3bd747 | 2000-06-27 01:37:10 +0000 | [diff] [blame] | 600 | target = swig_targets[source] |
Jeremy Hylton | cd8a114 | 2002-06-04 20:14:43 +0000 | [diff] [blame] | 601 | log.info("swigging %s to %s", source, target) |
Greg Ward | f3bd747 | 2000-06-27 01:37:10 +0000 | [diff] [blame] | 602 | self.spawn(swig_cmd + ["-o", target, source]) |
Greg Ward | ffcaf2d | 2000-06-24 00:19:35 +0000 | [diff] [blame] | 603 | |
| 604 | return new_sources |
| 605 | |
Collin Winter | 5b7e9d7 | 2007-08-30 03:52:21 +0000 | [diff] [blame] | 606 | def find_swig(self): |
Greg Ward | ffcaf2d | 2000-06-24 00:19:35 +0000 | [diff] [blame] | 607 | """Return the name of the SWIG executable. On Unix, this is |
| 608 | just "swig" -- it should be in the PATH. Tries a bit harder on |
| 609 | Windows. |
| 610 | """ |
Greg Ward | ffcaf2d | 2000-06-24 00:19:35 +0000 | [diff] [blame] | 611 | if os.name == "posix": |
| 612 | return "swig" |
| 613 | elif os.name == "nt": |
Greg Ward | ffcaf2d | 2000-06-24 00:19:35 +0000 | [diff] [blame] | 614 | # Look for SWIG in its standard installation directory on |
| 615 | # Windows (or so I presume!). If we find it there, great; |
| 616 | # if not, act like Unix and assume it's in the PATH. |
| 617 | for vers in ("1.3", "1.2", "1.1"): |
| 618 | fn = os.path.join("c:\\swig%s" % vers, "swig.exe") |
Greg Ward | cb1f4c4 | 2000-09-30 18:27:54 +0000 | [diff] [blame] | 619 | if os.path.isfile(fn): |
Greg Ward | ffcaf2d | 2000-06-24 00:19:35 +0000 | [diff] [blame] | 620 | return fn |
| 621 | else: |
| 622 | return "swig.exe" |
Marc-André Lemburg | 2544f51 | 2002-01-31 18:56:00 +0000 | [diff] [blame] | 623 | elif os.name == "os2": |
| 624 | # assume swig available in the PATH. |
| 625 | return "swig.exe" |
Greg Ward | ffcaf2d | 2000-06-24 00:19:35 +0000 | [diff] [blame] | 626 | else: |
Collin Winter | 5b7e9d7 | 2007-08-30 03:52:21 +0000 | [diff] [blame] | 627 | raise DistutilsPlatformError( |
| 628 | "I don't know how to find (much less run) SWIG " |
| 629 | "on platform '%s'" % os.name) |
Fred Drake | 21d4535 | 2001-12-06 21:01:19 +0000 | [diff] [blame] | 630 | |
Greg Ward | b081e18 | 2000-06-17 23:04:31 +0000 | [diff] [blame] | 631 | # -- Name generators ----------------------------------------------- |
| 632 | # (extension names, filenames, whatever) |
Tarek Ziadé | ff0e500 | 2009-05-12 17:14:01 +0000 | [diff] [blame] | 633 | def get_ext_fullpath(self, ext_name): |
| 634 | """Returns the path of the filename for a given extension. |
| 635 | |
| 636 | The file is located in `build_lib` or directly in the package |
| 637 | (inplace option). |
| 638 | """ |
Tarek Ziadé | 822eb84 | 2009-05-19 16:22:57 +0000 | [diff] [blame] | 639 | fullname = self.get_ext_fullname(ext_name) |
Tarek Ziadé | 0156f91 | 2009-06-29 16:19:22 +0000 | [diff] [blame] | 640 | modpath = fullname.split('.') |
Tarek Ziadé | e10d6de | 2009-07-03 08:33:28 +0000 | [diff] [blame] | 641 | filename = self.get_ext_filename(modpath[-1]) |
| 642 | |
Tarek Ziadé | 822eb84 | 2009-05-19 16:22:57 +0000 | [diff] [blame] | 643 | if not self.inplace: |
| 644 | # no further work needed |
Tarek Ziadé | e10d6de | 2009-07-03 08:33:28 +0000 | [diff] [blame] | 645 | # returning : |
| 646 | # build_dir/package/path/filename |
| 647 | filename = os.path.join(*modpath[:-1]+[filename]) |
Tarek Ziadé | ff0e500 | 2009-05-12 17:14:01 +0000 | [diff] [blame] | 648 | return os.path.join(self.build_lib, filename) |
Greg Ward | b081e18 | 2000-06-17 23:04:31 +0000 | [diff] [blame] | 649 | |
Tarek Ziadé | 822eb84 | 2009-05-19 16:22:57 +0000 | [diff] [blame] | 650 | # the inplace option requires to find the package directory |
Tarek Ziadé | e10d6de | 2009-07-03 08:33:28 +0000 | [diff] [blame] | 651 | # using the build_py command for that |
| 652 | package = '.'.join(modpath[0:-1]) |
Tarek Ziadé | 822eb84 | 2009-05-19 16:22:57 +0000 | [diff] [blame] | 653 | build_py = self.get_finalized_command('build_py') |
| 654 | package_dir = os.path.abspath(build_py.get_package_dir(package)) |
Tarek Ziadé | e10d6de | 2009-07-03 08:33:28 +0000 | [diff] [blame] | 655 | |
| 656 | # returning |
| 657 | # package_dir/filename |
Tarek Ziadé | 822eb84 | 2009-05-19 16:22:57 +0000 | [diff] [blame] | 658 | return os.path.join(package_dir, filename) |
| 659 | |
Collin Winter | 5b7e9d7 | 2007-08-30 03:52:21 +0000 | [diff] [blame] | 660 | def get_ext_fullname(self, ext_name): |
Tarek Ziadé | ff0e500 | 2009-05-12 17:14:01 +0000 | [diff] [blame] | 661 | """Returns the fullname of a given extension name. |
| 662 | |
| 663 | Adds the `package.` prefix""" |
Greg Ward | e51d69e | 2000-03-01 01:43:28 +0000 | [diff] [blame] | 664 | if self.package is None: |
| 665 | return ext_name |
| 666 | else: |
| 667 | return self.package + '.' + ext_name |
| 668 | |
Collin Winter | 5b7e9d7 | 2007-08-30 03:52:21 +0000 | [diff] [blame] | 669 | def get_ext_filename(self, ext_name): |
Ka-Ping Yee | 22fcae9 | 2001-03-10 09:33:14 +0000 | [diff] [blame] | 670 | r"""Convert the name of an extension (eg. "foo.bar") into the name |
Greg Ward | b081e18 | 2000-06-17 23:04:31 +0000 | [diff] [blame] | 671 | of the file from which it will be loaded (eg. "foo/bar.so", or |
| 672 | "foo\bar.pyd"). |
| 673 | """ |
Tarek Ziadé | 3679727 | 2010-07-22 12:50:05 +0000 | [diff] [blame] | 674 | from distutils.sysconfig import get_config_var |
Neal Norwitz | 9d72bb4 | 2007-04-17 08:48:32 +0000 | [diff] [blame] | 675 | ext_path = ext_name.split('.') |
Marc-André Lemburg | 2544f51 | 2002-01-31 18:56:00 +0000 | [diff] [blame] | 676 | # OS/2 has an 8 character module (extension) limit :-( |
| 677 | if os.name == "os2": |
| 678 | ext_path[len(ext_path) - 1] = ext_path[len(ext_path) - 1][:8] |
Greg Ward | 8422964 | 2000-03-31 03:50:23 +0000 | [diff] [blame] | 679 | # extensions in debug_mode are named 'module_d.pyd' under windows |
Tarek Ziadé | 3679727 | 2010-07-22 12:50:05 +0000 | [diff] [blame] | 680 | so_ext = get_config_var('SO') |
Greg Ward | 8422964 | 2000-03-31 03:50:23 +0000 | [diff] [blame] | 681 | if os.name == 'nt' and self.debug: |
Neal Norwitz | d910855 | 2006-03-17 08:00:19 +0000 | [diff] [blame] | 682 | return os.path.join(*ext_path) + '_d' + so_ext |
| 683 | return os.path.join(*ext_path) + so_ext |
Greg Ward | e393ddb | 1999-08-14 23:57:49 +0000 | [diff] [blame] | 684 | |
Collin Winter | 5b7e9d7 | 2007-08-30 03:52:21 +0000 | [diff] [blame] | 685 | def get_export_symbols(self, ext): |
Greg Ward | 0419a4f | 2000-08-01 23:54:29 +0000 | [diff] [blame] | 686 | """Return the list of symbols that a shared extension has to |
| 687 | export. This either uses 'ext.export_symbols' or, if it's not |
Amaury Forgeot d'Arc | 3b4e479 | 2008-06-11 17:46:10 +0000 | [diff] [blame] | 688 | provided, "PyInit_" + module_name. Only relevant on Windows, where |
Tarek Ziadé | 6504c66 | 2009-07-11 10:59:56 +0000 | [diff] [blame] | 689 | the .pyd file (DLL) must export the module "PyInit_" function. |
Greg Ward | 0419a4f | 2000-08-01 23:54:29 +0000 | [diff] [blame] | 690 | """ |
Amaury Forgeot d'Arc | 3b4e479 | 2008-06-11 17:46:10 +0000 | [diff] [blame] | 691 | initfunc_name = "PyInit_" + ext.name.split('.')[-1] |
Greg Ward | a35c931 | 2000-08-13 00:42:35 +0000 | [diff] [blame] | 692 | if initfunc_name not in ext.export_symbols: |
| 693 | ext.export_symbols.append(initfunc_name) |
| 694 | return ext.export_symbols |
Greg Ward | 0419a4f | 2000-08-01 23:54:29 +0000 | [diff] [blame] | 695 | |
Collin Winter | 5b7e9d7 | 2007-08-30 03:52:21 +0000 | [diff] [blame] | 696 | def get_libraries(self, ext): |
Greg Ward | 0419a4f | 2000-08-01 23:54:29 +0000 | [diff] [blame] | 697 | """Return the list of libraries to link against when building a |
| 698 | shared extension. On most platforms, this is just 'ext.libraries'; |
Marc-André Lemburg | 2544f51 | 2002-01-31 18:56:00 +0000 | [diff] [blame] | 699 | on Windows and OS/2, we add the Python library (eg. python20.dll). |
Greg Ward | 0419a4f | 2000-08-01 23:54:29 +0000 | [diff] [blame] | 700 | """ |
| 701 | # The python library is always needed on Windows. For MSVC, this |
| 702 | # is redundant, since the library is mentioned in a pragma in |
Martin v. Löwis | 4f1cd8b | 2001-07-26 13:41:06 +0000 | [diff] [blame] | 703 | # pyconfig.h that MSVC groks. The other Windows compilers all seem |
Greg Ward | 0419a4f | 2000-08-01 23:54:29 +0000 | [diff] [blame] | 704 | # to need it mentioned explicitly, though, so that's what we do. |
Thomas Heller | 18b9b93 | 2000-09-28 19:28:35 +0000 | [diff] [blame] | 705 | # Append '_d' to the python import library on debug builds. |
Jeremy Hylton | c01b350 | 2002-06-18 18:40:54 +0000 | [diff] [blame] | 706 | if sys.platform == "win32": |
| 707 | from distutils.msvccompiler import MSVCCompiler |
Tarek Ziadé | 3679727 | 2010-07-22 12:50:05 +0000 | [diff] [blame] | 708 | if not isinstance(self.compiler, MSVCCompiler): |
Jeremy Hylton | c01b350 | 2002-06-18 18:40:54 +0000 | [diff] [blame] | 709 | template = "python%d%d" |
| 710 | if self.debug: |
| 711 | template = template + '_d' |
| 712 | pythonlib = (template % |
| 713 | (sys.hexversion >> 24, (sys.hexversion >> 16) & 0xff)) |
| 714 | # don't extend ext.libraries, it may be shared with other |
| 715 | # extensions, it is a reference to the original list |
| 716 | return ext.libraries + [pythonlib] |
Thomas Heller | 05c9335 | 2002-10-31 14:26:37 +0000 | [diff] [blame] | 717 | else: |
| 718 | return ext.libraries |
Marc-André Lemburg | 2544f51 | 2002-01-31 18:56:00 +0000 | [diff] [blame] | 719 | elif sys.platform == "os2emx": |
| 720 | # EMX/GCC requires the python library explicitly, and I |
| 721 | # believe VACPP does as well (though not confirmed) - AIM Apr01 |
| 722 | template = "python%d%d" |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 723 | # debug versions of the main DLL aren't supported, at least |
Marc-André Lemburg | 2544f51 | 2002-01-31 18:56:00 +0000 | [diff] [blame] | 724 | # not at this time - AIM Apr01 |
| 725 | #if self.debug: |
| 726 | # template = template + '_d' |
| 727 | pythonlib = (template % |
| 728 | (sys.hexversion >> 24, (sys.hexversion >> 16) & 0xff)) |
| 729 | # don't extend ext.libraries, it may be shared with other |
| 730 | # extensions, it is a reference to the original list |
| 731 | return ext.libraries + [pythonlib] |
Andrew M. Kuchling | 506f0b1 | 2001-01-24 15:43:09 +0000 | [diff] [blame] | 732 | elif sys.platform[:6] == "cygwin": |
| 733 | template = "python%d.%d" |
| 734 | pythonlib = (template % |
| 735 | (sys.hexversion >> 24, (sys.hexversion >> 16) & 0xff)) |
| 736 | # don't extend ext.libraries, it may be shared with other |
| 737 | # extensions, it is a reference to the original list |
| 738 | return ext.libraries + [pythonlib] |
Tarek Ziadé | 3679727 | 2010-07-22 12:50:05 +0000 | [diff] [blame] | 739 | elif sys.platform[:6] == "atheos": |
| 740 | from distutils import sysconfig |
| 741 | |
| 742 | template = "python%d.%d" |
| 743 | pythonlib = (template % |
| 744 | (sys.hexversion >> 24, (sys.hexversion >> 16) & 0xff)) |
| 745 | # Get SHLIBS from Makefile |
| 746 | extra = [] |
| 747 | for lib in sysconfig.get_config_var('SHLIBS').split(): |
| 748 | if lib.startswith('-l'): |
| 749 | extra.append(lib[2:]) |
| 750 | else: |
| 751 | extra.append(lib) |
| 752 | # don't extend ext.libraries, it may be shared with other |
| 753 | # extensions, it is a reference to the original list |
| 754 | return ext.libraries + [pythonlib, "m"] + extra |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 755 | elif sys.platform == 'darwin': |
| 756 | # Don't use the default code below |
| 757 | return ext.libraries |
Antoine Pitrou | 8e6b407 | 2010-09-10 19:44:44 +0000 | [diff] [blame] | 758 | elif sys.platform[:3] == 'aix': |
| 759 | # Don't use the default code below |
| 760 | return ext.libraries |
Greg Ward | 0419a4f | 2000-08-01 23:54:29 +0000 | [diff] [blame] | 761 | else: |
Tarek Ziadé | 3679727 | 2010-07-22 12:50:05 +0000 | [diff] [blame] | 762 | from distutils import sysconfig |
| 763 | if sysconfig.get_config_var('Py_ENABLE_SHARED'): |
Barry Warsaw | 8cf4eae | 2010-10-16 01:04:07 +0000 | [diff] [blame] | 764 | pythonlib = 'python{}.{}{}'.format( |
| 765 | sys.hexversion >> 24, (sys.hexversion >> 16) & 0xff, |
| 766 | sys.abiflags) |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 767 | return ext.libraries + [pythonlib] |
| 768 | else: |
| 769 | return ext.libraries |