| 
									
										
										
										
											1996-11-27 19:52:01 +00:00
										 |  |  | #! /usr/bin/env python | 
					
						
							| 
									
										
										
										
											1994-10-03 10:25:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-08-26 05:14:20 +00:00
										 |  |  | """Freeze a Python script into a binary.
 | 
					
						
							| 
									
										
										
										
											1994-10-03 16:33:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1998-03-05 04:05:38 +00:00
										 |  |  | usage: freeze [options...] script [module]... | 
					
						
							| 
									
										
										
										
											1994-10-03 16:33:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-08-26 05:14:20 +00:00
										 |  |  | Options: | 
					
						
							| 
									
										
										
										
											1994-10-03 16:33:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-08-10 16:47:17 +00:00
										 |  |  | -p prefix:    This is the prefix used when you ran ``make install'' | 
					
						
							| 
									
										
										
										
											1996-08-26 05:14:20 +00:00
										 |  |  |               in the Python build directory. | 
					
						
							| 
									
										
										
										
											1994-10-05 16:13:01 +00:00
										 |  |  |               (If you never ran this, freeze won't work.) | 
					
						
							| 
									
										
										
										
											1996-08-26 05:14:20 +00:00
										 |  |  |               The default is whatever sys.prefix evaluates to. | 
					
						
							| 
									
										
										
										
											1997-08-10 16:56:48 +00:00
										 |  |  |               It can also be the top directory of the Python source | 
					
						
							|  |  |  |               tree; then -P must point to the build tree. | 
					
						
							| 
									
										
										
										
											1994-10-03 16:33:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1995-08-08 14:21:07 +00:00
										 |  |  | -P exec_prefix: Like -p but this is the 'exec_prefix', used to | 
					
						
							| 
									
										
										
										
											1997-08-10 16:56:48 +00:00
										 |  |  |                 install objects etc.  The default is whatever sys.exec_prefix | 
					
						
							|  |  |  |                 evaluates to, or the -p argument if given. | 
					
						
							|  |  |  |                 If -p points to the Python source tree, -P must point | 
					
						
							|  |  |  |                 to the build tree, if different. | 
					
						
							| 
									
										
										
										
											1995-08-08 14:21:07 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1994-10-05 16:13:01 +00:00
										 |  |  | -e extension: A directory containing additional .o files that | 
					
						
							|  |  |  |               may be used to resolve modules.  This directory | 
					
						
							|  |  |  |               should also have a Setup file describing the .o files. | 
					
						
							|  |  |  |               More than one -e option may be given. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-08-26 05:14:20 +00:00
										 |  |  | -o dir:       Directory where the output files are created; default '.'. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1998-03-05 03:42:00 +00:00
										 |  |  | -m:           Additional arguments are module names instead of filenames. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | -d:           Debugging mode for the module finder. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | -q:           Make the module finder totally quiet. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-08-10 16:47:17 +00:00
										 |  |  | -h:           Print this help message. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-08-14 01:45:33 +00:00
										 |  |  | -w:           Toggle Windows (NT or 95) behavior. | 
					
						
							|  |  |  |               (For debugging only -- on a win32 platform, win32 behaviour | 
					
						
							|  |  |  |               is automatic.) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | -s subsystem: Specify the subsystem; 'windows' or 'console' (default). | 
					
						
							|  |  |  |               (For Windows only.) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-08-26 05:14:20 +00:00
										 |  |  | Arguments: | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1998-03-05 04:05:38 +00:00
										 |  |  | script:       The Python script to be executed by the resulting binary. | 
					
						
							| 
									
										
										
										
											1994-10-05 16:13:01 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | module ...:   Additional Python modules (referenced by pathname) | 
					
						
							|  |  |  |               that will be included in the resulting binary.  These | 
					
						
							| 
									
										
										
										
											1998-03-05 03:42:00 +00:00
										 |  |  |               may be .py or .pyc files.  If -m is specified, these are | 
					
						
							|  |  |  |               module names that are search in the path instead. | 
					
						
							| 
									
										
										
										
											1995-08-08 14:21:07 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | NOTES: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | In order to use freeze successfully, you must have built Python and | 
					
						
							| 
									
										
										
										
											1996-06-17 17:49:13 +00:00
										 |  |  | installed it ("make install"). | 
					
						
							| 
									
										
										
										
											1995-08-08 14:21:07 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-08-26 05:14:20 +00:00
										 |  |  | The script should not use modules provided only as shared libraries; | 
					
						
							|  |  |  | if it does, the resulting binary is not self-contained. | 
					
						
							| 
									
										
										
										
											1994-10-05 16:13:01 +00:00
										 |  |  | """
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1994-10-03 16:33:08 +00:00
										 |  |  | # Import standard modules | 
					
						
							| 
									
										
										
										
											1994-10-03 10:25:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1994-10-05 16:13:01 +00:00
										 |  |  | import cmp | 
					
						
							| 
									
										
										
										
											1994-10-03 10:25:54 +00:00
										 |  |  | import getopt | 
					
						
							| 
									
										
										
										
											1994-10-03 16:33:08 +00:00
										 |  |  | import os | 
					
						
							| 
									
										
										
										
											1994-10-03 10:25:54 +00:00
										 |  |  | import string | 
					
						
							| 
									
										
										
										
											1994-10-03 16:33:08 +00:00
										 |  |  | import sys | 
					
						
							|  |  |  | import addpack | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # Import the freeze-private modules | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1994-10-05 16:13:01 +00:00
										 |  |  | import checkextensions | 
					
						
							| 
									
										
										
										
											1998-03-05 03:42:00 +00:00
										 |  |  | import modulefinder | 
					
						
							| 
									
										
										
										
											1994-10-03 16:33:08 +00:00
										 |  |  | import makeconfig | 
					
						
							|  |  |  | import makefreeze | 
					
						
							|  |  |  | import makemakefile | 
					
						
							|  |  |  | import parsesetup | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # Main program | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1994-10-03 10:25:54 +00:00
										 |  |  | def main(): | 
					
						
							| 
									
										
										
										
											1997-08-10 16:56:48 +00:00
										 |  |  |     # overridable context | 
					
						
							|  |  |  |     prefix = None                       # settable with -p option | 
					
						
							|  |  |  |     exec_prefix = None                  # settable with -P option | 
					
						
							|  |  |  |     extensions = [] | 
					
						
							| 
									
										
										
										
											1998-03-05 04:05:38 +00:00
										 |  |  |     path = sys.path[:] | 
					
						
							| 
									
										
										
										
											1998-03-05 03:42:00 +00:00
										 |  |  |     modargs = 0 | 
					
						
							|  |  |  |     debug = 1 | 
					
						
							| 
									
										
										
										
											1997-08-10 16:56:48 +00:00
										 |  |  |     odir = '' | 
					
						
							| 
									
										
										
										
											1997-08-14 01:45:33 +00:00
										 |  |  |     win = sys.platform[:3] == 'win' | 
					
						
							| 
									
										
										
										
											1997-08-10 16:56:48 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-12-08 05:01:06 +00:00
										 |  |  |     # modules that are imported by the Python runtime | 
					
						
							|  |  |  |     implicits = ["site", "exceptions"] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-08-10 16:56:48 +00:00
										 |  |  |     # output files | 
					
						
							|  |  |  |     frozen_c = 'frozen.c' | 
					
						
							|  |  |  |     config_c = 'config.c' | 
					
						
							|  |  |  |     target = 'a.out'                    # normally derived from script name | 
					
						
							|  |  |  |     makefile = 'Makefile' | 
					
						
							| 
									
										
										
										
											1997-08-14 01:45:33 +00:00
										 |  |  |     subsystem = 'console' | 
					
						
							| 
									
										
										
										
											1997-08-10 16:56:48 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     # parse command line | 
					
						
							|  |  |  |     try: | 
					
						
							| 
									
										
										
										
											1998-03-05 03:42:00 +00:00
										 |  |  |         opts, args = getopt.getopt(sys.argv[1:], 'deh:mo:p:P:qs:w') | 
					
						
							| 
									
										
										
										
											1997-08-10 16:56:48 +00:00
										 |  |  |     except getopt.error, msg: | 
					
						
							|  |  |  |         usage('getopt error: ' + str(msg)) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # proces option arguments | 
					
						
							|  |  |  |     for o, a in opts: | 
					
						
							|  |  |  |         if o == '-h': | 
					
						
							|  |  |  |             print __doc__ | 
					
						
							|  |  |  |             return | 
					
						
							| 
									
										
										
										
											1998-03-05 03:42:00 +00:00
										 |  |  |         if o == '-d': | 
					
						
							|  |  |  |             debug = debug + 1 | 
					
						
							| 
									
										
										
										
											1997-08-10 16:56:48 +00:00
										 |  |  |         if o == '-e': | 
					
						
							|  |  |  |             extensions.append(a) | 
					
						
							| 
									
										
										
										
											1998-03-05 03:42:00 +00:00
										 |  |  |         if o == '-m': | 
					
						
							|  |  |  |             modargs = 1 | 
					
						
							| 
									
										
										
										
											1997-08-10 16:56:48 +00:00
										 |  |  |         if o == '-o': | 
					
						
							|  |  |  |             odir = a | 
					
						
							|  |  |  |         if o == '-p': | 
					
						
							|  |  |  |             prefix = a | 
					
						
							|  |  |  |         if o == '-P': | 
					
						
							|  |  |  |             exec_prefix = a | 
					
						
							| 
									
										
										
										
											1998-03-05 03:42:00 +00:00
										 |  |  |         if o == '-q': | 
					
						
							|  |  |  |             debug = 0 | 
					
						
							| 
									
										
										
										
											1997-08-14 01:45:33 +00:00
										 |  |  |         if o == '-w': | 
					
						
							|  |  |  |             win = not win | 
					
						
							|  |  |  |         if o == '-s': | 
					
						
							|  |  |  |             if not win: | 
					
						
							|  |  |  |                 usage("-s subsystem option only on Windows") | 
					
						
							|  |  |  |             subsystem = a | 
					
						
							| 
									
										
										
										
											1997-08-10 16:56:48 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     # default prefix and exec_prefix | 
					
						
							|  |  |  |     if not exec_prefix: | 
					
						
							|  |  |  |         if prefix: | 
					
						
							|  |  |  |             exec_prefix = prefix | 
					
						
							|  |  |  |         else: | 
					
						
							|  |  |  |             exec_prefix = sys.exec_prefix | 
					
						
							|  |  |  |     if not prefix: | 
					
						
							|  |  |  |         prefix = sys.prefix | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # determine whether -p points to the Python source tree | 
					
						
							|  |  |  |     ishome = os.path.exists(os.path.join(prefix, 'Include', 'pythonrun.h')) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # locations derived from options | 
					
						
							|  |  |  |     version = sys.version[:3] | 
					
						
							|  |  |  |     if ishome: | 
					
						
							|  |  |  |         print "(Using Python source directory)" | 
					
						
							|  |  |  |         binlib = exec_prefix | 
					
						
							|  |  |  |         incldir = os.path.join(prefix, 'Include') | 
					
						
							|  |  |  |         config_c_in = os.path.join(prefix, 'Modules', 'config.c.in') | 
					
						
							| 
									
										
										
										
											1997-08-14 01:45:33 +00:00
										 |  |  |         frozenmain_c = os.path.join(prefix, 'Python', 'frozenmain.c') | 
					
						
							| 
									
										
										
										
											1997-08-10 16:56:48 +00:00
										 |  |  |         makefile_in = os.path.join(exec_prefix, 'Modules', 'Makefile') | 
					
						
							|  |  |  |     else: | 
					
						
							|  |  |  |         binlib = os.path.join(exec_prefix, | 
					
						
							|  |  |  |                               'lib', 'python%s' % version, 'config') | 
					
						
							|  |  |  |         incldir = os.path.join(prefix, 'include', 'python%s' % version) | 
					
						
							|  |  |  |         config_c_in = os.path.join(binlib, 'config.c.in') | 
					
						
							|  |  |  |         frozenmain_c = os.path.join(binlib, 'frozenmain.c') | 
					
						
							|  |  |  |         makefile_in = os.path.join(binlib, 'Makefile') | 
					
						
							|  |  |  |     supp_sources = [] | 
					
						
							|  |  |  |     defines = [] | 
					
						
							|  |  |  |     includes = ['-I' + incldir, '-I' + binlib] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # sanity check of directories and files | 
					
						
							|  |  |  |     for dir in [prefix, exec_prefix, binlib, incldir] + extensions: | 
					
						
							|  |  |  |         if not os.path.exists(dir): | 
					
						
							|  |  |  |             usage('needed directory %s not found' % dir) | 
					
						
							|  |  |  |         if not os.path.isdir(dir): | 
					
						
							|  |  |  |             usage('%s: not a directory' % dir) | 
					
						
							| 
									
										
										
										
											1997-08-14 01:45:33 +00:00
										 |  |  |     if win: | 
					
						
							|  |  |  |         files = supp_sources | 
					
						
							|  |  |  |     else: | 
					
						
							|  |  |  |         files = [config_c_in, makefile_in] + supp_sources | 
					
						
							|  |  |  |     for file in supp_sources: | 
					
						
							| 
									
										
										
										
											1997-08-10 16:56:48 +00:00
										 |  |  |         if not os.path.exists(file): | 
					
						
							|  |  |  |             usage('needed file %s not found' % file) | 
					
						
							|  |  |  |         if not os.path.isfile(file): | 
					
						
							|  |  |  |             usage('%s: not a plain file' % file) | 
					
						
							| 
									
										
										
										
											1997-08-14 01:45:33 +00:00
										 |  |  |     if not win: | 
					
						
							|  |  |  |         for dir in extensions: | 
					
						
							|  |  |  |             setup = os.path.join(dir, 'Setup') | 
					
						
							|  |  |  |             if not os.path.exists(setup): | 
					
						
							|  |  |  |                 usage('needed file %s not found' % setup) | 
					
						
							|  |  |  |             if not os.path.isfile(setup): | 
					
						
							|  |  |  |                 usage('%s: not a plain file' % setup) | 
					
						
							| 
									
										
										
										
											1997-08-10 16:56:48 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     # check that enough arguments are passed | 
					
						
							|  |  |  |     if not args: | 
					
						
							|  |  |  |         usage('at least one filename argument required') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # check that file arguments exist | 
					
						
							|  |  |  |     for arg in args: | 
					
						
							| 
									
										
										
										
											1998-03-05 04:05:38 +00:00
										 |  |  |         if arg == '-m': | 
					
						
							|  |  |  |             break | 
					
						
							| 
									
										
										
										
											1997-08-10 16:56:48 +00:00
										 |  |  |         if not os.path.exists(arg): | 
					
						
							|  |  |  |             usage('argument %s not found' % arg) | 
					
						
							|  |  |  |         if not os.path.isfile(arg): | 
					
						
							|  |  |  |             usage('%s: not a plain file' % arg) | 
					
						
							| 
									
										
										
										
											1998-03-05 04:05:38 +00:00
										 |  |  |         if modargs: | 
					
						
							|  |  |  |             break | 
					
						
							| 
									
										
										
										
											1997-08-10 16:56:48 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     # process non-option arguments | 
					
						
							|  |  |  |     scriptfile = args[0] | 
					
						
							|  |  |  |     modules = args[1:] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # derive target name from script name | 
					
						
							|  |  |  |     base = os.path.basename(scriptfile) | 
					
						
							|  |  |  |     base, ext = os.path.splitext(base) | 
					
						
							|  |  |  |     if base: | 
					
						
							|  |  |  |         if base != scriptfile: | 
					
						
							|  |  |  |             target = base | 
					
						
							|  |  |  |         else: | 
					
						
							|  |  |  |             target = base + '.bin' | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # handle -o option | 
					
						
							|  |  |  |     base_frozen_c = frozen_c | 
					
						
							|  |  |  |     base_config_c = config_c | 
					
						
							|  |  |  |     base_target = target | 
					
						
							|  |  |  |     if odir and not os.path.isdir(odir): | 
					
						
							|  |  |  |         try: | 
					
						
							|  |  |  |             os.mkdir(odir) | 
					
						
							|  |  |  |             print "Created output directory", odir | 
					
						
							|  |  |  |         except os.error, msg: | 
					
						
							|  |  |  |             usage('%s: mkdir failed (%s)' % (odir, str(msg))) | 
					
						
							|  |  |  |     if odir: | 
					
						
							|  |  |  |         frozen_c = os.path.join(odir, frozen_c) | 
					
						
							|  |  |  |         config_c = os.path.join(odir, config_c) | 
					
						
							|  |  |  |         target = os.path.join(odir, target) | 
					
						
							|  |  |  |         makefile = os.path.join(odir, makefile) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Actual work starts here... | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1998-03-05 03:42:00 +00:00
										 |  |  |     # collect all modules of the program | 
					
						
							| 
									
										
										
										
											1998-03-05 04:05:38 +00:00
										 |  |  |     dir = os.path.dirname(scriptfile) | 
					
						
							|  |  |  |     path[0] = dir | 
					
						
							| 
									
										
										
										
											1998-03-05 03:42:00 +00:00
										 |  |  |     mf = modulefinder.ModuleFinder(path, debug) | 
					
						
							|  |  |  |     for mod in implicits: | 
					
						
							|  |  |  |         mf.import_hook(mod) | 
					
						
							|  |  |  |     for mod in modules: | 
					
						
							|  |  |  |         if mod == '-m': | 
					
						
							|  |  |  |             modargs = 1 | 
					
						
							|  |  |  |             continue | 
					
						
							|  |  |  |         if modargs: | 
					
						
							|  |  |  |             if mod[-2:] == '.*': | 
					
						
							|  |  |  |                 mf.import_hook(mod[:-2], None, ["*"]) | 
					
						
							|  |  |  |             else: | 
					
						
							|  |  |  |                 mf.import_hook(mod) | 
					
						
							|  |  |  |         else: | 
					
						
							|  |  |  |             mf.load_file(mod) | 
					
						
							|  |  |  |     mf.run_script(scriptfile) | 
					
						
							|  |  |  |     if debug > 0: | 
					
						
							|  |  |  |         mf.report() | 
					
						
							|  |  |  |         print | 
					
						
							|  |  |  |     dict = mf.modules | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # generate output for frozen modules | 
					
						
							| 
									
										
										
										
											1997-08-10 16:56:48 +00:00
										 |  |  |     backup = frozen_c + '~' | 
					
						
							|  |  |  |     try: | 
					
						
							|  |  |  |         os.rename(frozen_c, backup) | 
					
						
							|  |  |  |     except os.error: | 
					
						
							|  |  |  |         backup = None | 
					
						
							|  |  |  |     outfp = open(frozen_c, 'w') | 
					
						
							|  |  |  |     try: | 
					
						
							| 
									
										
										
										
											1998-03-05 03:42:00 +00:00
										 |  |  |         makefreeze.makefreeze(outfp, dict, debug) | 
					
						
							| 
									
										
										
										
											1998-03-04 18:12:39 +00:00
										 |  |  |         if win and subsystem == 'windows': | 
					
						
							|  |  |  |             import winmakemakefile | 
					
						
							|  |  |  |             outfp.write(winmakemakefile.WINMAINTEMPLATE) | 
					
						
							| 
									
										
										
										
											1997-08-10 16:56:48 +00:00
										 |  |  |     finally: | 
					
						
							|  |  |  |         outfp.close() | 
					
						
							|  |  |  |     if backup: | 
					
						
							|  |  |  |         if cmp.cmp(backup, frozen_c): | 
					
						
							|  |  |  |             sys.stderr.write('%s not changed, not written\n' % | 
					
						
							|  |  |  |                              frozen_c) | 
					
						
							|  |  |  |             os.rename(backup, frozen_c) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1998-03-05 03:42:00 +00:00
										 |  |  |     # windows gets different treatment | 
					
						
							| 
									
										
										
										
											1997-08-14 01:45:33 +00:00
										 |  |  |     if win: | 
					
						
							|  |  |  |         # Taking a shortcut here... | 
					
						
							|  |  |  |         import winmakemakefile | 
					
						
							|  |  |  |         outfp = open(makefile, 'w') | 
					
						
							|  |  |  |         try: | 
					
						
							|  |  |  |             winmakemakefile.makemakefile(outfp, | 
					
						
							|  |  |  |                                          locals(), | 
					
						
							|  |  |  |                                          [frozenmain_c, frozen_c], | 
					
						
							|  |  |  |                                          target) | 
					
						
							|  |  |  |         finally: | 
					
						
							|  |  |  |             outfp.close() | 
					
						
							|  |  |  |         return | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1998-03-05 03:42:00 +00:00
										 |  |  |     # generate config.c and Makefile | 
					
						
							| 
									
										
										
										
											1997-08-10 16:56:48 +00:00
										 |  |  |     builtins = [] | 
					
						
							|  |  |  |     unknown = [] | 
					
						
							|  |  |  |     mods = dict.keys() | 
					
						
							|  |  |  |     mods.sort() | 
					
						
							|  |  |  |     for mod in mods: | 
					
						
							| 
									
										
										
										
											1998-03-05 03:42:00 +00:00
										 |  |  |         if dict[mod].__code__: | 
					
						
							|  |  |  |             continue | 
					
						
							|  |  |  |         if not dict[mod].__file__: | 
					
						
							| 
									
										
										
										
											1997-08-10 16:56:48 +00:00
										 |  |  |             builtins.append(mod) | 
					
						
							| 
									
										
										
										
											1998-03-05 03:42:00 +00:00
										 |  |  |         else: | 
					
						
							| 
									
										
										
										
											1997-08-10 16:56:48 +00:00
										 |  |  |             unknown.append(mod) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     addfiles = [] | 
					
						
							|  |  |  |     if unknown: | 
					
						
							|  |  |  |         addfiles, addmods = \ | 
					
						
							|  |  |  |                   checkextensions.checkextensions(unknown, extensions) | 
					
						
							|  |  |  |         for mod in addmods: | 
					
						
							|  |  |  |             unknown.remove(mod) | 
					
						
							|  |  |  |         builtins = builtins + addmods | 
					
						
							|  |  |  |     if unknown: | 
					
						
							|  |  |  |         sys.stderr.write('Warning: unknown modules remain: %s\n' % | 
					
						
							|  |  |  |                          string.join(unknown)) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     builtins.sort() | 
					
						
							|  |  |  |     infp = open(config_c_in) | 
					
						
							|  |  |  |     backup = config_c + '~' | 
					
						
							|  |  |  |     try: | 
					
						
							|  |  |  |         os.rename(config_c, backup) | 
					
						
							|  |  |  |     except os.error: | 
					
						
							|  |  |  |         backup = None | 
					
						
							|  |  |  |     outfp = open(config_c, 'w') | 
					
						
							|  |  |  |     try: | 
					
						
							|  |  |  |         makeconfig.makeconfig(infp, outfp, builtins) | 
					
						
							|  |  |  |     finally: | 
					
						
							|  |  |  |         outfp.close() | 
					
						
							|  |  |  |     infp.close() | 
					
						
							|  |  |  |     if backup: | 
					
						
							|  |  |  |         if cmp.cmp(backup, config_c): | 
					
						
							|  |  |  |             sys.stderr.write('%s not changed, not written\n' % | 
					
						
							|  |  |  |                              config_c) | 
					
						
							|  |  |  |             os.rename(backup, config_c) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     cflags = defines + includes + ['$(OPT)'] | 
					
						
							|  |  |  |     libs = [os.path.join(binlib, 'libpython$(VERSION).a')] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     somevars = {} | 
					
						
							| 
									
										
										
										
											1997-11-22 22:10:01 +00:00
										 |  |  |     if os.path.exists(makefile_in): | 
					
						
							|  |  |  |         makevars = parsesetup.getmakevars(makefile_in) | 
					
						
							| 
									
										
										
										
											1997-08-10 16:56:48 +00:00
										 |  |  |     for key in makevars.keys(): | 
					
						
							|  |  |  |         somevars[key] = makevars[key] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     somevars['CFLAGS'] = string.join(cflags) # override | 
					
						
							|  |  |  |     files = ['$(OPT)', '$(LDFLAGS)', base_config_c, base_frozen_c] + \ | 
					
						
							|  |  |  |             supp_sources +  addfiles + libs + \ | 
					
						
							|  |  |  |             ['$(MODLIBS)', '$(LIBS)', '$(SYSLIBS)'] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     backup = makefile + '~' | 
					
						
							|  |  |  |     try: | 
					
						
							|  |  |  |         os.rename(makefile, backup) | 
					
						
							|  |  |  |     except os.error: | 
					
						
							|  |  |  |         backup = None | 
					
						
							|  |  |  |     outfp = open(makefile, 'w') | 
					
						
							|  |  |  |     try: | 
					
						
							|  |  |  |         makemakefile.makemakefile(outfp, somevars, files, base_target) | 
					
						
							|  |  |  |     finally: | 
					
						
							|  |  |  |         outfp.close() | 
					
						
							|  |  |  |     if backup: | 
					
						
							|  |  |  |         if not cmp.cmp(backup, makefile): | 
					
						
							|  |  |  |             print 'previous Makefile saved as', backup | 
					
						
							|  |  |  |         else: | 
					
						
							|  |  |  |             sys.stderr.write('%s not changed, not written\n' % | 
					
						
							|  |  |  |                              makefile) | 
					
						
							|  |  |  |             os.rename(backup, makefile) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Done! | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if odir: | 
					
						
							|  |  |  |         print 'Now run "make" in', odir, | 
					
						
							|  |  |  |         print 'to build the target:', base_target | 
					
						
							|  |  |  |     else: | 
					
						
							|  |  |  |         print 'Now run "make" to build the target:', base_target | 
					
						
							| 
									
										
										
										
											1994-10-03 16:33:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1994-10-05 16:13:01 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | # Print usage message and exit | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-08-10 16:47:17 +00:00
										 |  |  | def usage(msg): | 
					
						
							| 
									
										
										
										
											1997-08-10 16:56:48 +00:00
										 |  |  |     sys.stdout = sys.stderr | 
					
						
							|  |  |  |     print "Error:", msg | 
					
						
							|  |  |  |     print "Use ``%s -h'' for help" % sys.argv[0] | 
					
						
							|  |  |  |     sys.exit(2) | 
					
						
							| 
									
										
										
										
											1994-10-05 16:13:01 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1994-10-03 10:25:54 +00:00
										 |  |  | main() | 
					
						
							| 
									
										
										
										
											1997-08-10 16:56:48 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | # Local Variables: | 
					
						
							|  |  |  | # indent-tabs-mode: nil | 
					
						
							|  |  |  | # End: |