blob: dfd0369627d8825520905e16c5a4a27db85aeb4b [file] [log] [blame]
Guido van Rossumf06ee5f1996-11-27 19:52:01 +00001#! /usr/bin/env python
Guido van Rossumdbaf3321994-10-03 10:25:54 +00002
Guido van Rossum96c4dd91996-08-26 05:14:20 +00003"""Freeze a Python script into a binary.
Guido van Rossumdbaf3321994-10-03 10:25:54 +00004
Guido van Rossum1e074031998-03-05 04:05:38 +00005usage: freeze [options...] script [module]...
Guido van Rossum00ff4331994-10-03 16:33:08 +00006
Guido van Rossum96c4dd91996-08-26 05:14:20 +00007Options:
Guido van Rossum9a6e8551997-08-10 16:47:17 +00008-p prefix: This is the prefix used when you ran ``make install''
Guido van Rossum96c4dd91996-08-26 05:14:20 +00009 in the Python build directory.
Guido van Rossumd8336c21994-10-05 16:13:01 +000010 (If you never ran this, freeze won't work.)
Guido van Rossum96c4dd91996-08-26 05:14:20 +000011 The default is whatever sys.prefix evaluates to.
Guido van Rossum0b4b8a21997-08-10 16:56:48 +000012 It can also be the top directory of the Python source
13 tree; then -P must point to the build tree.
Guido van Rossumd8336c21994-10-05 16:13:01 +000014
Guido van Rossum150316e1995-08-08 14:21:07 +000015-P exec_prefix: Like -p but this is the 'exec_prefix', used to
Guido van Rossum0b4b8a21997-08-10 16:56:48 +000016 install objects etc. The default is whatever sys.exec_prefix
17 evaluates to, or the -p argument if given.
18 If -p points to the Python source tree, -P must point
19 to the build tree, if different.
Guido van Rossum150316e1995-08-08 14:21:07 +000020
Guido van Rossumd8336c21994-10-05 16:13:01 +000021-e extension: A directory containing additional .o files that
22 may be used to resolve modules. This directory
23 should also have a Setup file describing the .o files.
Guido van Rossumbaf06031998-08-25 14:06:55 +000024 On Windows, the name of a .INI file describing one
25 or more extensions is passed.
Guido van Rossumd8336c21994-10-05 16:13:01 +000026 More than one -e option may be given.
27
Guido van Rossum96c4dd91996-08-26 05:14:20 +000028-o dir: Directory where the output files are created; default '.'.
29
Guido van Rossum75dc4961998-03-05 03:42:00 +000030-m: Additional arguments are module names instead of filenames.
31
Guido van Rossume35c6011998-05-18 20:25:54 +000032-a package=dir: Additional directories to be added to the package's
33 __path__. Used to simulate directories added by the
34 package at runtime (eg, by OpenGL and win32com).
35 More than one -a option may be given for each package.
36
Guido van Rossum78fc3631998-03-20 17:37:24 +000037-l file: Pass the file to the linker (windows only)
38
Guido van Rossum75dc4961998-03-05 03:42:00 +000039-d: Debugging mode for the module finder.
40
41-q: Make the module finder totally quiet.
42
Guido van Rossum9a6e8551997-08-10 16:47:17 +000043-h: Print this help message.
44
Guido van Rossum78fc3631998-03-20 17:37:24 +000045-x module Exclude the specified module.
46
Guido van Rossumbaf06031998-08-25 14:06:55 +000047-i filename: Include a file with additional command line options. Used
48 to prevent command lines growing beyond the capabilities of
49 the shell/OS. All arguments specified in filename
50 are read and the -i option replaced with the parsed
51 params (note - quoting args in this file is NOT supported)
52
Guido van Rossum78fc3631998-03-20 17:37:24 +000053-s subsystem: Specify the subsystem (For Windows only.);
54 'console' (default), 'windows', 'service' or 'com_dll'
55
Guido van Rossumbaf06031998-08-25 14:06:55 +000056-w: Toggle Windows (NT or 95) behavior.
Thomas Wouters7e474022000-07-16 12:04:32 +000057 (For debugging only -- on a win32 platform, win32 behavior
Guido van Rossumbaf06031998-08-25 14:06:55 +000058 is automatic.)
Guido van Rossum58a59481997-08-14 01:45:33 +000059
Guido van Rossum6b767ac2001-03-20 20:43:34 +000060-r prefix=f: Replace path prefix.
61 Replace prefix with f in the source path references
62 contained in the resulting binary.
63
Guido van Rossum96c4dd91996-08-26 05:14:20 +000064Arguments:
65
Guido van Rossum1e074031998-03-05 04:05:38 +000066script: The Python script to be executed by the resulting binary.
Guido van Rossumd8336c21994-10-05 16:13:01 +000067
68module ...: Additional Python modules (referenced by pathname)
69 that will be included in the resulting binary. These
Guido van Rossum75dc4961998-03-05 03:42:00 +000070 may be .py or .pyc files. If -m is specified, these are
71 module names that are search in the path instead.
Guido van Rossum150316e1995-08-08 14:21:07 +000072
73NOTES:
74
75In order to use freeze successfully, you must have built Python and
Guido van Rossumd4cc04c1996-06-17 17:49:13 +000076installed it ("make install").
Guido van Rossum150316e1995-08-08 14:21:07 +000077
Guido van Rossum96c4dd91996-08-26 05:14:20 +000078The script should not use modules provided only as shared libraries;
79if it does, the resulting binary is not self-contained.
Guido van Rossumd8336c21994-10-05 16:13:01 +000080"""
Guido van Rossum00ff4331994-10-03 16:33:08 +000081
82
Guido van Rossum00ff4331994-10-03 16:33:08 +000083# Import standard modules
84
Guido van Rossumdbaf3321994-10-03 10:25:54 +000085import getopt
Guido van Rossum00ff4331994-10-03 16:33:08 +000086import os
Guido van Rossumdbaf3321994-10-03 10:25:54 +000087import string
Guido van Rossum00ff4331994-10-03 16:33:08 +000088import sys
Guido van Rossumdbaf3321994-10-03 10:25:54 +000089
Guido van Rossumdbaf3321994-10-03 10:25:54 +000090
Guido van Rossum00ff4331994-10-03 16:33:08 +000091# Import the freeze-private modules
92
Guido van Rossumd8336c21994-10-05 16:13:01 +000093import checkextensions
Guido van Rossum75dc4961998-03-05 03:42:00 +000094import modulefinder
Guido van Rossum00ff4331994-10-03 16:33:08 +000095import makeconfig
96import makefreeze
97import makemakefile
98import parsesetup
Guido van Rossumbaf06031998-08-25 14:06:55 +000099import bkfile
Guido van Rossum00ff4331994-10-03 16:33:08 +0000100
Guido van Rossum00ff4331994-10-03 16:33:08 +0000101
102# Main program
103
Guido van Rossumdbaf3321994-10-03 10:25:54 +0000104def main():
Guido van Rossum0b4b8a21997-08-10 16:56:48 +0000105 # overridable context
106 prefix = None # settable with -p option
107 exec_prefix = None # settable with -P option
108 extensions = []
Guido van Rossum78fc3631998-03-20 17:37:24 +0000109 exclude = [] # settable with -x option
Guido van Rossume35c6011998-05-18 20:25:54 +0000110 addn_link = [] # settable with -l, but only honored under Windows.
Guido van Rossum1e074031998-03-05 04:05:38 +0000111 path = sys.path[:]
Guido van Rossum75dc4961998-03-05 03:42:00 +0000112 modargs = 0
113 debug = 1
Guido van Rossum0b4b8a21997-08-10 16:56:48 +0000114 odir = ''
Guido van Rossum58a59481997-08-14 01:45:33 +0000115 win = sys.platform[:3] == 'win'
Guido van Rossum6b767ac2001-03-20 20:43:34 +0000116 replace_paths = [] # settable with -r option
Guido van Rossum00ff4331994-10-03 16:33:08 +0000117
Guido van Rossum78fc3631998-03-20 17:37:24 +0000118 # default the exclude list for each platform
Guido van Rossumbaf06031998-08-25 14:06:55 +0000119 if win: exclude = exclude + [
Guido van Rossumf67c2382000-07-13 15:45:17 +0000120 'dos', 'dospath', 'mac', 'macpath', 'macfs', 'MACFS', 'posix', 'os2', 'ce']
Guido van Rossum78fc3631998-03-20 17:37:24 +0000121
Guido van Rossum94ce0d11997-12-08 05:01:06 +0000122 # modules that are imported by the Python runtime
123 implicits = ["site", "exceptions"]
124
Guido van Rossum0b4b8a21997-08-10 16:56:48 +0000125 # output files
126 frozen_c = 'frozen.c'
127 config_c = 'config.c'
128 target = 'a.out' # normally derived from script name
129 makefile = 'Makefile'
Guido van Rossum58a59481997-08-14 01:45:33 +0000130 subsystem = 'console'
Guido van Rossum00ff4331994-10-03 16:33:08 +0000131
Guido van Rossumbaf06031998-08-25 14:06:55 +0000132 # parse command line by first replacing any "-i" options with the file contents.
133 pos = 1
134 while pos < len(sys.argv)-1: # last option can not be "-i", so this ensures "pos+1" is in range!
135 if sys.argv[pos] == '-i':
136 try:
137 options = string.split(open(sys.argv[pos+1]).read())
138 except IOError, why:
139 usage("File name '%s' specified with the -i option can not be read - %s" % (sys.argv[pos+1], why) )
140 # Replace the '-i' and the filename with the read params.
141 sys.argv[pos:pos+2] = options
142 pos = pos + len(options) - 1 # Skip the name and the included args.
143 pos = pos + 1
144
145 # Now parse the command line with the extras inserted.
Guido van Rossum0b4b8a21997-08-10 16:56:48 +0000146 try:
Guido van Rossum6b767ac2001-03-20 20:43:34 +0000147 opts, args = getopt.getopt(sys.argv[1:], 'r:a:de:hmo:p:P:qs:wx:l:')
Guido van Rossum0b4b8a21997-08-10 16:56:48 +0000148 except getopt.error, msg:
149 usage('getopt error: ' + str(msg))
Guido van Rossum00ff4331994-10-03 16:33:08 +0000150
Guido van Rossum0b4b8a21997-08-10 16:56:48 +0000151 # proces option arguments
152 for o, a in opts:
153 if o == '-h':
154 print __doc__
155 return
Guido van Rossum75dc4961998-03-05 03:42:00 +0000156 if o == '-d':
157 debug = debug + 1
Guido van Rossum0b4b8a21997-08-10 16:56:48 +0000158 if o == '-e':
159 extensions.append(a)
Guido van Rossum75dc4961998-03-05 03:42:00 +0000160 if o == '-m':
161 modargs = 1
Guido van Rossum0b4b8a21997-08-10 16:56:48 +0000162 if o == '-o':
163 odir = a
164 if o == '-p':
165 prefix = a
166 if o == '-P':
167 exec_prefix = a
Guido van Rossum75dc4961998-03-05 03:42:00 +0000168 if o == '-q':
169 debug = 0
Guido van Rossum58a59481997-08-14 01:45:33 +0000170 if o == '-w':
171 win = not win
172 if o == '-s':
173 if not win:
174 usage("-s subsystem option only on Windows")
175 subsystem = a
Guido van Rossum78fc3631998-03-20 17:37:24 +0000176 if o == '-x':
177 exclude.append(a)
178 if o == '-l':
179 addn_link.append(a)
Guido van Rossume35c6011998-05-18 20:25:54 +0000180 if o == '-a':
181 apply(modulefinder.AddPackagePath, tuple(string.split(a,"=", 2)))
Guido van Rossum6b767ac2001-03-20 20:43:34 +0000182 if o == '-r':
183 f,r = string.split(a,"=", 2)
184 replace_paths.append( (f,r) )
Guido van Rossumdbaf3321994-10-03 10:25:54 +0000185
Guido van Rossum0b4b8a21997-08-10 16:56:48 +0000186 # default prefix and exec_prefix
187 if not exec_prefix:
188 if prefix:
189 exec_prefix = prefix
190 else:
191 exec_prefix = sys.exec_prefix
192 if not prefix:
193 prefix = sys.prefix
Guido van Rossum9a6e8551997-08-10 16:47:17 +0000194
Guido van Rossum0b4b8a21997-08-10 16:56:48 +0000195 # determine whether -p points to the Python source tree
Guido van Rossume0394251998-03-05 05:39:50 +0000196 ishome = os.path.exists(os.path.join(prefix, 'Python', 'ceval.c'))
Guido van Rossumdbaf3321994-10-03 10:25:54 +0000197
Guido van Rossum0b4b8a21997-08-10 16:56:48 +0000198 # locations derived from options
199 version = sys.version[:3]
Guido van Rossum5e32a771998-07-07 22:47:38 +0000200 if win:
201 extensions_c = 'frozen_extensions.c'
Guido van Rossum0b4b8a21997-08-10 16:56:48 +0000202 if ishome:
203 print "(Using Python source directory)"
204 binlib = exec_prefix
205 incldir = os.path.join(prefix, 'Include')
Guido van Rossum590fc2c1998-06-12 14:09:03 +0000206 config_h_dir = exec_prefix
Guido van Rossum0b4b8a21997-08-10 16:56:48 +0000207 config_c_in = os.path.join(prefix, 'Modules', 'config.c.in')
Guido van Rossum58a59481997-08-14 01:45:33 +0000208 frozenmain_c = os.path.join(prefix, 'Python', 'frozenmain.c')
Guido van Rossum0b4b8a21997-08-10 16:56:48 +0000209 makefile_in = os.path.join(exec_prefix, 'Modules', 'Makefile')
Guido van Rossume35c6011998-05-18 20:25:54 +0000210 if win:
211 frozendllmain_c = os.path.join(exec_prefix, 'Pc\\frozen_dllmain.c')
Guido van Rossum0b4b8a21997-08-10 16:56:48 +0000212 else:
213 binlib = os.path.join(exec_prefix,
214 'lib', 'python%s' % version, 'config')
215 incldir = os.path.join(prefix, 'include', 'python%s' % version)
Guido van Rossum590fc2c1998-06-12 14:09:03 +0000216 config_h_dir = os.path.join(exec_prefix, 'include',
217 'python%s' % version)
Guido van Rossum0b4b8a21997-08-10 16:56:48 +0000218 config_c_in = os.path.join(binlib, 'config.c.in')
219 frozenmain_c = os.path.join(binlib, 'frozenmain.c')
220 makefile_in = os.path.join(binlib, 'Makefile')
Guido van Rossum5e32a771998-07-07 22:47:38 +0000221 frozendllmain_c = os.path.join(binlib, 'frozen_dllmain.c')
Guido van Rossum0b4b8a21997-08-10 16:56:48 +0000222 supp_sources = []
223 defines = []
Guido van Rossum590fc2c1998-06-12 14:09:03 +0000224 includes = ['-I' + incldir, '-I' + config_h_dir]
Guido van Rossumd8336c21994-10-05 16:13:01 +0000225
Guido van Rossum0b4b8a21997-08-10 16:56:48 +0000226 # sanity check of directories and files
Guido van Rossumbaf06031998-08-25 14:06:55 +0000227 check_dirs = [prefix, exec_prefix, binlib, incldir]
228 if not win: check_dirs = check_dirs + extensions # These are not directories on Windows.
229 for dir in check_dirs:
Guido van Rossum0b4b8a21997-08-10 16:56:48 +0000230 if not os.path.exists(dir):
231 usage('needed directory %s not found' % dir)
232 if not os.path.isdir(dir):
233 usage('%s: not a directory' % dir)
Guido van Rossum58a59481997-08-14 01:45:33 +0000234 if win:
Guido van Rossumbaf06031998-08-25 14:06:55 +0000235 files = supp_sources + extensions # extensions are files on Windows.
Guido van Rossum58a59481997-08-14 01:45:33 +0000236 else:
237 files = [config_c_in, makefile_in] + supp_sources
238 for file in supp_sources:
Guido van Rossum0b4b8a21997-08-10 16:56:48 +0000239 if not os.path.exists(file):
240 usage('needed file %s not found' % file)
241 if not os.path.isfile(file):
242 usage('%s: not a plain file' % file)
Guido van Rossum58a59481997-08-14 01:45:33 +0000243 if not win:
244 for dir in extensions:
245 setup = os.path.join(dir, 'Setup')
246 if not os.path.exists(setup):
247 usage('needed file %s not found' % setup)
248 if not os.path.isfile(setup):
249 usage('%s: not a plain file' % setup)
Guido van Rossum00ff4331994-10-03 16:33:08 +0000250
Guido van Rossum0b4b8a21997-08-10 16:56:48 +0000251 # check that enough arguments are passed
252 if not args:
253 usage('at least one filename argument required')
Guido van Rossumd4cc04c1996-06-17 17:49:13 +0000254
Guido van Rossum0b4b8a21997-08-10 16:56:48 +0000255 # check that file arguments exist
256 for arg in args:
Guido van Rossum1e074031998-03-05 04:05:38 +0000257 if arg == '-m':
258 break
Guido van Rossum78fc3631998-03-20 17:37:24 +0000259 # if user specified -m on the command line before _any_
260 # file names, then nothing should be checked (as the
261 # very first file should be a module name)
262 if modargs:
263 break
Guido van Rossum0b4b8a21997-08-10 16:56:48 +0000264 if not os.path.exists(arg):
265 usage('argument %s not found' % arg)
266 if not os.path.isfile(arg):
267 usage('%s: not a plain file' % arg)
Guido van Rossum00ff4331994-10-03 16:33:08 +0000268
Guido van Rossum0b4b8a21997-08-10 16:56:48 +0000269 # process non-option arguments
270 scriptfile = args[0]
271 modules = args[1:]
Guido van Rossum00ff4331994-10-03 16:33:08 +0000272
Guido van Rossum0b4b8a21997-08-10 16:56:48 +0000273 # derive target name from script name
274 base = os.path.basename(scriptfile)
275 base, ext = os.path.splitext(base)
276 if base:
277 if base != scriptfile:
278 target = base
279 else:
280 target = base + '.bin'
Guido van Rossum00ff4331994-10-03 16:33:08 +0000281
Guido van Rossum0b4b8a21997-08-10 16:56:48 +0000282 # handle -o option
283 base_frozen_c = frozen_c
284 base_config_c = config_c
285 base_target = target
286 if odir and not os.path.isdir(odir):
287 try:
288 os.mkdir(odir)
289 print "Created output directory", odir
290 except os.error, msg:
291 usage('%s: mkdir failed (%s)' % (odir, str(msg)))
Guido van Rossumbaf06031998-08-25 14:06:55 +0000292 base = ''
Guido van Rossum0b4b8a21997-08-10 16:56:48 +0000293 if odir:
Guido van Rossumbaf06031998-08-25 14:06:55 +0000294 base = os.path.join(odir, '')
Guido van Rossum0b4b8a21997-08-10 16:56:48 +0000295 frozen_c = os.path.join(odir, frozen_c)
296 config_c = os.path.join(odir, config_c)
297 target = os.path.join(odir, target)
298 makefile = os.path.join(odir, makefile)
Guido van Rossume35c6011998-05-18 20:25:54 +0000299 if win: extensions_c = os.path.join(odir, extensions_c)
Guido van Rossum00ff4331994-10-03 16:33:08 +0000300
Guido van Rossum78fc3631998-03-20 17:37:24 +0000301 # Handle special entry point requirements
302 # (on Windows, some frozen programs do not use __main__, but
303 # import the module directly. Eg, DLLs, Services, etc
304 custom_entry_point = None # Currently only used on Windows
305 python_entry_is_main = 1 # Is the entry point called __main__?
306 # handle -s option on Windows
307 if win:
308 import winmakemakefile
309 try:
Guido van Rossume35c6011998-05-18 20:25:54 +0000310 custom_entry_point, python_entry_is_main = \
311 winmakemakefile.get_custom_entry_point(subsystem)
Guido van Rossum78fc3631998-03-20 17:37:24 +0000312 except ValueError, why:
313 usage(why)
314
315
Guido van Rossum0b4b8a21997-08-10 16:56:48 +0000316 # Actual work starts here...
Guido van Rossumd8336c21994-10-05 16:13:01 +0000317
Guido van Rossum75dc4961998-03-05 03:42:00 +0000318 # collect all modules of the program
Guido van Rossum1e074031998-03-05 04:05:38 +0000319 dir = os.path.dirname(scriptfile)
320 path[0] = dir
Guido van Rossum6b767ac2001-03-20 20:43:34 +0000321 mf = modulefinder.ModuleFinder(path, debug, exclude, replace_paths)
Guido van Rossum78fc3631998-03-20 17:37:24 +0000322
323 if win and subsystem=='service':
324 # If a Windows service, then add the "built-in" module.
325 mod = mf.add_module("servicemanager")
326 mod.__file__="dummy.pyd" # really built-in to the resulting EXE
327
Guido van Rossum75dc4961998-03-05 03:42:00 +0000328 for mod in implicits:
329 mf.import_hook(mod)
330 for mod in modules:
331 if mod == '-m':
332 modargs = 1
333 continue
334 if modargs:
335 if mod[-2:] == '.*':
336 mf.import_hook(mod[:-2], None, ["*"])
337 else:
338 mf.import_hook(mod)
339 else:
340 mf.load_file(mod)
Guido van Rossum78fc3631998-03-20 17:37:24 +0000341
342 # Add the main script as either __main__, or the actual module name.
343 if python_entry_is_main:
344 mf.run_script(scriptfile)
345 else:
Guido van Rossum4b1235c2000-05-06 03:18:08 +0000346 mf.load_file(scriptfile)
Guido van Rossum78fc3631998-03-20 17:37:24 +0000347
Guido van Rossum75dc4961998-03-05 03:42:00 +0000348 if debug > 0:
349 mf.report()
350 print
351 dict = mf.modules
Guido van Rossumdbaf3321994-10-03 10:25:54 +0000352
Guido van Rossum75dc4961998-03-05 03:42:00 +0000353 # generate output for frozen modules
Guido van Rossumbaf06031998-08-25 14:06:55 +0000354 files = makefreeze.makefreeze(base, dict, debug, custom_entry_point)
Guido van Rossumdbaf3321994-10-03 10:25:54 +0000355
Guido van Rossuma0e18351998-03-07 04:51:03 +0000356 # look for unfrozen modules (builtin and of unknown origin)
357 builtins = []
358 unknown = []
359 mods = dict.keys()
360 mods.sort()
361 for mod in mods:
362 if dict[mod].__code__:
363 continue
364 if not dict[mod].__file__:
365 builtins.append(mod)
366 else:
367 unknown.append(mod)
368
369 # search for unknown modules in extensions directories (not on Windows)
370 addfiles = []
Guido van Rossume35c6011998-05-18 20:25:54 +0000371 frozen_extensions = [] # Windows list of modules.
Guido van Rossuma937afd1998-04-23 14:39:24 +0000372 if unknown or (not win and builtins):
Guido van Rossum78fc3631998-03-20 17:37:24 +0000373 if not win:
374 addfiles, addmods = \
Guido van Rossuma937afd1998-04-23 14:39:24 +0000375 checkextensions.checkextensions(unknown+builtins,
376 extensions)
Guido van Rossum78fc3631998-03-20 17:37:24 +0000377 for mod in addmods:
Guido van Rossuma937afd1998-04-23 14:39:24 +0000378 if mod in unknown:
379 unknown.remove(mod)
380 builtins.append(mod)
Guido van Rossum78fc3631998-03-20 17:37:24 +0000381 else:
382 # Do the windows thang...
383 import checkextensions_win32
384 # Get a list of CExtension instances, each describing a module
385 # (including its source files)
Guido van Rossume35c6011998-05-18 20:25:54 +0000386 frozen_extensions = checkextensions_win32.checkextensions(
Guido van Rossumf67c2382000-07-13 15:45:17 +0000387 unknown, extensions, prefix)
Guido van Rossume35c6011998-05-18 20:25:54 +0000388 for mod in frozen_extensions:
Guido van Rossum78fc3631998-03-20 17:37:24 +0000389 unknown.remove(mod.name)
Guido van Rossuma0e18351998-03-07 04:51:03 +0000390
391 # report unknown modules
392 if unknown:
393 sys.stderr.write('Warning: unknown modules remain: %s\n' %
394 string.join(unknown))
395
Guido van Rossum75dc4961998-03-05 03:42:00 +0000396 # windows gets different treatment
Guido van Rossum58a59481997-08-14 01:45:33 +0000397 if win:
398 # Taking a shortcut here...
Guido van Rossume35c6011998-05-18 20:25:54 +0000399 import winmakemakefile, checkextensions_win32
400 checkextensions_win32.write_extension_table(extensions_c,
401 frozen_extensions)
402 # Create a module definition for the bootstrap C code.
403 xtras = [frozenmain_c, os.path.basename(frozen_c),
Guido van Rossum7039f501999-03-12 22:07:05 +0000404 frozendllmain_c, os.path.basename(extensions_c)] + files
Guido van Rossume35c6011998-05-18 20:25:54 +0000405 maindefn = checkextensions_win32.CExtension( '__main__', xtras )
406 frozen_extensions.append( maindefn )
Guido van Rossum58a59481997-08-14 01:45:33 +0000407 outfp = open(makefile, 'w')
408 try:
409 winmakemakefile.makemakefile(outfp,
410 locals(),
Guido van Rossume35c6011998-05-18 20:25:54 +0000411 frozen_extensions,
Guido van Rossum31d53ed1998-03-07 04:08:04 +0000412 os.path.basename(target))
Guido van Rossum58a59481997-08-14 01:45:33 +0000413 finally:
414 outfp.close()
415 return
416
Guido van Rossum75dc4961998-03-05 03:42:00 +0000417 # generate config.c and Makefile
Guido van Rossum0b4b8a21997-08-10 16:56:48 +0000418 builtins.sort()
419 infp = open(config_c_in)
Guido van Rossumbaf06031998-08-25 14:06:55 +0000420 outfp = bkfile.open(config_c, 'w')
Guido van Rossum0b4b8a21997-08-10 16:56:48 +0000421 try:
422 makeconfig.makeconfig(infp, outfp, builtins)
423 finally:
424 outfp.close()
425 infp.close()
Guido van Rossumdbaf3321994-10-03 10:25:54 +0000426
Guido van Rossum0b4b8a21997-08-10 16:56:48 +0000427 cflags = defines + includes + ['$(OPT)']
428 libs = [os.path.join(binlib, 'libpython$(VERSION).a')]
Guido van Rossum00ff4331994-10-03 16:33:08 +0000429
Guido van Rossum0b4b8a21997-08-10 16:56:48 +0000430 somevars = {}
Guido van Rossum345df171997-11-22 22:10:01 +0000431 if os.path.exists(makefile_in):
432 makevars = parsesetup.getmakevars(makefile_in)
Guido van Rossum0b4b8a21997-08-10 16:56:48 +0000433 for key in makevars.keys():
434 somevars[key] = makevars[key]
Guido van Rossum00ff4331994-10-03 16:33:08 +0000435
Guido van Rossum0b4b8a21997-08-10 16:56:48 +0000436 somevars['CFLAGS'] = string.join(cflags) # override
437 files = ['$(OPT)', '$(LDFLAGS)', base_config_c, base_frozen_c] + \
Guido van Rossumbaf06031998-08-25 14:06:55 +0000438 files + supp_sources + addfiles + libs + \
Guido van Rossum0b4b8a21997-08-10 16:56:48 +0000439 ['$(MODLIBS)', '$(LIBS)', '$(SYSLIBS)']
Guido van Rossum00ff4331994-10-03 16:33:08 +0000440
Guido van Rossumbaf06031998-08-25 14:06:55 +0000441 outfp = bkfile.open(makefile, 'w')
Guido van Rossum0b4b8a21997-08-10 16:56:48 +0000442 try:
443 makemakefile.makemakefile(outfp, somevars, files, base_target)
444 finally:
445 outfp.close()
Guido van Rossum0b4b8a21997-08-10 16:56:48 +0000446
447 # Done!
448
449 if odir:
450 print 'Now run "make" in', odir,
451 print 'to build the target:', base_target
452 else:
453 print 'Now run "make" to build the target:', base_target
Guido van Rossum00ff4331994-10-03 16:33:08 +0000454
Guido van Rossumd8336c21994-10-05 16:13:01 +0000455
456# Print usage message and exit
457
Guido van Rossum9a6e8551997-08-10 16:47:17 +0000458def usage(msg):
Guido van Rossum0b4b8a21997-08-10 16:56:48 +0000459 sys.stdout = sys.stderr
460 print "Error:", msg
461 print "Use ``%s -h'' for help" % sys.argv[0]
462 sys.exit(2)
Guido van Rossumd8336c21994-10-05 16:13:01 +0000463
464
Guido van Rossumdbaf3321994-10-03 10:25:54 +0000465main()