annotate PCbuild/build_ssl.py @ 54294:dba767bc3155 legacy-trunk

remove mention of old ctypes version
author Benjamin Peterson <benjamin@python.org>
date Sat, 23 May 2009 20:59:09 +0000
parents 89cfb38a4b98
children 787b969d37f0 4d3b9b4caff0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
43972
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
1 # Script for building the _ssl and _hashlib modules for Windows.
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
2 # Uses Perl to setup the OpenSSL environment correctly
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
3 # and build OpenSSL, then invokes a simple nmake session
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
4 # for the actual _ssl.pyd and _hashlib.pyd DLLs.
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
5
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
6 # THEORETICALLY, you can:
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
7 # * Unpack the latest SSL release one level above your main Python source
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
8 # directory. It is likely you will already find the zlib library and
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
9 # any other external packages there.
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
10 # * Install ActivePerl and ensure it is somewhere on your path.
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
11 # * Run this script from the PCBuild directory.
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
12 #
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
13 # it should configure and build SSL, then build the _ssl and _hashlib
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
14 # Python extensions without intervention.
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
15
43981
62cf08a64bc2 Backport of PCbuild9 fixes from py3k r59130
Christian Heimes <christian@cheimes.de>
parents: 43972
diff changeset
16 # Modified by Christian Heimes
62cf08a64bc2 Backport of PCbuild9 fixes from py3k r59130
Christian Heimes <christian@cheimes.de>
parents: 43972
diff changeset
17 # Now this script supports pre-generated makefiles and assembly files.
62cf08a64bc2 Backport of PCbuild9 fixes from py3k r59130
Christian Heimes <christian@cheimes.de>
parents: 43972
diff changeset
18 # Developers don't need an installation of Perl anymore to build Python. A svn
62cf08a64bc2 Backport of PCbuild9 fixes from py3k r59130
Christian Heimes <christian@cheimes.de>
parents: 43972
diff changeset
19 # checkout from our svn repository is enough.
62cf08a64bc2 Backport of PCbuild9 fixes from py3k r59130
Christian Heimes <christian@cheimes.de>
parents: 43972
diff changeset
20 #
62cf08a64bc2 Backport of PCbuild9 fixes from py3k r59130
Christian Heimes <christian@cheimes.de>
parents: 43972
diff changeset
21 # In Order to create the files in the case of an update you still need Perl.
62cf08a64bc2 Backport of PCbuild9 fixes from py3k r59130
Christian Heimes <christian@cheimes.de>
parents: 43972
diff changeset
22 # Run build_ssl in this order:
62cf08a64bc2 Backport of PCbuild9 fixes from py3k r59130
Christian Heimes <christian@cheimes.de>
parents: 43972
diff changeset
23 # python.exe build_ssl.py Release x64
62cf08a64bc2 Backport of PCbuild9 fixes from py3k r59130
Christian Heimes <christian@cheimes.de>
parents: 43972
diff changeset
24 # python.exe build_ssl.py Release Win32
62cf08a64bc2 Backport of PCbuild9 fixes from py3k r59130
Christian Heimes <christian@cheimes.de>
parents: 43972
diff changeset
25
43972
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
26 import os, sys, re, shutil
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
27
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
28 # Find all "foo.exe" files on the PATH.
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
29 def find_all_on_path(filename, extras = None):
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
30 entries = os.environ["PATH"].split(os.pathsep)
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
31 ret = []
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
32 for p in entries:
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
33 fname = os.path.abspath(os.path.join(p, filename))
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
34 if os.path.isfile(fname) and fname not in ret:
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
35 ret.append(fname)
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
36 if extras:
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
37 for p in extras:
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
38 fname = os.path.abspath(os.path.join(p, filename))
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
39 if os.path.isfile(fname) and fname not in ret:
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
40 ret.append(fname)
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
41 return ret
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
42
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
43 # Find a suitable Perl installation for OpenSSL.
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
44 # cygwin perl does *not* work. ActivePerl does.
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
45 # Being a Perl dummy, the simplest way I can check is if the "Win32" package
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
46 # is available.
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
47 def find_working_perl(perls):
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
48 for perl in perls:
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
49 fh = os.popen(perl + ' -e "use Win32;"')
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
50 fh.read()
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
51 rc = fh.close()
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
52 if rc:
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
53 continue
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
54 return perl
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
55 print("Can not find a suitable PERL:")
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
56 if perls:
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
57 print(" the following perl interpreters were found:")
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
58 for p in perls:
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
59 print(" ", p)
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
60 print(" None of these versions appear suitable for building OpenSSL")
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
61 else:
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
62 print(" NO perl interpreters were found on this machine at all!")
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
63 print(" Please install ActivePerl and ensure it appears on your path")
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
64 return None
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
65
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
66 # Locate the best SSL directory given a few roots to look into.
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
67 def find_best_ssl_dir(sources):
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
68 candidates = []
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
69 for s in sources:
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
70 try:
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
71 # note: do not abspath s; the build will fail if any
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
72 # higher up directory name has spaces in it.
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
73 fnames = os.listdir(s)
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
74 except os.error:
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
75 fnames = []
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
76 for fname in fnames:
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
77 fqn = os.path.join(s, fname)
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
78 if os.path.isdir(fqn) and fname.startswith("openssl-"):
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
79 candidates.append(fqn)
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
80 # Now we have all the candidates, locate the best.
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
81 best_parts = []
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
82 best_name = None
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
83 for c in candidates:
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
84 parts = re.split("[.-]", os.path.basename(c))[1:]
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
85 # eg - openssl-0.9.7-beta1 - ignore all "beta" or any other qualifiers
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
86 if len(parts) >= 4:
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
87 continue
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
88 if parts > best_parts:
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
89 best_parts = parts
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
90 best_name = c
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
91 if best_name is not None:
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
92 print("Found an SSL directory at '%s'" % (best_name,))
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
93 else:
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
94 print("Could not find an SSL directory in '%s'" % (sources,))
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
95 sys.stdout.flush()
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
96 return best_name
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
97
43981
62cf08a64bc2 Backport of PCbuild9 fixes from py3k r59130
Christian Heimes <christian@cheimes.de>
parents: 43972
diff changeset
98 def create_makefile64(makefile, m32):
62cf08a64bc2 Backport of PCbuild9 fixes from py3k r59130
Christian Heimes <christian@cheimes.de>
parents: 43972
diff changeset
99 """Create and fix makefile for 64bit
43972
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
100
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
101 Replace 32 with 64bit directories
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
102 """
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
103 if not os.path.isfile(m32):
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
104 return
45575
89cfb38a4b98 Port build_ssl.py to 2.4; support HOST_PYTHON variable
Martin v. Löwis <martin@v.loewis.de>
parents: 44395
diff changeset
105 # 2.4 compatibility
89cfb38a4b98 Port build_ssl.py to 2.4; support HOST_PYTHON variable
Martin v. Löwis <martin@v.loewis.de>
parents: 44395
diff changeset
106 fin = open(m32)
89cfb38a4b98 Port build_ssl.py to 2.4; support HOST_PYTHON variable
Martin v. Löwis <martin@v.loewis.de>
parents: 44395
diff changeset
107 if 1: # with open(m32) as fin:
89cfb38a4b98 Port build_ssl.py to 2.4; support HOST_PYTHON variable
Martin v. Löwis <martin@v.loewis.de>
parents: 44395
diff changeset
108 fout = open(makefile, 'w')
89cfb38a4b98 Port build_ssl.py to 2.4; support HOST_PYTHON variable
Martin v. Löwis <martin@v.loewis.de>
parents: 44395
diff changeset
109 if 1: # with open(makefile, 'w') as fout:
43972
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
110 for line in fin:
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
111 line = line.replace("=tmp32", "=tmp64")
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
112 line = line.replace("=out32", "=out64")
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
113 line = line.replace("=inc32", "=inc64")
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
114 # force 64 bit machine
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
115 line = line.replace("MKLIB=lib", "MKLIB=lib /MACHINE:X64")
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
116 line = line.replace("LFLAGS=", "LFLAGS=/MACHINE:X64 ")
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
117 # don't link against the lib on 64bit systems
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
118 line = line.replace("bufferoverflowu.lib", "")
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
119 fout.write(line)
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
120 os.unlink(m32)
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
121
43981
62cf08a64bc2 Backport of PCbuild9 fixes from py3k r59130
Christian Heimes <christian@cheimes.de>
parents: 43972
diff changeset
122 def fix_makefile(makefile):
62cf08a64bc2 Backport of PCbuild9 fixes from py3k r59130
Christian Heimes <christian@cheimes.de>
parents: 43972
diff changeset
123 """Fix some stuff in all makefiles
62cf08a64bc2 Backport of PCbuild9 fixes from py3k r59130
Christian Heimes <christian@cheimes.de>
parents: 43972
diff changeset
124 """
62cf08a64bc2 Backport of PCbuild9 fixes from py3k r59130
Christian Heimes <christian@cheimes.de>
parents: 43972
diff changeset
125 if not os.path.isfile(makefile):
62cf08a64bc2 Backport of PCbuild9 fixes from py3k r59130
Christian Heimes <christian@cheimes.de>
parents: 43972
diff changeset
126 return
45575
89cfb38a4b98 Port build_ssl.py to 2.4; support HOST_PYTHON variable
Martin v. Löwis <martin@v.loewis.de>
parents: 44395
diff changeset
127 # 2.4 compatibility
89cfb38a4b98 Port build_ssl.py to 2.4; support HOST_PYTHON variable
Martin v. Löwis <martin@v.loewis.de>
parents: 44395
diff changeset
128 fin = open(makefile)
89cfb38a4b98 Port build_ssl.py to 2.4; support HOST_PYTHON variable
Martin v. Löwis <martin@v.loewis.de>
parents: 44395
diff changeset
129 if 1: # with open(makefile) as fin:
43981
62cf08a64bc2 Backport of PCbuild9 fixes from py3k r59130
Christian Heimes <christian@cheimes.de>
parents: 43972
diff changeset
130 lines = fin.readlines()
45575
89cfb38a4b98 Port build_ssl.py to 2.4; support HOST_PYTHON variable
Martin v. Löwis <martin@v.loewis.de>
parents: 44395
diff changeset
131 fin.close()
89cfb38a4b98 Port build_ssl.py to 2.4; support HOST_PYTHON variable
Martin v. Löwis <martin@v.loewis.de>
parents: 44395
diff changeset
132 fout = open(makefile, 'w')
89cfb38a4b98 Port build_ssl.py to 2.4; support HOST_PYTHON variable
Martin v. Löwis <martin@v.loewis.de>
parents: 44395
diff changeset
133 if 1: # with open(makefile, 'w') as fout:
43981
62cf08a64bc2 Backport of PCbuild9 fixes from py3k r59130
Christian Heimes <christian@cheimes.de>
parents: 43972
diff changeset
134 for line in lines:
62cf08a64bc2 Backport of PCbuild9 fixes from py3k r59130
Christian Heimes <christian@cheimes.de>
parents: 43972
diff changeset
135 if line.startswith("PERL="):
62cf08a64bc2 Backport of PCbuild9 fixes from py3k r59130
Christian Heimes <christian@cheimes.de>
parents: 43972
diff changeset
136 continue
62cf08a64bc2 Backport of PCbuild9 fixes from py3k r59130
Christian Heimes <christian@cheimes.de>
parents: 43972
diff changeset
137 if line.startswith("CP="):
62cf08a64bc2 Backport of PCbuild9 fixes from py3k r59130
Christian Heimes <christian@cheimes.de>
parents: 43972
diff changeset
138 line = "CP=copy\n"
62cf08a64bc2 Backport of PCbuild9 fixes from py3k r59130
Christian Heimes <christian@cheimes.de>
parents: 43972
diff changeset
139 if line.startswith("MKDIR="):
62cf08a64bc2 Backport of PCbuild9 fixes from py3k r59130
Christian Heimes <christian@cheimes.de>
parents: 43972
diff changeset
140 line = "MKDIR=mkdir\n"
43999
b9b94785b2c7 Backport of fixes from py3k branch
Christian Heimes <christian@cheimes.de>
parents: 43981
diff changeset
141 if line.startswith("CFLAG="):
b9b94785b2c7 Backport of fixes from py3k branch
Christian Heimes <christian@cheimes.de>
parents: 43981
diff changeset
142 line = line.strip()
b9b94785b2c7 Backport of fixes from py3k branch
Christian Heimes <christian@cheimes.de>
parents: 43981
diff changeset
143 for algo in ("RC5", "MDC2", "IDEA"):
b9b94785b2c7 Backport of fixes from py3k branch
Christian Heimes <christian@cheimes.de>
parents: 43981
diff changeset
144 noalgo = " -DOPENSSL_NO_%s" % algo
b9b94785b2c7 Backport of fixes from py3k branch
Christian Heimes <christian@cheimes.de>
parents: 43981
diff changeset
145 if noalgo not in line:
b9b94785b2c7 Backport of fixes from py3k branch
Christian Heimes <christian@cheimes.de>
parents: 43981
diff changeset
146 line = line + noalgo
b9b94785b2c7 Backport of fixes from py3k branch
Christian Heimes <christian@cheimes.de>
parents: 43981
diff changeset
147 line = line + '\n'
43981
62cf08a64bc2 Backport of PCbuild9 fixes from py3k r59130
Christian Heimes <christian@cheimes.de>
parents: 43972
diff changeset
148 fout.write(line)
45575
89cfb38a4b98 Port build_ssl.py to 2.4; support HOST_PYTHON variable
Martin v. Löwis <martin@v.loewis.de>
parents: 44395
diff changeset
149 fout.close()
43981
62cf08a64bc2 Backport of PCbuild9 fixes from py3k r59130
Christian Heimes <christian@cheimes.de>
parents: 43972
diff changeset
150
43972
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
151 def run_configure(configure, do_script):
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
152 print("perl Configure "+configure)
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
153 os.system("perl Configure "+configure)
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
154 print(do_script)
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
155 os.system(do_script)
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
156
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
157 def main():
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
158 build_all = "-a" in sys.argv
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
159 if sys.argv[1] == "Release":
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
160 debug = False
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
161 elif sys.argv[1] == "Debug":
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
162 debug = True
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
163 else:
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
164 raise ValueError(str(sys.argv))
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
165
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
166 if sys.argv[2] == "Win32":
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
167 arch = "x86"
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
168 configure = "VC-WIN32"
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
169 do_script = "ms\\do_nasm"
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
170 makefile="ms\\nt.mak"
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
171 m32 = makefile
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
172 elif sys.argv[2] == "x64":
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
173 arch="amd64"
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
174 configure = "VC-WIN64A"
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
175 do_script = "ms\\do_win64a"
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
176 makefile = "ms\\nt64.mak"
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
177 m32 = makefile.replace('64', '')
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
178 #os.environ["VSEXTCOMP_USECL"] = "MS_OPTERON"
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
179 else:
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
180 raise ValueError(str(sys.argv))
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
181
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
182 make_flags = ""
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
183 if build_all:
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
184 make_flags = "-a"
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
185 # perl should be on the path, but we also look in "\perl" and "c:\\perl"
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
186 # as "well known" locations
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
187 perls = find_all_on_path("perl.exe", ["\\perl\\bin", "C:\\perl\\bin"])
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
188 perl = find_working_perl(perls)
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
189 if perl is None:
43981
62cf08a64bc2 Backport of PCbuild9 fixes from py3k r59130
Christian Heimes <christian@cheimes.de>
parents: 43972
diff changeset
190 print("No Perl installation was found. Existing Makefiles are used.")
43972
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
191
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
192 print("Found a working perl at '%s'" % (perl,))
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
193 sys.stdout.flush()
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
194 # Look for SSL 2 levels up from pcbuild - ie, same place zlib etc all live.
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
195 ssl_dir = find_best_ssl_dir(("..\\..",))
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
196 if ssl_dir is None:
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
197 sys.exit(1)
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
198
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
199 old_cd = os.getcwd()
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
200 try:
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
201 os.chdir(ssl_dir)
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
202 # rebuild makefile when we do the role over from 32 to 64 build
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
203 if arch == "amd64" and os.path.isfile(m32) and not os.path.isfile(makefile):
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
204 os.unlink(m32)
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
205
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
206 # If the ssl makefiles do not exist, we invoke Perl to generate them.
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
207 # Due to a bug in this script, the makefile sometimes ended up empty
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
208 # Force a regeneration if it is.
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
209 if not os.path.isfile(makefile) or os.path.getsize(makefile)==0:
43981
62cf08a64bc2 Backport of PCbuild9 fixes from py3k r59130
Christian Heimes <christian@cheimes.de>
parents: 43972
diff changeset
210 if perl is None:
62cf08a64bc2 Backport of PCbuild9 fixes from py3k r59130
Christian Heimes <christian@cheimes.de>
parents: 43972
diff changeset
211 print("Perl is required to build the makefiles!")
62cf08a64bc2 Backport of PCbuild9 fixes from py3k r59130
Christian Heimes <christian@cheimes.de>
parents: 43972
diff changeset
212 sys.exit(1)
62cf08a64bc2 Backport of PCbuild9 fixes from py3k r59130
Christian Heimes <christian@cheimes.de>
parents: 43972
diff changeset
213
43972
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
214 print("Creating the makefiles...")
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
215 sys.stdout.flush()
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
216 # Put our working Perl at the front of our path
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
217 os.environ["PATH"] = os.path.dirname(perl) + \
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
218 os.pathsep + \
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
219 os.environ["PATH"]
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
220 run_configure(configure, do_script)
43981
62cf08a64bc2 Backport of PCbuild9 fixes from py3k r59130
Christian Heimes <christian@cheimes.de>
parents: 43972
diff changeset
221 if debug:
62cf08a64bc2 Backport of PCbuild9 fixes from py3k r59130
Christian Heimes <christian@cheimes.de>
parents: 43972
diff changeset
222 print("OpenSSL debug builds aren't supported.")
62cf08a64bc2 Backport of PCbuild9 fixes from py3k r59130
Christian Heimes <christian@cheimes.de>
parents: 43972
diff changeset
223 #if arch=="x86" and debug:
62cf08a64bc2 Backport of PCbuild9 fixes from py3k r59130
Christian Heimes <christian@cheimes.de>
parents: 43972
diff changeset
224 # # the do_masm script in openssl doesn't generate a debug
62cf08a64bc2 Backport of PCbuild9 fixes from py3k r59130
Christian Heimes <christian@cheimes.de>
parents: 43972
diff changeset
225 # # build makefile so we generate it here:
62cf08a64bc2 Backport of PCbuild9 fixes from py3k r59130
Christian Heimes <christian@cheimes.de>
parents: 43972
diff changeset
226 # os.system("perl util\mk1mf.pl debug "+configure+" >"+makefile)
43972
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
227
43981
62cf08a64bc2 Backport of PCbuild9 fixes from py3k r59130
Christian Heimes <christian@cheimes.de>
parents: 43972
diff changeset
228 if arch == "amd64":
62cf08a64bc2 Backport of PCbuild9 fixes from py3k r59130
Christian Heimes <christian@cheimes.de>
parents: 43972
diff changeset
229 create_makefile64(makefile, m32)
62cf08a64bc2 Backport of PCbuild9 fixes from py3k r59130
Christian Heimes <christian@cheimes.de>
parents: 43972
diff changeset
230 fix_makefile(makefile)
62cf08a64bc2 Backport of PCbuild9 fixes from py3k r59130
Christian Heimes <christian@cheimes.de>
parents: 43972
diff changeset
231 shutil.copy(r"crypto\buildinf.h", r"crypto\buildinf_%s.h" % arch)
62cf08a64bc2 Backport of PCbuild9 fixes from py3k r59130
Christian Heimes <christian@cheimes.de>
parents: 43972
diff changeset
232 shutil.copy(r"crypto\opensslconf.h", r"crypto\opensslconf_%s.h" % arch)
43972
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
233
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
234 # Now run make.
43981
62cf08a64bc2 Backport of PCbuild9 fixes from py3k r59130
Christian Heimes <christian@cheimes.de>
parents: 43972
diff changeset
235 if arch == "amd64":
62cf08a64bc2 Backport of PCbuild9 fixes from py3k r59130
Christian Heimes <christian@cheimes.de>
parents: 43972
diff changeset
236 rc = os.system(r"ml64 -c -Foms\uptable.obj ms\uptable.asm")
62cf08a64bc2 Backport of PCbuild9 fixes from py3k r59130
Christian Heimes <christian@cheimes.de>
parents: 43972
diff changeset
237 if rc:
62cf08a64bc2 Backport of PCbuild9 fixes from py3k r59130
Christian Heimes <christian@cheimes.de>
parents: 43972
diff changeset
238 print("ml64 assembler has failed.")
62cf08a64bc2 Backport of PCbuild9 fixes from py3k r59130
Christian Heimes <christian@cheimes.de>
parents: 43972
diff changeset
239 sys.exit(rc)
62cf08a64bc2 Backport of PCbuild9 fixes from py3k r59130
Christian Heimes <christian@cheimes.de>
parents: 43972
diff changeset
240
62cf08a64bc2 Backport of PCbuild9 fixes from py3k r59130
Christian Heimes <christian@cheimes.de>
parents: 43972
diff changeset
241 shutil.copy(r"crypto\buildinf_%s.h" % arch, r"crypto\buildinf.h")
62cf08a64bc2 Backport of PCbuild9 fixes from py3k r59130
Christian Heimes <christian@cheimes.de>
parents: 43972
diff changeset
242 shutil.copy(r"crypto\opensslconf_%s.h" % arch, r"crypto\opensslconf.h")
62cf08a64bc2 Backport of PCbuild9 fixes from py3k r59130
Christian Heimes <christian@cheimes.de>
parents: 43972
diff changeset
243
62cf08a64bc2 Backport of PCbuild9 fixes from py3k r59130
Christian Heimes <christian@cheimes.de>
parents: 43972
diff changeset
244 #makeCommand = "nmake /nologo PERL=\"%s\" -f \"%s\"" %(perl, makefile)
62cf08a64bc2 Backport of PCbuild9 fixes from py3k r59130
Christian Heimes <christian@cheimes.de>
parents: 43972
diff changeset
245 makeCommand = "nmake /nologo -f \"%s\"" % makefile
43972
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
246 print("Executing ssl makefiles:", makeCommand)
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
247 sys.stdout.flush()
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
248 rc = os.system(makeCommand)
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
249 if rc:
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
250 print("Executing "+makefile+" failed")
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
251 print(rc)
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
252 sys.exit(rc)
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
253 finally:
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
254 os.chdir(old_cd)
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
255 sys.exit(rc)
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
256
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
257 if __name__=='__main__':
a8dd8874ff2d Backport of the PCbuild9 directory from the py3k branch.
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
258 main()