Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 58a5948

Browse files
committed
Changes for building under windows.
1 parent 41b9f00 commit 58a5948

2 files changed

Lines changed: 87 additions & 9 deletions

File tree

Tools/freeze/freeze.py

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@
2828
2929
-h: Print this help message.
3030
31+
-w: Toggle Windows (NT or 95) behavior.
32+
(For debugging only -- on a win32 platform, win32 behaviour
33+
is automatic.)
34+
35+
-s subsystem: Specify the subsystem; 'windows' or 'console' (default).
36+
(For Windows only.)
37+
3138
Arguments:
3239
3340
script.py: The Python script to be executed by the resulting binary.
@@ -76,16 +83,18 @@ def main():
7683
extensions = []
7784
path = sys.path
7885
odir = ''
86+
win = sys.platform[:3] == 'win'
7987

8088
# output files
8189
frozen_c = 'frozen.c'
8290
config_c = 'config.c'
8391
target = 'a.out' # normally derived from script name
8492
makefile = 'Makefile'
93+
subsystem = 'console'
8594

8695
# parse command line
8796
try:
88-
opts, args = getopt.getopt(sys.argv[1:], 'he:o:p:P:')
97+
opts, args = getopt.getopt(sys.argv[1:], 'he:o:p:P:s:w')
8998
except getopt.error, msg:
9099
usage('getopt error: ' + str(msg))
91100

@@ -102,6 +111,12 @@ def main():
102111
prefix = a
103112
if o == '-P':
104113
exec_prefix = a
114+
if o == '-w':
115+
win = not win
116+
if o == '-s':
117+
if not win:
118+
usage("-s subsystem option only on Windows")
119+
subsystem = a
105120

106121
# default prefix and exec_prefix
107122
if not exec_prefix:
@@ -122,7 +137,7 @@ def main():
122137
binlib = exec_prefix
123138
incldir = os.path.join(prefix, 'Include')
124139
config_c_in = os.path.join(prefix, 'Modules', 'config.c.in')
125-
frozenmain_c = os.path.join(prefix, 'Modules', 'frozenmain.c')
140+
frozenmain_c = os.path.join(prefix, 'Python', 'frozenmain.c')
126141
makefile_in = os.path.join(exec_prefix, 'Modules', 'Makefile')
127142
else:
128143
binlib = os.path.join(exec_prefix,
@@ -141,17 +156,22 @@ def main():
141156
usage('needed directory %s not found' % dir)
142157
if not os.path.isdir(dir):
143158
usage('%s: not a directory' % dir)
144-
for file in [config_c_in, makefile_in] + supp_sources:
159+
if win:
160+
files = supp_sources
161+
else:
162+
files = [config_c_in, makefile_in] + supp_sources
163+
for file in supp_sources:
145164
if not os.path.exists(file):
146165
usage('needed file %s not found' % file)
147166
if not os.path.isfile(file):
148167
usage('%s: not a plain file' % file)
149-
for dir in extensions:
150-
setup = os.path.join(dir, 'Setup')
151-
if not os.path.exists(setup):
152-
usage('needed file %s not found' % setup)
153-
if not os.path.isfile(setup):
154-
usage('%s: not a plain file' % setup)
168+
if not win:
169+
for dir in extensions:
170+
setup = os.path.join(dir, 'Setup')
171+
if not os.path.exists(setup):
172+
usage('needed file %s not found' % setup)
173+
if not os.path.isfile(setup):
174+
usage('%s: not a plain file' % setup)
155175

156176
# check that enough arguments are passed
157177
if not args:
@@ -222,6 +242,19 @@ def main():
222242
frozen_c)
223243
os.rename(backup, frozen_c)
224244

245+
if win:
246+
# Taking a shortcut here...
247+
import winmakemakefile
248+
outfp = open(makefile, 'w')
249+
try:
250+
winmakemakefile.makemakefile(outfp,
251+
locals(),
252+
[frozenmain_c, frozen_c],
253+
target)
254+
finally:
255+
outfp.close()
256+
return
257+
225258
builtins = []
226259
unknown = []
227260
mods = dict.keys()

Tools/freeze/winmakemakefile.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import sys, os, string
2+
3+
def makemakefile(outfp, vars, files, target):
4+
save = sys.stdout
5+
try:
6+
sys.stdout = outfp
7+
realwork(vars, files, target)
8+
finally:
9+
sys.stdout = save
10+
11+
def realwork(vars, files, target):
12+
print "# Makefile for Windows (NT or 95) generated by freeze.py script"
13+
print
14+
print "target =", target
15+
print "pythonhome =", vars['prefix']
16+
print "pythonlib =", vars['exec_prefix'] + "/pcbuild/release/python15.lib"
17+
print "subsystem =", vars['subsystem']
18+
print
19+
print "all: $(target).exe"
20+
print
21+
22+
objects = []
23+
for file in files:
24+
base = os.path.basename(file)
25+
base, ext = os.path.splitext(base)
26+
objects.append(base + ".obj")
27+
print "%s.obj: %s" % (base, file)
28+
print "\t$(CC) -c $(cdl)",
29+
print "-I$(pythonhome)/Include -I$(pythonhome)/PC \\"
30+
print "\t\t$(cflags) $(cdebug) $(cinclude) \\"
31+
print "\t\t", file
32+
print
33+
34+
print "$(target).exe:",
35+
for obj in objects: print obj,
36+
print
37+
print "\tlink -out:$(target).exe",
38+
for obj in objects: print obj,
39+
print "\\"
40+
print "\t\t$(pythonlib) $(lcustom) shell32.lib comdlg32.lib wsock32.lib \\"
41+
print "\t\t-subsystem:$(subsystem) $(resources)"
42+
43+
# Local Variables:
44+
# indent-tabs-mode: nil
45+
# End:

0 commit comments

Comments
 (0)