mirror of https://github.com/python/cpython
Changed indents to 4 *spaces*; added Emacs variables to avoid
inserting tabs. All this (and the previous patch) in preparation for porting to NT.
This commit is contained in:
parent
9a6e855a27
commit
0b4b8a21ce
|
@ -10,14 +10,14 @@ Options:
|
||||||
in the Python build directory.
|
in the Python build directory.
|
||||||
(If you never ran this, freeze won't work.)
|
(If you never ran this, freeze won't work.)
|
||||||
The default is whatever sys.prefix evaluates to.
|
The default is whatever sys.prefix evaluates to.
|
||||||
It can also be the top directory of the Python source
|
It can also be the top directory of the Python source
|
||||||
tree; then -P must point to the build tree.
|
tree; then -P must point to the build tree.
|
||||||
|
|
||||||
-P exec_prefix: Like -p but this is the 'exec_prefix', used to
|
-P exec_prefix: Like -p but this is the 'exec_prefix', used to
|
||||||
install objects etc. The default is whatever sys.exec_prefix
|
install objects etc. The default is whatever sys.exec_prefix
|
||||||
evaluates to, or the -p argument if given.
|
evaluates to, or the -p argument if given.
|
||||||
If -p points to the Python source tree, -P must point
|
If -p points to the Python source tree, -P must point
|
||||||
to the build tree, if different.
|
to the build tree, if different.
|
||||||
|
|
||||||
-e extension: A directory containing additional .o files that
|
-e extension: A directory containing additional .o files that
|
||||||
may be used to resolve modules. This directory
|
may be used to resolve modules. This directory
|
||||||
|
@ -31,7 +31,7 @@ Options:
|
||||||
Arguments:
|
Arguments:
|
||||||
|
|
||||||
script.py: The Python script to be executed by the resulting binary.
|
script.py: The Python script to be executed by the resulting binary.
|
||||||
It *must* end with a .py suffix!
|
It *must* end with a .py suffix!
|
||||||
|
|
||||||
module ...: Additional Python modules (referenced by pathname)
|
module ...: Additional Python modules (referenced by pathname)
|
||||||
that will be included in the resulting binary. These
|
that will be included in the resulting binary. These
|
||||||
|
@ -70,245 +70,249 @@ import parsesetup
|
||||||
# Main program
|
# Main program
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
# overridable context
|
# overridable context
|
||||||
prefix = None # settable with -p option
|
prefix = None # settable with -p option
|
||||||
exec_prefix = None # settable with -P option
|
exec_prefix = None # settable with -P option
|
||||||
extensions = []
|
extensions = []
|
||||||
path = sys.path
|
path = sys.path
|
||||||
odir = ''
|
odir = ''
|
||||||
|
|
||||||
# output files
|
# output files
|
||||||
frozen_c = 'frozen.c'
|
frozen_c = 'frozen.c'
|
||||||
config_c = 'config.c'
|
config_c = 'config.c'
|
||||||
target = 'a.out' # normally derived from script name
|
target = 'a.out' # normally derived from script name
|
||||||
makefile = 'Makefile'
|
makefile = 'Makefile'
|
||||||
|
|
||||||
# parse command line
|
# parse command line
|
||||||
try:
|
try:
|
||||||
opts, args = getopt.getopt(sys.argv[1:], 'he:o:p:P:')
|
opts, args = getopt.getopt(sys.argv[1:], 'he:o:p:P:')
|
||||||
except getopt.error, msg:
|
except getopt.error, msg:
|
||||||
usage('getopt error: ' + str(msg))
|
usage('getopt error: ' + str(msg))
|
||||||
|
|
||||||
# proces option arguments
|
# proces option arguments
|
||||||
for o, a in opts:
|
for o, a in opts:
|
||||||
if o == '-h':
|
if o == '-h':
|
||||||
print __doc__
|
print __doc__
|
||||||
return
|
return
|
||||||
if o == '-e':
|
if o == '-e':
|
||||||
extensions.append(a)
|
extensions.append(a)
|
||||||
if o == '-o':
|
if o == '-o':
|
||||||
odir = a
|
odir = a
|
||||||
if o == '-p':
|
if o == '-p':
|
||||||
prefix = a
|
prefix = a
|
||||||
if o == '-P':
|
if o == '-P':
|
||||||
exec_prefix = a
|
exec_prefix = a
|
||||||
|
|
||||||
# default prefix and exec_prefix
|
|
||||||
if not exec_prefix:
|
|
||||||
if prefix:
|
|
||||||
exec_prefix = prefix
|
|
||||||
else:
|
|
||||||
exec_prefix = sys.exec_prefix
|
|
||||||
if not prefix:
|
|
||||||
prefix = sys.prefix
|
|
||||||
|
|
||||||
# determine whether -p points to the Python source tree
|
# default prefix and exec_prefix
|
||||||
ishome = os.path.exists(os.path.join(prefix, 'Include', 'pythonrun.h'))
|
if not exec_prefix:
|
||||||
|
if prefix:
|
||||||
|
exec_prefix = prefix
|
||||||
|
else:
|
||||||
|
exec_prefix = sys.exec_prefix
|
||||||
|
if not prefix:
|
||||||
|
prefix = sys.prefix
|
||||||
|
|
||||||
# locations derived from options
|
# determine whether -p points to the Python source tree
|
||||||
version = sys.version[:3]
|
ishome = os.path.exists(os.path.join(prefix, 'Include', 'pythonrun.h'))
|
||||||
if ishome:
|
|
||||||
print "(Using Python source directory)"
|
|
||||||
binlib = exec_prefix
|
|
||||||
incldir = os.path.join(prefix, 'Include')
|
|
||||||
config_c_in = os.path.join(prefix, 'Modules', 'config.c.in')
|
|
||||||
frozenmain_c = os.path.join(prefix, 'Modules', 'frozenmain.c')
|
|
||||||
makefile_in = os.path.join(exec_prefix, 'Modules', 'Makefile')
|
|
||||||
else:
|
|
||||||
binlib = os.path.join(exec_prefix,
|
|
||||||
'lib', 'python%s' % version, 'config')
|
|
||||||
incldir = os.path.join(prefix, 'include', 'python%s' % version)
|
|
||||||
config_c_in = os.path.join(binlib, 'config.c.in')
|
|
||||||
frozenmain_c = os.path.join(binlib, 'frozenmain.c')
|
|
||||||
makefile_in = os.path.join(binlib, 'Makefile')
|
|
||||||
supp_sources = []
|
|
||||||
defines = []
|
|
||||||
includes = ['-I' + incldir, '-I' + binlib]
|
|
||||||
|
|
||||||
# sanity check of directories and files
|
# locations derived from options
|
||||||
for dir in [prefix, exec_prefix, binlib, incldir] + extensions:
|
version = sys.version[:3]
|
||||||
if not os.path.exists(dir):
|
if ishome:
|
||||||
usage('needed directory %s not found' % dir)
|
print "(Using Python source directory)"
|
||||||
if not os.path.isdir(dir):
|
binlib = exec_prefix
|
||||||
usage('%s: not a directory' % dir)
|
incldir = os.path.join(prefix, 'Include')
|
||||||
for file in [config_c_in, makefile_in] + supp_sources:
|
config_c_in = os.path.join(prefix, 'Modules', 'config.c.in')
|
||||||
if not os.path.exists(file):
|
frozenmain_c = os.path.join(prefix, 'Modules', 'frozenmain.c')
|
||||||
usage('needed file %s not found' % file)
|
makefile_in = os.path.join(exec_prefix, 'Modules', 'Makefile')
|
||||||
if not os.path.isfile(file):
|
else:
|
||||||
usage('%s: not a plain file' % file)
|
binlib = os.path.join(exec_prefix,
|
||||||
for dir in extensions:
|
'lib', 'python%s' % version, 'config')
|
||||||
setup = os.path.join(dir, 'Setup')
|
incldir = os.path.join(prefix, 'include', 'python%s' % version)
|
||||||
if not os.path.exists(setup):
|
config_c_in = os.path.join(binlib, 'config.c.in')
|
||||||
usage('needed file %s not found' % setup)
|
frozenmain_c = os.path.join(binlib, 'frozenmain.c')
|
||||||
if not os.path.isfile(setup):
|
makefile_in = os.path.join(binlib, 'Makefile')
|
||||||
usage('%s: not a plain file' % setup)
|
supp_sources = []
|
||||||
|
defines = []
|
||||||
|
includes = ['-I' + incldir, '-I' + binlib]
|
||||||
|
|
||||||
# check that enough arguments are passed
|
# sanity check of directories and files
|
||||||
if not args:
|
for dir in [prefix, exec_prefix, binlib, incldir] + extensions:
|
||||||
usage('at least one filename argument required')
|
if not os.path.exists(dir):
|
||||||
|
usage('needed directory %s not found' % dir)
|
||||||
|
if not os.path.isdir(dir):
|
||||||
|
usage('%s: not a directory' % dir)
|
||||||
|
for file in [config_c_in, makefile_in] + supp_sources:
|
||||||
|
if not os.path.exists(file):
|
||||||
|
usage('needed file %s not found' % file)
|
||||||
|
if not os.path.isfile(file):
|
||||||
|
usage('%s: not a plain file' % file)
|
||||||
|
for dir in extensions:
|
||||||
|
setup = os.path.join(dir, 'Setup')
|
||||||
|
if not os.path.exists(setup):
|
||||||
|
usage('needed file %s not found' % setup)
|
||||||
|
if not os.path.isfile(setup):
|
||||||
|
usage('%s: not a plain file' % setup)
|
||||||
|
|
||||||
# check that the script name ends in ".py"
|
# check that enough arguments are passed
|
||||||
if args[0][-3:] != ".py":
|
if not args:
|
||||||
usage('the script name must have a .py suffix')
|
usage('at least one filename argument required')
|
||||||
|
|
||||||
# check that file arguments exist
|
# check that the script name ends in ".py"
|
||||||
for arg in args:
|
if args[0][-3:] != ".py":
|
||||||
if not os.path.exists(arg):
|
usage('the script name must have a .py suffix')
|
||||||
usage('argument %s not found' % arg)
|
|
||||||
if not os.path.isfile(arg):
|
|
||||||
usage('%s: not a plain file' % arg)
|
|
||||||
|
|
||||||
# process non-option arguments
|
# check that file arguments exist
|
||||||
scriptfile = args[0]
|
for arg in args:
|
||||||
modules = args[1:]
|
if not os.path.exists(arg):
|
||||||
|
usage('argument %s not found' % arg)
|
||||||
|
if not os.path.isfile(arg):
|
||||||
|
usage('%s: not a plain file' % arg)
|
||||||
|
|
||||||
# derive target name from script name
|
# process non-option arguments
|
||||||
base = os.path.basename(scriptfile)
|
scriptfile = args[0]
|
||||||
base, ext = os.path.splitext(base)
|
modules = args[1:]
|
||||||
if base:
|
|
||||||
if base != scriptfile:
|
|
||||||
target = base
|
|
||||||
else:
|
|
||||||
target = base + '.bin'
|
|
||||||
|
|
||||||
# handle -o option
|
|
||||||
base_frozen_c = frozen_c
|
|
||||||
base_config_c = config_c
|
|
||||||
base_target = target
|
|
||||||
if odir and not os.path.isdir(odir):
|
|
||||||
try:
|
|
||||||
os.mkdir(odir)
|
|
||||||
print "Created output directory", odir
|
|
||||||
except os.error, msg:
|
|
||||||
usage('%s: mkdir failed (%s)' % (odir, str(msg)))
|
|
||||||
if odir:
|
|
||||||
frozen_c = os.path.join(odir, frozen_c)
|
|
||||||
config_c = os.path.join(odir, config_c)
|
|
||||||
target = os.path.join(odir, target)
|
|
||||||
makefile = os.path.join(odir,makefile)
|
|
||||||
|
|
||||||
# Actual work starts here...
|
# derive target name from script name
|
||||||
|
base = os.path.basename(scriptfile)
|
||||||
|
base, ext = os.path.splitext(base)
|
||||||
|
if base:
|
||||||
|
if base != scriptfile:
|
||||||
|
target = base
|
||||||
|
else:
|
||||||
|
target = base + '.bin'
|
||||||
|
|
||||||
dict = findmodules.findmodules(scriptfile, modules, path)
|
# handle -o option
|
||||||
names = dict.keys()
|
base_frozen_c = frozen_c
|
||||||
names.sort()
|
base_config_c = config_c
|
||||||
print "Modules being frozen:"
|
base_target = target
|
||||||
for name in names:
|
if odir and not os.path.isdir(odir):
|
||||||
print '\t', name
|
try:
|
||||||
|
os.mkdir(odir)
|
||||||
|
print "Created output directory", odir
|
||||||
|
except os.error, msg:
|
||||||
|
usage('%s: mkdir failed (%s)' % (odir, str(msg)))
|
||||||
|
if odir:
|
||||||
|
frozen_c = os.path.join(odir, frozen_c)
|
||||||
|
config_c = os.path.join(odir, config_c)
|
||||||
|
target = os.path.join(odir, target)
|
||||||
|
makefile = os.path.join(odir, makefile)
|
||||||
|
|
||||||
backup = frozen_c + '~'
|
# Actual work starts here...
|
||||||
try:
|
|
||||||
os.rename(frozen_c, backup)
|
|
||||||
except os.error:
|
|
||||||
backup = None
|
|
||||||
outfp = open(frozen_c, 'w')
|
|
||||||
try:
|
|
||||||
makefreeze.makefreeze(outfp, dict)
|
|
||||||
finally:
|
|
||||||
outfp.close()
|
|
||||||
if backup:
|
|
||||||
if cmp.cmp(backup, frozen_c):
|
|
||||||
sys.stderr.write('%s not changed, not written\n' %
|
|
||||||
frozen_c)
|
|
||||||
os.rename(backup, frozen_c)
|
|
||||||
|
|
||||||
builtins = []
|
dict = findmodules.findmodules(scriptfile, modules, path)
|
||||||
unknown = []
|
names = dict.keys()
|
||||||
mods = dict.keys()
|
names.sort()
|
||||||
mods.sort()
|
print "Modules being frozen:"
|
||||||
for mod in mods:
|
for name in names:
|
||||||
if dict[mod] == '<builtin>':
|
print '\t', name
|
||||||
builtins.append(mod)
|
|
||||||
elif dict[mod] == '<unknown>':
|
|
||||||
unknown.append(mod)
|
|
||||||
|
|
||||||
addfiles = []
|
backup = frozen_c + '~'
|
||||||
if unknown:
|
try:
|
||||||
addfiles, addmods = \
|
os.rename(frozen_c, backup)
|
||||||
checkextensions.checkextensions(unknown, extensions)
|
except os.error:
|
||||||
for mod in addmods:
|
backup = None
|
||||||
unknown.remove(mod)
|
outfp = open(frozen_c, 'w')
|
||||||
builtins = builtins + addmods
|
try:
|
||||||
if unknown:
|
makefreeze.makefreeze(outfp, dict)
|
||||||
sys.stderr.write('Warning: unknown modules remain: %s\n' %
|
finally:
|
||||||
string.join(unknown))
|
outfp.close()
|
||||||
|
if backup:
|
||||||
|
if cmp.cmp(backup, frozen_c):
|
||||||
|
sys.stderr.write('%s not changed, not written\n' %
|
||||||
|
frozen_c)
|
||||||
|
os.rename(backup, frozen_c)
|
||||||
|
|
||||||
builtins.sort()
|
builtins = []
|
||||||
infp = open(config_c_in)
|
unknown = []
|
||||||
backup = config_c + '~'
|
mods = dict.keys()
|
||||||
try:
|
mods.sort()
|
||||||
os.rename(config_c, backup)
|
for mod in mods:
|
||||||
except os.error:
|
if dict[mod] == '<builtin>':
|
||||||
backup = None
|
builtins.append(mod)
|
||||||
outfp = open(config_c, 'w')
|
elif dict[mod] == '<unknown>':
|
||||||
try:
|
unknown.append(mod)
|
||||||
makeconfig.makeconfig(infp, outfp, builtins)
|
|
||||||
finally:
|
|
||||||
outfp.close()
|
|
||||||
infp.close()
|
|
||||||
if backup:
|
|
||||||
if cmp.cmp(backup, config_c):
|
|
||||||
sys.stderr.write('%s not changed, not written\n' %
|
|
||||||
config_c)
|
|
||||||
os.rename(backup, config_c)
|
|
||||||
|
|
||||||
cflags = defines + includes + ['$(OPT)']
|
addfiles = []
|
||||||
libs = [os.path.join(binlib, 'libpython$(VERSION).a')]
|
if unknown:
|
||||||
|
addfiles, addmods = \
|
||||||
|
checkextensions.checkextensions(unknown, extensions)
|
||||||
|
for mod in addmods:
|
||||||
|
unknown.remove(mod)
|
||||||
|
builtins = builtins + addmods
|
||||||
|
if unknown:
|
||||||
|
sys.stderr.write('Warning: unknown modules remain: %s\n' %
|
||||||
|
string.join(unknown))
|
||||||
|
|
||||||
makevars = parsesetup.getmakevars(makefile_in)
|
builtins.sort()
|
||||||
somevars = {}
|
infp = open(config_c_in)
|
||||||
for key in makevars.keys():
|
backup = config_c + '~'
|
||||||
somevars[key] = makevars[key]
|
try:
|
||||||
|
os.rename(config_c, backup)
|
||||||
|
except os.error:
|
||||||
|
backup = None
|
||||||
|
outfp = open(config_c, 'w')
|
||||||
|
try:
|
||||||
|
makeconfig.makeconfig(infp, outfp, builtins)
|
||||||
|
finally:
|
||||||
|
outfp.close()
|
||||||
|
infp.close()
|
||||||
|
if backup:
|
||||||
|
if cmp.cmp(backup, config_c):
|
||||||
|
sys.stderr.write('%s not changed, not written\n' %
|
||||||
|
config_c)
|
||||||
|
os.rename(backup, config_c)
|
||||||
|
|
||||||
somevars['CFLAGS'] = string.join(cflags) # override
|
cflags = defines + includes + ['$(OPT)']
|
||||||
files = ['$(OPT)', '$(LDFLAGS)', base_config_c, base_frozen_c] + \
|
libs = [os.path.join(binlib, 'libpython$(VERSION).a')]
|
||||||
supp_sources + addfiles + libs + \
|
|
||||||
['$(MODLIBS)', '$(LIBS)', '$(SYSLIBS)']
|
|
||||||
|
|
||||||
backup = makefile + '~'
|
makevars = parsesetup.getmakevars(makefile_in)
|
||||||
try:
|
somevars = {}
|
||||||
os.rename(makefile, backup)
|
for key in makevars.keys():
|
||||||
except os.error:
|
somevars[key] = makevars[key]
|
||||||
backup = None
|
|
||||||
outfp = open(makefile, 'w')
|
|
||||||
try:
|
|
||||||
makemakefile.makemakefile(outfp, somevars, files, base_target)
|
|
||||||
finally:
|
|
||||||
outfp.close()
|
|
||||||
if backup:
|
|
||||||
if not cmp.cmp(backup, makefile):
|
|
||||||
print 'previous Makefile saved as', backup
|
|
||||||
else:
|
|
||||||
sys.stderr.write('%s not changed, not written\n' %
|
|
||||||
makefile)
|
|
||||||
os.rename(backup, makefile)
|
|
||||||
|
|
||||||
# Done!
|
somevars['CFLAGS'] = string.join(cflags) # override
|
||||||
|
files = ['$(OPT)', '$(LDFLAGS)', base_config_c, base_frozen_c] + \
|
||||||
|
supp_sources + addfiles + libs + \
|
||||||
|
['$(MODLIBS)', '$(LIBS)', '$(SYSLIBS)']
|
||||||
|
|
||||||
if odir:
|
backup = makefile + '~'
|
||||||
print 'Now run "make" in', odir,
|
try:
|
||||||
print 'to build the target:', base_target
|
os.rename(makefile, backup)
|
||||||
else:
|
except os.error:
|
||||||
print 'Now run "make" to build the target:', base_target
|
backup = None
|
||||||
|
outfp = open(makefile, 'w')
|
||||||
|
try:
|
||||||
|
makemakefile.makemakefile(outfp, somevars, files, base_target)
|
||||||
|
finally:
|
||||||
|
outfp.close()
|
||||||
|
if backup:
|
||||||
|
if not cmp.cmp(backup, makefile):
|
||||||
|
print 'previous Makefile saved as', backup
|
||||||
|
else:
|
||||||
|
sys.stderr.write('%s not changed, not written\n' %
|
||||||
|
makefile)
|
||||||
|
os.rename(backup, makefile)
|
||||||
|
|
||||||
|
# Done!
|
||||||
|
|
||||||
|
if odir:
|
||||||
|
print 'Now run "make" in', odir,
|
||||||
|
print 'to build the target:', base_target
|
||||||
|
else:
|
||||||
|
print 'Now run "make" to build the target:', base_target
|
||||||
|
|
||||||
|
|
||||||
# Print usage message and exit
|
# Print usage message and exit
|
||||||
|
|
||||||
def usage(msg):
|
def usage(msg):
|
||||||
sys.stdout = sys.stderr
|
sys.stdout = sys.stderr
|
||||||
print "Error:", msg
|
print "Error:", msg
|
||||||
print "Use ``%s -h'' for help" % sys.argv[0]
|
print "Use ``%s -h'' for help" % sys.argv[0]
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
|
|
||||||
|
|
||||||
main()
|
main()
|
||||||
|
|
||||||
|
# Local Variables:
|
||||||
|
# indent-tabs-mode: nil
|
||||||
|
# End:
|
||||||
|
|
Loading…
Reference in New Issue