| 
									
										
										
										
											1998-12-18 23:46:33 +00:00
										 |  |  | """Prototype sysconfig module that loads information when run as a script,
 | 
					
						
							|  |  |  | but only defines constants when imported. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | This should be run as a script as one of the last steps of the Python | 
					
						
							|  |  |  | installation process. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Written by:   Fred L. Drake, Jr. | 
					
						
							|  |  |  | Email:        <fdrake@acm.org> | 
					
						
							|  |  |  | Initial date: 17-Dec-1998 | 
					
						
							|  |  |  | """
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | __version__ = "$Revision$" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1999-01-06 14:46:06 +00:00
										 |  |  | import os | 
					
						
							|  |  |  | import re | 
					
						
							|  |  |  | import string | 
					
						
							|  |  |  | import sys | 
					
						
							| 
									
										
										
										
											1998-12-18 23:46:33 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1999-01-06 14:46:06 +00:00
										 |  |  | def get_config_h_filename(): | 
					
						
							|  |  |  |     return os.path.join(sys.exec_prefix, "lib", "python" + sys.version[:3], | 
					
						
							|  |  |  |                         "config", "config.h") | 
					
						
							| 
									
										
										
										
											1998-12-18 23:46:33 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1999-01-06 14:46:06 +00:00
										 |  |  | def get_makefile_filename(): | 
					
						
							|  |  |  |     return os.path.join(sys.exec_prefix, "lib", "python" + sys.version[:3], | 
					
						
							|  |  |  |                         "config", "Makefile") | 
					
						
							| 
									
										
										
										
											1998-12-18 23:46:33 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1999-01-06 14:46:06 +00:00
										 |  |  | def parse_config_h(fp, g=None): | 
					
						
							|  |  |  |     if g is None: | 
					
						
							|  |  |  |         g = {} | 
					
						
							| 
									
										
										
										
											1998-12-18 23:46:33 +00:00
										 |  |  |     define_rx = re.compile("#define ([A-Z][A-Z0-9_]+) (.*)\n") | 
					
						
							|  |  |  |     undef_rx = re.compile("/[*] #undef ([A-Z][A-Z0-9_]+) [*]/\n") | 
					
						
							| 
									
										
										
										
											1999-01-06 14:46:06 +00:00
										 |  |  |     # | 
					
						
							| 
									
										
										
										
											1998-12-18 23:46:33 +00:00
										 |  |  |     while 1: | 
					
						
							|  |  |  |         line = fp.readline() | 
					
						
							|  |  |  |         if not line: | 
					
						
							|  |  |  |             break | 
					
						
							|  |  |  |         m = define_rx.match(line) | 
					
						
							|  |  |  |         if m: | 
					
						
							|  |  |  |             n, v = m.group(1, 2) | 
					
						
							| 
									
										
										
										
											1998-12-22 12:42:04 +00:00
										 |  |  |             try: v = string.atoi(v) | 
					
						
							|  |  |  |             except ValueError: pass | 
					
						
							|  |  |  |             g[n] = v | 
					
						
							| 
									
										
										
										
											1998-12-18 23:46:33 +00:00
										 |  |  |         else: | 
					
						
							|  |  |  |             m = undef_rx.match(line) | 
					
						
							|  |  |  |             if m: | 
					
						
							|  |  |  |                 g[m.group(1)] = 0 | 
					
						
							| 
									
										
										
										
											1999-01-06 14:46:06 +00:00
										 |  |  |     return g | 
					
						
							| 
									
										
										
										
											1998-12-18 23:46:33 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1999-01-06 14:46:06 +00:00
										 |  |  | def parse_makefile(fp, g=None): | 
					
						
							|  |  |  |     if g is None: | 
					
						
							|  |  |  |         g = {} | 
					
						
							| 
									
										
										
										
											1998-12-18 23:46:33 +00:00
										 |  |  |     variable_rx = re.compile("([a-zA-Z][a-zA-Z0-9_]+)\s*=\s*(.*)\n") | 
					
						
							|  |  |  |     done = {} | 
					
						
							|  |  |  |     notdone = {} | 
					
						
							| 
									
										
										
										
											1999-01-06 14:46:06 +00:00
										 |  |  |     # | 
					
						
							| 
									
										
										
										
											1998-12-18 23:46:33 +00:00
										 |  |  |     while 1: | 
					
						
							|  |  |  |         line = fp.readline() | 
					
						
							|  |  |  |         if not line: | 
					
						
							|  |  |  |             break | 
					
						
							|  |  |  |         m = variable_rx.match(line) | 
					
						
							|  |  |  |         if m: | 
					
						
							|  |  |  |             n, v = m.group(1, 2) | 
					
						
							| 
									
										
										
										
											1998-12-22 12:42:04 +00:00
										 |  |  |             v = string.strip(v) | 
					
						
							| 
									
										
										
										
											1998-12-18 23:46:33 +00:00
										 |  |  |             if "$" in v: | 
					
						
							|  |  |  |                 notdone[n] = v | 
					
						
							|  |  |  |             else: | 
					
						
							| 
									
										
										
										
											1998-12-22 12:42:04 +00:00
										 |  |  |                 try: v = string.atoi(v) | 
					
						
							|  |  |  |                 except ValueError: pass | 
					
						
							| 
									
										
										
										
											1998-12-18 23:46:33 +00:00
										 |  |  |                 done[n] = v | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # do variable interpolation here | 
					
						
							|  |  |  |     findvar1_rx = re.compile(r"\$\(([A-Za-z][A-Za-z0-9_]*)\)") | 
					
						
							|  |  |  |     findvar2_rx = re.compile(r"\${([A-Za-z][A-Za-z0-9_]*)}") | 
					
						
							|  |  |  |     while notdone: | 
					
						
							|  |  |  |         for name in notdone.keys(): | 
					
						
							|  |  |  |             value = notdone[name] | 
					
						
							|  |  |  |             m = findvar1_rx.search(value) | 
					
						
							|  |  |  |             if not m: | 
					
						
							|  |  |  |                 m = findvar2_rx.search(value) | 
					
						
							|  |  |  |             if m: | 
					
						
							|  |  |  |                 n = m.group(1) | 
					
						
							|  |  |  |                 if done.has_key(n): | 
					
						
							|  |  |  |                     after = value[m.end():] | 
					
						
							|  |  |  |                     value = value[:m.start()] + done[n] + after | 
					
						
							|  |  |  |                     if "$" in after: | 
					
						
							|  |  |  |                         notdone[name] = value | 
					
						
							|  |  |  |                     else: | 
					
						
							| 
									
										
										
										
											1998-12-22 12:42:04 +00:00
										 |  |  |                         try: value = string.atoi(value) | 
					
						
							|  |  |  |                         except ValueError: pass | 
					
						
							|  |  |  |                         done[name] = string.strip(value) | 
					
						
							| 
									
										
										
										
											1998-12-18 23:46:33 +00:00
										 |  |  |                         del notdone[name] | 
					
						
							|  |  |  |                 elif notdone.has_key(n): | 
					
						
							|  |  |  |                     # get it on a subsequent round | 
					
						
							|  |  |  |                     pass | 
					
						
							|  |  |  |                 else: | 
					
						
							|  |  |  |                     done[n] = "" | 
					
						
							|  |  |  |                     after = value[m.end():] | 
					
						
							|  |  |  |                     value = value[:m.start()] + after | 
					
						
							|  |  |  |                     if "$" in after: | 
					
						
							|  |  |  |                         notdone[name] = value | 
					
						
							|  |  |  |                     else: | 
					
						
							| 
									
										
										
										
											1998-12-22 12:42:04 +00:00
										 |  |  |                         try: value = string.atoi(value) | 
					
						
							|  |  |  |                         except ValueError: pass | 
					
						
							|  |  |  |                         done[name] = string.strip(value) | 
					
						
							| 
									
										
										
										
											1998-12-18 23:46:33 +00:00
										 |  |  |                         del notdone[name] | 
					
						
							|  |  |  |             else: | 
					
						
							| 
									
										
										
										
											1998-12-22 12:42:04 +00:00
										 |  |  |                 # bogus variable reference; just drop it since we can't deal | 
					
						
							| 
									
										
										
										
											1998-12-18 23:46:33 +00:00
										 |  |  |                 del notdone[name] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # save the results in the global dictionary | 
					
						
							|  |  |  |     g.update(done) | 
					
						
							| 
									
										
										
										
											1999-01-06 14:46:06 +00:00
										 |  |  |     return g | 
					
						
							| 
									
										
										
										
											1998-12-18 23:46:33 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1999-01-06 14:46:06 +00:00
										 |  |  | def _init_posix(): | 
					
						
							|  |  |  |     g = globals() | 
					
						
							|  |  |  |     # load the installed config.h: | 
					
						
							|  |  |  |     parse_config_h(open(get_config_h_filename()), g) | 
					
						
							|  |  |  |     # load the installed Makefile.pre.in: | 
					
						
							|  |  |  |     parse_makefile(open(get_makefile_filename()), g) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | try: | 
					
						
							|  |  |  |     exec "_init_" + os.name | 
					
						
							|  |  |  | except NameError: | 
					
						
							|  |  |  |     # not needed for this platform | 
					
						
							|  |  |  |     pass | 
					
						
							|  |  |  | else: | 
					
						
							|  |  |  |     exec "_init_%s()" % os.name | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1998-12-18 23:46:33 +00:00
										 |  |  | del _init_posix |