blob: 95f066238bbbf92d2ebcd3a45d8cf58feadcf659 [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.
57 (For debugging only -- on a win32 platform, win32 behaviour
58 is automatic.)
Guido van Rossum58a59481997-08-14 01:45:33 +000059
Guido van Rossum96c4dd91996-08-26 05:14:20 +000060Arguments:
61
Guido van Rossum1e074031998-03-05 04:05:38 +000062script: The Python script to be executed by the resulting binary.
Guido van Rossumd8336c21994-10-05 16:13:01 +000063
64module ...: Additional Python modules (referenced by pathname)
65 that will be included in the resulting binary. These
Guido van Rossum75dc4961998-03-05 03:42:00 +000066 may be .py or .pyc files. If -m is specified, these are
67 module names that are search in the path instead.
Guido van Rossum150316e1995-08-08 14:21:07 +000068
69NOTES:
70
71In order to use freeze successfully, you must have built Python and
Guido van Rossumd4cc04c1996-06-17 17:49:13 +000072installed it ("make install").
Guido van Rossum150316e1995-08-08 14:21:07 +000073
Guido van Rossum96c4dd91996-08-26 05:14:20 +000074The script should not use modules provided only as shared libraries;
75if it does, the resulting binary is not self-contained.
Guido van Rossumd8336c21994-10-05 16:13:01 +000076"""
Guido van Rossum00ff4331994-10-03 16:33:08 +000077
78
Guido van Rossum00ff4331994-10-03 16:33:08 +000079# Import standard modules
80
Guido van Rossumdbaf3321994-10-03 10:25:54 +000081import getopt
Guido van Rossum00ff4331994-10-03 16:33:08 +000082import os
Guido van Rossumdbaf3321994-10-03 10:25:54 +000083import string
Guido van Rossum00ff4331994-10-03 16:33:08 +000084import sys
Guido van Rossumdbaf3321994-10-03 10:25:54 +000085
Guido van Rossumdbaf3321994-10-03 10:25:54 +000086
Guido van Rossum00ff4331994-10-03 16:33:08 +000087# Import the freeze-private modules
88
Guido van Rossumd8336c21994-10-05 16:13:01 +000089import checkextensions
Guido van Rossum75dc4961998-03-05 03:42:00 +000090import modulefinder
Guido van Rossum00ff4331994-10-03 16:33:08 +000091import makeconfig
92import makefreeze
93import makemakefile
94import parsesetup
Guido van Rossumbaf06031998-08-25 14:06:55 +000095import bkfile
Guido van Rossum00ff4331994-10-03 16:33:08 +000096
Guido van Rossum00ff4331994-10-03 16:33:08 +000097
98# Main program
99
Guido van Rossumdbaf3321994-10-03 10:25:54 +0000100def main():
Guido van Rossum0b4b8a21997-08-10 16:56:48 +0000101 # overridable context
102 prefix = None # settable with -p option
103 exec_prefix = None # settable with -P option
104 extensions = []
Guido van Rossum78fc3631998-03-20 17:37:24 +0000105 exclude = [] # settable with -x option
Guido van Rossume35c6011998-05-18 20:25:54 +0000106 addn_link = [] # settable with -l, but only honored under Windows.
Guido van Rossum1e074031998-03-05 04:05:38 +0000107 path = sys.path[:]
Guido van Rossum75dc4961998-03-05 03:42:00 +0000108 modargs = 0
109 debug = 1
Guido van Rossum0b4b8a21997-08-10 16:56:48 +0000110 odir = ''
Guido van Rossum58a59481997-08-14 01:45:33 +0000111 win = sys.platform[:3] == 'win'
Guido van Rossum00ff4331994-10-03 16:33:08 +0000112
Guido van Rossum78fc3631998-03-20 17:37:24 +0000113 # default the exclude list for each platform
Guido van Rossumbaf06031998-08-25 14:06:55 +0000114 if win: exclude = exclude + [
Guido van Rossumf67c2382000-07-13 15:45:17 +0000115 'dos', 'dospath', 'mac', 'macpath', 'macfs', 'MACFS', 'posix', 'os2', 'ce']
Guido van Rossum78fc3631998-03-20 17:37:24 +0000116
Guido van Rossum94ce0d11997-12-08 05:01:06 +0000117 # modules that are imported by the Python runtime
118 implicits = ["site", "exceptions"]
119
Guido van Rossum0b4b8a21997-08-10 16:56:48 +0000120 # output files
121 frozen_c = 'frozen.c'
122 config_c = 'config.c'
123 target = 'a.out' # normally derived from script name
124 makefile = 'Makefile'
Guido van Rossum58a59481997-08-14 01:45:33 +0000125 subsystem = 'console'
Guido van Rossum00ff4331994-10-03 16:33:08 +0000126
Guido van Rossumbaf06031998-08-25 14:06:55 +0000127 # parse command line by first replacing any "-i" options with the file contents.
128 pos = 1
129 while pos < len(sys.argv)-1: # last option can not be "-i", so this ensures "pos+1" is in range!
130 if sys.argv[pos] == '-i':
131 try:
132 options = string.split(open(sys.argv[pos+1]).read())
133 except IOError, why:
134 usage("File name '%s' specified with the -i option can not be read - %s" % (sys.argv[pos+1], why) )
135 # Replace the '-i' and the filename with the read params.
136 sys.argv[pos:pos+2] = options
137 pos = pos + len(options) - 1 # Skip the name and the included args.
138 pos = pos + 1
139
140 # Now parse the command line with the extras inserted.
Guido van Rossum0b4b8a21997-08-10 16:56:48 +0000141 try:
Guido van Rossume35c6011998-05-18 20:25:54 +0000142 opts, args = getopt.getopt(sys.argv[1:], 'a:de:hmo:p:P:qs:wx:l:')
Guido van Rossum0b4b8a21997-08-10 16:56:48 +0000143 except getopt.error, msg:
144 usage('getopt error: ' + str(msg))
Guido van Rossum00ff4331994-10-03 16:33:08 +0000145
Guido van Rossum0b4b8a21997-08-10 16:56:48 +0000146 # proces option arguments
147 for o, a in opts:
148 if o == '-h':
149 print __doc__
150 return
Guido van Rossum75dc4961998-03-05 03:42:00 +0000151 if o == '-d':
152 debug = debug + 1
Guido van Rossum0b4b8a21997-08-10 16:56:48 +0000153 if o == '-e':
154 extensions.append(a)
Guido van Rossum75dc4961998-03-05 03:42:00 +0000155 if o == '-m':
156 modargs = 1
Guido van Rossum0b4b8a21997-08-10 16:56:48 +0000157 if o == '-o':
158 odir = a
159 if o == '-p':
160 prefix = a
161 if o == '-P':
162 exec_prefix = a
Guido van Rossum75dc4961998-03-05 03:42:00 +0000163 if o == '-q':
164 debug = 0
Guido van Rossum58a59481997-08-14 01:45:33 +0000165 if o == '-w':
166 win = not win
167 if o == '-s':
168 if not win:
169 usage("-s subsystem option only on Windows")
170 subsystem = a
Guido van Rossum78fc3631998-03-20 17:37:24 +0000171 if o == '-x':
172 exclude.append(a)
173 if o == '-l':
174 addn_link.append(a)
Guido van Rossume35c6011998-05-18 20:25:54 +0000175 if o == '-a':
176 apply(modulefinder.AddPackagePath, tuple(string.split(a,"=", 2)))
Guido van Rossumdbaf3321994-10-03 10:25:54 +0000177
Guido van Rossum0b4b8a21997-08-10 16:56:48 +0000178 # default prefix and exec_prefix
179 if not exec_prefix:
180 if prefix:
181 exec_prefix = prefix
182 else:
183 exec_prefix = sys.exec_prefix
184 if not prefix:
185 prefix = sys.prefix
Guido van Rossum9a6e8551997-08-10 16:47:17 +0000186
Guido van Rossum0b4b8a21997-08-10 16:56:48 +0000187 # determine whether -p points to the Python source tree
Guido van Rossume0394251998-03-05 05:39:50 +0000188 ishome = os.path.exists(os.path.join(prefix, 'Python', 'ceval.c'))
Guido van Rossumdbaf3321994-10-03 10:25:54 +0000189
Guido van Rossum0b4b8a21997-08-10 16:56:48 +0000190 # locations derived from options
191 version = sys.version[:3]
Guido van Rossum5e32a771998-07-07 22:47:38 +0000192 if win:
193 extensions_c = 'frozen_extensions.c'
Guido van Rossum0b4b8a21997-08-10 16:56:48 +0000194 if ishome:
195 print "(Using Python source directory)"
196 binlib = exec_prefix
197 incldir = os.path.join(prefix, 'Include')
Guido van Rossum590fc2c1998-06-12 14:09:03 +0000198 config_h_dir = exec_prefix
Guido van Rossum0b4b8a21997-08-10 16:56:48 +0000199 config_c_in = os.path.join(prefix, 'Modules', 'config.c.in')
Guido van Rossum58a59481997-08-14 01:45:33 +0000200 frozenmain_c = os.path.join(prefix, 'Python', 'frozenmain.c')
Guido van Rossum0b4b8a21997-08-10 16:56:48 +0000201 makefile_in = os.path.join(exec_prefix, 'Modules', 'Makefile')
Guido van Rossume35c6011998-05-18 20:25:54 +0000202 if win:
203 frozendllmain_c = os.path.join(exec_prefix, 'Pc\\frozen_dllmain.c')
Guido van Rossum0b4b8a21997-08-10 16:56:48 +0000204 else:
205 binlib = os.path.join(exec_prefix,
206 'lib', 'python%s' % version, 'config')
207 incldir = os.path.join(prefix, 'include', 'python%s' % version)
Guido van Rossum590fc2c1998-06-12 14:09:03 +0000208 config_h_dir = os.path.join(exec_prefix, 'include',
209 'python%s' % version)
Guido van Rossum0b4b8a21997-08-10 16:56:48 +0000210 config_c_in = os.path.join(binlib, 'config.c.in')
211 frozenmain_c = os.path.join(binlib, 'frozenmain.c')
212 makefile_in = os.path.join(binlib, 'Makefile')
Guido van Rossum5e32a771998-07-07 22:47:38 +0000213 frozendllmain_c = os.path.join(binlib, 'frozen_dllmain.c')
Guido van Rossum0b4b8a21997-08-10 16:56:48 +0000214 supp_sources = []
215 defines = []
Guido van Rossum590fc2c1998-06-12 14:09:03 +0000216 includes = ['-I' + incldir, '-I' + config_h_dir]
Guido van Rossumd8336c21994-10-05 16:13:01 +0000217
Guido van Rossum0b4b8a21997-08-10 16:56:48 +0000218 # sanity check of directories and files
Guido van Rossumbaf06031998-08-25 14:06:55 +0000219 check_dirs = [prefix, exec_prefix, binlib, incldir]
220 if not win: check_dirs = check_dirs + extensions # These are not directories on Windows.
221 for dir in check_dirs:
Guido van Rossum0b4b8a21997-08-10 16:56:48 +0000222 if not os.path.exists(dir):
223 usage('needed directory %s not found' % dir)
224 if not os.path.isdir(dir):
225 usage('%s: not a directory' % dir)
Guido van Rossum58a59481997-08-14 01:45:33 +0000226 if win:
Guido van Rossumbaf06031998-08-25 14:06:55 +0000227 files = supp_sources + extensions # extensions are files on Windows.
Guido van Rossum58a59481997-08-14 01:45:33 +0000228 else:
229 files = [config_c_in, makefile_in] + supp_sources
230 for file in supp_sources:
Guido van Rossum0b4b8a21997-08-10 16:56:48 +0000231 if not os.path.exists(file):
232 usage('needed file %s not found' % file)
233 if not os.path.isfile(file):
234 usage('%s: not a plain file' % file)
Guido van Rossum58a59481997-08-14 01:45:33 +0000235 if not win:
236 for dir in extensions:
237 setup = os.path.join(dir, 'Setup')
238 if not os.path.exists(setup):
239 usage('needed file %s not found' % setup)
240 if not os.path.isfile(setup):
241 usage('%s: not a plain file' % setup)
Guido van Rossum00ff4331994-10-03 16:33:08 +0000242
Guido van Rossum0b4b8a21997-08-10 16:56:48 +0000243 # check that enough arguments are passed
244 if not args:
245 usage('at least one filename argument required')
Guido van Rossumd4cc04c1996-06-17 17:49:13 +0000246
Guido van Rossum0b4b8a21997-08-10 16:56:48 +0000247 # check that file arguments exist
248 for arg in args:
Guido van Rossum1e074031998-03-05 04:05:38 +0000249 if arg == '-m':
250 break
Guido van Rossum78fc3631998-03-20 17:37:24 +0000251 # if user specified -m on the command line before _any_
252 # file names, then nothing should be checked (as the
253 # very first file should be a module name)
254 if modargs:
255 break
Guido van Rossum0b4b8a21997-08-10 16:56:48 +0000256 if not os.path.exists(arg):
257 usage('argument %s not found' % arg)
258 if not os.path.isfile(arg):
259 usage('%s: not a plain file' % arg)
Guido van Rossum00ff4331994-10-03 16:33:08 +0000260
Guido van Rossum0b4b8a21997-08-10 16:56:48 +0000261 # process non-option arguments
262 scriptfile = args[0]
263 modules = args[1:]
Guido van Rossum00ff4331994-10-03 16:33:08 +0000264
Guido van Rossum0b4b8a21997-08-10 16:56:48 +0000265 # derive target name from script name
266 base = os.path.basename(scriptfile)
267 base, ext = os.path.splitext(base)
268 if base:
269 if base != scriptfile:
270 target = base
271 else:
272 target = base + '.bin'
Guido van Rossum00ff4331994-10-03 16:33:08 +0000273
Guido van Rossum0b4b8a21997-08-10 16:56:48 +0000274 # handle -o option
275 base_frozen_c = frozen_c
276 base_config_c = config_c
277 base_target = target
278 if odir and not os.path.isdir(odir):
279 try:
280 os.mkdir(odir)
281 print "Created output directory", odir
282 except os.error, msg:
283 usage('%s: mkdir failed (%s)' % (odir, str(msg)))
Guido van Rossumbaf06031998-08-25 14:06:55 +0000284 base = ''
Guido van Rossum0b4b8a21997-08-10 16:56:48 +0000285 if odir:
Guido van Rossumbaf06031998-08-25 14:06:55 +0000286 base = os.path.join(odir, '')
Guido van Rossum0b4b8a21997-08-10 16:56:48 +0000287 frozen_c = os.path.join(odir, frozen_c)
288 config_c = os.path.join(odir, config_c)
289 target = os.path.join(odir, target)
290 makefile = os.path.join(odir, makefile)
Guido van Rossume35c6011998-05-18 20:25:54 +0000291 if win: extensions_c = os.path.join(odir, extensions_c)
Guido van Rossum00ff4331994-10-03 16:33:08 +0000292
Guido van Rossum78fc3631998-03-20 17:37:24 +0000293 # Handle special entry point requirements
294 # (on Windows, some frozen programs do not use __main__, but
295 # import the module directly. Eg, DLLs, Services, etc
296 custom_entry_point = None # Currently only used on Windows
297 python_entry_is_main = 1 # Is the entry point called __main__?
298 # handle -s option on Windows
299 if win:
300 import winmakemakefile
301 try:
Guido van Rossume35c6011998-05-18 20:25:54 +0000302 custom_entry_point, python_entry_is_main = \
303 winmakemakefile.get_custom_entry_point(subsystem)
Guido van Rossum78fc3631998-03-20 17:37:24 +0000304 except ValueError, why:
305 usage(why)
306
307
Guido van Rossum0b4b8a21997-08-10 16:56:48 +0000308 # Actual work starts here...
Guido van Rossumd8336c21994-10-05 16:13:01 +0000309
Guido van Rossum75dc4961998-03-05 03:42:00 +0000310 # collect all modules of the program
Guido van Rossum1e074031998-03-05 04:05:38 +0000311 dir = os.path.dirname(scriptfile)
312 path[0] = dir
Guido van Rossum78fc3631998-03-20 17:37:24 +0000313 mf = modulefinder.ModuleFinder(path, debug, exclude)
314
315 if win and subsystem=='service':
316 # If a Windows service, then add the "built-in" module.
317 mod = mf.add_module("servicemanager")
318 mod.__file__="dummy.pyd" # really built-in to the resulting EXE
319
Guido van Rossum75dc4961998-03-05 03:42:00 +0000320 for mod in implicits:
321 mf.import_hook(mod)
322 for mod in modules:
323 if mod == '-m':
324 modargs = 1
325 continue
326 if modargs:
327 if mod[-2:] == '.*':
328 mf.import_hook(mod[:-2], None, ["*"])
329 else:
330 mf.import_hook(mod)
331 else:
332 mf.load_file(mod)
Guido van Rossum78fc3631998-03-20 17:37:24 +0000333
334 # Add the main script as either __main__, or the actual module name.
335 if python_entry_is_main:
336 mf.run_script(scriptfile)
337 else:
Guido van Rossum4b1235c2000-05-06 03:18:08 +0000338 mf.load_file(scriptfile)
Guido van Rossum78fc3631998-03-20 17:37:24 +0000339
Guido van Rossum75dc4961998-03-05 03:42:00 +0000340 if debug > 0:
341 mf.report()
342 print
343 dict = mf.modules
Guido van Rossumdbaf3321994-10-03 10:25:54 +0000344
Guido van Rossum75dc4961998-03-05 03:42:00 +0000345 # generate output for frozen modules
Guido van Rossumbaf06031998-08-25 14:06:55 +0000346 files = makefreeze.makefreeze(base, dict, debug, custom_entry_point)
Guido van Rossumdbaf3321994-10-03 10:25:54 +0000347
Guido van Rossuma0e18351998-03-07 04:51:03 +0000348 # look for unfrozen modules (builtin and of unknown origin)
349 builtins = []
350 unknown = []
351 mods = dict.keys()
352 mods.sort()
353 for mod in mods:
354 if dict[mod].__code__:
355 continue
356 if not dict[mod].__file__:
357 builtins.append(mod)
358 else:
359 unknown.append(mod)
360
361 # search for unknown modules in extensions directories (not on Windows)
362 addfiles = []
Guido van Rossume35c6011998-05-18 20:25:54 +0000363 frozen_extensions = [] # Windows list of modules.
Guido van Rossuma937afd1998-04-23 14:39:24 +0000364 if unknown or (not win and builtins):
Guido van Rossum78fc3631998-03-20 17:37:24 +0000365 if not win:
366 addfiles, addmods = \
Guido van Rossuma937afd1998-04-23 14:39:24 +0000367 checkextensions.checkextensions(unknown+builtins,
368 extensions)
Guido van Rossum78fc3631998-03-20 17:37:24 +0000369 for mod in addmods:
Guido van Rossuma937afd1998-04-23 14:39:24 +0000370 if mod in unknown:
371 unknown.remove(mod)
372 builtins.append(mod)
Guido van Rossum78fc3631998-03-20 17:37:24 +0000373 else:
374 # Do the windows thang...
375 import checkextensions_win32
376 # Get a list of CExtension instances, each describing a module
377 # (including its source files)
Guido van Rossume35c6011998-05-18 20:25:54 +0000378 frozen_extensions = checkextensions_win32.checkextensions(
Guido van Rossumf67c2382000-07-13 15:45:17 +0000379 unknown, extensions, prefix)
Guido van Rossume35c6011998-05-18 20:25:54 +0000380 for mod in frozen_extensions:
Guido van Rossum78fc3631998-03-20 17:37:24 +0000381 unknown.remove(mod.name)
Guido van Rossuma0e18351998-03-07 04:51:03 +0000382
383 # report unknown modules
384 if unknown:
385 sys.stderr.write('Warning: unknown modules remain: %s\n' %
386 string.join(unknown))
387
Guido van Rossum75dc4961998-03-05 03:42:00 +0000388 # windows gets different treatment
Guido van Rossum58a59481997-08-14 01:45:33 +0000389 if win:
390 # Taking a shortcut here...
Guido van Rossume35c6011998-05-18 20:25:54 +0000391 import winmakemakefile, checkextensions_win32
392 checkextensions_win32.write_extension_table(extensions_c,
393 frozen_extensions)
394 # Create a module definition for the bootstrap C code.
395 xtras = [frozenmain_c, os.path.basename(frozen_c),
Guido van Rossum7039f501999-03-12 22:07:05 +0000396 frozendllmain_c, os.path.basename(extensions_c)] + files
Guido van Rossume35c6011998-05-18 20:25:54 +0000397 maindefn = checkextensions_win32.CExtension( '__main__', xtras )
398 frozen_extensions.append( maindefn )
Guido van Rossum58a59481997-08-14 01:45:33 +0000399 outfp = open(makefile, 'w')
400 try:
401 winmakemakefile.makemakefile(outfp,
402 locals(),
Guido van Rossume35c6011998-05-18 20:25:54 +0000403 frozen_extensions,
Guido van Rossum31d53ed1998-03-07 04:08:04 +0000404 os.path.basename(target))
Guido van Rossum58a59481997-08-14 01:45:33 +0000405 finally:
406 outfp.close()
407 return
408
Guido van Rossum75dc4961998-03-05 03:42:00 +0000409 # generate config.c and Makefile
Guido van Rossum0b4b8a21997-08-10 16:56:48 +0000410 builtins.sort()
411 infp = open(config_c_in)
Guido van Rossumbaf06031998-08-25 14:06:55 +0000412 outfp = bkfile.open(config_c, 'w')
Guido van Rossum0b4b8a21997-08-10 16:56:48 +0000413 try:
414 makeconfig.makeconfig(infp, outfp, builtins)
415 finally:
416 outfp.close()
417 infp.close()
Guido van Rossumdbaf3321994-10-03 10:25:54 +0000418
Guido van Rossum0b4b8a21997-08-10 16:56:48 +0000419 cflags = defines + includes + ['$(OPT)']
420 libs = [os.path.join(binlib, 'libpython$(VERSION).a')]
Guido van Rossum00ff4331994-10-03 16:33:08 +0000421
Guido van Rossum0b4b8a21997-08-10 16:56:48 +0000422 somevars = {}
Guido van Rossum345df171997-11-22 22:10:01 +0000423 if os.path.exists(makefile_in):
424 makevars = parsesetup.getmakevars(makefile_in)
Guido van Rossum0b4b8a21997-08-10 16:56:48 +0000425 for key in makevars.keys():
426 somevars[key] = makevars[key]
Guido van Rossum00ff4331994-10-03 16:33:08 +0000427
Guido van Rossum0b4b8a21997-08-10 16:56:48 +0000428 somevars['CFLAGS'] = string.join(cflags) # override
429 files = ['$(OPT)', '$(LDFLAGS)', base_config_c, base_frozen_c] + \
Guido van Rossumbaf06031998-08-25 14:06:55 +0000430 files + supp_sources + addfiles + libs + \
Guido van Rossum0b4b8a21997-08-10 16:56:48 +0000431 ['$(MODLIBS)', '$(LIBS)', '$(SYSLIBS)']
Guido van Rossum00ff4331994-10-03 16:33:08 +0000432
Guido van Rossumbaf06031998-08-25 14:06:55 +0000433 outfp = bkfile.open(makefile, 'w')
Guido van Rossum0b4b8a21997-08-10 16:56:48 +0000434 try:
435 makemakefile.makemakefile(outfp, somevars, files, base_target)
436 finally:
437 outfp.close()
Guido van Rossum0b4b8a21997-08-10 16:56:48 +0000438
439 # Done!
440
441 if odir:
442 print 'Now run "make" in', odir,
443 print 'to build the target:', base_target
444 else:
445 print 'Now run "make" to build the target:', base_target
Guido van Rossum00ff4331994-10-03 16:33:08 +0000446
Guido van Rossumd8336c21994-10-05 16:13:01 +0000447
448# Print usage message and exit
449
Guido van Rossum9a6e8551997-08-10 16:47:17 +0000450def usage(msg):
Guido van Rossum0b4b8a21997-08-10 16:56:48 +0000451 sys.stdout = sys.stderr
452 print "Error:", msg
453 print "Use ``%s -h'' for help" % sys.argv[0]
454 sys.exit(2)
Guido van Rossumd8336c21994-10-05 16:13:01 +0000455
456
Guido van Rossumdbaf3321994-10-03 10:25:54 +0000457main()