You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1120 lines
46 KiB

This patch fixes the following bugs: [#413582] g++ must be called for c++ extensions [#454030] distutils cannot link C++ code with GCC topdir = "Lib/distutils" * bcppcompiler.py (BCPPCompiler.create_static_lib): Fixed prototype, removing extra_preargs and extra_postargs parameters. Included target_lang parameter. (BCPPCompiler.link): Included target_lang parameter. * msvccompiler.py (MSVCCompiler.create_static_lib): Fixed prototype, removing extra_preargs and extra_postargs parameters. Included target_lang parameter. (MSVCCompiler.link): Included target_lang parameter. * ccompiler.py (CCompiler): New language_map and language_order attributes, used by CCompiler.detect_language(). (CCompiler.detect_language): New method, will return the language of a given source, or list of sources. Individual source language is detected using the language_map dict. When mixed sources are used, language_order will stablish the language precedence. (CCompiler.create_static_lib, CCompiler.link, CCompiler.link_executable, CCompiler.link_shared_object, CCompiler.link_shared_lib): Inlcuded target_lang parameter. * cygwinccompiler.py (CygwinCCompiler.link): Included target_lang parameter. * emxccompiler.py (EMXCCompiler.link): Included target_lang parameter. * mwerkscompiler.py (MWerksCompiler.link): Included target_lang parameter. * extension.py (Extension.__init__): New 'language' parameter/attribute, initialized to None by default. If provided will overlap the automatic detection made by CCompiler.detect_language(), in build_ext command. * sysconfig.py (customize_compiler): Check Makefile for CXX option, and also the environment variable CXX. Use the resulting value in the 'compiler_cxx' parameter of compiler.set_executables(). * unixccompiler.py (UnixCCompiler): Included 'compiler_cxx' in executables dict, defaulting to 'cc'. (UnixCCompiler.create_static_lib): Included target_lang parameter. (UnixCCompiler.link): Included target_lang parameter, and made linker command use compiler_cxx, if target_lang is 'c++'. * command/build_ext.py (build_ext.build_extension): Pass new ext.language attribute to compiler.link_shared_object()'s target_lang parameter. If ext.language is not provided, detect language using compiler.detect_language(sources) instead. * command/config.py (config._link): Pass already available lang parameter as target_lang parameter of compiler.link_executable().
24 years ago
Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60751,60753,60756-60757,60759-60761,60763-60764,60766,60769-60770,60774-60784,60787-60789,60793,60796,60799-60809,60812-60813,60815-60821,60823-60826,60828-60829,60831-60834,60836,60838-60839,60846-60849,60852-60854,60856-60859,60861-60870,60874-60875,60880-60881,60886,60888-60890,60892,60894-60898,60900-60931,60933-60958 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r60901 | eric.smith | 2008-02-19 14:21:56 +0100 (Tue, 19 Feb 2008) | 1 line Added PEP 3101. ........ r60907 | georg.brandl | 2008-02-20 20:12:36 +0100 (Wed, 20 Feb 2008) | 2 lines Fixes contributed by Ori Avtalion. ........ r60909 | eric.smith | 2008-02-21 00:34:22 +0100 (Thu, 21 Feb 2008) | 1 line Trim leading zeros from a floating point exponent, per C99. See issue 1600. As far as I know, this only affects Windows. Add float type 'n' to PyOS_ascii_formatd (see PEP 3101 for 'n' description). ........ r60910 | eric.smith | 2008-02-21 00:39:28 +0100 (Thu, 21 Feb 2008) | 1 line Now that PyOS_ascii_formatd supports the 'n' format, simplify the float formatting code to just call it. ........ r60918 | andrew.kuchling | 2008-02-21 15:23:38 +0100 (Thu, 21 Feb 2008) | 2 lines Close manifest file. This change doesn't make any difference to CPython, but is a necessary fix for Jython. ........ r60921 | guido.van.rossum | 2008-02-21 18:46:16 +0100 (Thu, 21 Feb 2008) | 2 lines Remove news about float repr() -- issue 1580 is still in limbo. ........ r60923 | guido.van.rossum | 2008-02-21 19:18:37 +0100 (Thu, 21 Feb 2008) | 5 lines Removed uses of dict.has_key() from distutils, and uses of callable() from copy_reg.py, so the interpreter now starts up without warnings when '-3' is given. More work like this needs to be done in the rest of the stdlib. ........ r60924 | thomas.heller | 2008-02-21 19:28:48 +0100 (Thu, 21 Feb 2008) | 4 lines configure.ac: Remove the configure check for _Bool, it is already done in the top-level Python configure script. configure, fficonfig.h.in: regenerated. ........ r60925 | thomas.heller | 2008-02-21 19:52:20 +0100 (Thu, 21 Feb 2008) | 3 lines Replace 'has_key()' with 'in'. Replace 'raise Error, stuff' with 'raise Error(stuff)'. ........ r60927 | raymond.hettinger | 2008-02-21 20:24:53 +0100 (Thu, 21 Feb 2008) | 1 line Update more instances of has_key(). ........ r60928 | guido.van.rossum | 2008-02-21 20:46:35 +0100 (Thu, 21 Feb 2008) | 3 lines Fix a few typos and layout glitches (more work is needed). Move 2.5 news to Misc/HISTORY. ........ r60936 | georg.brandl | 2008-02-21 21:33:38 +0100 (Thu, 21 Feb 2008) | 2 lines #2079: typo in userdict docs. ........ r60938 | georg.brandl | 2008-02-21 21:38:13 +0100 (Thu, 21 Feb 2008) | 2 lines Part of #2154: minimal syntax fixes in doc example snippets. ........ r60942 | raymond.hettinger | 2008-02-22 04:16:42 +0100 (Fri, 22 Feb 2008) | 1 line First draft for itertools.product(). Docs and other updates forthcoming. ........ r60955 | nick.coghlan | 2008-02-22 11:54:06 +0100 (Fri, 22 Feb 2008) | 1 line Try to make command line error messages from runpy easier to understand (and suppress traceback cruft from the implicitly invoked runpy machinery) ........ r60956 | georg.brandl | 2008-02-22 13:31:45 +0100 (Fri, 22 Feb 2008) | 2 lines A lot more typo fixes by Ori Avtalion. ........ r60957 | georg.brandl | 2008-02-22 13:56:34 +0100 (Fri, 22 Feb 2008) | 2 lines Don't reference pyshell. ........ r60958 | georg.brandl | 2008-02-22 13:57:05 +0100 (Fri, 22 Feb 2008) | 2 lines Another fix. ........
18 years ago
Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60751,60753,60756-60757,60759-60761,60763-60764,60766,60769-60770,60774-60784,60787-60789,60793,60796,60799-60809,60812-60813,60815-60821,60823-60826,60828-60829,60831-60834,60836,60838-60839,60846-60849,60852-60854,60856-60859,60861-60870,60874-60875,60880-60881,60886,60888-60890,60892,60894-60898,60900-60931,60933-60958 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r60901 | eric.smith | 2008-02-19 14:21:56 +0100 (Tue, 19 Feb 2008) | 1 line Added PEP 3101. ........ r60907 | georg.brandl | 2008-02-20 20:12:36 +0100 (Wed, 20 Feb 2008) | 2 lines Fixes contributed by Ori Avtalion. ........ r60909 | eric.smith | 2008-02-21 00:34:22 +0100 (Thu, 21 Feb 2008) | 1 line Trim leading zeros from a floating point exponent, per C99. See issue 1600. As far as I know, this only affects Windows. Add float type 'n' to PyOS_ascii_formatd (see PEP 3101 for 'n' description). ........ r60910 | eric.smith | 2008-02-21 00:39:28 +0100 (Thu, 21 Feb 2008) | 1 line Now that PyOS_ascii_formatd supports the 'n' format, simplify the float formatting code to just call it. ........ r60918 | andrew.kuchling | 2008-02-21 15:23:38 +0100 (Thu, 21 Feb 2008) | 2 lines Close manifest file. This change doesn't make any difference to CPython, but is a necessary fix for Jython. ........ r60921 | guido.van.rossum | 2008-02-21 18:46:16 +0100 (Thu, 21 Feb 2008) | 2 lines Remove news about float repr() -- issue 1580 is still in limbo. ........ r60923 | guido.van.rossum | 2008-02-21 19:18:37 +0100 (Thu, 21 Feb 2008) | 5 lines Removed uses of dict.has_key() from distutils, and uses of callable() from copy_reg.py, so the interpreter now starts up without warnings when '-3' is given. More work like this needs to be done in the rest of the stdlib. ........ r60924 | thomas.heller | 2008-02-21 19:28:48 +0100 (Thu, 21 Feb 2008) | 4 lines configure.ac: Remove the configure check for _Bool, it is already done in the top-level Python configure script. configure, fficonfig.h.in: regenerated. ........ r60925 | thomas.heller | 2008-02-21 19:52:20 +0100 (Thu, 21 Feb 2008) | 3 lines Replace 'has_key()' with 'in'. Replace 'raise Error, stuff' with 'raise Error(stuff)'. ........ r60927 | raymond.hettinger | 2008-02-21 20:24:53 +0100 (Thu, 21 Feb 2008) | 1 line Update more instances of has_key(). ........ r60928 | guido.van.rossum | 2008-02-21 20:46:35 +0100 (Thu, 21 Feb 2008) | 3 lines Fix a few typos and layout glitches (more work is needed). Move 2.5 news to Misc/HISTORY. ........ r60936 | georg.brandl | 2008-02-21 21:33:38 +0100 (Thu, 21 Feb 2008) | 2 lines #2079: typo in userdict docs. ........ r60938 | georg.brandl | 2008-02-21 21:38:13 +0100 (Thu, 21 Feb 2008) | 2 lines Part of #2154: minimal syntax fixes in doc example snippets. ........ r60942 | raymond.hettinger | 2008-02-22 04:16:42 +0100 (Fri, 22 Feb 2008) | 1 line First draft for itertools.product(). Docs and other updates forthcoming. ........ r60955 | nick.coghlan | 2008-02-22 11:54:06 +0100 (Fri, 22 Feb 2008) | 1 line Try to make command line error messages from runpy easier to understand (and suppress traceback cruft from the implicitly invoked runpy machinery) ........ r60956 | georg.brandl | 2008-02-22 13:31:45 +0100 (Fri, 22 Feb 2008) | 2 lines A lot more typo fixes by Ori Avtalion. ........ r60957 | georg.brandl | 2008-02-22 13:56:34 +0100 (Fri, 22 Feb 2008) | 2 lines Don't reference pyshell. ........ r60958 | georg.brandl | 2008-02-22 13:57:05 +0100 (Fri, 22 Feb 2008) | 2 lines Another fix. ........
18 years ago
Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60751,60753,60756-60757,60759-60761,60763-60764,60766,60769-60770,60774-60784,60787-60789,60793,60796,60799-60809,60812-60813,60815-60821,60823-60826,60828-60829,60831-60834,60836,60838-60839,60846-60849,60852-60854,60856-60859,60861-60870,60874-60875,60880-60881,60886,60888-60890,60892,60894-60898,60900-60931,60933-60958 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r60901 | eric.smith | 2008-02-19 14:21:56 +0100 (Tue, 19 Feb 2008) | 1 line Added PEP 3101. ........ r60907 | georg.brandl | 2008-02-20 20:12:36 +0100 (Wed, 20 Feb 2008) | 2 lines Fixes contributed by Ori Avtalion. ........ r60909 | eric.smith | 2008-02-21 00:34:22 +0100 (Thu, 21 Feb 2008) | 1 line Trim leading zeros from a floating point exponent, per C99. See issue 1600. As far as I know, this only affects Windows. Add float type 'n' to PyOS_ascii_formatd (see PEP 3101 for 'n' description). ........ r60910 | eric.smith | 2008-02-21 00:39:28 +0100 (Thu, 21 Feb 2008) | 1 line Now that PyOS_ascii_formatd supports the 'n' format, simplify the float formatting code to just call it. ........ r60918 | andrew.kuchling | 2008-02-21 15:23:38 +0100 (Thu, 21 Feb 2008) | 2 lines Close manifest file. This change doesn't make any difference to CPython, but is a necessary fix for Jython. ........ r60921 | guido.van.rossum | 2008-02-21 18:46:16 +0100 (Thu, 21 Feb 2008) | 2 lines Remove news about float repr() -- issue 1580 is still in limbo. ........ r60923 | guido.van.rossum | 2008-02-21 19:18:37 +0100 (Thu, 21 Feb 2008) | 5 lines Removed uses of dict.has_key() from distutils, and uses of callable() from copy_reg.py, so the interpreter now starts up without warnings when '-3' is given. More work like this needs to be done in the rest of the stdlib. ........ r60924 | thomas.heller | 2008-02-21 19:28:48 +0100 (Thu, 21 Feb 2008) | 4 lines configure.ac: Remove the configure check for _Bool, it is already done in the top-level Python configure script. configure, fficonfig.h.in: regenerated. ........ r60925 | thomas.heller | 2008-02-21 19:52:20 +0100 (Thu, 21 Feb 2008) | 3 lines Replace 'has_key()' with 'in'. Replace 'raise Error, stuff' with 'raise Error(stuff)'. ........ r60927 | raymond.hettinger | 2008-02-21 20:24:53 +0100 (Thu, 21 Feb 2008) | 1 line Update more instances of has_key(). ........ r60928 | guido.van.rossum | 2008-02-21 20:46:35 +0100 (Thu, 21 Feb 2008) | 3 lines Fix a few typos and layout glitches (more work is needed). Move 2.5 news to Misc/HISTORY. ........ r60936 | georg.brandl | 2008-02-21 21:33:38 +0100 (Thu, 21 Feb 2008) | 2 lines #2079: typo in userdict docs. ........ r60938 | georg.brandl | 2008-02-21 21:38:13 +0100 (Thu, 21 Feb 2008) | 2 lines Part of #2154: minimal syntax fixes in doc example snippets. ........ r60942 | raymond.hettinger | 2008-02-22 04:16:42 +0100 (Fri, 22 Feb 2008) | 1 line First draft for itertools.product(). Docs and other updates forthcoming. ........ r60955 | nick.coghlan | 2008-02-22 11:54:06 +0100 (Fri, 22 Feb 2008) | 1 line Try to make command line error messages from runpy easier to understand (and suppress traceback cruft from the implicitly invoked runpy machinery) ........ r60956 | georg.brandl | 2008-02-22 13:31:45 +0100 (Fri, 22 Feb 2008) | 2 lines A lot more typo fixes by Ori Avtalion. ........ r60957 | georg.brandl | 2008-02-22 13:56:34 +0100 (Fri, 22 Feb 2008) | 2 lines Don't reference pyshell. ........ r60958 | georg.brandl | 2008-02-22 13:57:05 +0100 (Fri, 22 Feb 2008) | 2 lines Another fix. ........
18 years ago
24 years ago
This patch fixes the following bugs: [#413582] g++ must be called for c++ extensions [#454030] distutils cannot link C++ code with GCC topdir = "Lib/distutils" * bcppcompiler.py (BCPPCompiler.create_static_lib): Fixed prototype, removing extra_preargs and extra_postargs parameters. Included target_lang parameter. (BCPPCompiler.link): Included target_lang parameter. * msvccompiler.py (MSVCCompiler.create_static_lib): Fixed prototype, removing extra_preargs and extra_postargs parameters. Included target_lang parameter. (MSVCCompiler.link): Included target_lang parameter. * ccompiler.py (CCompiler): New language_map and language_order attributes, used by CCompiler.detect_language(). (CCompiler.detect_language): New method, will return the language of a given source, or list of sources. Individual source language is detected using the language_map dict. When mixed sources are used, language_order will stablish the language precedence. (CCompiler.create_static_lib, CCompiler.link, CCompiler.link_executable, CCompiler.link_shared_object, CCompiler.link_shared_lib): Inlcuded target_lang parameter. * cygwinccompiler.py (CygwinCCompiler.link): Included target_lang parameter. * emxccompiler.py (EMXCCompiler.link): Included target_lang parameter. * mwerkscompiler.py (MWerksCompiler.link): Included target_lang parameter. * extension.py (Extension.__init__): New 'language' parameter/attribute, initialized to None by default. If provided will overlap the automatic detection made by CCompiler.detect_language(), in build_ext command. * sysconfig.py (customize_compiler): Check Makefile for CXX option, and also the environment variable CXX. Use the resulting value in the 'compiler_cxx' parameter of compiler.set_executables(). * unixccompiler.py (UnixCCompiler): Included 'compiler_cxx' in executables dict, defaulting to 'cc'. (UnixCCompiler.create_static_lib): Included target_lang parameter. (UnixCCompiler.link): Included target_lang parameter, and made linker command use compiler_cxx, if target_lang is 'c++'. * command/build_ext.py (build_ext.build_extension): Pass new ext.language attribute to compiler.link_shared_object()'s target_lang parameter. If ext.language is not provided, detect language using compiler.detect_language(sources) instead. * command/config.py (config._link): Pass already available lang parameter as target_lang parameter of compiler.link_executable().
24 years ago
This patch fixes the following bugs: [#413582] g++ must be called for c++ extensions [#454030] distutils cannot link C++ code with GCC topdir = "Lib/distutils" * bcppcompiler.py (BCPPCompiler.create_static_lib): Fixed prototype, removing extra_preargs and extra_postargs parameters. Included target_lang parameter. (BCPPCompiler.link): Included target_lang parameter. * msvccompiler.py (MSVCCompiler.create_static_lib): Fixed prototype, removing extra_preargs and extra_postargs parameters. Included target_lang parameter. (MSVCCompiler.link): Included target_lang parameter. * ccompiler.py (CCompiler): New language_map and language_order attributes, used by CCompiler.detect_language(). (CCompiler.detect_language): New method, will return the language of a given source, or list of sources. Individual source language is detected using the language_map dict. When mixed sources are used, language_order will stablish the language precedence. (CCompiler.create_static_lib, CCompiler.link, CCompiler.link_executable, CCompiler.link_shared_object, CCompiler.link_shared_lib): Inlcuded target_lang parameter. * cygwinccompiler.py (CygwinCCompiler.link): Included target_lang parameter. * emxccompiler.py (EMXCCompiler.link): Included target_lang parameter. * mwerkscompiler.py (MWerksCompiler.link): Included target_lang parameter. * extension.py (Extension.__init__): New 'language' parameter/attribute, initialized to None by default. If provided will overlap the automatic detection made by CCompiler.detect_language(), in build_ext command. * sysconfig.py (customize_compiler): Check Makefile for CXX option, and also the environment variable CXX. Use the resulting value in the 'compiler_cxx' parameter of compiler.set_executables(). * unixccompiler.py (UnixCCompiler): Included 'compiler_cxx' in executables dict, defaulting to 'cc'. (UnixCCompiler.create_static_lib): Included target_lang parameter. (UnixCCompiler.link): Included target_lang parameter, and made linker command use compiler_cxx, if target_lang is 'c++'. * command/build_ext.py (build_ext.build_extension): Pass new ext.language attribute to compiler.link_shared_object()'s target_lang parameter. If ext.language is not provided, detect language using compiler.detect_language(sources) instead. * command/config.py (config._link): Pass already available lang parameter as target_lang parameter of compiler.link_executable().
24 years ago
This patch fixes the following bugs: [#413582] g++ must be called for c++ extensions [#454030] distutils cannot link C++ code with GCC topdir = "Lib/distutils" * bcppcompiler.py (BCPPCompiler.create_static_lib): Fixed prototype, removing extra_preargs and extra_postargs parameters. Included target_lang parameter. (BCPPCompiler.link): Included target_lang parameter. * msvccompiler.py (MSVCCompiler.create_static_lib): Fixed prototype, removing extra_preargs and extra_postargs parameters. Included target_lang parameter. (MSVCCompiler.link): Included target_lang parameter. * ccompiler.py (CCompiler): New language_map and language_order attributes, used by CCompiler.detect_language(). (CCompiler.detect_language): New method, will return the language of a given source, or list of sources. Individual source language is detected using the language_map dict. When mixed sources are used, language_order will stablish the language precedence. (CCompiler.create_static_lib, CCompiler.link, CCompiler.link_executable, CCompiler.link_shared_object, CCompiler.link_shared_lib): Inlcuded target_lang parameter. * cygwinccompiler.py (CygwinCCompiler.link): Included target_lang parameter. * emxccompiler.py (EMXCCompiler.link): Included target_lang parameter. * mwerkscompiler.py (MWerksCompiler.link): Included target_lang parameter. * extension.py (Extension.__init__): New 'language' parameter/attribute, initialized to None by default. If provided will overlap the automatic detection made by CCompiler.detect_language(), in build_ext command. * sysconfig.py (customize_compiler): Check Makefile for CXX option, and also the environment variable CXX. Use the resulting value in the 'compiler_cxx' parameter of compiler.set_executables(). * unixccompiler.py (UnixCCompiler): Included 'compiler_cxx' in executables dict, defaulting to 'cc'. (UnixCCompiler.create_static_lib): Included target_lang parameter. (UnixCCompiler.link): Included target_lang parameter, and made linker command use compiler_cxx, if target_lang is 'c++'. * command/build_ext.py (build_ext.build_extension): Pass new ext.language attribute to compiler.link_shared_object()'s target_lang parameter. If ext.language is not provided, detect language using compiler.detect_language(sources) instead. * command/config.py (config._link): Pass already available lang parameter as target_lang parameter of compiler.link_executable().
24 years ago
This patch fixes the following bugs: [#413582] g++ must be called for c++ extensions [#454030] distutils cannot link C++ code with GCC topdir = "Lib/distutils" * bcppcompiler.py (BCPPCompiler.create_static_lib): Fixed prototype, removing extra_preargs and extra_postargs parameters. Included target_lang parameter. (BCPPCompiler.link): Included target_lang parameter. * msvccompiler.py (MSVCCompiler.create_static_lib): Fixed prototype, removing extra_preargs and extra_postargs parameters. Included target_lang parameter. (MSVCCompiler.link): Included target_lang parameter. * ccompiler.py (CCompiler): New language_map and language_order attributes, used by CCompiler.detect_language(). (CCompiler.detect_language): New method, will return the language of a given source, or list of sources. Individual source language is detected using the language_map dict. When mixed sources are used, language_order will stablish the language precedence. (CCompiler.create_static_lib, CCompiler.link, CCompiler.link_executable, CCompiler.link_shared_object, CCompiler.link_shared_lib): Inlcuded target_lang parameter. * cygwinccompiler.py (CygwinCCompiler.link): Included target_lang parameter. * emxccompiler.py (EMXCCompiler.link): Included target_lang parameter. * mwerkscompiler.py (MWerksCompiler.link): Included target_lang parameter. * extension.py (Extension.__init__): New 'language' parameter/attribute, initialized to None by default. If provided will overlap the automatic detection made by CCompiler.detect_language(), in build_ext command. * sysconfig.py (customize_compiler): Check Makefile for CXX option, and also the environment variable CXX. Use the resulting value in the 'compiler_cxx' parameter of compiler.set_executables(). * unixccompiler.py (UnixCCompiler): Included 'compiler_cxx' in executables dict, defaulting to 'cc'. (UnixCCompiler.create_static_lib): Included target_lang parameter. (UnixCCompiler.link): Included target_lang parameter, and made linker command use compiler_cxx, if target_lang is 'c++'. * command/build_ext.py (build_ext.build_extension): Pass new ext.language attribute to compiler.link_shared_object()'s target_lang parameter. If ext.language is not provided, detect language using compiler.detect_language(sources) instead. * command/config.py (config._link): Pass already available lang parameter as target_lang parameter of compiler.link_executable().
24 years ago
This patch fixes the following bugs: [#413582] g++ must be called for c++ extensions [#454030] distutils cannot link C++ code with GCC topdir = "Lib/distutils" * bcppcompiler.py (BCPPCompiler.create_static_lib): Fixed prototype, removing extra_preargs and extra_postargs parameters. Included target_lang parameter. (BCPPCompiler.link): Included target_lang parameter. * msvccompiler.py (MSVCCompiler.create_static_lib): Fixed prototype, removing extra_preargs and extra_postargs parameters. Included target_lang parameter. (MSVCCompiler.link): Included target_lang parameter. * ccompiler.py (CCompiler): New language_map and language_order attributes, used by CCompiler.detect_language(). (CCompiler.detect_language): New method, will return the language of a given source, or list of sources. Individual source language is detected using the language_map dict. When mixed sources are used, language_order will stablish the language precedence. (CCompiler.create_static_lib, CCompiler.link, CCompiler.link_executable, CCompiler.link_shared_object, CCompiler.link_shared_lib): Inlcuded target_lang parameter. * cygwinccompiler.py (CygwinCCompiler.link): Included target_lang parameter. * emxccompiler.py (EMXCCompiler.link): Included target_lang parameter. * mwerkscompiler.py (MWerksCompiler.link): Included target_lang parameter. * extension.py (Extension.__init__): New 'language' parameter/attribute, initialized to None by default. If provided will overlap the automatic detection made by CCompiler.detect_language(), in build_ext command. * sysconfig.py (customize_compiler): Check Makefile for CXX option, and also the environment variable CXX. Use the resulting value in the 'compiler_cxx' parameter of compiler.set_executables(). * unixccompiler.py (UnixCCompiler): Included 'compiler_cxx' in executables dict, defaulting to 'cc'. (UnixCCompiler.create_static_lib): Included target_lang parameter. (UnixCCompiler.link): Included target_lang parameter, and made linker command use compiler_cxx, if target_lang is 'c++'. * command/build_ext.py (build_ext.build_extension): Pass new ext.language attribute to compiler.link_shared_object()'s target_lang parameter. If ext.language is not provided, detect language using compiler.detect_language(sources) instead. * command/config.py (config._link): Pass already available lang parameter as target_lang parameter of compiler.link_executable().
24 years ago
This patch fixes the following bugs: [#413582] g++ must be called for c++ extensions [#454030] distutils cannot link C++ code with GCC topdir = "Lib/distutils" * bcppcompiler.py (BCPPCompiler.create_static_lib): Fixed prototype, removing extra_preargs and extra_postargs parameters. Included target_lang parameter. (BCPPCompiler.link): Included target_lang parameter. * msvccompiler.py (MSVCCompiler.create_static_lib): Fixed prototype, removing extra_preargs and extra_postargs parameters. Included target_lang parameter. (MSVCCompiler.link): Included target_lang parameter. * ccompiler.py (CCompiler): New language_map and language_order attributes, used by CCompiler.detect_language(). (CCompiler.detect_language): New method, will return the language of a given source, or list of sources. Individual source language is detected using the language_map dict. When mixed sources are used, language_order will stablish the language precedence. (CCompiler.create_static_lib, CCompiler.link, CCompiler.link_executable, CCompiler.link_shared_object, CCompiler.link_shared_lib): Inlcuded target_lang parameter. * cygwinccompiler.py (CygwinCCompiler.link): Included target_lang parameter. * emxccompiler.py (EMXCCompiler.link): Included target_lang parameter. * mwerkscompiler.py (MWerksCompiler.link): Included target_lang parameter. * extension.py (Extension.__init__): New 'language' parameter/attribute, initialized to None by default. If provided will overlap the automatic detection made by CCompiler.detect_language(), in build_ext command. * sysconfig.py (customize_compiler): Check Makefile for CXX option, and also the environment variable CXX. Use the resulting value in the 'compiler_cxx' parameter of compiler.set_executables(). * unixccompiler.py (UnixCCompiler): Included 'compiler_cxx' in executables dict, defaulting to 'cc'. (UnixCCompiler.create_static_lib): Included target_lang parameter. (UnixCCompiler.link): Included target_lang parameter, and made linker command use compiler_cxx, if target_lang is 'c++'. * command/build_ext.py (build_ext.build_extension): Pass new ext.language attribute to compiler.link_shared_object()'s target_lang parameter. If ext.language is not provided, detect language using compiler.detect_language(sources) instead. * command/config.py (config._link): Pass already available lang parameter as target_lang parameter of compiler.link_executable().
24 years ago
This patch fixes the following bugs: [#413582] g++ must be called for c++ extensions [#454030] distutils cannot link C++ code with GCC topdir = "Lib/distutils" * bcppcompiler.py (BCPPCompiler.create_static_lib): Fixed prototype, removing extra_preargs and extra_postargs parameters. Included target_lang parameter. (BCPPCompiler.link): Included target_lang parameter. * msvccompiler.py (MSVCCompiler.create_static_lib): Fixed prototype, removing extra_preargs and extra_postargs parameters. Included target_lang parameter. (MSVCCompiler.link): Included target_lang parameter. * ccompiler.py (CCompiler): New language_map and language_order attributes, used by CCompiler.detect_language(). (CCompiler.detect_language): New method, will return the language of a given source, or list of sources. Individual source language is detected using the language_map dict. When mixed sources are used, language_order will stablish the language precedence. (CCompiler.create_static_lib, CCompiler.link, CCompiler.link_executable, CCompiler.link_shared_object, CCompiler.link_shared_lib): Inlcuded target_lang parameter. * cygwinccompiler.py (CygwinCCompiler.link): Included target_lang parameter. * emxccompiler.py (EMXCCompiler.link): Included target_lang parameter. * mwerkscompiler.py (MWerksCompiler.link): Included target_lang parameter. * extension.py (Extension.__init__): New 'language' parameter/attribute, initialized to None by default. If provided will overlap the automatic detection made by CCompiler.detect_language(), in build_ext command. * sysconfig.py (customize_compiler): Check Makefile for CXX option, and also the environment variable CXX. Use the resulting value in the 'compiler_cxx' parameter of compiler.set_executables(). * unixccompiler.py (UnixCCompiler): Included 'compiler_cxx' in executables dict, defaulting to 'cc'. (UnixCCompiler.create_static_lib): Included target_lang parameter. (UnixCCompiler.link): Included target_lang parameter, and made linker command use compiler_cxx, if target_lang is 'c++'. * command/build_ext.py (build_ext.build_extension): Pass new ext.language attribute to compiler.link_shared_object()'s target_lang parameter. If ext.language is not provided, detect language using compiler.detect_language(sources) instead. * command/config.py (config._link): Pass already available lang parameter as target_lang parameter of compiler.link_executable().
24 years ago
Merged revisions 67654,67676-67677,67681,67692,67725,67761,67784-67785,67787-67788,67802,67848-67850,67862-67864,67880,67882 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r67654 | georg.brandl | 2008-12-07 16:42:09 -0600 (Sun, 07 Dec 2008) | 2 lines #4457: rewrite __import__() documentation. ........ r67676 | benjamin.peterson | 2008-12-08 20:03:03 -0600 (Mon, 08 Dec 2008) | 1 line specify how things are copied ........ r67677 | benjamin.peterson | 2008-12-08 20:05:11 -0600 (Mon, 08 Dec 2008) | 1 line revert unrelated change to installer script ........ r67681 | jeremy.hylton | 2008-12-09 15:03:10 -0600 (Tue, 09 Dec 2008) | 2 lines Add simple unittests for Request ........ r67692 | amaury.forgeotdarc | 2008-12-10 18:03:42 -0600 (Wed, 10 Dec 2008) | 2 lines #1030250: correctly pass the dry_run option to the mkpath() function. ........ r67725 | benjamin.peterson | 2008-12-12 22:02:20 -0600 (Fri, 12 Dec 2008) | 1 line fix incorrect example ........ r67761 | benjamin.peterson | 2008-12-14 11:26:04 -0600 (Sun, 14 Dec 2008) | 1 line fix missing bracket ........ r67784 | georg.brandl | 2008-12-15 02:33:58 -0600 (Mon, 15 Dec 2008) | 2 lines #4446: document "platforms" argument for setup(). ........ r67785 | georg.brandl | 2008-12-15 02:36:11 -0600 (Mon, 15 Dec 2008) | 2 lines #4611: fix typo. ........ r67787 | georg.brandl | 2008-12-15 02:58:59 -0600 (Mon, 15 Dec 2008) | 2 lines #4578: fix has_key() usage in compiler package. ........ r67788 | georg.brandl | 2008-12-15 03:07:39 -0600 (Mon, 15 Dec 2008) | 2 lines #4568: remove limitation in varargs callback example. ........ r67802 | amaury.forgeotdarc | 2008-12-15 16:29:14 -0600 (Mon, 15 Dec 2008) | 4 lines #3632: the "pyo" macro from gdbinit can now run when the GIL is released. Patch by haypo. ........ r67848 | benjamin.peterson | 2008-12-18 20:28:56 -0600 (Thu, 18 Dec 2008) | 1 line fix typo ........ r67849 | benjamin.peterson | 2008-12-18 20:31:35 -0600 (Thu, 18 Dec 2008) | 1 line _call_method -> _callmethod and _get_value to _getvalue ........ r67850 | raymond.hettinger | 2008-12-19 03:06:07 -0600 (Fri, 19 Dec 2008) | 9 lines Fix-up and clean-up docs for int.bit_length(). * Replace dramatic footnote with in-line comment about possible round-off errors in logarithms of large numbers. * Add comments to the pure python code equivalent. * replace floor() with int() in the mathematical equivalent so the type is correct (should be an int, not a float). * add abs() to the mathematical equivalent so that it matches the previous line that it is supposed to be equivalent to. * make one combined example with a negative input. ........ r67862 | benjamin.peterson | 2008-12-19 20:48:02 -0600 (Fri, 19 Dec 2008) | 1 line copy sentence from docstring ........ r67863 | benjamin.peterson | 2008-12-19 20:51:26 -0600 (Fri, 19 Dec 2008) | 1 line add headings ........ r67864 | benjamin.peterson | 2008-12-19 20:57:19 -0600 (Fri, 19 Dec 2008) | 1 line beef up docstring ........ r67880 | benjamin.peterson | 2008-12-20 16:49:24 -0600 (Sat, 20 Dec 2008) | 1 line remove redundant sentence ........ r67882 | benjamin.peterson | 2008-12-20 16:59:49 -0600 (Sat, 20 Dec 2008) | 1 line add some recent releases to the list ........
17 years ago
  1. """distutils.ccompiler
  2. Contains CCompiler, an abstract base class that defines the interface
  3. for the Distutils compiler abstraction model."""
  4. __revision__ = "$Id$"
  5. import sys, os, re
  6. from distutils.errors import *
  7. from distutils.spawn import spawn
  8. from distutils.file_util import move_file
  9. from distutils.dir_util import mkpath
  10. from distutils.dep_util import newer_pairwise, newer_group
  11. from distutils.util import split_quoted, execute
  12. from distutils import log
  13. class CCompiler:
  14. """Abstract base class to define the interface that must be implemented
  15. by real compiler classes. Also has some utility methods used by
  16. several compiler classes.
  17. The basic idea behind a compiler abstraction class is that each
  18. instance can be used for all the compile/link steps in building a
  19. single project. Thus, attributes common to all of those compile and
  20. link steps -- include directories, macros to define, libraries to link
  21. against, etc. -- are attributes of the compiler instance. To allow for
  22. variability in how individual files are treated, most of those
  23. attributes may be varied on a per-compilation or per-link basis.
  24. """
  25. # 'compiler_type' is a class attribute that identifies this class. It
  26. # keeps code that wants to know what kind of compiler it's dealing with
  27. # from having to import all possible compiler classes just to do an
  28. # 'isinstance'. In concrete CCompiler subclasses, 'compiler_type'
  29. # should really, really be one of the keys of the 'compiler_class'
  30. # dictionary (see below -- used by the 'new_compiler()' factory
  31. # function) -- authors of new compiler interface classes are
  32. # responsible for updating 'compiler_class'!
  33. compiler_type = None
  34. # XXX things not handled by this compiler abstraction model:
  35. # * client can't provide additional options for a compiler,
  36. # e.g. warning, optimization, debugging flags. Perhaps this
  37. # should be the domain of concrete compiler abstraction classes
  38. # (UnixCCompiler, MSVCCompiler, etc.) -- or perhaps the base
  39. # class should have methods for the common ones.
  40. # * can't completely override the include or library searchg
  41. # path, ie. no "cc -I -Idir1 -Idir2" or "cc -L -Ldir1 -Ldir2".
  42. # I'm not sure how widely supported this is even by Unix
  43. # compilers, much less on other platforms. And I'm even less
  44. # sure how useful it is; maybe for cross-compiling, but
  45. # support for that is a ways off. (And anyways, cross
  46. # compilers probably have a dedicated binary with the
  47. # right paths compiled in. I hope.)
  48. # * can't do really freaky things with the library list/library
  49. # dirs, e.g. "-Ldir1 -lfoo -Ldir2 -lfoo" to link against
  50. # different versions of libfoo.a in different locations. I
  51. # think this is useless without the ability to null out the
  52. # library search path anyways.
  53. # Subclasses that rely on the standard filename generation methods
  54. # implemented below should override these; see the comment near
  55. # those methods ('object_filenames()' et. al.) for details:
  56. src_extensions = None # list of strings
  57. obj_extension = None # string
  58. static_lib_extension = None
  59. shared_lib_extension = None # string
  60. static_lib_format = None # format string
  61. shared_lib_format = None # prob. same as static_lib_format
  62. exe_extension = None # string
  63. # Default language settings. language_map is used to detect a source
  64. # file or Extension target language, checking source filenames.
  65. # language_order is used to detect the language precedence, when deciding
  66. # what language to use when mixing source types. For example, if some
  67. # extension has two files with ".c" extension, and one with ".cpp", it
  68. # is still linked as c++.
  69. language_map = {".c" : "c",
  70. ".cc" : "c++",
  71. ".cpp" : "c++",
  72. ".cxx" : "c++",
  73. ".m" : "objc",
  74. }
  75. language_order = ["c++", "objc", "c"]
  76. def __init__(self, verbose=0, dry_run=0, force=0):
  77. self.dry_run = dry_run
  78. self.force = force
  79. self.verbose = verbose
  80. # 'output_dir': a common output directory for object, library,
  81. # shared object, and shared library files
  82. self.output_dir = None
  83. # 'macros': a list of macro definitions (or undefinitions). A
  84. # macro definition is a 2-tuple (name, value), where the value is
  85. # either a string or None (no explicit value). A macro
  86. # undefinition is a 1-tuple (name,).
  87. self.macros = []
  88. # 'include_dirs': a list of directories to search for include files
  89. self.include_dirs = []
  90. # 'libraries': a list of libraries to include in any link
  91. # (library names, not filenames: eg. "foo" not "libfoo.a")
  92. self.libraries = []
  93. # 'library_dirs': a list of directories to search for libraries
  94. self.library_dirs = []
  95. # 'runtime_library_dirs': a list of directories to search for
  96. # shared libraries/objects at runtime
  97. self.runtime_library_dirs = []
  98. # 'objects': a list of object files (or similar, such as explicitly
  99. # named library files) to include on any link
  100. self.objects = []
  101. for key in self.executables.keys():
  102. self.set_executable(key, self.executables[key])
  103. def set_executables(self, **kwargs):
  104. """Define the executables (and options for them) that will be run
  105. to perform the various stages of compilation. The exact set of
  106. executables that may be specified here depends on the compiler
  107. class (via the 'executables' class attribute), but most will have:
  108. compiler the C/C++ compiler
  109. linker_so linker used to create shared objects and libraries
  110. linker_exe linker used to create binary executables
  111. archiver static library creator
  112. On platforms with a command-line (Unix, DOS/Windows), each of these
  113. is a string that will be split into executable name and (optional)
  114. list of arguments. (Splitting the string is done similarly to how
  115. Unix shells operate: words are delimited by spaces, but quotes and
  116. backslashes can override this. See
  117. 'distutils.util.split_quoted()'.)
  118. """
  119. # Note that some CCompiler implementation classes will define class
  120. # attributes 'cpp', 'cc', etc. with hard-coded executable names;
  121. # this is appropriate when a compiler class is for exactly one
  122. # compiler/OS combination (eg. MSVCCompiler). Other compiler
  123. # classes (UnixCCompiler, in particular) are driven by information
  124. # discovered at run-time, since there are many different ways to do
  125. # basically the same things with Unix C compilers.
  126. for key in kwargs:
  127. if key not in self.executables:
  128. raise ValueError("unknown executable '%s' for class %s" %
  129. (key, self.__class__.__name__))
  130. self.set_executable(key, kwargs[key])
  131. def set_executable(self, key, value):
  132. if isinstance(value, str):
  133. setattr(self, key, split_quoted(value))
  134. else:
  135. setattr(self, key, value)
  136. def _find_macro(self, name):
  137. i = 0
  138. for defn in self.macros:
  139. if defn[0] == name:
  140. return i
  141. i += 1
  142. return None
  143. def _check_macro_definitions(self, definitions):
  144. """Ensures that every element of 'definitions' is a valid macro
  145. definition, ie. either (name,value) 2-tuple or a (name,) tuple. Do
  146. nothing if all definitions are OK, raise TypeError otherwise.
  147. """
  148. for defn in definitions:
  149. if not (isinstance(defn, tuple) and
  150. (len(defn) in (1, 2) and
  151. (isinstance (defn[1], str) or defn[1] is None)) and
  152. isinstance (defn[0], str)):
  153. raise TypeError(("invalid macro definition '%s': " % defn) + \
  154. "must be tuple (string,), (string, string), or " + \
  155. "(string, None)")
  156. # -- Bookkeeping methods -------------------------------------------
  157. def define_macro(self, name, value=None):
  158. """Define a preprocessor macro for all compilations driven by this
  159. compiler object. The optional parameter 'value' should be a
  160. string; if it is not supplied, then the macro will be defined
  161. without an explicit value and the exact outcome depends on the
  162. compiler used (XXX true? does ANSI say anything about this?)
  163. """
  164. # Delete from the list of macro definitions/undefinitions if
  165. # already there (so that this one will take precedence).
  166. i = self._find_macro (name)
  167. if i is not None:
  168. del self.macros[i]
  169. self.macros.append((name, value))
  170. def undefine_macro(self, name):
  171. """Undefine a preprocessor macro for all compilations driven by
  172. this compiler object. If the same macro is defined by
  173. 'define_macro()' and undefined by 'undefine_macro()' the last call
  174. takes precedence (including multiple redefinitions or
  175. undefinitions). If the macro is redefined/undefined on a
  176. per-compilation basis (ie. in the call to 'compile()'), then that
  177. takes precedence.
  178. """
  179. # Delete from the list of macro definitions/undefinitions if
  180. # already there (so that this one will take precedence).
  181. i = self._find_macro (name)
  182. if i is not None:
  183. del self.macros[i]
  184. undefn = (name,)
  185. self.macros.append(undefn)
  186. def add_include_dir(self, dir):
  187. """Add 'dir' to the list of directories that will be searched for
  188. header files. The compiler is instructed to search directories in
  189. the order in which they are supplied by successive calls to
  190. 'add_include_dir()'.
  191. """
  192. self.include_dirs.append(dir)
  193. def set_include_dirs(self, dirs):
  194. """Set the list of directories that will be searched to 'dirs' (a
  195. list of strings). Overrides any preceding calls to
  196. 'add_include_dir()'; subsequence calls to 'add_include_dir()' add
  197. to the list passed to 'set_include_dirs()'. This does not affect
  198. any list of standard include directories that the compiler may
  199. search by default.
  200. """
  201. self.include_dirs = dirs[:]
  202. def add_library(self, libname):
  203. """Add 'libname' to the list of libraries that will be included in
  204. all links driven by this compiler object. Note that 'libname'
  205. should *not* be the name of a file containing a library, but the
  206. name of the library itself: the actual filename will be inferred by
  207. the linker, the compiler, or the compiler class (depending on the
  208. platform).
  209. The linker will be instructed to link against libraries in the
  210. order they were supplied to 'add_library()' and/or
  211. 'set_libraries()'. It is perfectly valid to duplicate library
  212. names; the linker will be instructed to link against libraries as
  213. many times as they are mentioned.
  214. """
  215. self.libraries.append(libname)
  216. def set_libraries(self, libnames):
  217. """Set the list of libraries to be included in all links driven by
  218. this compiler object to 'libnames' (a list of strings). This does
  219. not affect any standard system libraries that the linker may
  220. include by default.
  221. """
  222. self.libraries = libnames[:]
  223. def add_library_dir(self, dir):
  224. """Add 'dir' to the list of directories that will be searched for
  225. libraries specified to 'add_library()' and 'set_libraries()'. The
  226. linker will be instructed to search for libraries in the order they
  227. are supplied to 'add_library_dir()' and/or 'set_library_dirs()'.
  228. """
  229. self.library_dirs.append(dir)
  230. def set_library_dirs(self, dirs):
  231. """Set the list of library search directories to 'dirs' (a list of
  232. strings). This does not affect any standard library search path
  233. that the linker may search by default.
  234. """
  235. self.library_dirs = dirs[:]
  236. def add_runtime_library_dir(self, dir):
  237. """Add 'dir' to the list of directories that will be searched for
  238. shared libraries at runtime.
  239. """
  240. self.runtime_library_dirs.append(dir)
  241. def set_runtime_library_dirs(self, dirs):
  242. """Set the list of directories to search for shared libraries at
  243. runtime to 'dirs' (a list of strings). This does not affect any
  244. standard search path that the runtime linker may search by
  245. default.
  246. """
  247. self.runtime_library_dirs = dirs[:]
  248. def add_link_object(self, object):
  249. """Add 'object' to the list of object files (or analogues, such as
  250. explicitly named library files or the output of "resource
  251. compilers") to be included in every link driven by this compiler
  252. object.
  253. """
  254. self.objects.append(object)
  255. def set_link_objects(self, objects):
  256. """Set the list of object files (or analogues) to be included in
  257. every link to 'objects'. This does not affect any standard object
  258. files that the linker may include by default (such as system
  259. libraries).
  260. """
  261. self.objects = objects[:]
  262. # -- Private utility methods --------------------------------------
  263. # (here for the convenience of subclasses)
  264. # Helper method to prep compiler in subclass compile() methods
  265. def _setup_compile(self, outdir, macros, incdirs, sources, depends,
  266. extra):
  267. """Process arguments and decide which source files to compile."""
  268. if outdir is None:
  269. outdir = self.output_dir
  270. elif not isinstance(outdir, str):
  271. raise TypeError("'output_dir' must be a string or None")
  272. if macros is None:
  273. macros = self.macros
  274. elif isinstance(macros, list):
  275. macros = macros + (self.macros or [])
  276. else:
  277. raise TypeError("'macros' (if supplied) must be a list of tuples")
  278. if incdirs is None:
  279. incdirs = self.include_dirs
  280. elif isinstance(incdirs, (list, tuple)):
  281. incdirs = list(incdirs) + (self.include_dirs or [])
  282. else:
  283. raise TypeError(
  284. "'include_dirs' (if supplied) must be a list of strings")
  285. if extra is None:
  286. extra = []
  287. # Get the list of expected output (object) files
  288. objects = self.object_filenames(sources, strip_dir=0,
  289. output_dir=outdir)
  290. assert len(objects) == len(sources)
  291. pp_opts = gen_preprocess_options(macros, incdirs)
  292. build = {}
  293. for i in range(len(sources)):
  294. src = sources[i]
  295. obj = objects[i]
  296. ext = os.path.splitext(src)[1]
  297. self.mkpath(os.path.dirname(obj))
  298. build[obj] = (src, ext)
  299. return macros, objects, extra, pp_opts, build
  300. def _get_cc_args(self, pp_opts, debug, before):
  301. # works for unixccompiler, emxccompiler, cygwinccompiler
  302. cc_args = pp_opts + ['-c']
  303. if debug:
  304. cc_args[:0] = ['-g']
  305. if before:
  306. cc_args[:0] = before
  307. return cc_args
  308. def _fix_compile_args(self, output_dir, macros, include_dirs):
  309. """Typecheck and fix-up some of the arguments to the 'compile()'
  310. method, and return fixed-up values. Specifically: if 'output_dir'
  311. is None, replaces it with 'self.output_dir'; ensures that 'macros'
  312. is a list, and augments it with 'self.macros'; ensures that
  313. 'include_dirs' is a list, and augments it with 'self.include_dirs'.
  314. Guarantees that the returned values are of the correct type,
  315. i.e. for 'output_dir' either string or None, and for 'macros' and
  316. 'include_dirs' either list or None.
  317. """
  318. if output_dir is None:
  319. output_dir = self.output_dir
  320. elif not isinstance(output_dir, str):
  321. raise TypeError("'output_dir' must be a string or None")
  322. if macros is None:
  323. macros = self.macros
  324. elif isinstance(macros, list):
  325. macros = macros + (self.macros or [])
  326. else:
  327. raise TypeError("'macros' (if supplied) must be a list of tuples")
  328. if include_dirs is None:
  329. include_dirs = self.include_dirs
  330. elif isinstance(include_dirs, (list, tuple)):
  331. include_dirs = list(include_dirs) + (self.include_dirs or [])
  332. else:
  333. raise TypeError(
  334. "'include_dirs' (if supplied) must be a list of strings")
  335. return output_dir, macros, include_dirs
  336. def _prep_compile(self, sources, output_dir, depends=None):
  337. """Decide which souce files must be recompiled.
  338. Determine the list of object files corresponding to 'sources',
  339. and figure out which ones really need to be recompiled.
  340. Return a list of all object files and a dictionary telling
  341. which source files can be skipped.
  342. """
  343. # Get the list of expected output (object) files
  344. objects = self.object_filenames(sources, output_dir=output_dir)
  345. assert len(objects) == len(sources)
  346. # Return an empty dict for the "which source files can be skipped"
  347. # return value to preserve API compatibility.
  348. return objects, {}
  349. def _fix_object_args(self, objects, output_dir):
  350. """Typecheck and fix up some arguments supplied to various methods.
  351. Specifically: ensure that 'objects' is a list; if output_dir is
  352. None, replace with self.output_dir. Return fixed versions of
  353. 'objects' and 'output_dir'.
  354. """
  355. if not isinstance(objects, (list, tuple)):
  356. raise TypeError("'objects' must be a list or tuple of strings")
  357. objects = list(objects)
  358. if output_dir is None:
  359. output_dir = self.output_dir
  360. elif not isinstance(output_dir, str):
  361. raise TypeError("'output_dir' must be a string or None")
  362. return (objects, output_dir)
  363. def _fix_lib_args(self, libraries, library_dirs, runtime_library_dirs):
  364. """Typecheck and fix up some of the arguments supplied to the
  365. 'link_*' methods. Specifically: ensure that all arguments are
  366. lists, and augment them with their permanent versions
  367. (eg. 'self.libraries' augments 'libraries'). Return a tuple with
  368. fixed versions of all arguments.
  369. """
  370. if libraries is None:
  371. libraries = self.libraries
  372. elif isinstance(libraries, (list, tuple)):
  373. libraries = list (libraries) + (self.libraries or [])
  374. else:
  375. raise TypeError(
  376. "'libraries' (if supplied) must be a list of strings")
  377. if library_dirs is None:
  378. library_dirs = self.library_dirs
  379. elif isinstance(library_dirs, (list, tuple)):
  380. library_dirs = list (library_dirs) + (self.library_dirs or [])
  381. else:
  382. raise TypeError(
  383. "'library_dirs' (if supplied) must be a list of strings")
  384. if runtime_library_dirs is None:
  385. runtime_library_dirs = self.runtime_library_dirs
  386. elif isinstance(runtime_library_dirs, (list, tuple)):
  387. runtime_library_dirs = (list(runtime_library_dirs) +
  388. (self.runtime_library_dirs or []))
  389. else:
  390. raise TypeError("'runtime_library_dirs' (if supplied) "
  391. "must be a list of strings")
  392. return (libraries, library_dirs, runtime_library_dirs)
  393. def _need_link(self, objects, output_file):
  394. """Return true if we need to relink the files listed in 'objects'
  395. to recreate 'output_file'.
  396. """
  397. if self.force:
  398. return True
  399. else:
  400. if self.dry_run:
  401. newer = newer_group (objects, output_file, missing='newer')
  402. else:
  403. newer = newer_group (objects, output_file)
  404. return newer
  405. def detect_language(self, sources):
  406. """Detect the language of a given file, or list of files. Uses
  407. language_map, and language_order to do the job.
  408. """
  409. if not isinstance(sources, list):
  410. sources = [sources]
  411. lang = None
  412. index = len(self.language_order)
  413. for source in sources:
  414. base, ext = os.path.splitext(source)
  415. extlang = self.language_map.get(ext)
  416. try:
  417. extindex = self.language_order.index(extlang)
  418. if extindex < index:
  419. lang = extlang
  420. index = extindex
  421. except ValueError:
  422. pass
  423. return lang
  424. # -- Worker methods ------------------------------------------------
  425. # (must be implemented by subclasses)
  426. def preprocess(self, source, output_file=None, macros=None,
  427. include_dirs=None, extra_preargs=None, extra_postargs=None):
  428. """Preprocess a single C/C++ source file, named in 'source'.
  429. Output will be written to file named 'output_file', or stdout if
  430. 'output_file' not supplied. 'macros' is a list of macro
  431. definitions as for 'compile()', which will augment the macros set
  432. with 'define_macro()' and 'undefine_macro()'. 'include_dirs' is a
  433. list of directory names that will be added to the default list.
  434. Raises PreprocessError on failure.
  435. """
  436. pass
  437. def compile(self, sources, output_dir=None, macros=None,
  438. include_dirs=None, debug=0, extra_preargs=None,
  439. extra_postargs=None, depends=None):
  440. """Compile one or more source files.
  441. 'sources' must be a list of filenames, most likely C/C++
  442. files, but in reality anything that can be handled by a
  443. particular compiler and compiler class (eg. MSVCCompiler can
  444. handle resource files in 'sources'). Return a list of object
  445. filenames, one per source filename in 'sources'. Depending on
  446. the implementation, not all source files will necessarily be
  447. compiled, but all corresponding object filenames will be
  448. returned.
  449. If 'output_dir' is given, object files will be put under it, while
  450. retaining their original path component. That is, "foo/bar.c"
  451. normally compiles to "foo/bar.o" (for a Unix implementation); if
  452. 'output_dir' is "build", then it would compile to
  453. "build/foo/bar.o".
  454. 'macros', if given, must be a list of macro definitions. A macro
  455. definition is either a (name, value) 2-tuple or a (name,) 1-tuple.
  456. The former defines a macro; if the value is None, the macro is
  457. defined without an explicit value. The 1-tuple case undefines a
  458. macro. Later definitions/redefinitions/ undefinitions take
  459. precedence.
  460. 'include_dirs', if given, must be a list of strings, the
  461. directories to add to the default include file search path for this
  462. compilation only.
  463. 'debug' is a boolean; if true, the compiler will be instructed to
  464. output debug symbols in (or alongside) the object file(s).
  465. 'extra_preargs' and 'extra_postargs' are implementation- dependent.
  466. On platforms that have the notion of a command-line (e.g. Unix,
  467. DOS/Windows), they are most likely lists of strings: extra
  468. command-line arguments to prepand/append to the compiler command
  469. line. On other platforms, consult the implementation class
  470. documentation. In any event, they are intended as an escape hatch
  471. for those occasions when the abstract compiler framework doesn't
  472. cut the mustard.
  473. 'depends', if given, is a list of filenames that all targets
  474. depend on. If a source file is older than any file in
  475. depends, then the source file will be recompiled. This
  476. supports dependency tracking, but only at a coarse
  477. granularity.
  478. Raises CompileError on failure.
  479. """
  480. # A concrete compiler class can either override this method
  481. # entirely or implement _compile().
  482. macros, objects, extra_postargs, pp_opts, build = \
  483. self._setup_compile(output_dir, macros, include_dirs, sources,
  484. depends, extra_postargs)
  485. cc_args = self._get_cc_args(pp_opts, debug, extra_preargs)
  486. for obj in objects:
  487. try:
  488. src, ext = build[obj]
  489. except KeyError:
  490. continue
  491. self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts)
  492. # Return *all* object filenames, not just the ones we just built.
  493. return objects
  494. def _compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts):
  495. """Compile 'src' to product 'obj'."""
  496. # A concrete compiler class that does not override compile()
  497. # should implement _compile().
  498. pass
  499. def create_static_lib(self, objects, output_libname, output_dir=None,
  500. debug=0, target_lang=None):
  501. """Link a bunch of stuff together to create a static library file.
  502. The "bunch of stuff" consists of the list of object files supplied
  503. as 'objects', the extra object files supplied to
  504. 'add_link_object()' and/or 'set_link_objects()', the libraries
  505. supplied to 'add_library()' and/or 'set_libraries()', and the
  506. libraries supplied as 'libraries' (if any).
  507. 'output_libname' should be a library name, not a filename; the
  508. filename will be inferred from the library name. 'output_dir' is
  509. the directory where the library file will be put.
  510. 'debug' is a boolean; if true, debugging information will be
  511. included in the library (note that on most platforms, it is the
  512. compile step where this matters: the 'debug' flag is included here
  513. just for consistency).
  514. 'target_lang' is the target language for which the given objects
  515. are being compiled. This allows specific linkage time treatment of
  516. certain languages.
  517. Raises LibError on failure.
  518. """
  519. pass
  520. # values for target_desc parameter in link()
  521. SHARED_OBJECT = "shared_object"
  522. SHARED_LIBRARY = "shared_library"
  523. EXECUTABLE = "executable"
  524. def link(self,
  525. target_desc,
  526. objects,
  527. output_filename,
  528. output_dir=None,
  529. libraries=None,
  530. library_dirs=None,
  531. runtime_library_dirs=None,
  532. export_symbols=None,
  533. debug=0,
  534. extra_preargs=None,
  535. extra_postargs=None,
  536. build_temp=None,
  537. target_lang=None):
  538. """Link a bunch of stuff together to create an executable or
  539. shared library file.
  540. The "bunch of stuff" consists of the list of object files supplied
  541. as 'objects'. 'output_filename' should be a filename. If
  542. 'output_dir' is supplied, 'output_filename' is relative to it
  543. (i.e. 'output_filename' can provide directory components if
  544. needed).
  545. 'libraries' is a list of libraries to link against. These are
  546. library names, not filenames, since they're translated into
  547. filenames in a platform-specific way (eg. "foo" becomes "libfoo.a"
  548. on Unix and "foo.lib" on DOS/Windows). However, they can include a
  549. directory component, which means the linker will look in that
  550. specific directory rather than searching all the normal locations.
  551. 'library_dirs', if supplied, should be a list of directories to
  552. search for libraries that were specified as bare library names
  553. (ie. no directory component). These are on top of the system
  554. default and those supplied to 'add_library_dir()' and/or
  555. 'set_library_dirs()'. 'runtime_library_dirs' is a list of
  556. directories that will be embedded into the shared library and used
  557. to search for other shared libraries that *it* depends on at
  558. run-time. (This may only be relevant on Unix.)
  559. 'export_symbols' is a list of symbols that the shared library will
  560. export. (This appears to be relevant only on Windows.)
  561. 'debug' is as for 'compile()' and 'create_static_lib()', with the
  562. slight distinction that it actually matters on most platforms (as
  563. opposed to 'create_static_lib()', which includes a 'debug' flag
  564. mostly for form's sake).
  565. 'extra_preargs' and 'extra_postargs' are as for 'compile()' (except
  566. of course that they supply command-line arguments for the
  567. particular linker being used).
  568. 'target_lang' is the target language for which the given objects
  569. are being compiled. This allows specific linkage time treatment of
  570. certain languages.
  571. Raises LinkError on failure.
  572. """
  573. raise NotImplementedError
  574. # Old 'link_*()' methods, rewritten to use the new 'link()' method.
  575. def link_shared_lib(self,
  576. objects,
  577. output_libname,
  578. output_dir=None,
  579. libraries=None,
  580. library_dirs=None,
  581. runtime_library_dirs=None,
  582. export_symbols=None,
  583. debug=0,
  584. extra_preargs=None,
  585. extra_postargs=None,
  586. build_temp=None,
  587. target_lang=None):
  588. self.link(CCompiler.SHARED_LIBRARY, objects,
  589. self.library_filename(output_libname, lib_type='shared'),
  590. output_dir,
  591. libraries, library_dirs, runtime_library_dirs,
  592. export_symbols, debug,
  593. extra_preargs, extra_postargs, build_temp, target_lang)
  594. def link_shared_object(self,
  595. objects,
  596. output_filename,
  597. output_dir=None,
  598. libraries=None,
  599. library_dirs=None,
  600. runtime_library_dirs=None,
  601. export_symbols=None,
  602. debug=0,
  603. extra_preargs=None,
  604. extra_postargs=None,
  605. build_temp=None,
  606. target_lang=None):
  607. self.link(CCompiler.SHARED_OBJECT, objects,
  608. output_filename, output_dir,
  609. libraries, library_dirs, runtime_library_dirs,
  610. export_symbols, debug,
  611. extra_preargs, extra_postargs, build_temp, target_lang)
  612. def link_executable(self,
  613. objects,
  614. output_progname,
  615. output_dir=None,
  616. libraries=None,
  617. library_dirs=None,
  618. runtime_library_dirs=None,
  619. debug=0,
  620. extra_preargs=None,
  621. extra_postargs=None,
  622. target_lang=None):
  623. self.link(CCompiler.EXECUTABLE, objects,
  624. self.executable_filename(output_progname), output_dir,
  625. libraries, library_dirs, runtime_library_dirs, None,
  626. debug, extra_preargs, extra_postargs, None, target_lang)
  627. # -- Miscellaneous methods -----------------------------------------
  628. # These are all used by the 'gen_lib_options() function; there is
  629. # no appropriate default implementation so subclasses should
  630. # implement all of these.
  631. def library_dir_option(self, dir):
  632. """Return the compiler option to add 'dir' to the list of
  633. directories searched for libraries.
  634. """
  635. raise NotImplementedError
  636. def runtime_library_dir_option(self, dir):
  637. """Return the compiler option to add 'dir' to the list of
  638. directories searched for runtime libraries.
  639. """
  640. raise NotImplementedError
  641. def library_option(self, lib):
  642. """Return the compiler option to add 'dir' to the list of libraries
  643. linked into the shared library or executable.
  644. """
  645. raise NotImplementedError
  646. def has_function(self, funcname, includes=None, include_dirs=None,
  647. libraries=None, library_dirs=None):
  648. """Return a boolean indicating whether funcname is supported on
  649. the current platform. The optional arguments can be used to
  650. augment the compilation environment.
  651. """
  652. # this can't be included at module scope because it tries to
  653. # import math which might not be available at that point - maybe
  654. # the necessary logic should just be inlined?
  655. import tempfile
  656. if includes is None:
  657. includes = []
  658. if include_dirs is None:
  659. include_dirs = []
  660. if libraries is None:
  661. libraries = []
  662. if library_dirs is None:
  663. library_dirs = []
  664. fd, fname = tempfile.mkstemp(".c", funcname, text=True)
  665. f = os.fdopen(fd, "w")
  666. try:
  667. for incl in includes:
  668. f.write("""#include "%s"\n""" % incl)
  669. f.write("""\
  670. main (int argc, char **argv) {
  671. %s();
  672. }
  673. """ % funcname)
  674. finally:
  675. f.close()
  676. try:
  677. objects = self.compile([fname], include_dirs=include_dirs)
  678. except CompileError:
  679. return False
  680. try:
  681. self.link_executable(objects, "a.out",
  682. libraries=libraries,
  683. library_dirs=library_dirs)
  684. except (LinkError, TypeError):
  685. return False
  686. return True
  687. def find_library_file (self, dirs, lib, debug=0):
  688. """Search the specified list of directories for a static or shared
  689. library file 'lib' and return the full path to that file. If
  690. 'debug' true, look for a debugging version (if that makes sense on
  691. the current platform). Return None if 'lib' wasn't found in any of
  692. the specified directories.
  693. """
  694. raise NotImplementedError
  695. # -- Filename generation methods -----------------------------------
  696. # The default implementation of the filename generating methods are
  697. # prejudiced towards the Unix/DOS/Windows view of the world:
  698. # * object files are named by replacing the source file extension
  699. # (eg. .c/.cpp -> .o/.obj)
  700. # * library files (shared or static) are named by plugging the
  701. # library name and extension into a format string, eg.
  702. # "lib%s.%s" % (lib_name, ".a") for Unix static libraries
  703. # * executables are named by appending an extension (possibly
  704. # empty) to the program name: eg. progname + ".exe" for
  705. # Windows
  706. #
  707. # To reduce redundant code, these methods expect to find
  708. # several attributes in the current object (presumably defined
  709. # as class attributes):
  710. # * src_extensions -
  711. # list of C/C++ source file extensions, eg. ['.c', '.cpp']
  712. # * obj_extension -
  713. # object file extension, eg. '.o' or '.obj'
  714. # * static_lib_extension -
  715. # extension for static library files, eg. '.a' or '.lib'
  716. # * shared_lib_extension -
  717. # extension for shared library/object files, eg. '.so', '.dll'
  718. # * static_lib_format -
  719. # format string for generating static library filenames,
  720. # eg. 'lib%s.%s' or '%s.%s'
  721. # * shared_lib_format
  722. # format string for generating shared library filenames
  723. # (probably same as static_lib_format, since the extension
  724. # is one of the intended parameters to the format string)
  725. # * exe_extension -
  726. # extension for executable files, eg. '' or '.exe'
  727. def object_filenames(self, source_filenames, strip_dir=0, output_dir=''):
  728. if output_dir is None:
  729. output_dir = ''
  730. obj_names = []
  731. for src_name in source_filenames:
  732. base, ext = os.path.splitext(src_name)
  733. base = os.path.splitdrive(base)[1] # Chop off the drive
  734. base = base[os.path.isabs(base):] # If abs, chop off leading /
  735. if ext not in self.src_extensions:
  736. raise UnknownFileError(
  737. "unknown file type '%s' (from '%s')" % (ext, src_name))
  738. if strip_dir:
  739. base = os.path.basename(base)
  740. obj_names.append(os.path.join(output_dir,
  741. base + self.obj_extension))
  742. return obj_names
  743. def shared_object_filename(self, basename, strip_dir=0, output_dir=''):
  744. assert output_dir is not None
  745. if strip_dir:
  746. basename = os.path.basename(basename)
  747. return os.path.join(output_dir, basename + self.shared_lib_extension)
  748. def executable_filename(self, basename, strip_dir=0, output_dir=''):
  749. assert output_dir is not None
  750. if strip_dir:
  751. basename = os.path.basename(basename)
  752. return os.path.join(output_dir, basename + (self.exe_extension or ''))
  753. def library_filename(self, libname, lib_type='static', # or 'shared'
  754. strip_dir=0, output_dir=''):
  755. assert output_dir is not None
  756. if lib_type not in ("static", "shared", "dylib"):
  757. raise ValueError(
  758. "'lib_type' must be \"static\", \"shared\" or \"dylib\"")
  759. fmt = getattr(self, lib_type + "_lib_format")
  760. ext = getattr(self, lib_type + "_lib_extension")
  761. dir, base = os.path.split(libname)
  762. filename = fmt % (base, ext)
  763. if strip_dir:
  764. dir = ''
  765. return os.path.join(output_dir, dir, filename)
  766. # -- Utility methods -----------------------------------------------
  767. def announce(self, msg, level=1):
  768. log.debug(msg)
  769. def debug_print(self, msg):
  770. from distutils.debug import DEBUG
  771. if DEBUG:
  772. print(msg)
  773. def warn(self, msg):
  774. sys.stderr.write("warning: %s\n" % msg)
  775. def execute(self, func, args, msg=None, level=1):
  776. execute(func, args, msg, self.dry_run)
  777. def spawn(self, cmd):
  778. spawn(cmd, dry_run=self.dry_run)
  779. def move_file(self, src, dst):
  780. return move_file(src, dst, dry_run=self.dry_run)
  781. def mkpath (self, name, mode=0o777):
  782. mkpath(name, mode, dry_run=self.dry_run)
  783. # Map a sys.platform/os.name ('posix', 'nt') to the default compiler
  784. # type for that platform. Keys are interpreted as re match
  785. # patterns. Order is important; platform mappings are preferred over
  786. # OS names.
  787. _default_compilers = (
  788. # Platform string mappings
  789. # on a cygwin built python we can use gcc like an ordinary UNIXish
  790. # compiler
  791. ('cygwin.*', 'unix'),
  792. ('os2emx', 'emx'),
  793. # OS name mappings
  794. ('posix', 'unix'),
  795. ('nt', 'msvc'),
  796. )
  797. def get_default_compiler(osname=None, platform=None):
  798. """Determine the default compiler to use for the given platform.
  799. osname should be one of the standard Python OS names (i.e. the
  800. ones returned by os.name) and platform the common value
  801. returned by sys.platform for the platform in question.
  802. The default values are os.name and sys.platform in case the
  803. parameters are not given.
  804. """
  805. if osname is None:
  806. osname = os.name
  807. if platform is None:
  808. platform = sys.platform
  809. for pattern, compiler in _default_compilers:
  810. if re.match(pattern, platform) is not None or \
  811. re.match(pattern, osname) is not None:
  812. return compiler
  813. # Default to Unix compiler
  814. return 'unix'
  815. # Map compiler types to (module_name, class_name) pairs -- ie. where to
  816. # find the code that implements an interface to this compiler. (The module
  817. # is assumed to be in the 'distutils' package.)
  818. compiler_class = { 'unix': ('unixccompiler', 'UnixCCompiler',
  819. "standard UNIX-style compiler"),
  820. 'msvc': ('msvccompiler', 'MSVCCompiler',
  821. "Microsoft Visual C++"),
  822. 'cygwin': ('cygwinccompiler', 'CygwinCCompiler',
  823. "Cygwin port of GNU C Compiler for Win32"),
  824. 'mingw32': ('cygwinccompiler', 'Mingw32CCompiler',
  825. "Mingw32 port of GNU C Compiler for Win32"),
  826. 'bcpp': ('bcppcompiler', 'BCPPCompiler',
  827. "Borland C++ Compiler"),
  828. 'emx': ('emxccompiler', 'EMXCCompiler',
  829. "EMX port of GNU C Compiler for OS/2"),
  830. }
  831. def show_compilers():
  832. """Print list of available compilers (used by the "--help-compiler"
  833. options to "build", "build_ext", "build_clib").
  834. """
  835. # XXX this "knows" that the compiler option it's describing is
  836. # "--compiler", which just happens to be the case for the three
  837. # commands that use it.
  838. from distutils.fancy_getopt import FancyGetopt
  839. compilers = []
  840. for compiler in compiler_class.keys():
  841. compilers.append(("compiler="+compiler, None,
  842. compiler_class[compiler][2]))
  843. compilers.sort()
  844. pretty_printer = FancyGetopt(compilers)
  845. pretty_printer.print_help("List of available compilers:")
  846. def new_compiler(plat=None, compiler=None, verbose=0, dry_run=0, force=0):
  847. """Generate an instance of some CCompiler subclass for the supplied
  848. platform/compiler combination. 'plat' defaults to 'os.name'
  849. (eg. 'posix', 'nt'), and 'compiler' defaults to the default compiler
  850. for that platform. Currently only 'posix' and 'nt' are supported, and
  851. the default compilers are "traditional Unix interface" (UnixCCompiler
  852. class) and Visual C++ (MSVCCompiler class). Note that it's perfectly
  853. possible to ask for a Unix compiler object under Windows, and a
  854. Microsoft compiler object under Unix -- if you supply a value for
  855. 'compiler', 'plat' is ignored.
  856. """
  857. if plat is None:
  858. plat = os.name
  859. try:
  860. if compiler is None:
  861. compiler = get_default_compiler(plat)
  862. (module_name, class_name, long_description) = compiler_class[compiler]
  863. except KeyError:
  864. msg = "don't know how to compile C/C++ code on platform '%s'" % plat
  865. if compiler is not None:
  866. msg = msg + " with '%s' compiler" % compiler
  867. raise DistutilsPlatformError(msg)
  868. try:
  869. module_name = "distutils." + module_name
  870. __import__ (module_name)
  871. module = sys.modules[module_name]
  872. klass = vars(module)[class_name]
  873. except ImportError:
  874. raise DistutilsModuleError(
  875. "can't compile C/C++ code: unable to load module '%s'" % \
  876. module_name)
  877. except KeyError:
  878. raise DistutilsModuleError(
  879. "can't compile C/C++ code: unable to find class '%s' "
  880. "in module '%s'" % (class_name, module_name))
  881. # XXX The None is necessary to preserve backwards compatibility
  882. # with classes that expect verbose to be the first positional
  883. # argument.
  884. return klass(None, dry_run, force)
  885. def gen_preprocess_options(macros, include_dirs):
  886. """Generate C pre-processor options (-D, -U, -I) as used by at least
  887. two types of compilers: the typical Unix compiler and Visual C++.
  888. 'macros' is the usual thing, a list of 1- or 2-tuples, where (name,)
  889. means undefine (-U) macro 'name', and (name,value) means define (-D)
  890. macro 'name' to 'value'. 'include_dirs' is just a list of directory
  891. names to be added to the header file search path (-I). Returns a list
  892. of command-line options suitable for either Unix compilers or Visual
  893. C++.
  894. """
  895. # XXX it would be nice (mainly aesthetic, and so we don't generate
  896. # stupid-looking command lines) to go over 'macros' and eliminate
  897. # redundant definitions/undefinitions (ie. ensure that only the
  898. # latest mention of a particular macro winds up on the command
  899. # line). I don't think it's essential, though, since most (all?)
  900. # Unix C compilers only pay attention to the latest -D or -U
  901. # mention of a macro on their command line. Similar situation for
  902. # 'include_dirs'. I'm punting on both for now. Anyways, weeding out
  903. # redundancies like this should probably be the province of
  904. # CCompiler, since the data structures used are inherited from it
  905. # and therefore common to all CCompiler classes.
  906. pp_opts = []
  907. for macro in macros:
  908. if not (isinstance(macro, tuple) and 1 <= len(macro) <= 2):
  909. raise TypeError(
  910. "bad macro definition '%s': "
  911. "each element of 'macros' list must be a 1- or 2-tuple"
  912. % macro)
  913. if len(macro) == 1: # undefine this macro
  914. pp_opts.append("-U%s" % macro[0])
  915. elif len(macro) == 2:
  916. if macro[1] is None: # define with no explicit value
  917. pp_opts.append("-D%s" % macro[0])
  918. else:
  919. # XXX *don't* need to be clever about quoting the
  920. # macro value here, because we're going to avoid the
  921. # shell at all costs when we spawn the command!
  922. pp_opts.append("-D%s=%s" % macro)
  923. for dir in include_dirs:
  924. pp_opts.append("-I%s" % dir)
  925. return pp_opts
  926. def gen_lib_options (compiler, library_dirs, runtime_library_dirs, libraries):
  927. """Generate linker options for searching library directories and
  928. linking with specific libraries. 'libraries' and 'library_dirs' are,
  929. respectively, lists of library names (not filenames!) and search
  930. directories. Returns a list of command-line options suitable for use
  931. with some compiler (depending on the two format strings passed in).
  932. """
  933. lib_opts = []
  934. for dir in library_dirs:
  935. lib_opts.append(compiler.library_dir_option(dir))
  936. for dir in runtime_library_dirs:
  937. opt = compiler.runtime_library_dir_option(dir)
  938. if isinstance(opt, list):
  939. lib_opts = lib_opts + opt
  940. else:
  941. lib_opts.append(opt)
  942. # XXX it's important that we *not* remove redundant library mentions!
  943. # sometimes you really do have to say "-lfoo -lbar -lfoo" in order to
  944. # resolve all symbols. I just hope we never have to say "-lfoo obj.o
  945. # -lbar" to get things to work -- that's certainly a possibility, but a
  946. # pretty nasty way to arrange your C code.
  947. for lib in libraries:
  948. (lib_dir, lib_name) = os.path.split(lib)
  949. if lib_dir:
  950. lib_file = compiler.find_library_file([lib_dir], lib_name)
  951. if lib_file:
  952. lib_opts.append(lib_file)
  953. else:
  954. compiler.warn("no library file corresponding to "
  955. "'%s' found (skipping)" % lib)
  956. else:
  957. lib_opts.append(compiler.library_option (lib))
  958. return lib_opts