source: trunk/essentials/dev-lang/python/Tools/freeze/makefreeze.py@ 3391

Last change on this file since 3391 was 3225, checked in by bird, 19 years ago

Python 2.5

File size: 2.6 KB
Line 
1import marshal
2import bkfile
3
4
5# Write a file containing frozen code for the modules in the dictionary.
6
7header = """
8#include "Python.h"
9
10static struct _frozen _PyImport_FrozenModules[] = {
11"""
12trailer = """\
13 {0, 0, 0} /* sentinel */
14};
15"""
16
17# if __debug__ == 0 (i.e. -O option given), set Py_OptimizeFlag in frozen app.
18default_entry_point = """
19int
20main(int argc, char **argv)
21{
22 extern int Py_FrozenMain(int, char **);
23""" + ((not __debug__ and """
24 Py_OptimizeFlag++;
25""") or "") + """
26 PyImport_FrozenModules = _PyImport_FrozenModules;
27 return Py_FrozenMain(argc, argv);
28}
29
30"""
31
32def makefreeze(base, dict, debug=0, entry_point=None, fail_import=()):
33 if entry_point is None: entry_point = default_entry_point
34 done = []
35 files = []
36 mods = dict.keys()
37 mods.sort()
38 for mod in mods:
39 m = dict[mod]
40 mangled = "__".join(mod.split("."))
41 if m.__code__:
42 file = 'M_' + mangled + '.c'
43 outfp = bkfile.open(base + file, 'w')
44 files.append(file)
45 if debug:
46 print "freezing", mod, "..."
47 str = marshal.dumps(m.__code__)