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