1313# it should configure and build SSL, then build the ssl Python extension
1414# without intervention.
1515
16- import os , sys , re
16+ import os , sys , re , shutil
1717
1818# Find all "foo.exe" files on the PATH.
1919def find_all_on_path (filename , extras = None ):
@@ -42,24 +42,24 @@ def find_working_perl(perls):
4242 if rc :
4343 continue
4444 return perl
45- print "Can not find a suitable PERL:"
45+ print ( "Can not find a suitable PERL:" )
4646 if perls :
47- print " the following perl interpreters were found:"
47+ print ( " the following perl interpreters were found:" )
4848 for p in perls :
49- print " " , p
50- print " None of these versions appear suitable for building OpenSSL"
49+ print ( " " , p )
50+ print ( " None of these versions appear suitable for building OpenSSL" )
5151 else :
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"
52+ print (" NO perl interpreters were found on this machine at all!" )
53+ print (" Please install ActivePerl and ensure it appears on your path" )
5554 return None
5655
5756# Locate the best SSL directory given a few roots to look into.
5857def find_best_ssl_dir (sources ):
5958 candidates = []
6059 for s in sources :
6160 try :
62- s = os .path .abspath (s )
61+ # note: do not abspath s; the build will fail if any
62+ # higher up directory name has spaces in it.
6363 fnames = os .listdir (s )
6464 except os .error :
6565 fnames = []
@@ -79,14 +79,57 @@ def find_best_ssl_dir(sources):
7979 best_parts = parts
8080 best_name = c
8181 if best_name is not None :
82- print "Found an SSL directory at '%s'" % (best_name ,)
82+ print ( "Found an SSL directory at '%s'" % (best_name ,) )
8383 else :
84- print "Could not find an SSL directory in '%s'" % (sources ,)
84+ print ("Could not find an SSL directory in '%s'" % (sources ,))
85+ sys .stdout .flush ()
8586 return best_name
8687
88+ def fix_makefile (makefile ):
89+ """Fix some stuff in all makefiles
90+ """
91+ if not os .path .isfile (makefile ):
92+ return
93+ # 2.4 compatibility
94+ fin = open (makefile )
95+ if 1 : # with open(makefile) as fin:
96+ lines = fin .readlines ()
97+ fin .close ()
98+ fout = open (makefile , 'w' )
99+ if 1 : # with open(makefile, 'w') as fout:
100+ for line in lines :
101+ if line .startswith ("PERL=" ):
102+ continue
103+ if line .startswith ("CP=" ):
104+ line = "CP=copy\n "
105+ if line .startswith ("MKDIR=" ):
106+ line = "MKDIR=mkdir\n "
107+ if line .startswith ("CFLAG=" ):
108+ line = line .strip ()
109+ for algo in ("RC5" , "MDC2" , "IDEA" ):
110+ noalgo = " -DOPENSSL_NO_%s" % algo
111+ if noalgo not in line :
112+ line = line + noalgo
113+ line = line + '\n '
114+ fout .write (line )
115+ fout .close ()
116+
117+ def run_configure (configure , do_script ):
118+ print ("perl Configure " + configure )
119+ os .system ("perl Configure " + configure )
120+ print (do_script )
121+ os .system (do_script )
122+
87123def main ():
88124 debug = "-d" in sys .argv
89125 build_all = "-a" in sys .argv
126+ if 1 : # Win32
127+ arch = "x86"
128+ configure = "VC-WIN32"
129+ do_script = "ms\\ do_nasm"
130+ makefile = "ms\\ nt.mak"
131+ m32 = makefile
132+ configure += " no-idea no-rc5 no-mdc2"
90133 make_flags = ""
91134 if build_all :
92135 make_flags = "-a"
@@ -95,61 +138,57 @@ def main():
95138 perls = find_all_on_path ("perl.exe" , ["\\ perl\\ bin" , "C:\\ perl\\ bin" ])
96139 perl = find_working_perl (perls )
97140 if perl is None :
98- sys .exit (1 )
99-
100- print "Found a working perl at '%s'" % (perl ,)
141+ print ("No Perl installation was found. Existing Makefiles are used." )
142+ else :
143+ print ("Found a working perl at '%s'" % (perl ,))
144+ sys .stdout .flush ()
101145 # Look for SSL 3 levels up from pcbuild - ie, same place zlib etc all live.
102- ssl_dir = find_best_ssl_dir (("../../ .." ,))
146+ ssl_dir = find_best_ssl_dir (("..\\ .. \\ .." ,))
103147 if ssl_dir is None :
104148 sys .exit (1 )
105149
106150 old_cd = os .getcwd ()
107151 try :
108152 os .chdir (ssl_dir )
109153 # If the ssl makefiles do not exist, we invoke Perl to generate them.
110- if not os .path .isfile (os .path .join (ssl_dir , "32.mak" )) or \
111- not os .path .isfile (os .path .join (ssl_dir , "d32.mak" )):
112- print "Creating the makefiles..."
154+ # Due to a bug in this script, the makefile sometimes ended up empty
155+ # Force a regeneration if it is.
156+ if not os .path .isfile (makefile ) or os .path .getsize (makefile )== 0 :
157+ if perl is None :
158+ print ("Perl is required to build the makefiles!" )
159+ sys .exit (1 )
160+
161+ print ("Creating the makefiles..." )
162+ sys .stdout .flush ()
113163 # Put our working Perl at the front of our path
114- os .environ ["PATH" ] = os .path .split (perl )[ 0 ] + \
164+ os .environ ["PATH" ] = os .path .dirname (perl ) + \
115165 os .pathsep + \
116166 os .environ ["PATH" ]
117- # ms\32all.bat will reconfigure OpenSSL and then try to build
118- # all outputs (debug/nondebug/dll/lib). So we filter the file
119- # to exclude any "nmake" commands and then execute.
120- tempname = "ms\\ 32all_py.bat"
167+ run_configure (configure , do_script )
168+ if debug :
169+ print ("OpenSSL debug builds aren't supported." )
170+ #if arch=="x86" and debug:
171+ # # the do_masm script in openssl doesn't generate a debug
172+ # # build makefile so we generate it here:
173+ # os.system("perl util\mk1mf.pl debug "+configure+" >"+makefile)
121174
122- in_bat = open ("ms\\ 32all.bat" )
123- temp_bat = open (tempname ,"w" )
124- while 1 :
125- cmd = in_bat .readline ()
126- print 'cmd' , repr (cmd )
127- if not cmd : break
128- if cmd .strip ()[:5 ].lower () == "nmake" :
129- continue
130- temp_bat .write (cmd )
131- in_bat .close ()
132- temp_bat .close ()
133- os .system (tempname )
134- try :
135- os .remove (tempname )
136- except :
137- pass
175+ fix_makefile (makefile )
176+ shutil .copy (r"crypto\buildinf.h" , r"crypto\buildinf_%s.h" % arch )
177+ shutil .copy (r"crypto\opensslconf.h" , r"crypto\opensslconf_%s.h" % arch )
138178
139179 # Now run make.
140- print "Executing nmake over the ssl makefiles..."
141- if debug :
142- rc = os .system ("nmake /nologo -f d32.mak" )
143- if rc :
144- print "Executing d32.mak failed"
145- print rc
146- sys .exit (rc )
147- else :
148- rc = os .system ("nmake /nologo -f 32.mak" )
149- if rc :
150- print "Executing 32.mak failed"
151- print rc
152- sys .exit (rc )
180+ shutil .copy (r"crypto\buildinf_%s.h" % arch , r"crypto\buildinf.h" )
181+ shutil .copy (r"crypto\opensslconf_%s.h" % arch , r"crypto\opensslconf.h" )
182+
183+ #makeCommand = "nmake /nologo PERL=\"%s\" -f \"%s\"" %(perl, makefile)
184+ makeCommand = "nmake /nologo -f \" %s\" " % makefile
185+ print ("Executing ssl makefiles:" , makeCommand )
186+ sys .stdout .flush ()
187+ rc = os .system (makeCommand )
188+ if rc :
189+ print ("Executing " + makefile + " failed" )
190+ print (rc )
191+ sys .exit (rc )
153192 finally :
154193 os .chdir (old_cd )
155194 # And finally, we can build the _ssl module itself for Python.
0 commit comments