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