build_ext.py 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693
  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 37828 2004-11-10 22:23:15Z loewis $"
  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 string.find(sys.executable, sys.exec_prefix) != -1:
  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. # The argument parsing will result in self.define being a string, but
  168. # it has to be a list of 2-tuples. All the preprocessor symbols
  169. # specified by the 'define' option will be set to '1'. Multiple
  170. # symbols can be separated with commas.
  171. if self.define:
  172. defines = string.split(self.define, ',')
  173. self.define = map(lambda symbol: (symbol, '1'), defines)
  174. # The option for macros to undefine is also a string from the
  175. # option parsing, but has to be a list. Multiple symbols can also
  176. # be separated with commas here.
  177. if self.undef:
  178. self.undef = string.split(self.undef, ',')
  179. if self.swig_opts is None:
  180. self.swig_opts = []
  181. else:
  182. self.swig_opts = self.swig_opts.split(' ')
  183. # finalize_options ()
  184. def run (self):
  185. from distutils.ccompiler import new_compiler
  186. # 'self.extensions', as supplied by setup.py, is a list of
  187. # Extension instances. See the documentation for Extension (in
  188. # distutils.extension) for details.
  189. #
  190. # For backwards compatibility with Distutils 0.8.2 and earlier, we
  191. # also allow the 'extensions' list to be a list of tuples:
  192. # (ext_name, build_info)
  193. # where build_info is a dictionary containing everything that
  194. # Extension instances do except the name, with a few things being
  195. # differently named. We convert these 2-tuples to Extension
  196. # instances as needed.
  197. if not self.extensions:
  198. return
  199. # If we were asked to build any C/C++ libraries, make sure that the
  200. # directory where we put them is in the library search path for
  201. # linking extensions.
  202. if self.distribution.has_c_libraries():
  203. build_clib = self.get_finalized_command('build_clib')
  204. self.libraries.extend(build_clib.get_library_names() or [])
  205. self.library_dirs.append(build_clib.build_clib)
  206. # Setup the CCompiler object that we'll use to do all the
  207. # compiling and linking
  208. self.compiler = new_compiler(compiler=self.compiler,
  209. verbose=self.verbose,
  210. dry_run=self.dry_run,
  211. force=self.force)
  212. customize_compiler(self.compiler)
  213. # And make sure that any compile/link-related options (which might
  214. # come from the command-line or from the setup script) are set in
  215. # that CCompiler object -- that way, they automatically apply to
  216. # all compiling and linking done here.
  217. if self.include_dirs is not None:
  218. self.compiler.set_include_dirs(self.include_dirs)
  219. if self.define is not None:
  220. # 'define' option is a list of (name,value) tuples
  221. for (name,value) in self.define:
  222. self.compiler.define_macro(name, value)
  223. if self.undef is not None:
  224. for macro in self.undef:
  225. self.compiler.undefine_macro(macro)
  226. if self.libraries is not None:
  227. self.compiler.set_libraries(self.libraries)
  228. if self.library_dirs is not None:
  229. self.compiler.set_library_dirs(self.library_dirs)
  230. if self.rpath is not None:
  231. self.compiler.set_runtime_library_dirs(self.rpath)
  232. if self.link_objects is not None:
  233. self.compiler.set_link_objects(self.link_objects)
  234. # Now actually compile and link everything.
  235. self.build_extensions()
  236. # run ()
  237. def check_extensions_list (self, extensions):
  238. """Ensure that the list of extensions (presumably provided as a
  239. command option 'extensions') is valid, i.e. it is a list of
  240. Extension objects. We also support the old-style list of 2-tuples,
  241. where the tuples are (ext_name, build_info), which are converted to
  242. Extension instances here.
  243. Raise DistutilsSetupError if the structure is invalid anywhere;
  244. just returns otherwise.
  245. """
  246. if type(extensions) is not ListType:
  247. raise DistutilsSetupError, \
  248. "'ext_modules' option must be a list of Extension instances"
  249. for i in range(len(extensions)):
  250. ext = extensions[i]
  251. if isinstance(ext, Extension):
  252. continue # OK! (assume type-checking done
  253. # by Extension constructor)
  254. (ext_name, build_info) = ext
  255. log.warn(("old-style (ext_name, build_info) tuple found in "
  256. "ext_modules for extension '%s'"
  257. "-- please convert to Extension instance" % ext_name))
  258. if type(ext) is not TupleType and len(ext) != 2:
  259. raise DistutilsSetupError, \
  260. ("each element of 'ext_modules' option must be an "
  261. "Extension instance or 2-tuple")
  262. if not (type(ext_name) is StringType and
  263. extension_name_re.match(ext_name)):
  264. raise DistutilsSetupError, \
  265. ("first element of each tuple in 'ext_modules' "
  266. "must be the extension name (a string)")
  267. if type(build_info) is not DictionaryType:
  268. raise DistutilsSetupError, \
  269. ("second element of each tuple in 'ext_modules' "
  270. "must be a dictionary (build info)")
  271. # OK, the (ext_name, build_info) dict is type-safe: convert it
  272. # to an Extension instance.
  273. ext = Extension(ext_name, build_info['sources'])
  274. # Easy stuff: one-to-one mapping from dict elements to
  275. # instance attributes.
  276. for key in ('include_dirs',
  277. 'library_dirs',
  278. 'libraries',
  279. 'extra_objects',
  280. 'extra_compile_args',
  281. 'extra_link_args'):
  282. val = build_info.get(key)
  283. if val is not None:
  284. setattr(ext, key, val)
  285. # Medium-easy stuff: same syntax/semantics, different names.
  286. ext.runtime_library_dirs = build_info.get('rpath')
  287. if build_info.has_key('def_file'):
  288. log.warn("'def_file' element of build info dict "
  289. "no longer supported")
  290. # Non-trivial stuff: 'macros' split into 'define_macros'
  291. # and 'undef_macros'.
  292. macros = build_info.get('macros')
  293. if macros:
  294. ext.define_macros = []
  295. ext.undef_macros = []
  296. for macro in macros:
  297. if not (type(macro) is TupleType and
  298. 1 <= len(macro) <= 2):
  299. raise DistutilsSetupError, \
  300. ("'macros' element of build info dict "
  301. "must be 1- or 2-tuple")
  302. if len(macro) == 1:
  303. ext.undef_macros.append(macro[0])
  304. elif len(macro) == 2:
  305. ext.define_macros.append(macro)
  306. extensions[i] = ext
  307. # for extensions
  308. # check_extensions_list ()
  309. def get_source_files (self):
  310. self.check_extensions_list(self.extensions)
  311. filenames = []
  312. # Wouldn't it be neat if we knew the names of header files too...
  313. for ext in self.extensions:
  314. filenames.extend(ext.sources)
  315. return filenames
  316. def get_outputs (self):
  317. # Sanity check the 'extensions' list -- can't assume this is being
  318. # done in the same run as a 'build_extensions()' call (in fact, we
  319. # can probably assume that it *isn't*!).
  320. self.check_extensions_list(self.extensions)
  321. # And build the list of output (built) filenames. Note that this
  322. # ignores the 'inplace' flag, and assumes everything goes in the
  323. # "build" tree.
  324. outputs = []
  325. for ext in self.extensions:
  326. fullname = self.get_ext_fullname(ext.name)
  327. outputs.append(os.path.join(self.build_lib,
  328. self.get_ext_filename(fullname)))
  329. return outputs
  330. # get_outputs ()
  331. def build_extensions(self):
  332. # First, sanity-check the 'extensions' list
  333. self.check_extensions_list(self.extensions)
  334. for ext in self.extensions:
  335. self.build_extension(ext)
  336. def build_extension(self, ext):
  337. sources = ext.sources
  338. if sources is None or type(sources) not in (ListType, TupleType):
  339. raise DistutilsSetupError, \
  340. ("in 'ext_modules' option (extension '%s'), " +
  341. "'sources' must be present and must be " +
  342. "a list of source filenames") % ext.name
  343. sources = list(sources)
  344. fullname = self.get_ext_fullname(ext.name)
  345. if self.inplace:
  346. # ignore build-lib -- put the compiled extension into
  347. # the source tree along with pure Python modules
  348. modpath = string.split(fullname, '.')
  349. package = string.join(modpath[0:-1], '.')
  350. base = modpath[-1]
  351. build_py = self.get_finalized_command('build_py')
  352. package_dir = build_py.get_package_dir(package)
  353. ext_filename = os.path.join(package_dir,
  354. self.get_ext_filename(base))
  355. else:
  356. ext_filename = os.path.join(self.build_lib,
  357. self.get_ext_filename(fullname))
  358. depends = sources + ext.depends
  359. if not (self.force or newer_group(depends, ext_filename, 'newer')):
  360. log.debug("skipping '%s' extension (up-to-date)", ext.name)
  361. return
  362. else:
  363. log.info("building '%s' extension", ext.name)
  364. # First, scan the sources for SWIG definition files (.i), run
  365. # SWIG on 'em to create .c files, and modify the sources list
  366. # accordingly.
  367. sources = self.swig_sources(sources, ext)
  368. # Next, compile the source code to object files.
  369. # XXX not honouring 'define_macros' or 'undef_macros' -- the
  370. # CCompiler API needs to change to accommodate this, and I
  371. # want to do one thing at a time!
  372. # Two possible sources for extra compiler arguments:
  373. # - 'extra_compile_args' in Extension object
  374. # - CFLAGS environment variable (not particularly
  375. # elegant, but people seem to expect it and I
  376. # guess it's useful)
  377. # The environment variable should take precedence, and
  378. # any sensible compiler will give precedence to later
  379. # command line args. Hence we combine them in order:
  380. extra_args = ext.extra_compile_args or []
  381. macros = ext.define_macros[:]
  382. for undef in ext.undef_macros:
  383. macros.append((undef,))
  384. objects = self.compiler.compile(sources,
  385. output_dir=self.build_temp,
  386. macros=macros,
  387. include_dirs=ext.include_dirs,
  388. debug=self.debug,
  389. extra_postargs=extra_args,
  390. depends=ext.depends)
  391. # XXX -- this is a Vile HACK!
  392. #
  393. # The setup.py script for Python on Unix needs to be able to
  394. # get this list so it can perform all the clean up needed to
  395. # avoid keeping object files around when cleaning out a failed
  396. # build of an extension module. Since Distutils does not
  397. # track dependencies, we have to get rid of intermediates to
  398. # ensure all the intermediates will be properly re-built.
  399. #
  400. self._built_objects = objects[:]
  401. # Now link the object files together into a "shared object" --
  402. # of course, first we have to figure out all the other things
  403. # that go into the mix.
  404. if ext.extra_objects:
  405. objects.extend(ext.extra_objects)
  406. extra_args = ext.extra_link_args or []
  407. # Detect target language, if not provided
  408. language = ext.language or self.compiler.detect_language(sources)
  409. self.compiler.link_shared_object(
  410. objects, ext_filename,
  411. libraries=self.get_libraries(ext),
  412. library_dirs=ext.library_dirs,
  413. runtime_library_dirs=ext.runtime_library_dirs,
  414. extra_postargs=extra_args,
  415. export_symbols=self.get_export_symbols(ext),
  416. debug=self.debug,
  417. build_temp=self.build_temp,
  418. target_lang=language)
  419. def swig_sources (self, sources, extension):
  420. """Walk the list of source files in 'sources', looking for SWIG
  421. interface (.i) files. Run SWIG on all that are found, and
  422. return a modified 'sources' list with SWIG source files replaced
  423. by the generated C (or C++) files.
  424. """
  425. new_sources = []
  426. swig_sources = []
  427. swig_targets = {}
  428. # XXX this drops generated C/C++ files into the source tree, which
  429. # is fine for developers who want to distribute the generated
  430. # source -- but there should be an option to put SWIG output in
  431. # the temp dir.
  432. if self.swig_cpp:
  433. log.warn("--swig-cpp is deprecated - use --swig-opts=-c++")
  434. if self.swig_cpp or ('-c++' in self.swig_opts):
  435. target_ext = '.cpp'
  436. else:
  437. target_ext = '.c'
  438. for source in sources:
  439. (base, ext) = os.path.splitext(source)
  440. if ext == ".i": # SWIG interface file
  441. new_sources.append(base + '_wrap' + target_ext)
  442. swig_sources.append(source)
  443. swig_targets[source] = new_sources[-1]
  444. else:
  445. new_sources.append(source)
  446. if not swig_sources:
  447. return new_sources
  448. swig = self.swig or self.find_swig()
  449. swig_cmd = [swig, "-python"]
  450. swig_cmd.extend(self.swig_opts)
  451. if self.swig_cpp:
  452. swig_cmd.append("-c++")
  453. # Do not override commandline arguments
  454. if not self.swig_opts:
  455. for o in extension.swig_opts:
  456. swig_cmd.append(o)
  457. for source in swig_sources:
  458. target = swig_targets[source]
  459. log.info("swigging %s to %s", source, target)
  460. self.spawn(swig_cmd + ["-o", target, source])
  461. return new_sources
  462. # swig_sources ()
  463. def find_swig (self):
  464. """Return the name of the SWIG executable. On Unix, this is
  465. just "swig" -- it should be in the PATH. Tries a bit harder on
  466. Windows.
  467. """
  468. if os.name == "posix":
  469. return "swig"
  470. elif os.name == "nt":
  471. # Look for SWIG in its standard installation directory on
  472. # Windows (or so I presume!). If we find it there, great;
  473. # if not, act like Unix and assume it's in the PATH.
  474. for vers in ("1.3", "1.2", "1.1"):
  475. fn = os.path.join("c:\\swig%s" % vers, "swig.exe")
  476. if os.path.isfile(fn):
  477. return fn
  478. else:
  479. return "swig.exe"
  480. elif os.name == "os2":
  481. # assume swig available in the PATH.
  482. return "swig.exe"
  483. else:
  484. raise DistutilsPlatformError, \
  485. ("I don't know how to find (much less run) SWIG "
  486. "on platform '%s'") % os.name
  487. # find_swig ()
  488. # -- Name generators -----------------------------------------------
  489. # (extension names, filenames, whatever)
  490. def get_ext_fullname (self, ext_name):
  491. if self.package is None:
  492. return ext_name
  493. else:
  494. return self.package + '.' + ext_name
  495. def get_ext_filename (self, ext_name):
  496. r"""Convert the name of an extension (eg. "foo.bar") into the name
  497. of the file from which it will be loaded (eg. "foo/bar.so", or
  498. "foo\bar.pyd").
  499. """
  500. from distutils.sysconfig import get_config_var
  501. ext_path = string.split(ext_name, '.')
  502. # OS/2 has an 8 character module (extension) limit :-(
  503. if os.name == "os2":
  504. ext_path[len(ext_path) - 1] = ext_path[len(ext_path) - 1][:8]
  505. # extensions in debug_mode are named 'module_d.pyd' under windows
  506. so_ext = get_config_var('SO')
  507. if os.name == 'nt' and self.debug:
  508. return apply(os.path.join, ext_path) + '_d' + so_ext
  509. return apply(os.path.join, ext_path) + so_ext
  510. def get_export_symbols (self, ext):
  511. """Return the list of symbols that a shared extension has to
  512. export. This either uses 'ext.export_symbols' or, if it's not
  513. provided, "init" + module_name. Only relevant on Windows, where
  514. the .pyd file (DLL) must export the module "init" function.
  515. """
  516. initfunc_name = "init" + string.split(ext.name,'.')[-1]
  517. if initfunc_name not in ext.export_symbols:
  518. ext.export_symbols.append(initfunc_name)
  519. return ext.export_symbols
  520. def get_libraries (self, ext):
  521. """Return the list of libraries to link against when building a
  522. shared extension. On most platforms, this is just 'ext.libraries';
  523. on Windows and OS/2, we add the Python library (eg. python20.dll).
  524. """
  525. # The python library is always needed on Windows. For MSVC, this
  526. # is redundant, since the library is mentioned in a pragma in
  527. # pyconfig.h that MSVC groks. The other Windows compilers all seem
  528. # to need it mentioned explicitly, though, so that's what we do.
  529. # Append '_d' to the python import library on debug builds.
  530. if sys.platform == "win32":
  531. from distutils.msvccompiler import MSVCCompiler
  532. if not isinstance(self.compiler, MSVCCompiler):
  533. template = "python%d%d"
  534. if self.debug:
  535. template = template + '_d'
  536. pythonlib = (template %
  537. (sys.hexversion >> 24, (sys.hexversion >> 16) & 0xff))
  538. # don't extend ext.libraries, it may be shared with other
  539. # extensions, it is a reference to the original list
  540. return ext.libraries + [pythonlib]
  541. else:
  542. return ext.libraries
  543. elif sys.platform == "os2emx":
  544. # EMX/GCC requires the python library explicitly, and I
  545. # believe VACPP does as well (though not confirmed) - AIM Apr01
  546. template = "python%d%d"
  547. # debug versions of the main DLL aren't supported, at least
  548. # not at this time - AIM Apr01
  549. #if self.debug:
  550. # template = template + '_d'
  551. pythonlib = (template %
  552. (sys.hexversion >> 24, (sys.hexversion >> 16) & 0xff))
  553. # don't extend ext.libraries, it may be shared with other
  554. # extensions, it is a reference to the original list
  555. return ext.libraries + [pythonlib]
  556. elif sys.platform[:6] == "cygwin":
  557. template = "python%d.%d"
  558. pythonlib = (template %
  559. (sys.hexversion >> 24, (sys.hexversion >> 16) & 0xff))
  560. # don't extend ext.libraries, it may be shared with other
  561. # extensions, it is a reference to the original list
  562. return ext.libraries + [pythonlib]
  563. elif sys.platform[:6] == "atheos":
  564. from distutils import sysconfig
  565. template = "python%d.%d"
  566. pythonlib = (template %
  567. (sys.hexversion >> 24, (sys.hexversion >> 16) & 0xff))
  568. # Get SHLIBS from Makefile
  569. extra = []
  570. for lib in sysconfig.get_config_var('SHLIBS').split():
  571. if lib.startswith('-l'):
  572. extra.append(lib[2:])
  573. else:
  574. extra.append(lib)
  575. # don't extend ext.libraries, it may be shared with other
  576. # extensions, it is a reference to the original list
  577. return ext.libraries + [pythonlib, "m"] + extra
  578. else:
  579. return ext.libraries
  580. # class build_ext