Fix the HTML tarball target to generate the HTML if needed instead of
[python/dscho.git] / Mac / Tools / macfreeze / macgen_src.py
blobad0739ef192064db60691c2cb058e177ec0a0eb4
1 """macgen_info - Generate CodeWarrior project, config source, resource file"""
2 import EasyDialogs
3 import os
4 import sys
5 import macfs
6 import MacOS
7 import macostools
8 import macgen_rsrc
9 # Note: this depends on being frozen, or on sys.path already being
10 # modified by macmodulefinder.
11 import makeconfig
13 TEMPLATEDIR=os.path.join(sys.prefix, ':Mac:mwerks:projects:build.macfreeze')
14 PROJECT_TEMPLATE=os.path.join(TEMPLATEDIR, ':frozen.prj')
15 CONFIG_TEMPLATE=os.path.join(TEMPLATEDIR, ':templatefrozenconfig.c')
16 BUNDLE_TEMPLATE=os.path.join(TEMPLATEDIR, ':frozenbundle.rsrc')
18 def generate(output, module_dict, debug=0):
19 problems = 0
20 output_created=0
21 if not os.path.exists(output):
22 print 'Creating project folder', output
23 os.mkdir(output)
24 output_created = 1
25 # Resolve aliases, if needed
26 try:
27 fss, dummy1, dummy2 = macfs.ResolveAliasFile(output)
28 except macfs.error:
29 pass
30 else:
31 newname = fss.as_pathname()
32 if newname != output:
33 if debug:
34 print 'Alias', output
35 print 'Resolved to', newname
36 output = newname
37 # Construct the filenames
38 dummy, outfile = os.path.split(output)
39 build, ext = os.path.splitext(outfile)
40 if build == 'build' and ext[0] == '.':
41 # This is probably a good name for the project
42 projname = ext[1:]
43 else:
44 projname = 'frozenapplet.prj'
45 config_name = os.path.join(output, ':macfrozenconfig.c')
46 project_name = os.path.join(output, ':' + projname + '.prj')
47 resource_name = os.path.join(output, ':frozenmodules.rsrc')
48 bundle_name = os.path.join(output, ':frozenbundle.rsrc')
50 # Fill the output folder, if needed.
51 if output_created:
52 # Create the project, if needed
53 if not os.path.exists(project_name):
54 print 'Creating project', project_name
55 if not os.path.exists(PROJECT_TEMPLATE):
56 print '** No template CodeWarrior project found at', PROJECT_TEMPLATE
57 print ' To generate standalone Python applications from source you need'
58 print ' a full source distribution. Check http://www.cwi.nl/~jack/macpython.html'
59 print ' for details.'
60 problems = 1
61 else:
62 macostools.copy(PROJECT_TEMPLATE, project_name)
63 print 'A template CodeWarrior project has been copied to', project_name
64 print 'It is up to you to make the following changes:'
65 print '- Change the output file name'
66 print '- Change the search path, unless the folder is in the python home'
67 print '- Add sourcefiles/libraries for any extension modules used'
68 print '- Remove unused sources, to speed up the build process'
69 print '- Remove unused resource files (like tcl/tk) for a smaller binary'
70 problems = 1
71 macostools.copy(BUNDLE_TEMPLATE, bundle_name)
72 print 'A template bundle file has also been copied to', bundle_name
73 print 'You may want to adapt signature, size resource, etc'
76 # Create the resource file
77 macgen_rsrc.generate(resource_name, module_dict, debug=debug)
79 # Create the config.c file
80 if not os.path.exists(CONFIG_TEMPLATE):
81 print '** No template config.c found at', PROJECT_TEMPLATE
82 print ' To generate standalone Python applications from source you need'
83 print ' a full source distribution. Check http://www.cwi.nl/~jack/macpython.html'
84 print ' for details.'
85 problems = 1
86 else:
87 # Find elegible modules (builtins and dynamically loaded modules)
88 c_modules = []
89 for module in module_dict.keys():
90 if module_dict[module].gettype() in ('builtin', 'dynamic'):
91 c_modules.append(module)
92 ifp = open(CONFIG_TEMPLATE)
93 ofp = open(config_name, 'w')
94 makeconfig.makeconfig(ifp, ofp, c_modules)
95 ifp.close()
96 ofp.close()
97 MacOS.SetCreatorAndType(config_name, 'CWIE', 'TEXT')
99 if warnings(module_dict):
100 problems = 1
101 return problems
103 def warnings(module_dict):
104 problems = 0
105 for name, module in module_dict.items():
106 if module.gettype() not in ('builtin', 'module', 'dynamic'):
107 problems = problems + 1
108 print 'Warning: %s not included: %s %s'%(name, module.gettype(), module)
109 return problems