Fred Drake | 70b014d | 2001-07-18 18:39:56 +0000 | [diff] [blame] | 1 | """Provide access to Python's configuration information. The specific |
| 2 | configuration variables available depend heavily on the platform and |
| 3 | configuration. The values may be retrieved using |
| 4 | get_config_var(name), and the list of variables is available via |
| 5 | get_config_vars().keys(). Additional convenience functions are also |
| 6 | available. |
Greg Ward | 1190ee3 | 1998-12-18 23:46:33 +0000 | [diff] [blame] | 7 | |
| 8 | Written by: Fred L. Drake, Jr. |
| 9 | Email: <fdrake@acm.org> |
Greg Ward | 1190ee3 | 1998-12-18 23:46:33 +0000 | [diff] [blame] | 10 | """ |
| 11 | |
Greg Ward | 82d71ca | 2000-06-03 00:44:30 +0000 | [diff] [blame] | 12 | __revision__ = "$Id$" |
Greg Ward | 1190ee3 | 1998-12-18 23:46:33 +0000 | [diff] [blame] | 13 | |
Guido van Rossum | 63236cf | 2007-05-25 18:39:29 +0000 | [diff] [blame] | 14 | import io |
Greg Ward | 9ddaaa1 | 1999-01-06 14:46:06 +0000 | [diff] [blame] | 15 | import os |
| 16 | import re |
Greg Ward | 9ddaaa1 | 1999-01-06 14:46:06 +0000 | [diff] [blame] | 17 | import sys |
Greg Ward | 1190ee3 | 1998-12-18 23:46:33 +0000 | [diff] [blame] | 18 | |
Guido van Rossum | 45aecf4 | 2006-03-15 04:58:47 +0000 | [diff] [blame] | 19 | from .errors import DistutilsPlatformError |
Greg Ward | a0ca3f2 | 2000-02-02 00:05:14 +0000 | [diff] [blame] | 20 | |
Greg Ward | 879f0f1 | 2000-09-15 01:15:08 +0000 | [diff] [blame] | 21 | # These are needed in a couple of spots, so just compute them once. |
Greg Ward | cf6bea3 | 2000-04-10 01:15:06 +0000 | [diff] [blame] | 22 | PREFIX = os.path.normpath(sys.prefix) |
| 23 | EXEC_PREFIX = os.path.normpath(sys.exec_prefix) |
Fred Drake | c1ee39a | 2000-03-09 15:54:52 +0000 | [diff] [blame] | 24 | |
Christian Heimes | 255f53b | 2007-12-08 15:33:56 +0000 | [diff] [blame] | 25 | # Path to the base directory of the project. On Windows the binary may |
| 26 | # live in project/PCBuild9 |
| 27 | project_base = os.path.dirname(os.path.abspath(sys.executable)) |
| 28 | if os.name == "nt" and "pcbuild" in project_base[-8:].lower(): |
| 29 | project_base = os.path.abspath(os.path.join(project_base, os.path.pardir)) |
Christian Heimes | d9a4d1d | 2008-01-01 14:42:15 +0000 | [diff] [blame] | 30 | # PC/VS7.1 |
| 31 | if os.name == "nt" and "\\pc\\v" in project_base[-10:].lower(): |
| 32 | project_base = os.path.abspath(os.path.join(project_base, os.path.pardir, |
| 33 | os.path.pardir)) |
Christian Heimes | 255f53b | 2007-12-08 15:33:56 +0000 | [diff] [blame] | 34 | |
Fred Drake | 16c8d70 | 2002-06-04 15:28:21 +0000 | [diff] [blame] | 35 | # python_build: (Boolean) if true, we're either building Python or |
| 36 | # building an extension with an un-installed Python, so we use |
| 37 | # different (hard-wired) directories. |
Christian Heimes | 0449f63 | 2007-12-15 01:27:15 +0000 | [diff] [blame] | 38 | # Setup.local is available for Makefile builds including VPATH builds, |
| 39 | # Setup.dist is available on Windows |
| 40 | python_build = any(os.path.isfile(os.path.join(project_base, "Modules", fn)) |
| 41 | for fn in ("Setup.dist", "Setup.local")) |
Fred Drake | c916cdc | 2001-08-02 20:03:12 +0000 | [diff] [blame] | 42 | |
Martin v. Löwis | df37c8c | 2005-03-03 11:08:03 +0000 | [diff] [blame] | 43 | def get_python_version(): |
Andrew M. Kuchling | 0ff98b9 | 2002-11-14 01:43:00 +0000 | [diff] [blame] | 44 | """Return a string containing the major and minor Python version, |
| 45 | leaving off the patchlevel. Sample return values could be '1.5' |
| 46 | or '2.2'. |
| 47 | """ |
| 48 | return sys.version[:3] |
| 49 | |
| 50 | |
Greg Ward | d38e6f7 | 2000-04-10 01:17:49 +0000 | [diff] [blame] | 51 | def get_python_inc(plat_specific=0, prefix=None): |
Greg Ward | 7d73b9e | 2000-03-09 03:16:05 +0000 | [diff] [blame] | 52 | """Return the directory containing installed Python header files. |
Fred Drake | c1ee39a | 2000-03-09 15:54:52 +0000 | [diff] [blame] | 53 | |
| 54 | If 'plat_specific' is false (the default), this is the path to the |
| 55 | non-platform-specific header files, i.e. Python.h and so on; |
| 56 | otherwise, this is the path to platform-specific header files |
Martin v. Löwis | 4f1cd8b | 2001-07-26 13:41:06 +0000 | [diff] [blame] | 57 | (namely pyconfig.h). |
Fred Drake | c1ee39a | 2000-03-09 15:54:52 +0000 | [diff] [blame] | 58 | |
Greg Ward | d38e6f7 | 2000-04-10 01:17:49 +0000 | [diff] [blame] | 59 | If 'prefix' is supplied, use it instead of sys.prefix or |
| 60 | sys.exec_prefix -- i.e., ignore 'plat_specific'. |
Fred Drake | b94b849 | 2001-12-06 20:51:35 +0000 | [diff] [blame] | 61 | """ |
Greg Ward | d38e6f7 | 2000-04-10 01:17:49 +0000 | [diff] [blame] | 62 | if prefix is None: |
Fred Drake | 70b014d | 2001-07-18 18:39:56 +0000 | [diff] [blame] | 63 | prefix = plat_specific and EXEC_PREFIX or PREFIX |
Greg Ward | 7d73b9e | 2000-03-09 03:16:05 +0000 | [diff] [blame] | 64 | if os.name == "posix": |
Andrew M. Kuchling | c14fa30 | 2001-01-17 15:16:52 +0000 | [diff] [blame] | 65 | if python_build: |
Fred Drake | 16c8d70 | 2002-06-04 15:28:21 +0000 | [diff] [blame] | 66 | base = os.path.dirname(os.path.abspath(sys.executable)) |
| 67 | if plat_specific: |
| 68 | inc_dir = base |
| 69 | else: |
| 70 | inc_dir = os.path.join(base, "Include") |
| 71 | if not os.path.exists(inc_dir): |
| 72 | inc_dir = os.path.join(os.path.dirname(base), "Include") |
| 73 | return inc_dir |
Martin v. Löwis | df37c8c | 2005-03-03 11:08:03 +0000 | [diff] [blame] | 74 | return os.path.join(prefix, "include", "python" + get_python_version()) |
Greg Ward | 7d73b9e | 2000-03-09 03:16:05 +0000 | [diff] [blame] | 75 | elif os.name == "nt": |
Fred Drake | c916cdc | 2001-08-02 20:03:12 +0000 | [diff] [blame] | 76 | return os.path.join(prefix, "include") |
Greg Ward | 7d73b9e | 2000-03-09 03:16:05 +0000 | [diff] [blame] | 77 | elif os.name == "mac": |
Neal Norwitz | 80a3e0a | 2002-06-26 22:05:33 +0000 | [diff] [blame] | 78 | if plat_specific: |
Martin v. Löwis | 23b44a3 | 2003-10-24 20:09:23 +0000 | [diff] [blame] | 79 | return os.path.join(prefix, "Mac", "Include") |
Neal Norwitz | 80a3e0a | 2002-06-26 22:05:33 +0000 | [diff] [blame] | 80 | else: |
Martin v. Löwis | 23b44a3 | 2003-10-24 20:09:23 +0000 | [diff] [blame] | 81 | return os.path.join(prefix, "Include") |
Marc-André Lemburg | 2544f51 | 2002-01-31 18:56:00 +0000 | [diff] [blame] | 82 | elif os.name == "os2": |
| 83 | return os.path.join(prefix, "Include") |
Greg Ward | 7d73b9e | 2000-03-09 03:16:05 +0000 | [diff] [blame] | 84 | else: |
Fred Drake | 70b014d | 2001-07-18 18:39:56 +0000 | [diff] [blame] | 85 | raise DistutilsPlatformError( |
| 86 | "I don't know where Python installs its C header files " |
| 87 | "on platform '%s'" % os.name) |
Greg Ward | 7d73b9e | 2000-03-09 03:16:05 +0000 | [diff] [blame] | 88 | |
| 89 | |
Greg Ward | d38e6f7 | 2000-04-10 01:17:49 +0000 | [diff] [blame] | 90 | def get_python_lib(plat_specific=0, standard_lib=0, prefix=None): |
Greg Ward | 7d73b9e | 2000-03-09 03:16:05 +0000 | [diff] [blame] | 91 | """Return the directory containing the Python library (standard or |
Fred Drake | c1ee39a | 2000-03-09 15:54:52 +0000 | [diff] [blame] | 92 | site additions). |
Greg Ward | 7d73b9e | 2000-03-09 03:16:05 +0000 | [diff] [blame] | 93 | |
Fred Drake | c1ee39a | 2000-03-09 15:54:52 +0000 | [diff] [blame] | 94 | If 'plat_specific' is true, return the directory containing |
| 95 | platform-specific modules, i.e. any module from a non-pure-Python |
| 96 | module distribution; otherwise, return the platform-shared library |
| 97 | directory. If 'standard_lib' is true, return the directory |
| 98 | containing standard Python library modules; otherwise, return the |
| 99 | directory for site-specific modules. |
| 100 | |
Greg Ward | d38e6f7 | 2000-04-10 01:17:49 +0000 | [diff] [blame] | 101 | If 'prefix' is supplied, use it instead of sys.prefix or |
| 102 | sys.exec_prefix -- i.e., ignore 'plat_specific'. |
Fred Drake | c1ee39a | 2000-03-09 15:54:52 +0000 | [diff] [blame] | 103 | """ |
Greg Ward | d38e6f7 | 2000-04-10 01:17:49 +0000 | [diff] [blame] | 104 | if prefix is None: |
Fred Drake | 70b014d | 2001-07-18 18:39:56 +0000 | [diff] [blame] | 105 | prefix = plat_specific and EXEC_PREFIX or PREFIX |
Fred Drake | c916cdc | 2001-08-02 20:03:12 +0000 | [diff] [blame] | 106 | |
Greg Ward | 7d73b9e | 2000-03-09 03:16:05 +0000 | [diff] [blame] | 107 | if os.name == "posix": |
Greg Ward | cf6bea3 | 2000-04-10 01:15:06 +0000 | [diff] [blame] | 108 | libpython = os.path.join(prefix, |
Andrew M. Kuchling | 0ff98b9 | 2002-11-14 01:43:00 +0000 | [diff] [blame] | 109 | "lib", "python" + get_python_version()) |
Greg Ward | 7d73b9e | 2000-03-09 03:16:05 +0000 | [diff] [blame] | 110 | if standard_lib: |
| 111 | return libpython |
| 112 | else: |
Fred Drake | c1ee39a | 2000-03-09 15:54:52 +0000 | [diff] [blame] | 113 | return os.path.join(libpython, "site-packages") |
Greg Ward | 7d73b9e | 2000-03-09 03:16:05 +0000 | [diff] [blame] | 114 | elif os.name == "nt": |
| 115 | if standard_lib: |
Fred Drake | c916cdc | 2001-08-02 20:03:12 +0000 | [diff] [blame] | 116 | return os.path.join(prefix, "Lib") |
Greg Ward | 7d73b9e | 2000-03-09 03:16:05 +0000 | [diff] [blame] | 117 | else: |
Martin v. Löwis | df37c8c | 2005-03-03 11:08:03 +0000 | [diff] [blame] | 118 | if get_python_version() < "2.2": |
Greg Ward | f17efb9 | 2001-08-23 20:53:27 +0000 | [diff] [blame] | 119 | return prefix |
| 120 | else: |
| 121 | return os.path.join(PREFIX, "Lib", "site-packages") |
Greg Ward | 7d73b9e | 2000-03-09 03:16:05 +0000 | [diff] [blame] | 122 | elif os.name == "mac": |
Greg Ward | dc9fe8a | 2000-08-02 01:49:40 +0000 | [diff] [blame] | 123 | if plat_specific: |
Greg Ward | 7d73b9e | 2000-03-09 03:16:05 +0000 | [diff] [blame] | 124 | if standard_lib: |
Jack Jansen | 212a2e1 | 2001-09-04 12:01:49 +0000 | [diff] [blame] | 125 | return os.path.join(prefix, "Lib", "lib-dynload") |
Greg Ward | 7d73b9e | 2000-03-09 03:16:05 +0000 | [diff] [blame] | 126 | else: |
Jack Jansen | 212a2e1 | 2001-09-04 12:01:49 +0000 | [diff] [blame] | 127 | return os.path.join(prefix, "Lib", "site-packages") |
Greg Ward | 7d73b9e | 2000-03-09 03:16:05 +0000 | [diff] [blame] | 128 | else: |
| 129 | if standard_lib: |
Fred Drake | c916cdc | 2001-08-02 20:03:12 +0000 | [diff] [blame] | 130 | return os.path.join(prefix, "Lib") |
Greg Ward | 7d73b9e | 2000-03-09 03:16:05 +0000 | [diff] [blame] | 131 | else: |
Jack Jansen | 212a2e1 | 2001-09-04 12:01:49 +0000 | [diff] [blame] | 132 | return os.path.join(prefix, "Lib", "site-packages") |
Marc-André Lemburg | 2544f51 | 2002-01-31 18:56:00 +0000 | [diff] [blame] | 133 | elif os.name == "os2": |
| 134 | if standard_lib: |
| 135 | return os.path.join(PREFIX, "Lib") |
| 136 | else: |
| 137 | return os.path.join(PREFIX, "Lib", "site-packages") |
Greg Ward | 7d73b9e | 2000-03-09 03:16:05 +0000 | [diff] [blame] | 138 | else: |
Fred Drake | 70b014d | 2001-07-18 18:39:56 +0000 | [diff] [blame] | 139 | raise DistutilsPlatformError( |
| 140 | "I don't know where Python installs its library " |
| 141 | "on platform '%s'" % os.name) |
Greg Ward | 7d73b9e | 2000-03-09 03:16:05 +0000 | [diff] [blame] | 142 | |
Greg Ward | 7d73b9e | 2000-03-09 03:16:05 +0000 | [diff] [blame] | 143 | |
Fred Drake | 70b014d | 2001-07-18 18:39:56 +0000 | [diff] [blame] | 144 | def customize_compiler(compiler): |
Fred Drake | c916cdc | 2001-08-02 20:03:12 +0000 | [diff] [blame] | 145 | """Do any platform-specific customization of a CCompiler instance. |
| 146 | |
| 147 | Mainly needed on Unix, so we can plug in the information that |
| 148 | varies across Unices and is stored in Python's Makefile. |
Greg Ward | bb7baa7 | 2000-06-25 02:09:14 +0000 | [diff] [blame] | 149 | """ |
| 150 | if compiler.compiler_type == "unix": |
Martin v. Löwis | d7c795e | 2005-04-25 07:14:03 +0000 | [diff] [blame] | 151 | (cc, cxx, opt, cflags, ccshared, ldshared, so_ext) = \ |
Tim Peters | fffc4b7 | 2005-05-18 02:18:09 +0000 | [diff] [blame] | 152 | get_config_vars('CC', 'CXX', 'OPT', 'CFLAGS', |
Brett Cannon | 08cd598 | 2005-04-24 22:26:38 +0000 | [diff] [blame] | 153 | 'CCSHARED', 'LDSHARED', 'SO') |
Greg Ward | bb7baa7 | 2000-06-25 02:09:14 +0000 | [diff] [blame] | 154 | |
Guido van Rossum | e2b70bc | 2006-08-18 22:13:04 +0000 | [diff] [blame] | 155 | if 'CC' in os.environ: |
Andrew M. Kuchling | 29c8623 | 2002-11-04 19:53:24 +0000 | [diff] [blame] | 156 | cc = os.environ['CC'] |
Guido van Rossum | e2b70bc | 2006-08-18 22:13:04 +0000 | [diff] [blame] | 157 | if 'CXX' in os.environ: |
Gustavo Niemeyer | 6b01685 | 2002-11-05 16:12:02 +0000 | [diff] [blame] | 158 | cxx = os.environ['CXX'] |
Guido van Rossum | e2b70bc | 2006-08-18 22:13:04 +0000 | [diff] [blame] | 159 | if 'LDSHARED' in os.environ: |
Anthony Baxter | 22dcf66 | 2004-10-13 15:54:17 +0000 | [diff] [blame] | 160 | ldshared = os.environ['LDSHARED'] |
Guido van Rossum | e2b70bc | 2006-08-18 22:13:04 +0000 | [diff] [blame] | 161 | if 'CPP' in os.environ: |
Andrew M. Kuchling | 29c8623 | 2002-11-04 19:53:24 +0000 | [diff] [blame] | 162 | cpp = os.environ['CPP'] |
| 163 | else: |
| 164 | cpp = cc + " -E" # not always |
Guido van Rossum | e2b70bc | 2006-08-18 22:13:04 +0000 | [diff] [blame] | 165 | if 'LDFLAGS' in os.environ: |
Andrew M. Kuchling | 29c8623 | 2002-11-04 19:53:24 +0000 | [diff] [blame] | 166 | ldshared = ldshared + ' ' + os.environ['LDFLAGS'] |
Guido van Rossum | e2b70bc | 2006-08-18 22:13:04 +0000 | [diff] [blame] | 167 | if 'CFLAGS' in os.environ: |
Martin v. Löwis | d7c795e | 2005-04-25 07:14:03 +0000 | [diff] [blame] | 168 | cflags = opt + ' ' + os.environ['CFLAGS'] |
Andrew M. Kuchling | 29c8623 | 2002-11-04 19:53:24 +0000 | [diff] [blame] | 169 | ldshared = ldshared + ' ' + os.environ['CFLAGS'] |
Guido van Rossum | e2b70bc | 2006-08-18 22:13:04 +0000 | [diff] [blame] | 170 | if 'CPPFLAGS' in os.environ: |
Andrew M. Kuchling | 29c8623 | 2002-11-04 19:53:24 +0000 | [diff] [blame] | 171 | cpp = cpp + ' ' + os.environ['CPPFLAGS'] |
Martin v. Löwis | d7c795e | 2005-04-25 07:14:03 +0000 | [diff] [blame] | 172 | cflags = cflags + ' ' + os.environ['CPPFLAGS'] |
Andrew M. Kuchling | 29c8623 | 2002-11-04 19:53:24 +0000 | [diff] [blame] | 173 | ldshared = ldshared + ' ' + os.environ['CPPFLAGS'] |
| 174 | |
Martin v. Löwis | d7c795e | 2005-04-25 07:14:03 +0000 | [diff] [blame] | 175 | cc_cmd = cc + ' ' + cflags |
Greg Ward | 879f0f1 | 2000-09-15 01:15:08 +0000 | [diff] [blame] | 176 | compiler.set_executables( |
Andrew M. Kuchling | 29c8623 | 2002-11-04 19:53:24 +0000 | [diff] [blame] | 177 | preprocessor=cpp, |
Greg Ward | 879f0f1 | 2000-09-15 01:15:08 +0000 | [diff] [blame] | 178 | compiler=cc_cmd, |
| 179 | compiler_so=cc_cmd + ' ' + ccshared, |
Gustavo Niemeyer | 6b01685 | 2002-11-05 16:12:02 +0000 | [diff] [blame] | 180 | compiler_cxx=cxx, |
Greg Ward | 879f0f1 | 2000-09-15 01:15:08 +0000 | [diff] [blame] | 181 | linker_so=ldshared, |
| 182 | linker_exe=cc) |
| 183 | |
| 184 | compiler.shared_lib_extension = so_ext |
Greg Ward | bb7baa7 | 2000-06-25 02:09:14 +0000 | [diff] [blame] | 185 | |
| 186 | |
Greg Ward | 9ddaaa1 | 1999-01-06 14:46:06 +0000 | [diff] [blame] | 187 | def get_config_h_filename(): |
Martin v. Löwis | 4f1cd8b | 2001-07-26 13:41:06 +0000 | [diff] [blame] | 188 | """Return full pathname of installed pyconfig.h file.""" |
Fred Drake | c916cdc | 2001-08-02 20:03:12 +0000 | [diff] [blame] | 189 | if python_build: |
Christian Heimes | 255f53b | 2007-12-08 15:33:56 +0000 | [diff] [blame] | 190 | if os.name == "nt": |
| 191 | inc_dir = os.path.join(project_base, "PC") |
| 192 | else: |
| 193 | inc_dir = project_base |
Fred Drake | c916cdc | 2001-08-02 20:03:12 +0000 | [diff] [blame] | 194 | else: |
| 195 | inc_dir = get_python_inc(plat_specific=1) |
Martin v. Löwis | df37c8c | 2005-03-03 11:08:03 +0000 | [diff] [blame] | 196 | if get_python_version() < '2.2': |
Marc-André Lemburg | 7cf92fa | 2001-07-26 18:06:58 +0000 | [diff] [blame] | 197 | config_h = 'config.h' |
| 198 | else: |
| 199 | # The name of the config.h file changed in 2.2 |
| 200 | config_h = 'pyconfig.h' |
| 201 | return os.path.join(inc_dir, config_h) |
Greg Ward | 7d73b9e | 2000-03-09 03:16:05 +0000 | [diff] [blame] | 202 | |
Greg Ward | 1190ee3 | 1998-12-18 23:46:33 +0000 | [diff] [blame] | 203 | |
Greg Ward | 9ddaaa1 | 1999-01-06 14:46:06 +0000 | [diff] [blame] | 204 | def get_makefile_filename(): |
Fred Drake | 522af3a | 1999-01-06 16:28:34 +0000 | [diff] [blame] | 205 | """Return full pathname of installed Makefile from the Python build.""" |
Andrew M. Kuchling | c14fa30 | 2001-01-17 15:16:52 +0000 | [diff] [blame] | 206 | if python_build: |
Fred Drake | 16c8d70 | 2002-06-04 15:28:21 +0000 | [diff] [blame] | 207 | return os.path.join(os.path.dirname(sys.executable), "Makefile") |
Fred Drake | c1ee39a | 2000-03-09 15:54:52 +0000 | [diff] [blame] | 208 | lib_dir = get_python_lib(plat_specific=1, standard_lib=1) |
| 209 | return os.path.join(lib_dir, "config", "Makefile") |
Greg Ward | 7d73b9e | 2000-03-09 03:16:05 +0000 | [diff] [blame] | 210 | |
Greg Ward | 1190ee3 | 1998-12-18 23:46:33 +0000 | [diff] [blame] | 211 | |
Greg Ward | 9ddaaa1 | 1999-01-06 14:46:06 +0000 | [diff] [blame] | 212 | def parse_config_h(fp, g=None): |
Fred Drake | c1ee39a | 2000-03-09 15:54:52 +0000 | [diff] [blame] | 213 | """Parse a config.h-style file. |
| 214 | |
| 215 | A dictionary containing name/value pairs is returned. If an |
| 216 | optional dictionary is passed in as the second argument, it is |
| 217 | used instead of a new dictionary. |
Fred Drake | 522af3a | 1999-01-06 16:28:34 +0000 | [diff] [blame] | 218 | """ |
Greg Ward | 9ddaaa1 | 1999-01-06 14:46:06 +0000 | [diff] [blame] | 219 | if g is None: |
| 220 | g = {} |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 221 | define_rx = re.compile("#define ([A-Z][A-Za-z0-9_]+) (.*)\n") |
| 222 | undef_rx = re.compile("/[*] #undef ([A-Z][A-Za-z0-9_]+) [*]/\n") |
Greg Ward | 9ddaaa1 | 1999-01-06 14:46:06 +0000 | [diff] [blame] | 223 | # |
Collin Winter | 5b7e9d7 | 2007-08-30 03:52:21 +0000 | [diff] [blame] | 224 | while True: |
Greg Ward | 1190ee3 | 1998-12-18 23:46:33 +0000 | [diff] [blame] | 225 | line = fp.readline() |
| 226 | if not line: |
| 227 | break |
| 228 | m = define_rx.match(line) |
| 229 | if m: |
| 230 | n, v = m.group(1, 2) |
Jeremy Hylton | a5f4c07 | 2002-11-05 20:11:08 +0000 | [diff] [blame] | 231 | try: v = int(v) |
Greg Ward | 3c8e54b | 1998-12-22 12:42:04 +0000 | [diff] [blame] | 232 | except ValueError: pass |
| 233 | g[n] = v |
Greg Ward | 1190ee3 | 1998-12-18 23:46:33 +0000 | [diff] [blame] | 234 | else: |
| 235 | m = undef_rx.match(line) |
| 236 | if m: |
| 237 | g[m.group(1)] = 0 |
Greg Ward | 9ddaaa1 | 1999-01-06 14:46:06 +0000 | [diff] [blame] | 238 | return g |
Greg Ward | 1190ee3 | 1998-12-18 23:46:33 +0000 | [diff] [blame] | 239 | |
Greg Ward | d283ce7 | 2000-09-17 00:53:02 +0000 | [diff] [blame] | 240 | |
| 241 | # Regexes needed for parsing Makefile (and similar syntaxes, |
| 242 | # like old-style Setup files). |
| 243 | _variable_rx = re.compile("([a-zA-Z][a-zA-Z0-9_]+)\s*=\s*(.*)") |
| 244 | _findvar1_rx = re.compile(r"\$\(([A-Za-z][A-Za-z0-9_]*)\)") |
| 245 | _findvar2_rx = re.compile(r"\${([A-Za-z][A-Za-z0-9_]*)}") |
| 246 | |
Greg Ward | 3fff8d2 | 2000-09-15 00:03:13 +0000 | [diff] [blame] | 247 | def parse_makefile(fn, g=None): |
Fred Drake | c1ee39a | 2000-03-09 15:54:52 +0000 | [diff] [blame] | 248 | """Parse a Makefile-style file. |
| 249 | |
| 250 | A dictionary containing name/value pairs is returned. If an |
| 251 | optional dictionary is passed in as the second argument, it is |
| 252 | used instead of a new dictionary. |
Fred Drake | 522af3a | 1999-01-06 16:28:34 +0000 | [diff] [blame] | 253 | """ |
Greg Ward | 3fff8d2 | 2000-09-15 00:03:13 +0000 | [diff] [blame] | 254 | from distutils.text_file import TextFile |
Greg Ward | d283ce7 | 2000-09-17 00:53:02 +0000 | [diff] [blame] | 255 | fp = TextFile(fn, strip_comments=1, skip_blanks=1, join_lines=1) |
Greg Ward | 3fff8d2 | 2000-09-15 00:03:13 +0000 | [diff] [blame] | 256 | |
Greg Ward | 9ddaaa1 | 1999-01-06 14:46:06 +0000 | [diff] [blame] | 257 | if g is None: |
| 258 | g = {} |
Greg Ward | 1190ee3 | 1998-12-18 23:46:33 +0000 | [diff] [blame] | 259 | done = {} |
| 260 | notdone = {} |
Greg Ward | 3fff8d2 | 2000-09-15 00:03:13 +0000 | [diff] [blame] | 261 | |
Collin Winter | 5b7e9d7 | 2007-08-30 03:52:21 +0000 | [diff] [blame] | 262 | while True: |
Greg Ward | 1190ee3 | 1998-12-18 23:46:33 +0000 | [diff] [blame] | 263 | line = fp.readline() |
Collin Winter | 5b7e9d7 | 2007-08-30 03:52:21 +0000 | [diff] [blame] | 264 | if line is None: # eof |
Greg Ward | 1190ee3 | 1998-12-18 23:46:33 +0000 | [diff] [blame] | 265 | break |
Greg Ward | d283ce7 | 2000-09-17 00:53:02 +0000 | [diff] [blame] | 266 | m = _variable_rx.match(line) |
Greg Ward | 1190ee3 | 1998-12-18 23:46:33 +0000 | [diff] [blame] | 267 | if m: |
| 268 | n, v = m.group(1, 2) |
Neal Norwitz | 9d72bb4 | 2007-04-17 08:48:32 +0000 | [diff] [blame] | 269 | v = v.strip() |
Greg Ward | 1190ee3 | 1998-12-18 23:46:33 +0000 | [diff] [blame] | 270 | if "$" in v: |
| 271 | notdone[n] = v |
| 272 | else: |
Jeremy Hylton | a5f4c07 | 2002-11-05 20:11:08 +0000 | [diff] [blame] | 273 | try: v = int(v) |
Greg Ward | 3c8e54b | 1998-12-22 12:42:04 +0000 | [diff] [blame] | 274 | except ValueError: pass |
Greg Ward | 1190ee3 | 1998-12-18 23:46:33 +0000 | [diff] [blame] | 275 | done[n] = v |
| 276 | |
| 277 | # do variable interpolation here |
Greg Ward | 1190ee3 | 1998-12-18 23:46:33 +0000 | [diff] [blame] | 278 | while notdone: |
Guido van Rossum | cc2b016 | 2007-02-11 06:12:03 +0000 | [diff] [blame] | 279 | for name in list(notdone): |
Greg Ward | 1190ee3 | 1998-12-18 23:46:33 +0000 | [diff] [blame] | 280 | value = notdone[name] |
Greg Ward | d283ce7 | 2000-09-17 00:53:02 +0000 | [diff] [blame] | 281 | m = _findvar1_rx.search(value) or _findvar2_rx.search(value) |
Greg Ward | 1190ee3 | 1998-12-18 23:46:33 +0000 | [diff] [blame] | 282 | if m: |
| 283 | n = m.group(1) |
Martin v. Löwis | d7c795e | 2005-04-25 07:14:03 +0000 | [diff] [blame] | 284 | found = True |
Guido van Rossum | e2b70bc | 2006-08-18 22:13:04 +0000 | [diff] [blame] | 285 | if n in done: |
Martin v. Löwis | d7c795e | 2005-04-25 07:14:03 +0000 | [diff] [blame] | 286 | item = str(done[n]) |
Guido van Rossum | e2b70bc | 2006-08-18 22:13:04 +0000 | [diff] [blame] | 287 | elif n in notdone: |
Greg Ward | 1190ee3 | 1998-12-18 23:46:33 +0000 | [diff] [blame] | 288 | # get it on a subsequent round |
Martin v. Löwis | d7c795e | 2005-04-25 07:14:03 +0000 | [diff] [blame] | 289 | found = False |
Guido van Rossum | e2b70bc | 2006-08-18 22:13:04 +0000 | [diff] [blame] | 290 | elif n in os.environ: |
Martin v. Löwis | d7c795e | 2005-04-25 07:14:03 +0000 | [diff] [blame] | 291 | # do it like make: fall back to environment |
| 292 | item = os.environ[n] |
Greg Ward | 1190ee3 | 1998-12-18 23:46:33 +0000 | [diff] [blame] | 293 | else: |
Martin v. Löwis | d7c795e | 2005-04-25 07:14:03 +0000 | [diff] [blame] | 294 | done[n] = item = "" |
| 295 | if found: |
Greg Ward | 1190ee3 | 1998-12-18 23:46:33 +0000 | [diff] [blame] | 296 | after = value[m.end():] |
Martin v. Löwis | d7c795e | 2005-04-25 07:14:03 +0000 | [diff] [blame] | 297 | value = value[:m.start()] + item + after |
Greg Ward | 1190ee3 | 1998-12-18 23:46:33 +0000 | [diff] [blame] | 298 | if "$" in after: |
| 299 | notdone[name] = value |
| 300 | else: |
Jeremy Hylton | a5f4c07 | 2002-11-05 20:11:08 +0000 | [diff] [blame] | 301 | try: value = int(value) |
Andrew M. Kuchling | b11bd03 | 2001-01-16 16:33:28 +0000 | [diff] [blame] | 302 | except ValueError: |
Neal Norwitz | 9d72bb4 | 2007-04-17 08:48:32 +0000 | [diff] [blame] | 303 | done[name] = value.strip() |
Andrew M. Kuchling | b11bd03 | 2001-01-16 16:33:28 +0000 | [diff] [blame] | 304 | else: |
| 305 | done[name] = value |
Greg Ward | 1190ee3 | 1998-12-18 23:46:33 +0000 | [diff] [blame] | 306 | del notdone[name] |
| 307 | else: |
Greg Ward | 3c8e54b | 1998-12-22 12:42:04 +0000 | [diff] [blame] | 308 | # bogus variable reference; just drop it since we can't deal |
Greg Ward | 1190ee3 | 1998-12-18 23:46:33 +0000 | [diff] [blame] | 309 | del notdone[name] |
| 310 | |
Greg Ward | d283ce7 | 2000-09-17 00:53:02 +0000 | [diff] [blame] | 311 | fp.close() |
| 312 | |
Greg Ward | 1190ee3 | 1998-12-18 23:46:33 +0000 | [diff] [blame] | 313 | # save the results in the global dictionary |
| 314 | g.update(done) |
Greg Ward | 9ddaaa1 | 1999-01-06 14:46:06 +0000 | [diff] [blame] | 315 | return g |
Greg Ward | 1190ee3 | 1998-12-18 23:46:33 +0000 | [diff] [blame] | 316 | |
| 317 | |
Greg Ward | d283ce7 | 2000-09-17 00:53:02 +0000 | [diff] [blame] | 318 | def expand_makefile_vars(s, vars): |
| 319 | """Expand Makefile-style variables -- "${foo}" or "$(foo)" -- in |
| 320 | 'string' according to 'vars' (a dictionary mapping variable names to |
| 321 | values). Variables not present in 'vars' are silently expanded to the |
| 322 | empty string. The variable values in 'vars' should not contain further |
| 323 | variable expansions; if 'vars' is the output of 'parse_makefile()', |
| 324 | you're fine. Returns a variable-expanded version of 's'. |
| 325 | """ |
| 326 | |
| 327 | # This algorithm does multiple expansion, so if vars['foo'] contains |
| 328 | # "${bar}", it will expand ${foo} to ${bar}, and then expand |
| 329 | # ${bar}... and so forth. This is fine as long as 'vars' comes from |
| 330 | # 'parse_makefile()', which takes care of such expansions eagerly, |
| 331 | # according to make's variable expansion semantics. |
| 332 | |
Collin Winter | 5b7e9d7 | 2007-08-30 03:52:21 +0000 | [diff] [blame] | 333 | while True: |
Greg Ward | d283ce7 | 2000-09-17 00:53:02 +0000 | [diff] [blame] | 334 | m = _findvar1_rx.search(s) or _findvar2_rx.search(s) |
| 335 | if m: |
Greg Ward | d283ce7 | 2000-09-17 00:53:02 +0000 | [diff] [blame] | 336 | (beg, end) = m.span() |
| 337 | s = s[0:beg] + vars.get(m.group(1)) + s[end:] |
| 338 | else: |
| 339 | break |
| 340 | return s |
| 341 | |
| 342 | |
Greg Ward | 879f0f1 | 2000-09-15 01:15:08 +0000 | [diff] [blame] | 343 | _config_vars = None |
| 344 | |
Greg Ward | 9ddaaa1 | 1999-01-06 14:46:06 +0000 | [diff] [blame] | 345 | def _init_posix(): |
Fred Drake | 522af3a | 1999-01-06 16:28:34 +0000 | [diff] [blame] | 346 | """Initialize the module as appropriate for POSIX systems.""" |
Greg Ward | 879f0f1 | 2000-09-15 01:15:08 +0000 | [diff] [blame] | 347 | g = {} |
Greg Ward | a0ca3f2 | 2000-02-02 00:05:14 +0000 | [diff] [blame] | 348 | # load the installed Makefile: |
Greg Ward | a570c05 | 2000-05-23 23:14:00 +0000 | [diff] [blame] | 349 | try: |
| 350 | filename = get_makefile_filename() |
Greg Ward | 3fff8d2 | 2000-09-15 00:03:13 +0000 | [diff] [blame] | 351 | parse_makefile(filename, g) |
Guido van Rossum | b940e11 | 2007-01-10 16:19:56 +0000 | [diff] [blame] | 352 | except IOError as msg: |
Greg Ward | a570c05 | 2000-05-23 23:14:00 +0000 | [diff] [blame] | 353 | my_msg = "invalid Python installation: unable to open %s" % filename |
| 354 | if hasattr(msg, "strerror"): |
| 355 | my_msg = my_msg + " (%s)" % msg.strerror |
| 356 | |
Fred Drake | 70b014d | 2001-07-18 18:39:56 +0000 | [diff] [blame] | 357 | raise DistutilsPlatformError(my_msg) |
Fred Drake | c916cdc | 2001-08-02 20:03:12 +0000 | [diff] [blame] | 358 | |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 359 | # load the installed pyconfig.h: |
| 360 | try: |
| 361 | filename = get_config_h_filename() |
Guido van Rossum | 63236cf | 2007-05-25 18:39:29 +0000 | [diff] [blame] | 362 | parse_config_h(io.open(filename), g) |
Guido van Rossum | b940e11 | 2007-01-10 16:19:56 +0000 | [diff] [blame] | 363 | except IOError as msg: |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 364 | my_msg = "invalid Python installation: unable to open %s" % filename |
| 365 | if hasattr(msg, "strerror"): |
| 366 | my_msg = my_msg + " (%s)" % msg.strerror |
| 367 | |
| 368 | raise DistutilsPlatformError(my_msg) |
| 369 | |
Jack Jansen | 6b08a40 | 2004-06-03 12:41:45 +0000 | [diff] [blame] | 370 | # On MacOSX we need to check the setting of the environment variable |
| 371 | # MACOSX_DEPLOYMENT_TARGET: configure bases some choices on it so |
| 372 | # it needs to be compatible. |
Jack Jansen | be95462 | 2004-12-26 23:07:48 +0000 | [diff] [blame] | 373 | # If it isn't set we set it to the configure-time value |
Guido van Rossum | e2b70bc | 2006-08-18 22:13:04 +0000 | [diff] [blame] | 374 | if sys.platform == 'darwin' and 'MACOSX_DEPLOYMENT_TARGET' in g: |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 375 | cfg_target = g['MACOSX_DEPLOYMENT_TARGET'] |
Jack Jansen | 6b08a40 | 2004-06-03 12:41:45 +0000 | [diff] [blame] | 376 | cur_target = os.getenv('MACOSX_DEPLOYMENT_TARGET', '') |
Jack Jansen | be95462 | 2004-12-26 23:07:48 +0000 | [diff] [blame] | 377 | if cur_target == '': |
| 378 | cur_target = cfg_target |
| 379 | os.putenv('MACOSX_DEPLOYMENT_TARGET', cfg_target) |
Guido van Rossum | c1f779c | 2007-07-03 08:25:58 +0000 | [diff] [blame] | 380 | elif [int(x) for x in cfg_target.split('.')] > [int(x) for x in cur_target.split('.')]: |
Jack Jansen | 6b08a40 | 2004-06-03 12:41:45 +0000 | [diff] [blame] | 381 | my_msg = ('$MACOSX_DEPLOYMENT_TARGET mismatch: now "%s" but "%s" during configure' |
| 382 | % (cur_target, cfg_target)) |
| 383 | raise DistutilsPlatformError(my_msg) |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 384 | |
Greg Ward | 4f88028 | 2000-06-27 01:59:06 +0000 | [diff] [blame] | 385 | # On AIX, there are wrong paths to the linker scripts in the Makefile |
| 386 | # -- these paths are relative to the Python source, but when installed |
| 387 | # the scripts are in another directory. |
Neil Schemenauer | 1a02086 | 2001-02-16 03:31:13 +0000 | [diff] [blame] | 388 | if python_build: |
Andrew M. Kuchling | 6335773 | 2001-02-28 19:40:27 +0000 | [diff] [blame] | 389 | g['LDSHARED'] = g['BLDSHARED'] |
Fred Drake | b94b849 | 2001-12-06 20:51:35 +0000 | [diff] [blame] | 390 | |
Martin v. Löwis | df37c8c | 2005-03-03 11:08:03 +0000 | [diff] [blame] | 391 | elif get_python_version() < '2.1': |
Andrew M. Kuchling | 045af6f | 2001-09-05 12:02:59 +0000 | [diff] [blame] | 392 | # The following two branches are for 1.5.2 compatibility. |
| 393 | if sys.platform == 'aix4': # what about AIX 3.x ? |
| 394 | # Linker script is in the config directory, not in Modules as the |
| 395 | # Makefile says. |
| 396 | python_lib = get_python_lib(standard_lib=1) |
| 397 | ld_so_aix = os.path.join(python_lib, 'config', 'ld_so_aix') |
| 398 | python_exp = os.path.join(python_lib, 'config', 'python.exp') |
Greg Ward | 879f0f1 | 2000-09-15 01:15:08 +0000 | [diff] [blame] | 399 | |
Andrew M. Kuchling | 045af6f | 2001-09-05 12:02:59 +0000 | [diff] [blame] | 400 | g['LDSHARED'] = "%s %s -bI:%s" % (ld_so_aix, g['CC'], python_exp) |
| 401 | |
Greg Ward | 879f0f1 | 2000-09-15 01:15:08 +0000 | [diff] [blame] | 402 | global _config_vars |
| 403 | _config_vars = g |
Greg Ward | 66e966f | 2000-09-01 01:23:26 +0000 | [diff] [blame] | 404 | |
Greg Ward | 9ddaaa1 | 1999-01-06 14:46:06 +0000 | [diff] [blame] | 405 | |
Greg Ward | 4d74d73 | 1999-06-08 01:58:36 +0000 | [diff] [blame] | 406 | def _init_nt(): |
| 407 | """Initialize the module as appropriate for NT""" |
Greg Ward | 879f0f1 | 2000-09-15 01:15:08 +0000 | [diff] [blame] | 408 | g = {} |
Greg Ward | 4d74d73 | 1999-06-08 01:58:36 +0000 | [diff] [blame] | 409 | # set basic install directories |
Fred Drake | c1ee39a | 2000-03-09 15:54:52 +0000 | [diff] [blame] | 410 | g['LIBDEST'] = get_python_lib(plat_specific=0, standard_lib=1) |
| 411 | g['BINLIBDEST'] = get_python_lib(plat_specific=1, standard_lib=1) |
Greg Ward | 4d74d73 | 1999-06-08 01:58:36 +0000 | [diff] [blame] | 412 | |
Greg Ward | 32162e8 | 1999-08-29 18:22:13 +0000 | [diff] [blame] | 413 | # XXX hmmm.. a normal install puts include files here |
Fred Drake | c1ee39a | 2000-03-09 15:54:52 +0000 | [diff] [blame] | 414 | g['INCLUDEPY'] = get_python_inc(plat_specific=0) |
Greg Ward | 32162e8 | 1999-08-29 18:22:13 +0000 | [diff] [blame] | 415 | |
Fred Drake | 69e2c6e | 2000-02-08 15:55:42 +0000 | [diff] [blame] | 416 | g['SO'] = '.pyd' |
Greg Ward | 82d71ca | 2000-06-03 00:44:30 +0000 | [diff] [blame] | 417 | g['EXE'] = ".exe" |
Christian Heimes | 255f53b | 2007-12-08 15:33:56 +0000 | [diff] [blame] | 418 | g['VERSION'] = get_python_version().replace(".", "") |
| 419 | g['BINDIR'] = os.path.dirname(os.path.abspath(sys.executable)) |
Greg Ward | 879f0f1 | 2000-09-15 01:15:08 +0000 | [diff] [blame] | 420 | |
| 421 | global _config_vars |
| 422 | _config_vars = g |
Greg Ward | 82d71ca | 2000-06-03 00:44:30 +0000 | [diff] [blame] | 423 | |
Fred Drake | 69e2c6e | 2000-02-08 15:55:42 +0000 | [diff] [blame] | 424 | |
Greg Ward | 0eff87a | 2000-03-07 03:30:09 +0000 | [diff] [blame] | 425 | def _init_mac(): |
| 426 | """Initialize the module as appropriate for Macintosh systems""" |
Greg Ward | 879f0f1 | 2000-09-15 01:15:08 +0000 | [diff] [blame] | 427 | g = {} |
Greg Ward | 0eff87a | 2000-03-07 03:30:09 +0000 | [diff] [blame] | 428 | # set basic install directories |
Fred Drake | c1ee39a | 2000-03-09 15:54:52 +0000 | [diff] [blame] | 429 | g['LIBDEST'] = get_python_lib(plat_specific=0, standard_lib=1) |
| 430 | g['BINLIBDEST'] = get_python_lib(plat_specific=1, standard_lib=1) |
Greg Ward | 0eff87a | 2000-03-07 03:30:09 +0000 | [diff] [blame] | 431 | |
| 432 | # XXX hmmm.. a normal install puts include files here |
Fred Drake | c1ee39a | 2000-03-09 15:54:52 +0000 | [diff] [blame] | 433 | g['INCLUDEPY'] = get_python_inc(plat_specific=0) |
Greg Ward | 0eff87a | 2000-03-07 03:30:09 +0000 | [diff] [blame] | 434 | |
Jack Jansen | dd13a20 | 2001-05-17 12:52:01 +0000 | [diff] [blame] | 435 | import MacOS |
| 436 | if not hasattr(MacOS, 'runtimemodel'): |
Guido van Rossum | 99f9baa | 2001-05-17 15:03:14 +0000 | [diff] [blame] | 437 | g['SO'] = '.ppc.slb' |
Jack Jansen | dd13a20 | 2001-05-17 12:52:01 +0000 | [diff] [blame] | 438 | else: |
| 439 | g['SO'] = '.%s.slb' % MacOS.runtimemodel |
Greg Ward | 7d73b9e | 2000-03-09 03:16:05 +0000 | [diff] [blame] | 440 | |
| 441 | # XXX are these used anywhere? |
Greg Ward | cf6bea3 | 2000-04-10 01:15:06 +0000 | [diff] [blame] | 442 | g['install_lib'] = os.path.join(EXEC_PREFIX, "Lib") |
| 443 | g['install_platlib'] = os.path.join(EXEC_PREFIX, "Mac", "Lib") |
Greg Ward | 0eff87a | 2000-03-07 03:30:09 +0000 | [diff] [blame] | 444 | |
Jack Jansen | ab5320b | 2002-06-26 15:42:49 +0000 | [diff] [blame] | 445 | # These are used by the extension module build |
| 446 | g['srcdir'] = ':' |
Greg Ward | 879f0f1 | 2000-09-15 01:15:08 +0000 | [diff] [blame] | 447 | global _config_vars |
| 448 | _config_vars = g |
Greg Ward | 9ddaaa1 | 1999-01-06 14:46:06 +0000 | [diff] [blame] | 449 | |
Fred Drake | 69e2c6e | 2000-02-08 15:55:42 +0000 | [diff] [blame] | 450 | |
Marc-André Lemburg | 2544f51 | 2002-01-31 18:56:00 +0000 | [diff] [blame] | 451 | def _init_os2(): |
| 452 | """Initialize the module as appropriate for OS/2""" |
| 453 | g = {} |
| 454 | # set basic install directories |
| 455 | g['LIBDEST'] = get_python_lib(plat_specific=0, standard_lib=1) |
| 456 | g['BINLIBDEST'] = get_python_lib(plat_specific=1, standard_lib=1) |
| 457 | |
| 458 | # XXX hmmm.. a normal install puts include files here |
| 459 | g['INCLUDEPY'] = get_python_inc(plat_specific=0) |
| 460 | |
| 461 | g['SO'] = '.pyd' |
| 462 | g['EXE'] = ".exe" |
| 463 | |
| 464 | global _config_vars |
| 465 | _config_vars = g |
| 466 | |
| 467 | |
Greg Ward | 879f0f1 | 2000-09-15 01:15:08 +0000 | [diff] [blame] | 468 | def get_config_vars(*args): |
| 469 | """With no arguments, return a dictionary of all configuration |
| 470 | variables relevant for the current platform. Generally this includes |
| 471 | everything needed to build extensions and install both pure modules and |
| 472 | extensions. On Unix, this means every variable defined in Python's |
| 473 | installed Makefile; on Windows and Mac OS it's a much smaller set. |
| 474 | |
| 475 | With arguments, return a list of values that result from looking up |
| 476 | each argument in the configuration variable dictionary. |
| 477 | """ |
| 478 | global _config_vars |
| 479 | if _config_vars is None: |
Greg Ward | 879f0f1 | 2000-09-15 01:15:08 +0000 | [diff] [blame] | 480 | func = globals().get("_init_" + os.name) |
| 481 | if func: |
| 482 | func() |
| 483 | else: |
| 484 | _config_vars = {} |
| 485 | |
| 486 | # Normalized versions of prefix and exec_prefix are handy to have; |
| 487 | # in fact, these are the standard versions used most places in the |
| 488 | # Distutils. |
| 489 | _config_vars['prefix'] = PREFIX |
| 490 | _config_vars['exec_prefix'] = EXEC_PREFIX |
| 491 | |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 492 | if sys.platform == 'darwin': |
| 493 | kernel_version = os.uname()[2] # Kernel version (8.4.3) |
| 494 | major_version = int(kernel_version.split('.')[0]) |
| 495 | |
| 496 | if major_version < 8: |
| 497 | # On Mac OS X before 10.4, check if -arch and -isysroot |
| 498 | # are in CFLAGS or LDFLAGS and remove them if they are. |
| 499 | # This is needed when building extensions on a 10.3 system |
| 500 | # using a universal build of python. |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 501 | for key in ('LDFLAGS', 'BASECFLAGS', |
| 502 | # a number of derived variables. These need to be |
| 503 | # patched up as well. |
| 504 | 'CFLAGS', 'PY_CFLAGS', 'BLDSHARED'): |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 505 | flags = _config_vars[key] |
| 506 | flags = re.sub('-arch\s+\w+\s', ' ', flags) |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 507 | flags = re.sub('-isysroot [^ \t]*', ' ', flags) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 508 | _config_vars[key] = flags |
| 509 | |
Greg Ward | 879f0f1 | 2000-09-15 01:15:08 +0000 | [diff] [blame] | 510 | if args: |
| 511 | vals = [] |
| 512 | for name in args: |
| 513 | vals.append(_config_vars.get(name)) |
| 514 | return vals |
| 515 | else: |
| 516 | return _config_vars |
| 517 | |
| 518 | def get_config_var(name): |
| 519 | """Return the value of a single variable using the dictionary |
| 520 | returned by 'get_config_vars()'. Equivalent to |
Fred Drake | c916cdc | 2001-08-02 20:03:12 +0000 | [diff] [blame] | 521 | get_config_vars().get(name) |
Greg Ward | 879f0f1 | 2000-09-15 01:15:08 +0000 | [diff] [blame] | 522 | """ |
| 523 | return get_config_vars().get(name) |