1 # Script for building the _ssl module for Windows.
2 # Uses Perl to setup the OpenSSL environment correctly
3 # and build OpenSSL, then invokes a simple nmake session
6 # THEORETICALLY, you can:
7 # * Unpack the latest SSL release one level above your main Python source
8 # directory. It is likely you will already find the zlib library and
9 # any other external packages there.
10 # * Install ActivePerl and ensure it is somewhere on your path.
11 # * Run this script from the PCBuild directory.
13 # it should configure and build SSL, then build the ssl Python extension
14 # without intervention.
18 # Find all "foo.exe" files on the PATH.
19 def find_all_on_path(filename
, extras
= None):
20 entries
= os
.environ
["PATH"].split(os
.pathsep
)
23 fname
= os
.path
.abspath(os
.path
.join(p
, filename
))
24 if os
.path
.isfile(fname
) and fname
not in ret
:
28 fname
= os
.path
.abspath(os
.path
.join(p
, filename
))
29 if os
.path
.isfile(fname
) and fname
not in ret
:
33 # Find a suitable Perl installation for OpenSSL.
34 # cygwin perl does *not* work. ActivePerl does.
35 # Being a Perl dummy, the simplest way I can check is if the "Win32" package
37 def find_working_perl(perls
):
39 fh
= os
.popen(perl
+ ' -e "use Win32;"')
45 print "Can not find a suitable PERL:"
47 print " the following perl interpreters were found:"
50 print " None of these versions appear suitable for building OpenSSL"
52 print " NO perl interpreters were found on this machine at all!"
53 print " Please install ActivePerl and ensure it appears on your path"
54 print "The Python SSL module was not built"
57 # Locate the best SSL directory given a few roots to look into.
58 def find_best_ssl_dir(sources
):
62 s
= os
.path
.abspath(s
)
63 fnames
= os
.listdir(s
)
67 fqn
= os
.path
.join(s
, fname
)
68 if os
.path
.isdir(fqn
) and fname
.startswith("openssl-"):
69 candidates
.append(fqn
)
70 # Now we have all the candidates, locate the best.
74 parts
= re
.split("[.-]", os
.path
.basename(c
))[1:]
75 # eg - openssl-0.9.7-beta1 - ignore all "beta" or any other qualifiers
78 if parts
> best_parts
:
81 if best_name
is not None:
82 print "Found an SSL directory at '%s'" % (best_name
,)
84 print "Could not find an SSL directory in '%s'" % (sources
,)
88 # ms\32all.bat will reconfigure OpenSSL and then try to build
89 # all outputs (debug/nondebug/dll/lib). So we filter the file
90 # to exclude any "nmake" commands and then execute.
91 tempname
= "ms\\32all_py.bat"
93 in_bat
= open("ms\\32all.bat")
94 temp_bat
= open(tempname
,"w")
96 cmd
= in_bat
.readline()
97 print 'cmd', repr(cmd
)
99 if cmd
.strip()[:5].lower() == "nmake":
110 def run_configure(configure
, do_script
):
111 os
.system("perl Configure "+configure
)
115 build_all
= "-a" in sys
.argv
116 if sys
.argv
[1] == "Release":
119 configure
= "VC-WIN32"
121 elif sys
.argv
[1] == "Debug":
124 configure
= "VC-WIN32"
126 elif sys
.argv
[1] == "ReleaseItanium":
129 configure
= "VC-WIN64I"
130 do_script
= "ms\\do_win64i"
131 makefile
= "ms\\nt.mak"
132 os
.environ
["VSEXTCOMP_USECL"] = "MS_ITANIUM"
133 elif sys
.argv
[1] == "ReleaseAMD64":
136 configure
= "VC-WIN64A"
137 do_script
= "ms\\do_win64a"
138 makefile
= "ms\\nt.mak"
139 os
.environ
["VSEXTCOMP_USECL"] = "MS_OPTERON"
143 # perl should be on the path, but we also look in "\perl" and "c:\\perl"
144 # as "well known" locations
145 perls
= find_all_on_path("perl.exe", ["\\perl\\bin", "C:\\perl\\bin"])
146 perl
= find_working_perl(perls
)
150 print "Found a working perl at '%s'" % (perl
,)
151 # Look for SSL 2 levels up from pcbuild - ie, same place zlib etc all live.
152 ssl_dir
= find_best_ssl_dir(("../..",))
159 # If the ssl makefiles do not exist, we invoke Perl to generate them.
160 if not os
.path
.isfile(makefile
):
161 print "Creating the makefiles..."
162 # Put our working Perl at the front of our path
163 os
.environ
["PATH"] = os
.path
.split(perl
)[0] + \
169 run_configure(configure
, do_script
)
172 print "Executing nmake over the ssl makefiles..."
173 rc
= os
.system("nmake /nologo -f "+makefile
)
175 print "Executing d32.mak failed"
180 # And finally, we can build the _ssl module itself for Python.
181 defs
= "SSL_DIR=%s" % (ssl_dir
,)
183 defs
= defs
+ " " + "DEBUG=1"
184 rc
= os
.system('nmake /nologo -f _ssl.mak ' + defs
+ " " + make_flags
)
187 if __name__
=='__main__':