PageRenderTime 50ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/python/lib/Lib/distutils/command/build_ext.py

http://github.com/JetBrains/intellij-community
Python | 717 lines | 544 code | 68 blank | 105 comment | 63 complexity | a67c0522fa38fab6b93fcf99c30fc2bc MD5 | raw file
Possible License(s): BSD-3-Clause, Apache-2.0, MPL-2.0-no-copyleft-exception, MIT, EPL-1.0, AGPL-1.0
  1. """distutils.command.build_ext
  2. Implements the Distutils 'build_ext' command, for building extension
  3. modules (currently limited to C extensions, should accommodate C++
  4. extensions ASAP)."""
  5. # This module should be kept compatible with Python 2.1.
  6. __revision__ = "$Id: build_ext.py 54942 2007-04-24 15:27:25Z georg.brandl $"
  7. import sys, os, string, re
  8. from types import *
  9. from distutils.core import Command
  10. from distutils.errors import *
  11. from distutils.sysconfig import customize_compiler, get_python_version
  12. from distutils.dep_util import newer_group
  13. from distutils.extension import Extension
  14. from distutils import log
  15. # An extension name is just a dot-separated list of Python NAMEs (ie.
  16. # the same as a fully-qualified module name).
  17. extension_name_re = re.compile \
  18. (r'^[a-zA-Z_][a-zA-Z_0-9]*(\.[a-zA-Z_][a-zA-Z_0-9]*)*$')
  19. def show_compilers ():
  20. from distutils.ccompiler import show_compilers
  21. show_compilers()
  22. class build_ext (Command):
  23. description = "build C/C++ extensions (compile/link to build directory)"
  24. # XXX thoughts on how to deal with complex command-line options like
  25. # these, i.e. how to make it so fancy_getopt can suck them off the
  26. # command line and make it look like setup.py defined the appropriate
  27. # lists of tuples of what-have-you.
  28. # - each command needs a callback to process its command-line options
  29. # - Command.__init__() needs access to its share of the whole
  30. # command line (must ultimately come from
  31. # Distribution.parse_command_line())
  32. # - it then calls the current command class' option-parsing
  33. # callback to deal with weird options like -D, which have to
  34. # parse the option text and churn out some custom data
  35. # structure
  36. # - that data structure (in this case, a list of 2-tuples)
  37. # will then be present in the command object by the time
  38. # we get to finalize_options() (i.e. the constructor
  39. # takes care of both command-line and client options
  40. # in between initialize_options() and finalize_options())
  41. sep_by = " (separated by '%s')" % os.pathsep
  42. user_options = [
  43. ('build-lib=', 'b',
  44. "directory for compiled extension modules"),
  45. ('build-temp=', 't',
  46. "directory for temporary files (build by-products)"),
  47. ('inplace', 'i',
  48. "ignore build-lib and put compiled extensions into the source " +
  49. "directory alongside your pure Python modules"),
  50. ('include-dirs=', 'I',
  51. "list of directories to search for header files" + sep_by),
  52. ('define=', 'D',
  53. "C preprocessor macros to define"),
  54. ('undef=', 'U',
  55. "C preprocessor macros to undefine"),
  56. ('libraries=', 'l',
  57. "external C libraries to link with"),
  58. ('library-dirs=', 'L',
  59. "directories to search for external C libraries" + sep_by),
  60. ('rpath=', 'R',
  61. "directories to search for shared C libraries at runtime"),
  62. ('link-objects=', 'O',
  63. "extra explicit link objects to include in the link"),
  64. ('debug', 'g',
  65. "compile/link with debugging information"),
  66. ('force', 'f',
  67. "forcibly build everything (ignore file timestamps)"),
  68. ('compiler=', 'c',
  69. "specify the compiler type"),
  70. ('swig-cpp', None,
  71. "make SWIG create C++ files (default is C)"),
  72. ('swig-opts=', None,
  73. "list of SWIG command line options"),
  74. ('swig=', None,
  75. "path to the SWIG executable"),
  76. ]
  77. boolean_options = ['inplace', 'debug', 'force', 'swig-cpp']
  78. help_options = [
  79. ('help-compiler', None,
  80. "list available compilers", show_compilers),
  81. ]
  82. def initialize_options (self):
  83. self.extensions = None
  84. self.build_lib = None
  85. self.build_temp = None
  86. self.inplace = 0
  87. self.package = None
  88. self.include_dirs = None
  89. self.define = None
  90. self.undef = None
  91. self.libraries = None
  92. self.library_dirs = None
  93. self.rpath = None
  94. self.link_objects = None
  95. self.debug = None
  96. self.force = None
  97. self.compiler = None
  98. self.swig = None
  99. self.swig_cpp = None
  100. self.swig_opts = None
  101. def finalize_options (self):
  102. from distutils import sysconfig
  103. self.set_undefined_options('build',
  104. ('build_lib', 'build_lib'),
  105. ('build_temp', 'build_temp'),
  106. ('compiler', 'compiler'),
  107. ('debug', 'debug'),
  108. ('force', 'force'))
  109. if self.package is None:
  110. self.package = self.distribution.ext_package
  111. self.extensions = self.distribution.ext_modules
  112. # Make sure Python's include directories (for Python.h, pyconfig.h,
  113. # etc.) are in the include search path.
  114. py_include = sysconfig.get_python_inc()
  115. plat_py_include = sysconfig.get_python_inc(plat_specific=1)
  116. if self.include_dirs is None:
  117. self.include_dirs = self.distribution.include_dirs or []
  118. if type(self.include_dirs) is StringType:
  119. self.include_dirs = string.split(self.include_dirs, os.pathsep)
  120. # Put the Python "system" include dir at the end, so that
  121. # any local include dirs take precedence.
  122. self.include_dirs.append(py_include)
  123. if plat_py_include != py_include:
  124. self.include_dirs.append(plat_py_include)
  125. if type(self.libraries) is StringType:
  126. self.libraries = [self.libraries]
  127. # Life is easier if we're not forever checking for None, so
  128. # simplify these options to empty lists if unset
  129. if self.libraries is None:
  130. self.libraries = []
  131. if self.library_dirs is None:
  132. self.library_dirs = []
  133. elif type(self.library_dirs) is StringType:
  134. self.library_dirs = string.split(self.library_dirs, os.pathsep)
  135. if self.rpath is None:
  136. self.rpath = []
  137. elif type(self.rpath) is StringType:
  138. self.rpath = string.split(self.rpath, os.pathsep)
  139. # for extensions under windows use different directories
  140. # for Release and Debug builds.
  141. # also Python's library directory must be appended to library_dirs
  142. if os.name == 'nt':
  143. self.library_dirs.append(os.path.join(sys.exec_prefix, 'libs'))
  144. if self.debug:
  145. self.build_temp = os.path.join(self.build_temp, "Debug")
  146. else:
  147. self.build_temp = os.path.join(self.build_temp, "Release")
  148. # Append the source distribution include and library directories,
  149. # this allows distutils on windows to work in the source tree
  150. self.include_dirs.append(os.path.join(sys.exec_prefix, 'PC'))
  151. self.library_dirs.append(os.path.join(sys.exec_prefix, 'PCBuild'))
  152. # OS/2 (EMX) doesn't support Debug vs Release builds, but has the
  153. # import libraries in its "Config" subdirectory
  154. if os.name == 'os2':
  155. self.library_dirs.append(os.path.join(sys.exec_prefix, 'Config'))
  156. # for extensions under Cygwin and AtheOS Python's library directory must be
  157. # appended to library_dirs
  158. if sys.platform[:6] == 'cygwin' or sys.platform[:6] == 'atheos':
  159. if sys.executable.startswith(os.path.join(sys.exec_prefix, "bin")):
  160. # building third party extensions
  161. self.library_dirs.append(os.path.join(sys.prefix, "lib",
  162. "python" + get_python_version(),
  163. "config"))
  164. else:
  165. # building python standard extensions
  166. self.library_dirs.append('.')
  167. # for extensions under Linux with a shared Python library,
  168. # Python's library directory must be appended to library_dirs
  169. if (sys.platform.startswith('linux') or sys.platform.startswith('gnu')) \
  170. and sysconfig.get_config_var('Py_ENABLE_SHARED'):
  171. if sys.executable.startswith(os.path.join(sys.exec_prefix, "bin")):
  172. # building third party extensions
  173. self.library_dirs.append(sysconfig.get_config_var('LIBDIR'))
  174. else:
  175. # building python standard extensions
  176. self.library_dirs.append('.')
  177. # The argument parsing will result in self.define being a string, but
  178. # it has to be a list of 2-tuples. All the preprocessor symbols
  179. # specified by the 'define' option will be set to '1'. Multiple
  180. # symbols can be separated with commas.
  181. if self.define:
  182. defines = string.split(self.define, ',')
  183. self.define = map(lambda symbol: (symbol, '1'), defines)
  184. # The option for macros to undefine is also a string from the
  185. # option parsing, but has to be a list. Multiple symbols can also
  186. # be separated with commas here.
  187. if self.undef:
  188. self.undef = string.split(self.undef, ',')
  189. if self.swig_opts is None:
  190. self.swig_opts = []
  191. else:
  192. self.swig_opts = self.swig_opts.split(' ')
  193. # finalize_options ()
  194. def run (self):
  195. from distutils.ccompiler import new_compiler
  196. # 'self.extensions', as supplied by setup.py, is a list of
  197. # Extension instances. See the documentation for Extension (in
  198. # distutils.extension) for details.
  199. #
  200. # For backwards compatibility with Distutils 0.8.2 and earlier, we
  201. # also allow the 'extensions' list to be a list of tuples:
  202. # (ext_name, build_info)
  203. # where build_info is a dictionary containing everything that
  204. # Extension instances do except the name, with a few things being
  205. # differently named. We convert these 2-tuples to Extension
  206. # instances as needed.
  207. if not self.extensions:
  208. return
  209. # If we were asked to build any C/C++ libraries, make sure that the
  210. # directory where we put them is in the library search path for
  211. # linking extensions.
  212. if self.distribution.has_c_libraries():
  213. build_clib = self.get_finalized_command('build_clib')
  214. self.libraries.extend(build_clib.get_library_names() or [])
  215. self.library_dirs.append(build_clib.build_clib)
  216. # Setup the CCompiler object that we'll use to do all the
  217. # compiling and linking
  218. self.compiler = new_compiler(compiler=self.compiler,
  219. verbose=self.verbose,
  220. dry_run=self.dry_run,
  221. force=self.force)
  222. customize_compiler(self.compiler)
  223. # And make sure that any compile/link-related options (which might
  224. # come from the command-line or from the setup script) are set in
  225. # that CCompiler object -- that way, they automatically apply to
  226. # all compiling and linking done here.
  227. if self.include_dirs is not None:
  228. self.compiler.set_include_dirs(self.include_dirs)
  229. if self.define is not None:
  230. # 'define' option is a list of (name,value) tuples
  231. for (name,value) in self.define:
  232. self.compiler.define_macro(name, value)
  233. if self.undef is not None:
  234. for macro in self.undef:
  235. self.compiler.undefine_macro(macro)
  236. if self.libraries is not None:
  237. self.compiler.set_libraries(self.libraries)
  238. if self.library_dirs is not None:
  239. self.compiler.set_library_dirs(self.library_dirs)
  240. if self.rpath is not None:
  241. self.compiler.set_runtime_library_dirs(self.rpath)
  242. if self.link_objects is not None:
  243. self.compiler.set_link_objects(self.link_objects)
  244. # Now actually compile and link everything.
  245. self.build_extensions()
  246. # run ()
  247. def check_extensions_list (self, extensions):
  248. """Ensure that the list of extensions (presumably provided as a
  249. command option 'extensions') is valid, i.e. it is a list of
  250. Extension objects. We also support the old-style list of 2-tuples,
  251. where the tuples are (ext_name, build_info), which are converted to
  252. Extension instances here.
  253. Raise DistutilsSetupError if the structure is invalid anywhere;
  254. just returns otherwise.
  255. """
  256. if type(extensions) is not ListType:
  257. raise DistutilsSetupError, \
  258. "'ext_modules' option must be a list of Extension instances"
  259. for i in range(len(extensions)):
  260. ext = extensions[i]
  261. if isinstance(ext, Extension):
  262. continue # OK! (assume type-checking done
  263. # by Extension constructor)
  264. (ext_name, build_info) = ext
  265. log.warn(("old-style (ext_name, build_info) tuple found in "
  266. "ext_modules for extension '%s'"
  267. "-- please convert to Extension instance" % ext_name))
  268. if type(ext) is not TupleType and len(ext) != 2:
  269. raise DistutilsSetupError, \
  270. ("each element of 'ext_modules' option must be an "
  271. "Extension instance or 2-tuple")
  272. if not (type(ext_name) is StringType and
  273. extension_name_re.match(ext_name)):
  274. raise DistutilsSetupError, \
  275. ("first element of each tuple in 'ext_modules' "
  276. "must be the extension name (a string)")
  277. if type(build_info) is not DictionaryType:
  278. raise DistutilsSetupError, \
  279. ("second element of each tuple in 'ext_modules' "
  280. "must be a dictionary (build info)")
  281. # OK, the (ext_name, build_info) dict is type-safe: convert it
  282. # to an Extension instance.
  283. ext = Extension(ext_name, build_info['sources'])
  284. # Easy stuff: one-to-one mapping from dict elements to
  285. # instance attributes.
  286. for key in ('include_dirs',
  287. 'library_dirs',
  288. 'libraries',
  289. 'extra_objects',
  290. 'extra_compile_args',
  291. 'extra_link_args'):
  292. val = build_info.get(key)
  293. if val is not None:
  294. setattr(ext, key, val)
  295. # Medium-easy stuff: same syntax/semantics, different names.
  296. ext.runtime_library_dirs = build_info.get('rpath')
  297. if build_info.has_key('def_file'):
  298. log.warn("'def_file' element of build info dict "
  299. "no longer supported")
  300. # Non-trivial stuff: 'macros' split into 'define_macros'
  301. # and 'undef_macros'.
  302. macros = build_info.get('macros')
  303. if macros:
  304. ext.define_macros = []
  305. ext.undef_macros = []
  306. for macro in macros:
  307. if not (type(macro) is TupleType and
  308. 1 <= len(macro) <= 2):
  309. raise DistutilsSetupError, \
  310. ("'macros' element of build info dict "
  311. "must be 1- or 2-tuple")
  312. if len(macro) == 1:
  313. ext.undef_macros.append(macro[0])
  314. elif len(macro) == 2:
  315. ext.define_macros.append(macro)
  316. extensions[i] = ext
  317. # for extensions
  318. # check_extensions_list ()
  319. def get_source_files (self):
  320. self.check_extensions_list(self.extensions)
  321. filenames = []
  322. # Wouldn't it be neat if we knew the names of header files too...
  323. for ext in self.extensions:
  324. filenames.extend(ext.sources)
  325. return filenames
  326. def get_outputs (self):
  327. # Sanity check the 'extensions' list -- can't assume this is being
  328. # done in the same run as a 'build_extensions()' call (in fact, we
  329. # can probably assume that it *isn't*!).
  330. self.check_extensions_list(self.extensions)
  331. # And build the list of output (built) filenames. Note that this
  332. # ignores the 'inplace' flag, and assumes everything goes in the
  333. # "build" tree.
  334. outputs = []
  335. for ext in self.extensions:
  336. fullname = self.get_ext_fullname(ext.name)
  337. outputs.append(os.path.join(self.build_lib,
  338. self.get_ext_filename(fullname)))
  339. return outputs
  340. # get_outputs ()
  341. def build_extensions(self):
  342. # First, sanity-check the 'extensions' list
  343. self.check_extensions_list(self.extensions)
  344. for ext in self.extensions:
  345. self.build_extension(ext)
  346. def build_extension(self, ext):
  347. sources = ext.sources
  348. if sources is None or type(sources) not in (ListType, TupleType):
  349. raise DistutilsSetupError, \
  350. ("in 'ext_modules' option (extension '%s'), " +
  351. "'sources' must be present and must be " +
  352. "a list of source filenames") % ext.name
  353. sources = list(sources)
  354. fullname = self.get_ext_fullname(ext.name)
  355. if self.inplace:
  356. # ignore build-lib -- put the compiled extension into
  357. # the source tree along with pure Python modules
  358. modpath = string.split(fullname, '.')
  359. package = string.join(modpath[0:-1], '.')
  360. base = modpath[-1]
  361. build_py = self.get_finalized_command('build_py')
  362. package_dir = build_py.get_package_dir(package)
  363. ext_filename = os.path.join(package_dir,
  364. self.get_ext_filename(base))
  365. else:
  366. ext_filename = os.path.join(self.build_lib,
  367. self.get_ext_filename(fullname))
  368. depends = sources + ext.depends
  369. if not (self.force or newer_group(depends, ext_filename, 'newer')):
  370. log.debug("skipping '%s' extension (up-to-date)", ext.name)
  371. return
  372. else:
  373. log.info("building '%s' extension", ext.name)
  374. # First, scan the sources for SWIG definition files (.i), run
  375. # SWIG on 'em to create .c files, and modify the sources list
  376. # accordingly.
  377. sources = self.swig_sources(sources, ext)
  378. # Next, compile the source code to object files.
  379. # XXX not honouring 'define_macros' or 'undef_macros' -- the
  380. # CCompiler API needs to change to accommodate this, and I
  381. # want to do one thing at a time!
  382. # Two possible sources for extra compiler arguments:
  383. # - 'extra_compile_args' in Extension object
  384. # - CFLAGS environment variable (not particularly
  385. # elegant, but people seem to expect it and I
  386. # guess it's useful)
  387. # The environment variable should take precedence, and
  388. # any sensible compiler will give precedence to later
  389. # command line args. Hence we combine them in order:
  390. extra_args = ext.extra_compile_args or []
  391. macros = ext.define_macros[:]
  392. for undef in ext.undef_macros:
  393. macros.append((undef,))
  394. objects = self.compiler.compile(sources,
  395. output_dir=self.build_temp,
  396. macros=macros,
  397. include_dirs=ext.include_dirs,
  398. debug=self.debug,
  399. extra_postargs=extra_args,
  400. depends=ext.depends)
  401. # XXX -- this is a Vile HACK!
  402. #
  403. # The setup.py script for Python on Unix needs to be able to
  404. # get this list so it can perform all the clean up needed to
  405. # avoid keeping object files around when cleaning out a failed
  406. # build of an extension module. Since Distutils does not
  407. # track dependencies, we have to get rid of intermediates to
  408. # ensure all the intermediates will be properly re-built.
  409. #
  410. self._built_objects = objects[:]
  411. # Now link the object files together into a "shared object" --
  412. # of course, first we have to figure out all the other things
  413. # that go into the mix.
  414. if ext.extra_objects:
  415. objects.extend(ext.extra_objects)
  416. extra_args = ext.extra_link_args or []
  417. # Detect target language, if not provided
  418. language = ext.language or self.compiler.detect_language(sources)
  419. self.compiler.link_shared_object(
  420. objects, ext_filename,
  421. libraries=self.get_libraries(ext),
  422. library_dirs=ext.library_dirs,
  423. runtime_library_dirs=ext.runtime_library_dirs,
  424. extra_postargs=extra_args,
  425. export_symbols=self.get_export_symbols(ext),
  426. debug=self.debug,
  427. build_temp=self.build_temp,
  428. target_lang=language)
  429. def swig_sources (self, sources, extension):
  430. """Walk the list of source files in 'sources', looking for SWIG
  431. interface (.i) files. Run SWIG on all that are found, and
  432. return a modified 'sources' list with SWIG source files replaced
  433. by the generated C (or C++) files.
  434. """
  435. new_sources = []
  436. swig_sources = []
  437. swig_targets = {}
  438. # XXX this drops generated C/C++ files into the source tree, which
  439. # is fine for developers who want to distribute the generated
  440. # source -- but there should be an option to put SWIG output in
  441. # the temp dir.
  442. if self.swig_cpp:
  443. log.warn("--swig-cpp is deprecated - use --swig-opts=-c++")
  444. if self.swig_cpp or ('-c++' in self.swig_opts) or \
  445. ('-c++' in extension.swig_opts):
  446. target_ext = '.cpp'
  447. else:
  448. target_ext = '.c'
  449. for source in sources:
  450. (base, ext) = os.path.splitext(source)
  451. if ext == ".i": # SWIG interface file
  452. new_sources.append(base + '_wrap' + target_ext)
  453. swig_sources.append(source)
  454. swig_targets[source] = new_sources[-1]
  455. else:
  456. new_sources.append(source)
  457. if not swig_sources:
  458. return new_sources
  459. swig = self.swig or self.find_swig()
  460. swig_cmd = [swig, "-python"]
  461. swig_cmd.extend(self.swig_opts)
  462. if self.swig_cpp:
  463. swig_cmd.append("-c++")
  464. # Do not override commandline arguments
  465. if not self.swig_opts:
  466. for o in extension.swig_opts:
  467. swig_cmd.append(o)
  468. for source in swig_sources:
  469. target = swig_targets[source]
  470. log.info("swigging %s to %s", source, target)
  471. self.spawn(swig_cmd + ["-o", target, source])
  472. return new_sources
  473. # swig_sources ()
  474. def find_swig (self):
  475. """Return the name of the SWIG executable. On Unix, this is
  476. just "swig" -- it should be in the PATH. Tries a bit harder on
  477. Windows.
  478. """
  479. if os.name == "posix":
  480. return "swig"
  481. elif os.name == "nt":
  482. # Look for SWIG in its standard installation directory on
  483. # Windows (or so I presume!). If we find it there, great;
  484. # if not, act like Unix and assume it's in the PATH.
  485. for vers in ("1.3", "1.2", "1.1"):
  486. fn = os.path.join("c:\\swig%s" % vers, "swig.exe")
  487. if os.path.isfile(fn):
  488. return fn
  489. else:
  490. return "swig.exe"
  491. elif os.name == "os2":
  492. # assume swig available in the PATH.
  493. return "swig.exe"
  494. else:
  495. raise DistutilsPlatformError, \
  496. ("I don't know how to find (much less run) SWIG "
  497. "on platform '%s'") % os.name
  498. # find_swig ()
  499. # -- Name generators -----------------------------------------------
  500. # (extension names, filenames, whatever)
  501. def get_ext_fullname (self, ext_name):
  502. if self.package is None:
  503. return ext_name
  504. else:
  505. return self.package + '.' + ext_name
  506. def get_ext_filename (self, ext_name):
  507. r"""Convert the name of an extension (eg. "foo.bar") into the name
  508. of the file from which it will be loaded (eg. "foo/bar.so", or
  509. "foo\bar.pyd").
  510. """
  511. from distutils.sysconfig import get_config_var
  512. ext_path = string.split(ext_name, '.')
  513. # OS/2 has an 8 character module (extension) limit :-(
  514. if os.name == "os2":
  515. ext_path[len(ext_path) - 1] = ext_path[len(ext_path) - 1][:8]
  516. # extensions in debug_mode are named 'module_d.pyd' under windows
  517. so_ext = get_config_var('SO')
  518. if os.name == 'nt' and self.debug:
  519. return apply(os.path.join, ext_path) + '_d' + so_ext
  520. return apply(os.path.join, ext_path) + so_ext
  521. def get_export_symbols (self, ext):
  522. """Return the list of symbols that a shared extension has to
  523. export. This either uses 'ext.export_symbols' or, if it's not
  524. provided, "init" + module_name. Only relevant on Windows, where
  525. the .pyd file (DLL) must export the module "init" function.
  526. """
  527. initfunc_name = "init" + string.split(ext.name,'.')[-1]
  528. if initfunc_name not in ext.export_symbols:
  529. ext.export_symbols.append(initfunc_name)
  530. return ext.export_symbols
  531. def get_libraries (self, ext):
  532. """Return the list of libraries to link against when building a
  533. shared extension. On most platforms, this is just 'ext.libraries';
  534. on Windows and OS/2, we add the Python library (eg. python20.dll).
  535. """
  536. # The python library is always needed on Windows. For MSVC, this
  537. # is redundant, since the library is mentioned in a pragma in
  538. # pyconfig.h that MSVC groks. The other Windows compilers all seem
  539. # to need it mentioned explicitly, though, so that's what we do.
  540. # Append '_d' to the python import library on debug builds.
  541. if sys.platform == "win32":
  542. from distutils.msvccompiler import MSVCCompiler
  543. if not isinstance(self.compiler, MSVCCompiler):
  544. template = "python%d%d"
  545. if self.debug:
  546. template = template + '_d'
  547. pythonlib = (template %
  548. (sys.hexversion >> 24, (sys.hexversion >> 16) & 0xff))
  549. # don't extend ext.libraries, it may be shared with other
  550. # extensions, it is a reference to the original list
  551. return ext.libraries + [pythonlib]
  552. else:
  553. return ext.libraries
  554. elif sys.platform == "os2emx":
  555. # EMX/GCC requires the python library explicitly, and I
  556. # believe VACPP does as well (though not confirmed) - AIM Apr01
  557. template = "python%d%d"
  558. # debug versions of the main DLL aren't supported, at least
  559. # not at this time - AIM Apr01
  560. #if self.debug:
  561. # template = template + '_d'
  562. pythonlib = (template %
  563. (sys.hexversion >> 24, (sys.hexversion >> 16) & 0xff))
  564. # don't extend ext.libraries, it may be shared with other
  565. # extensions, it is a reference to the original list
  566. return ext.libraries + [pythonlib]
  567. elif sys.platform[:6] == "cygwin":
  568. template = "python%d.%d"
  569. pythonlib = (template %
  570. (sys.hexversion >> 24, (sys.hexversion >> 16) & 0xff))
  571. # don't extend ext.libraries, it may be shared with other
  572. # extensions, it is a reference to the original list
  573. return ext.libraries + [pythonlib]
  574. elif sys.platform[:6] == "atheos":
  575. from distutils import sysconfig
  576. template = "python%d.%d"
  577. pythonlib = (template %
  578. (sys.hexversion >> 24, (sys.hexversion >> 16) & 0xff))
  579. # Get SHLIBS from Makefile
  580. extra = []
  581. for lib in sysconfig.get_config_var('SHLIBS').split():
  582. if lib.startswith('-l'):
  583. extra.append(lib[2:])
  584. else:
  585. extra.append(lib)
  586. # don't extend ext.libraries, it may be shared with other
  587. # extensions, it is a reference to the original list
  588. return ext.libraries + [pythonlib, "m"] + extra
  589. elif sys.platform == 'darwin':
  590. # Don't use the default code below
  591. return ext.libraries
  592. else:
  593. from distutils import sysconfig
  594. if sysconfig.get_config_var('Py_ENABLE_SHARED'):
  595. template = "python%d.%d"
  596. pythonlib = (template %
  597. (sys.hexversion >> 24, (sys.hexversion >> 16) & 0xff))
  598. return ext.libraries + [pythonlib]
  599. else:
  600. return ext.libraries
  601. # class build_ext