1 """macgen_info - Generate CodeWarrior project, config source, resource file"""
9 # Note: this depends on being frozen, or on sys.path already being
10 # modified by macmodulefinder.
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):
21 if not os
.path
.exists(output
):
22 print 'Creating project folder', output
25 # Resolve aliases, if needed
27 fss
, dummy1
, dummy2
= macfs
.ResolveAliasFile(output
)
31 newname
= fss
.as_pathname()
35 print 'Resolved to', 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
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.
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'
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'
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'
87 # Find elegible modules (builtins and dynamically loaded 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
)
97 MacOS
.SetCreatorAndType(config_name
, 'CWIE', 'TEXT')
99 if warnings(module_dict
):
103 def warnings(module_dict
):
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
)