Fred Drake | 522af3a | 1999-01-06 16:28:34 +0000 | [diff] [blame] | 1 | """Provide access to Python's configuration information. The specific names |
| 2 | defined in the module depend heavily on the platform and configuration. |
Greg Ward | 1190ee3 | 1998-12-18 23:46:33 +0000 | [diff] [blame] | 3 | |
| 4 | Written by: Fred L. Drake, Jr. |
| 5 | Email: <fdrake@acm.org> |
| 6 | Initial date: 17-Dec-1998 |
| 7 | """ |
| 8 | |
Greg Ward | 82d71ca | 2000-06-03 00:44:30 +0000 | [diff] [blame] | 9 | __revision__ = "$Id$" |
Greg Ward | 1190ee3 | 1998-12-18 23:46:33 +0000 | [diff] [blame] | 10 | |
Greg Ward | 9ddaaa1 | 1999-01-06 14:46:06 +0000 | [diff] [blame] | 11 | import os |
| 12 | import re |
| 13 | import string |
| 14 | import sys |
Greg Ward | 1190ee3 | 1998-12-18 23:46:33 +0000 | [diff] [blame] | 15 | |
Fred Drake | c1ee39a | 2000-03-09 15:54:52 +0000 | [diff] [blame] | 16 | from errors import DistutilsPlatformError |
Greg Ward | a0ca3f2 | 2000-02-02 00:05:14 +0000 | [diff] [blame] | 17 | |
Greg Ward | 879f0f1 | 2000-09-15 01:15:08 +0000 | [diff] [blame] | 18 | # 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] | 19 | PREFIX = os.path.normpath(sys.prefix) |
| 20 | EXEC_PREFIX = os.path.normpath(sys.exec_prefix) |
Fred Drake | c1ee39a | 2000-03-09 15:54:52 +0000 | [diff] [blame] | 21 | |
Andrew M. Kuchling | c14fa30 | 2001-01-17 15:16:52 +0000 | [diff] [blame] | 22 | # Boolean; if it's true, we're still building Python, so |
| 23 | # we use different (hard-wired) directories. |
| 24 | |
| 25 | python_build = 0 |
| 26 | |
| 27 | def set_python_build(): |
| 28 | """Set the python_build flag to true; this means that we're |
| 29 | building Python itself. Only called from the setup.py script |
| 30 | shipped with Python. |
| 31 | """ |
| 32 | |
| 33 | global python_build |
| 34 | python_build = 1 |
Fred Drake | c1ee39a | 2000-03-09 15:54:52 +0000 | [diff] [blame] | 35 | |
Greg Ward | d38e6f7 | 2000-04-10 01:17:49 +0000 | [diff] [blame] | 36 | def get_python_inc(plat_specific=0, prefix=None): |
Greg Ward | 7d73b9e | 2000-03-09 03:16:05 +0000 | [diff] [blame] | 37 | """Return the directory containing installed Python header files. |
Fred Drake | c1ee39a | 2000-03-09 15:54:52 +0000 | [diff] [blame] | 38 | |
| 39 | If 'plat_specific' is false (the default), this is the path to the |
| 40 | non-platform-specific header files, i.e. Python.h and so on; |
| 41 | otherwise, this is the path to platform-specific header files |
| 42 | (namely config.h). |
| 43 | |
Greg Ward | d38e6f7 | 2000-04-10 01:17:49 +0000 | [diff] [blame] | 44 | If 'prefix' is supplied, use it instead of sys.prefix or |
| 45 | sys.exec_prefix -- i.e., ignore 'plat_specific'. |
Fred Drake | c1ee39a | 2000-03-09 15:54:52 +0000 | [diff] [blame] | 46 | """ |
Greg Ward | d38e6f7 | 2000-04-10 01:17:49 +0000 | [diff] [blame] | 47 | if prefix is None: |
| 48 | prefix = (plat_specific and EXEC_PREFIX or PREFIX) |
Greg Ward | 7d73b9e | 2000-03-09 03:16:05 +0000 | [diff] [blame] | 49 | if os.name == "posix": |
Andrew M. Kuchling | c14fa30 | 2001-01-17 15:16:52 +0000 | [diff] [blame] | 50 | if python_build: |
| 51 | return "Include/" |
Greg Ward | cf6bea3 | 2000-04-10 01:15:06 +0000 | [diff] [blame] | 52 | return os.path.join(prefix, "include", "python" + sys.version[:3]) |
Greg Ward | 7d73b9e | 2000-03-09 03:16:05 +0000 | [diff] [blame] | 53 | elif os.name == "nt": |
Greg Ward | cf6bea3 | 2000-04-10 01:15:06 +0000 | [diff] [blame] | 54 | return os.path.join(prefix, "Include") # include or Include? |
Greg Ward | 7d73b9e | 2000-03-09 03:16:05 +0000 | [diff] [blame] | 55 | elif os.name == "mac": |
Greg Ward | cf6bea3 | 2000-04-10 01:15:06 +0000 | [diff] [blame] | 56 | return os.path.join(prefix, "Include") |
Greg Ward | 7d73b9e | 2000-03-09 03:16:05 +0000 | [diff] [blame] | 57 | else: |
| 58 | raise DistutilsPlatformError, \ |
| 59 | ("I don't know where Python installs its C header files " + |
| 60 | "on platform '%s'") % os.name |
| 61 | |
| 62 | |
Greg Ward | d38e6f7 | 2000-04-10 01:17:49 +0000 | [diff] [blame] | 63 | def get_python_lib(plat_specific=0, standard_lib=0, prefix=None): |
Greg Ward | 7d73b9e | 2000-03-09 03:16:05 +0000 | [diff] [blame] | 64 | """Return the directory containing the Python library (standard or |
Fred Drake | c1ee39a | 2000-03-09 15:54:52 +0000 | [diff] [blame] | 65 | site additions). |
Greg Ward | 7d73b9e | 2000-03-09 03:16:05 +0000 | [diff] [blame] | 66 | |
Fred Drake | c1ee39a | 2000-03-09 15:54:52 +0000 | [diff] [blame] | 67 | If 'plat_specific' is true, return the directory containing |
| 68 | platform-specific modules, i.e. any module from a non-pure-Python |
| 69 | module distribution; otherwise, return the platform-shared library |
| 70 | directory. If 'standard_lib' is true, return the directory |
| 71 | containing standard Python library modules; otherwise, return the |
| 72 | directory for site-specific modules. |
| 73 | |
Greg Ward | d38e6f7 | 2000-04-10 01:17:49 +0000 | [diff] [blame] | 74 | If 'prefix' is supplied, use it instead of sys.prefix or |
| 75 | sys.exec_prefix -- i.e., ignore 'plat_specific'. |
Fred Drake | c1ee39a | 2000-03-09 15:54:52 +0000 | [diff] [blame] | 76 | """ |
Greg Ward | d38e6f7 | 2000-04-10 01:17:49 +0000 | [diff] [blame] | 77 | if prefix is None: |
| 78 | prefix = (plat_specific and EXEC_PREFIX or PREFIX) |
Greg Ward | 7d73b9e | 2000-03-09 03:16:05 +0000 | [diff] [blame] | 79 | |
| 80 | if os.name == "posix": |
Greg Ward | cf6bea3 | 2000-04-10 01:15:06 +0000 | [diff] [blame] | 81 | libpython = os.path.join(prefix, |
Fred Drake | c1ee39a | 2000-03-09 15:54:52 +0000 | [diff] [blame] | 82 | "lib", "python" + sys.version[:3]) |
Greg Ward | 7d73b9e | 2000-03-09 03:16:05 +0000 | [diff] [blame] | 83 | if standard_lib: |
| 84 | return libpython |
| 85 | else: |
Fred Drake | c1ee39a | 2000-03-09 15:54:52 +0000 | [diff] [blame] | 86 | return os.path.join(libpython, "site-packages") |
Greg Ward | 7d73b9e | 2000-03-09 03:16:05 +0000 | [diff] [blame] | 87 | |
| 88 | elif os.name == "nt": |
| 89 | if standard_lib: |
Greg Ward | cf6bea3 | 2000-04-10 01:15:06 +0000 | [diff] [blame] | 90 | return os.path.join(PREFIX, "Lib") |
Greg Ward | 7d73b9e | 2000-03-09 03:16:05 +0000 | [diff] [blame] | 91 | else: |
Greg Ward | cf6bea3 | 2000-04-10 01:15:06 +0000 | [diff] [blame] | 92 | return prefix |
Greg Ward | 7d73b9e | 2000-03-09 03:16:05 +0000 | [diff] [blame] | 93 | |
| 94 | elif os.name == "mac": |
Greg Ward | dc9fe8a | 2000-08-02 01:49:40 +0000 | [diff] [blame] | 95 | if plat_specific: |
Greg Ward | 7d73b9e | 2000-03-09 03:16:05 +0000 | [diff] [blame] | 96 | if standard_lib: |
Greg Ward | cf6bea3 | 2000-04-10 01:15:06 +0000 | [diff] [blame] | 97 | return os.path.join(EXEC_PREFIX, "Mac", "Plugins") |
Greg Ward | 7d73b9e | 2000-03-09 03:16:05 +0000 | [diff] [blame] | 98 | else: |
| 99 | raise DistutilsPlatformError, \ |
| 100 | "OK, where DO site-specific extensions go on the Mac?" |
| 101 | else: |
| 102 | if standard_lib: |
Greg Ward | cf6bea3 | 2000-04-10 01:15:06 +0000 | [diff] [blame] | 103 | return os.path.join(PREFIX, "Lib") |
Greg Ward | 7d73b9e | 2000-03-09 03:16:05 +0000 | [diff] [blame] | 104 | else: |
| 105 | raise DistutilsPlatformError, \ |
| 106 | "OK, where DO site-specific modules go on the Mac?" |
| 107 | else: |
| 108 | raise DistutilsPlatformError, \ |
| 109 | ("I don't know where Python installs its library " + |
| 110 | "on platform '%s'") % os.name |
| 111 | |
Fred Drake | c1ee39a | 2000-03-09 15:54:52 +0000 | [diff] [blame] | 112 | # get_python_lib() |
Greg Ward | 7d73b9e | 2000-03-09 03:16:05 +0000 | [diff] [blame] | 113 | |
| 114 | |
Greg Ward | bb7baa7 | 2000-06-25 02:09:14 +0000 | [diff] [blame] | 115 | def customize_compiler (compiler): |
| 116 | """Do any platform-specific customization of the CCompiler instance |
| 117 | 'compiler'. Mainly needed on Unix, so we can plug in the information |
| 118 | that varies across Unices and is stored in Python's Makefile. |
| 119 | """ |
| 120 | if compiler.compiler_type == "unix": |
Greg Ward | 879f0f1 | 2000-09-15 01:15:08 +0000 | [diff] [blame] | 121 | (cc, opt, ccshared, ldshared, so_ext) = \ |
| 122 | get_config_vars('CC', 'OPT', 'CCSHARED', 'LDSHARED', 'SO') |
Greg Ward | bb7baa7 | 2000-06-25 02:09:14 +0000 | [diff] [blame] | 123 | |
Greg Ward | 879f0f1 | 2000-09-15 01:15:08 +0000 | [diff] [blame] | 124 | cc_cmd = cc + ' ' + opt |
| 125 | compiler.set_executables( |
| 126 | preprocessor=cc + " -E", # not always! |
| 127 | compiler=cc_cmd, |
| 128 | compiler_so=cc_cmd + ' ' + ccshared, |
| 129 | linker_so=ldshared, |
| 130 | linker_exe=cc) |
| 131 | |
| 132 | compiler.shared_lib_extension = so_ext |
Greg Ward | bb7baa7 | 2000-06-25 02:09:14 +0000 | [diff] [blame] | 133 | |
| 134 | |
Greg Ward | 9ddaaa1 | 1999-01-06 14:46:06 +0000 | [diff] [blame] | 135 | def get_config_h_filename(): |
Fred Drake | 522af3a | 1999-01-06 16:28:34 +0000 | [diff] [blame] | 136 | """Return full pathname of installed config.h file.""" |
Andrew M. Kuchling | c14fa30 | 2001-01-17 15:16:52 +0000 | [diff] [blame] | 137 | if python_build: inc_dir = '.' |
| 138 | else: inc_dir = get_python_inc(plat_specific=1) |
Fred Drake | c1ee39a | 2000-03-09 15:54:52 +0000 | [diff] [blame] | 139 | return os.path.join(inc_dir, "config.h") |
Greg Ward | 7d73b9e | 2000-03-09 03:16:05 +0000 | [diff] [blame] | 140 | |
Greg Ward | 1190ee3 | 1998-12-18 23:46:33 +0000 | [diff] [blame] | 141 | |
Greg Ward | 9ddaaa1 | 1999-01-06 14:46:06 +0000 | [diff] [blame] | 142 | def get_makefile_filename(): |
Fred Drake | 522af3a | 1999-01-06 16:28:34 +0000 | [diff] [blame] | 143 | """Return full pathname of installed Makefile from the Python build.""" |
Andrew M. Kuchling | c14fa30 | 2001-01-17 15:16:52 +0000 | [diff] [blame] | 144 | if python_build: |
Neil Schemenauer | 84d14ba | 2001-01-24 17:17:20 +0000 | [diff] [blame] | 145 | return './Makefile' |
Fred Drake | c1ee39a | 2000-03-09 15:54:52 +0000 | [diff] [blame] | 146 | lib_dir = get_python_lib(plat_specific=1, standard_lib=1) |
| 147 | return os.path.join(lib_dir, "config", "Makefile") |
Greg Ward | 7d73b9e | 2000-03-09 03:16:05 +0000 | [diff] [blame] | 148 | |
Greg Ward | 1190ee3 | 1998-12-18 23:46:33 +0000 | [diff] [blame] | 149 | |
Greg Ward | 9ddaaa1 | 1999-01-06 14:46:06 +0000 | [diff] [blame] | 150 | def parse_config_h(fp, g=None): |
Fred Drake | c1ee39a | 2000-03-09 15:54:52 +0000 | [diff] [blame] | 151 | """Parse a config.h-style file. |
| 152 | |
| 153 | A dictionary containing name/value pairs is returned. If an |
| 154 | optional dictionary is passed in as the second argument, it is |
| 155 | used instead of a new dictionary. |
Fred Drake | 522af3a | 1999-01-06 16:28:34 +0000 | [diff] [blame] | 156 | """ |
Greg Ward | 9ddaaa1 | 1999-01-06 14:46:06 +0000 | [diff] [blame] | 157 | if g is None: |
| 158 | g = {} |
Greg Ward | 1190ee3 | 1998-12-18 23:46:33 +0000 | [diff] [blame] | 159 | define_rx = re.compile("#define ([A-Z][A-Z0-9_]+) (.*)\n") |
| 160 | undef_rx = re.compile("/[*] #undef ([A-Z][A-Z0-9_]+) [*]/\n") |
Greg Ward | 9ddaaa1 | 1999-01-06 14:46:06 +0000 | [diff] [blame] | 161 | # |
Greg Ward | 1190ee3 | 1998-12-18 23:46:33 +0000 | [diff] [blame] | 162 | while 1: |
| 163 | line = fp.readline() |
| 164 | if not line: |
| 165 | break |
| 166 | m = define_rx.match(line) |
| 167 | if m: |
| 168 | n, v = m.group(1, 2) |
Greg Ward | 3c8e54b | 1998-12-22 12:42:04 +0000 | [diff] [blame] | 169 | try: v = string.atoi(v) |
| 170 | except ValueError: pass |
| 171 | g[n] = v |
Greg Ward | 1190ee3 | 1998-12-18 23:46:33 +0000 | [diff] [blame] | 172 | else: |
| 173 | m = undef_rx.match(line) |
| 174 | if m: |
| 175 | g[m.group(1)] = 0 |
Greg Ward | 9ddaaa1 | 1999-01-06 14:46:06 +0000 | [diff] [blame] | 176 | return g |
Greg Ward | 1190ee3 | 1998-12-18 23:46:33 +0000 | [diff] [blame] | 177 | |
Greg Ward | d283ce7 | 2000-09-17 00:53:02 +0000 | [diff] [blame] | 178 | |
| 179 | # Regexes needed for parsing Makefile (and similar syntaxes, |
| 180 | # like old-style Setup files). |
| 181 | _variable_rx = re.compile("([a-zA-Z][a-zA-Z0-9_]+)\s*=\s*(.*)") |
| 182 | _findvar1_rx = re.compile(r"\$\(([A-Za-z][A-Za-z0-9_]*)\)") |
| 183 | _findvar2_rx = re.compile(r"\${([A-Za-z][A-Za-z0-9_]*)}") |
| 184 | |
Greg Ward | 3fff8d2 | 2000-09-15 00:03:13 +0000 | [diff] [blame] | 185 | def parse_makefile(fn, g=None): |
Fred Drake | c1ee39a | 2000-03-09 15:54:52 +0000 | [diff] [blame] | 186 | """Parse a Makefile-style file. |
| 187 | |
| 188 | A dictionary containing name/value pairs is returned. If an |
| 189 | optional dictionary is passed in as the second argument, it is |
| 190 | used instead of a new dictionary. |
| 191 | |
Fred Drake | 522af3a | 1999-01-06 16:28:34 +0000 | [diff] [blame] | 192 | """ |
Greg Ward | 3fff8d2 | 2000-09-15 00:03:13 +0000 | [diff] [blame] | 193 | from distutils.text_file import TextFile |
Greg Ward | d283ce7 | 2000-09-17 00:53:02 +0000 | [diff] [blame] | 194 | fp = TextFile(fn, strip_comments=1, skip_blanks=1, join_lines=1) |
Greg Ward | 3fff8d2 | 2000-09-15 00:03:13 +0000 | [diff] [blame] | 195 | |
Greg Ward | 9ddaaa1 | 1999-01-06 14:46:06 +0000 | [diff] [blame] | 196 | if g is None: |
| 197 | g = {} |
Greg Ward | 1190ee3 | 1998-12-18 23:46:33 +0000 | [diff] [blame] | 198 | done = {} |
| 199 | notdone = {} |
Greg Ward | 3fff8d2 | 2000-09-15 00:03:13 +0000 | [diff] [blame] | 200 | |
Greg Ward | 1190ee3 | 1998-12-18 23:46:33 +0000 | [diff] [blame] | 201 | while 1: |
| 202 | line = fp.readline() |
Greg Ward | d283ce7 | 2000-09-17 00:53:02 +0000 | [diff] [blame] | 203 | if line is None: # eof |
Greg Ward | 1190ee3 | 1998-12-18 23:46:33 +0000 | [diff] [blame] | 204 | break |
Greg Ward | d283ce7 | 2000-09-17 00:53:02 +0000 | [diff] [blame] | 205 | m = _variable_rx.match(line) |
Greg Ward | 1190ee3 | 1998-12-18 23:46:33 +0000 | [diff] [blame] | 206 | if m: |
| 207 | n, v = m.group(1, 2) |
Greg Ward | 3c8e54b | 1998-12-22 12:42:04 +0000 | [diff] [blame] | 208 | v = string.strip(v) |
Greg Ward | 1190ee3 | 1998-12-18 23:46:33 +0000 | [diff] [blame] | 209 | if "$" in v: |
| 210 | notdone[n] = v |
| 211 | else: |
Greg Ward | 3c8e54b | 1998-12-22 12:42:04 +0000 | [diff] [blame] | 212 | try: v = string.atoi(v) |
| 213 | except ValueError: pass |
Greg Ward | 1190ee3 | 1998-12-18 23:46:33 +0000 | [diff] [blame] | 214 | done[n] = v |
| 215 | |
| 216 | # do variable interpolation here |
Greg Ward | 1190ee3 | 1998-12-18 23:46:33 +0000 | [diff] [blame] | 217 | while notdone: |
| 218 | for name in notdone.keys(): |
| 219 | value = notdone[name] |
Greg Ward | d283ce7 | 2000-09-17 00:53:02 +0000 | [diff] [blame] | 220 | m = _findvar1_rx.search(value) or _findvar2_rx.search(value) |
Greg Ward | 1190ee3 | 1998-12-18 23:46:33 +0000 | [diff] [blame] | 221 | if m: |
| 222 | n = m.group(1) |
| 223 | if done.has_key(n): |
| 224 | after = value[m.end():] |
Andrew M. Kuchling | b11bd03 | 2001-01-16 16:33:28 +0000 | [diff] [blame] | 225 | value = value[:m.start()] + str(done[n]) + after |
Greg Ward | 1190ee3 | 1998-12-18 23:46:33 +0000 | [diff] [blame] | 226 | if "$" in after: |
| 227 | notdone[name] = value |
| 228 | else: |
Greg Ward | 3c8e54b | 1998-12-22 12:42:04 +0000 | [diff] [blame] | 229 | try: value = string.atoi(value) |
Andrew M. Kuchling | b11bd03 | 2001-01-16 16:33:28 +0000 | [diff] [blame] | 230 | except ValueError: |
| 231 | done[name] = string.strip(value) |
| 232 | else: |
| 233 | done[name] = value |
Greg Ward | 1190ee3 | 1998-12-18 23:46:33 +0000 | [diff] [blame] | 234 | del notdone[name] |
| 235 | elif notdone.has_key(n): |
| 236 | # get it on a subsequent round |
| 237 | pass |
| 238 | else: |
| 239 | done[n] = "" |
| 240 | after = value[m.end():] |
| 241 | value = value[:m.start()] + after |
| 242 | if "$" in after: |
| 243 | notdone[name] = value |
| 244 | else: |
Greg Ward | 3c8e54b | 1998-12-22 12:42:04 +0000 | [diff] [blame] | 245 | try: value = string.atoi(value) |
Andrew M. Kuchling | b11bd03 | 2001-01-16 16:33:28 +0000 | [diff] [blame] | 246 | except ValueError: |
| 247 | done[name] = string.strip(value) |
| 248 | else: |
| 249 | done[name] = value |
Greg Ward | 1190ee3 | 1998-12-18 23:46:33 +0000 | [diff] [blame] | 250 | del notdone[name] |
| 251 | else: |
Greg Ward | 3c8e54b | 1998-12-22 12:42:04 +0000 | [diff] [blame] | 252 | # bogus variable reference; just drop it since we can't deal |
Greg Ward | 1190ee3 | 1998-12-18 23:46:33 +0000 | [diff] [blame] | 253 | del notdone[name] |
| 254 | |
Greg Ward | d283ce7 | 2000-09-17 00:53:02 +0000 | [diff] [blame] | 255 | fp.close() |
| 256 | |
Greg Ward | 1190ee3 | 1998-12-18 23:46:33 +0000 | [diff] [blame] | 257 | # save the results in the global dictionary |
| 258 | g.update(done) |
Greg Ward | 9ddaaa1 | 1999-01-06 14:46:06 +0000 | [diff] [blame] | 259 | return g |
Greg Ward | 1190ee3 | 1998-12-18 23:46:33 +0000 | [diff] [blame] | 260 | |
| 261 | |
Greg Ward | d283ce7 | 2000-09-17 00:53:02 +0000 | [diff] [blame] | 262 | def expand_makefile_vars(s, vars): |
| 263 | """Expand Makefile-style variables -- "${foo}" or "$(foo)" -- in |
| 264 | 'string' according to 'vars' (a dictionary mapping variable names to |
| 265 | values). Variables not present in 'vars' are silently expanded to the |
| 266 | empty string. The variable values in 'vars' should not contain further |
| 267 | variable expansions; if 'vars' is the output of 'parse_makefile()', |
| 268 | you're fine. Returns a variable-expanded version of 's'. |
| 269 | """ |
| 270 | |
| 271 | # This algorithm does multiple expansion, so if vars['foo'] contains |
| 272 | # "${bar}", it will expand ${foo} to ${bar}, and then expand |
| 273 | # ${bar}... and so forth. This is fine as long as 'vars' comes from |
| 274 | # 'parse_makefile()', which takes care of such expansions eagerly, |
| 275 | # according to make's variable expansion semantics. |
| 276 | |
| 277 | while 1: |
| 278 | m = _findvar1_rx.search(s) or _findvar2_rx.search(s) |
| 279 | if m: |
| 280 | name = m.group(1) |
| 281 | (beg, end) = m.span() |
| 282 | s = s[0:beg] + vars.get(m.group(1)) + s[end:] |
| 283 | else: |
| 284 | break |
| 285 | return s |
| 286 | |
| 287 | |
Greg Ward | 879f0f1 | 2000-09-15 01:15:08 +0000 | [diff] [blame] | 288 | _config_vars = None |
| 289 | |
Greg Ward | 9ddaaa1 | 1999-01-06 14:46:06 +0000 | [diff] [blame] | 290 | def _init_posix(): |
Fred Drake | 522af3a | 1999-01-06 16:28:34 +0000 | [diff] [blame] | 291 | """Initialize the module as appropriate for POSIX systems.""" |
Greg Ward | 879f0f1 | 2000-09-15 01:15:08 +0000 | [diff] [blame] | 292 | g = {} |
Greg Ward | a0ca3f2 | 2000-02-02 00:05:14 +0000 | [diff] [blame] | 293 | # load the installed Makefile: |
Greg Ward | a570c05 | 2000-05-23 23:14:00 +0000 | [diff] [blame] | 294 | try: |
| 295 | filename = get_makefile_filename() |
Greg Ward | 3fff8d2 | 2000-09-15 00:03:13 +0000 | [diff] [blame] | 296 | parse_makefile(filename, g) |
Greg Ward | a570c05 | 2000-05-23 23:14:00 +0000 | [diff] [blame] | 297 | except IOError, msg: |
| 298 | my_msg = "invalid Python installation: unable to open %s" % filename |
| 299 | if hasattr(msg, "strerror"): |
| 300 | my_msg = my_msg + " (%s)" % msg.strerror |
| 301 | |
| 302 | raise DistutilsPlatformError, my_msg |
| 303 | |
Greg Ward | 4f88028 | 2000-06-27 01:59:06 +0000 | [diff] [blame] | 304 | |
| 305 | # On AIX, there are wrong paths to the linker scripts in the Makefile |
| 306 | # -- these paths are relative to the Python source, but when installed |
| 307 | # the scripts are in another directory. |
Greg Ward | b231e1a | 2000-06-27 01:59:43 +0000 | [diff] [blame] | 308 | if sys.platform == 'aix4': # what about AIX 3.x ? |
Greg Ward | 4f88028 | 2000-06-27 01:59:06 +0000 | [diff] [blame] | 309 | # Linker script is in the config directory, not in Modules as the |
| 310 | # Makefile says. |
| 311 | python_lib = get_python_lib(standard_lib=1) |
| 312 | ld_so_aix = os.path.join(python_lib, 'config', 'ld_so_aix') |
| 313 | python_exp = os.path.join(python_lib, 'config', 'python.exp') |
| 314 | |
| 315 | g['LDSHARED'] = "%s %s -bI:%s" % (ld_so_aix, g['CC'], python_exp) |
Greg Ward | 9ddaaa1 | 1999-01-06 14:46:06 +0000 | [diff] [blame] | 316 | |
Greg Ward | 879f0f1 | 2000-09-15 01:15:08 +0000 | [diff] [blame] | 317 | elif sys.platform == 'beos': |
Greg Ward | 66e966f | 2000-09-01 01:23:26 +0000 | [diff] [blame] | 318 | |
| 319 | # Linker script is in the config directory. In the Makefile it is |
| 320 | # relative to the srcdir, which after installation no longer makes |
| 321 | # sense. |
| 322 | python_lib = get_python_lib(standard_lib=1) |
| 323 | linkerscript_name = os.path.basename(string.split(g['LDSHARED'])[0]) |
| 324 | linkerscript = os.path.join(python_lib, 'config', linkerscript_name) |
| 325 | |
| 326 | # XXX this isn't the right place to do this: adding the Python |
| 327 | # library to the link, if needed, should be in the "build_ext" |
| 328 | # command. (It's also needed for non-MS compilers on Windows, and |
| 329 | # it's taken care of for them by the 'build_ext.get_libraries()' |
| 330 | # method.) |
| 331 | g['LDSHARED'] = ("%s -L%s/lib -lpython%s" % |
Greg Ward | 879f0f1 | 2000-09-15 01:15:08 +0000 | [diff] [blame] | 332 | (linkerscript, PREFIX, sys.version[0:3])) |
| 333 | |
| 334 | global _config_vars |
| 335 | _config_vars = g |
Greg Ward | 66e966f | 2000-09-01 01:23:26 +0000 | [diff] [blame] | 336 | |
Greg Ward | 9ddaaa1 | 1999-01-06 14:46:06 +0000 | [diff] [blame] | 337 | |
Greg Ward | 4d74d73 | 1999-06-08 01:58:36 +0000 | [diff] [blame] | 338 | def _init_nt(): |
| 339 | """Initialize the module as appropriate for NT""" |
Greg Ward | 879f0f1 | 2000-09-15 01:15:08 +0000 | [diff] [blame] | 340 | g = {} |
Greg Ward | 4d74d73 | 1999-06-08 01:58:36 +0000 | [diff] [blame] | 341 | # set basic install directories |
Fred Drake | c1ee39a | 2000-03-09 15:54:52 +0000 | [diff] [blame] | 342 | g['LIBDEST'] = get_python_lib(plat_specific=0, standard_lib=1) |
| 343 | g['BINLIBDEST'] = get_python_lib(plat_specific=1, standard_lib=1) |
Greg Ward | 4d74d73 | 1999-06-08 01:58:36 +0000 | [diff] [blame] | 344 | |
Greg Ward | 32162e8 | 1999-08-29 18:22:13 +0000 | [diff] [blame] | 345 | # XXX hmmm.. a normal install puts include files here |
Fred Drake | c1ee39a | 2000-03-09 15:54:52 +0000 | [diff] [blame] | 346 | g['INCLUDEPY'] = get_python_inc(plat_specific=0) |
Greg Ward | 32162e8 | 1999-08-29 18:22:13 +0000 | [diff] [blame] | 347 | |
Fred Drake | 69e2c6e | 2000-02-08 15:55:42 +0000 | [diff] [blame] | 348 | g['SO'] = '.pyd' |
Greg Ward | 82d71ca | 2000-06-03 00:44:30 +0000 | [diff] [blame] | 349 | g['EXE'] = ".exe" |
Greg Ward | 879f0f1 | 2000-09-15 01:15:08 +0000 | [diff] [blame] | 350 | |
| 351 | global _config_vars |
| 352 | _config_vars = g |
Greg Ward | 82d71ca | 2000-06-03 00:44:30 +0000 | [diff] [blame] | 353 | |
Fred Drake | 69e2c6e | 2000-02-08 15:55:42 +0000 | [diff] [blame] | 354 | |
Greg Ward | 0eff87a | 2000-03-07 03:30:09 +0000 | [diff] [blame] | 355 | def _init_mac(): |
| 356 | """Initialize the module as appropriate for Macintosh systems""" |
Greg Ward | 879f0f1 | 2000-09-15 01:15:08 +0000 | [diff] [blame] | 357 | g = {} |
Greg Ward | 0eff87a | 2000-03-07 03:30:09 +0000 | [diff] [blame] | 358 | # set basic install directories |
Fred Drake | c1ee39a | 2000-03-09 15:54:52 +0000 | [diff] [blame] | 359 | g['LIBDEST'] = get_python_lib(plat_specific=0, standard_lib=1) |
| 360 | g['BINLIBDEST'] = get_python_lib(plat_specific=1, standard_lib=1) |
Greg Ward | 0eff87a | 2000-03-07 03:30:09 +0000 | [diff] [blame] | 361 | |
| 362 | # XXX hmmm.. a normal install puts include files here |
Fred Drake | c1ee39a | 2000-03-09 15:54:52 +0000 | [diff] [blame] | 363 | g['INCLUDEPY'] = get_python_inc(plat_specific=0) |
Greg Ward | 0eff87a | 2000-03-07 03:30:09 +0000 | [diff] [blame] | 364 | |
| 365 | g['SO'] = '.ppc.slb' |
Greg Ward | 7d73b9e | 2000-03-09 03:16:05 +0000 | [diff] [blame] | 366 | |
| 367 | # XXX are these used anywhere? |
Greg Ward | cf6bea3 | 2000-04-10 01:15:06 +0000 | [diff] [blame] | 368 | g['install_lib'] = os.path.join(EXEC_PREFIX, "Lib") |
| 369 | g['install_platlib'] = os.path.join(EXEC_PREFIX, "Mac", "Lib") |
Greg Ward | 0eff87a | 2000-03-07 03:30:09 +0000 | [diff] [blame] | 370 | |
Greg Ward | 879f0f1 | 2000-09-15 01:15:08 +0000 | [diff] [blame] | 371 | global _config_vars |
| 372 | _config_vars = g |
Greg Ward | 9ddaaa1 | 1999-01-06 14:46:06 +0000 | [diff] [blame] | 373 | |
Fred Drake | 69e2c6e | 2000-02-08 15:55:42 +0000 | [diff] [blame] | 374 | |
Greg Ward | 879f0f1 | 2000-09-15 01:15:08 +0000 | [diff] [blame] | 375 | def get_config_vars(*args): |
| 376 | """With no arguments, return a dictionary of all configuration |
| 377 | variables relevant for the current platform. Generally this includes |
| 378 | everything needed to build extensions and install both pure modules and |
| 379 | extensions. On Unix, this means every variable defined in Python's |
| 380 | installed Makefile; on Windows and Mac OS it's a much smaller set. |
| 381 | |
| 382 | With arguments, return a list of values that result from looking up |
| 383 | each argument in the configuration variable dictionary. |
| 384 | """ |
| 385 | global _config_vars |
| 386 | if _config_vars is None: |
Greg Ward | 879f0f1 | 2000-09-15 01:15:08 +0000 | [diff] [blame] | 387 | func = globals().get("_init_" + os.name) |
| 388 | if func: |
| 389 | func() |
| 390 | else: |
| 391 | _config_vars = {} |
| 392 | |
| 393 | # Normalized versions of prefix and exec_prefix are handy to have; |
| 394 | # in fact, these are the standard versions used most places in the |
| 395 | # Distutils. |
| 396 | _config_vars['prefix'] = PREFIX |
| 397 | _config_vars['exec_prefix'] = EXEC_PREFIX |
| 398 | |
| 399 | if args: |
| 400 | vals = [] |
| 401 | for name in args: |
| 402 | vals.append(_config_vars.get(name)) |
| 403 | return vals |
| 404 | else: |
| 405 | return _config_vars |
| 406 | |
| 407 | def get_config_var(name): |
| 408 | """Return the value of a single variable using the dictionary |
| 409 | returned by 'get_config_vars()'. Equivalent to |
| 410 | get_config_vars().get(name) |
| 411 | """ |
| 412 | return get_config_vars().get(name) |