1313# it should configure and build SSL, then build the ssl Python extension
1414# without intervention.
1515
16+ # Modified by Christian Heimes
17+ # Now this script supports pre-generated makefiles and assembly files.
18+ # Developers don't need an installation of Perl anymore to build Python. A svn
19+ # checkout from our svn repository is enough.
20+
1621import os , sys , re , shutil
1722
1823# Find all "foo.exe" files on the PATH.
@@ -36,7 +41,7 @@ def find_all_on_path(filename, extras = None):
3641# is available.
3742def find_working_perl (perls ):
3843 for perl in perls :
39- fh = os .popen (perl + ' -e "use Win32;"' )
44+ fh = os .popen ('"%s" -e "use Win32;"' % perl )
4045 fh .read ()
4146 rc = fh .close ()
4247 if rc :
@@ -90,13 +95,9 @@ def fix_makefile(makefile):
9095 """
9196 if not os .path .isfile (makefile ):
9297 return
93- # 2.4 compatibility
94- fin = open (makefile )
95- if 1 : # with open(makefile) as fin:
98+ with open (makefile ) as fin :
9699 lines = fin .readlines ()
97- fin .close ()
98- fout = open (makefile , 'w' )
99- if 1 : # with open(makefile, 'w') as fout:
100+ with open (makefile , 'w' ) as fout :
100101 for line in lines :
101102 if line .startswith ("PERL=" ):
102103 continue
@@ -112,14 +113,29 @@ def fix_makefile(makefile):
112113 line = line + noalgo
113114 line = line + '\n '
114115 fout .write (line )
115- fout .close ()
116116
117117def run_configure (configure , do_script ):
118118 print ("perl Configure " + configure )
119119 os .system ("perl Configure " + configure )
120120 print (do_script )
121121 os .system (do_script )
122122
123+ def cmp (f1 , f2 ):
124+ bufsize = 1024 * 8
125+ with open (f1 , 'rb' ) as fp1 , open (f2 , 'rb' ) as fp2 :
126+ while True :
127+ b1 = fp1 .read (bufsize )
128+ b2 = fp2 .read (bufsize )
129+ if b1 != b2 :
130+ return False
131+ if not b1 :
132+ return True
133+
134+ def copy (src , dst ):
135+ if os .path .isfile (dst ) and cmp (src , dst ):
136+ return
137+ shutil .copy (src , dst )
138+
123139def main ():
124140 debug = "-d" in sys .argv
125141 build_all = "-a" in sys .argv
@@ -129,6 +145,7 @@ def main():
129145 do_script = "ms\\ do_nasm"
130146 makefile = "ms\\ nt.mak"
131147 m32 = makefile
148+ dirsuffix = "32"
132149 configure += " no-idea no-rc5 no-mdc2"
133150 make_flags = ""
134151 if build_all :
@@ -137,12 +154,12 @@ def main():
137154 # as "well known" locations
138155 perls = find_all_on_path ("perl.exe" , ["\\ perl\\ bin" , "C:\\ perl\\ bin" ])
139156 perl = find_working_perl (perls )
140- if perl is None :
141- print ("No Perl installation was found. Existing Makefiles are used." )
142- else :
157+ if perl :
143158 print ("Found a working perl at '%s'" % (perl ,))
159+ else :
160+ print ("No Perl installation was found. Existing Makefiles are used." )
144161 sys .stdout .flush ()
145- # Look for SSL 3 levels up from pcbuild - ie, same place zlib etc all live.
162+ # Look for SSL 3 levels up from PC/VC6 - ie, same place zlib etc all live.
146163 ssl_dir = find_best_ssl_dir (("..\\ ..\\ .." ,))
147164 if ssl_dir is None :
148165 sys .exit (1 )
@@ -173,12 +190,21 @@ def main():
173190 # os.system("perl util\mk1mf.pl debug "+configure+" >"+makefile)
174191
175192 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 )
193+ copy (r"crypto\buildinf.h" , r"crypto\buildinf_%s.h" % arch )
194+ copy (r"crypto\opensslconf.h" , r"crypto\opensslconf_%s.h" % arch )
195+
196+ # If the assembler files don't exist in tmpXX, copy them there
197+ if perl is None :
198+ if not os .path .exists ("tmp" + dirsuffix ):
199+ os .mkdir ("tmp" + dirsuffix )
200+ for f in os .listdir ("asm" + dirsuffix ):
201+ if not f .endswith (".asm" ): continue
202+ if os .path .isfile (r"tmp%s\%s" % (dirsuffix , f )): continue
203+ shutil .copy (r"asm%s\%s" % (dirsuffix , f ), "tmp" + dirsuffix )
178204
179205 # Now run make.
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" )
206+ copy (r"crypto\buildinf_%s.h" % arch , r"crypto\buildinf.h" )
207+ copy (r"crypto\opensslconf_%s.h" % arch , r"crypto\opensslconf.h" )
182208
183209 #makeCommand = "nmake /nologo PERL=\"%s\" -f \"%s\"" %(perl, makefile)
184210 makeCommand = "nmake /nologo -f \" %s\" " % makefile
0 commit comments