Merged revisions 59605-59624 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r59606 | georg.brandl | 2007-12-29 11:57:00 +0100 (Sat, 29 Dec 2007) | 2 lines

  Some cleanup in the docs.
........
  r59611 | martin.v.loewis | 2007-12-29 19:49:21 +0100 (Sat, 29 Dec 2007) | 2 lines

  Bug #1699: Define _BSD_SOURCE only on OpenBSD.
........
  r59612 | raymond.hettinger | 2007-12-29 23:09:34 +0100 (Sat, 29 Dec 2007) | 1 line

  Simpler documentation for itertools.tee().  Should be backported.
........
  r59613 | raymond.hettinger | 2007-12-29 23:16:24 +0100 (Sat, 29 Dec 2007) | 1 line

  Improve docs for itertools.groupby().  The use of xrange(0) to create a unique object is less obvious than object().
........
  r59620 | christian.heimes | 2007-12-31 15:47:07 +0100 (Mon, 31 Dec 2007) | 3 lines

  Added wininst-9.0.exe executable for VS 2008
  Integrated bdist_wininst into PCBuild9 directory
........
  r59621 | christian.heimes | 2007-12-31 15:51:18 +0100 (Mon, 31 Dec 2007) | 1 line

  Moved PCbuild directory to PC/VS7.1
........
  r59622 | christian.heimes | 2007-12-31 15:59:26 +0100 (Mon, 31 Dec 2007) | 1 line

  Fix paths for build bot
........
  r59623 | christian.heimes | 2007-12-31 16:02:41 +0100 (Mon, 31 Dec 2007) | 1 line

  Fix paths for build bot, part 2
........
  r59624 | christian.heimes | 2007-12-31 16:18:55 +0100 (Mon, 31 Dec 2007) | 1 line

  Renamed PCBuild9 directory to PCBuild
........
diff --git a/PCbuild/build_ssl.py b/PCbuild/build_ssl.py
index 12a78e0..2ccceec 100644
--- a/PCbuild/build_ssl.py
+++ b/PCbuild/build_ssl.py
@@ -13,7 +13,17 @@
 # it should configure and build SSL, then build the _ssl and _hashlib
 # Python extensions without intervention.
 
-import os, sys, re
+# Modified by Christian Heimes
+# Now this script supports pre-generated makefiles and assembly files.
+# Developers don't need an installation of Perl anymore to build Python. A svn
+# checkout from our svn repository is enough.
+#
+# In Order to create the files in the case of an update you still need Perl.
+# Run build_ssl in this order:
+# python.exe build_ssl.py Release x64
+# python.exe build_ssl.py Release Win32
+
+import os, sys, re, shutil
 
 # Find all "foo.exe" files on the PATH.
 def find_all_on_path(filename, extras = None):
@@ -51,7 +61,6 @@
     else:
         print(" NO perl interpreters were found on this machine at all!")
     print(" Please install ActivePerl and ensure it appears on your path")
-    print("The Python SSL module was not built")
     return None
 
 # Locate the best SSL directory given a few roots to look into.
@@ -86,38 +95,82 @@
     sys.stdout.flush()
     return best_name
 
+def create_makefile64(makefile, m32):
+    """Create and fix makefile for 64bit
+
+    Replace 32 with 64bit directories
+    """
+    if not os.path.isfile(m32):
+        return
+    with open(m32) as fin:
+        with open(makefile, 'w') as fout:
+            for line in fin:
+                line = line.replace("=tmp32", "=tmp64")
+                line = line.replace("=out32", "=out64")
+                line = line.replace("=inc32", "=inc64")
+                # force 64 bit machine
+                line = line.replace("MKLIB=lib", "MKLIB=lib /MACHINE:X64")
+                line = line.replace("LFLAGS=", "LFLAGS=/MACHINE:X64 ")
+                # don't link against the lib on 64bit systems
+                line = line.replace("bufferoverflowu.lib", "")
+                fout.write(line)
+    os.unlink(m32)
+
+def fix_makefile(makefile):
+    """Fix some stuff in all makefiles
+    """
+    if not os.path.isfile(makefile):
+        return
+    with open(makefile) as fin:
+        lines = fin.readlines()
+    with open(makefile, 'w') as fout:
+        for line in lines:
+            if line.startswith("PERL="):
+                continue
+            if line.startswith("CP="):
+                line = "CP=copy\n"
+            if line.startswith("MKDIR="):
+                line = "MKDIR=mkdir\n"
+            if line.startswith("CFLAG="):
+                line = line.strip()
+                for algo in ("RC5", "MDC2", "IDEA"):
+                    noalgo = " -DOPENSSL_NO_%s" % algo
+                    if noalgo not in line:
+                        line = line + noalgo
+                line = line + '\n'
+            fout.write(line)
+
 def run_configure(configure, do_script):
+    print("perl Configure "+configure)
     os.system("perl Configure "+configure)
+    print(do_script)
     os.system(do_script)
 
 def main():
     build_all = "-a" in sys.argv
     if sys.argv[1] == "Release":
-        arch = "x86"
         debug = False
-        configure = "VC-WIN32"
-        do_script = "ms\\do_masm"
-        makefile = "ms\\nt.mak"
     elif sys.argv[1] == "Debug":
-        arch = "x86"
         debug = True
+    else:
+        raise ValueError(str(sys.argv))
+
+    if sys.argv[2] == "Win32":
+        arch = "x86"
         configure = "VC-WIN32"
-        do_script = "ms\\do_masm"
-        makefile="ms\\d32.mak"
-    elif sys.argv[1] == "ReleaseItanium":
-        arch = "ia64"
-        debug = False
-        configure = "VC-WIN64I"
-        do_script = "ms\\do_win64i"
-        makefile = "ms\\nt.mak"
-        os.environ["VSEXTCOMP_USECL"] = "MS_ITANIUM"
-    elif sys.argv[1] == "ReleaseAMD64":
+        do_script = "ms\\do_nasm"
+        makefile="ms\\nt.mak"
+        m32 = makefile
+    elif sys.argv[2] == "x64":
         arch="amd64"
-        debug=False
         configure = "VC-WIN64A"
         do_script = "ms\\do_win64a"
-        makefile = "ms\\nt.mak"
-        os.environ["VSEXTCOMP_USECL"] = "MS_OPTERON"
+        makefile = "ms\\nt64.mak"
+        m32 = makefile.replace('64', '')
+        #os.environ["VSEXTCOMP_USECL"] = "MS_OPTERON"
+    else:
+        raise ValueError(str(sys.argv))
+
     make_flags = ""
     if build_all:
         make_flags = "-a"
@@ -126,7 +179,7 @@
     perls = find_all_on_path("perl.exe", ["\\perl\\bin", "C:\\perl\\bin"])
     perl = find_working_perl(perls)
     if perl is None:
-        sys.exit(1)
+        print("No Perl installation was found. Existing Makefiles are used.")
 
     print("Found a working perl at '%s'" % (perl,))
     sys.stdout.flush()
@@ -138,10 +191,18 @@
     old_cd = os.getcwd()
     try:
         os.chdir(ssl_dir)
+        # rebuild makefile when we do the role over from 32 to 64 build
+        if arch == "amd64" and os.path.isfile(m32) and not os.path.isfile(makefile):
+            os.unlink(m32)
+
         # If the ssl makefiles do not exist, we invoke Perl to generate them.
         # Due to a bug in this script, the makefile sometimes ended up empty
         # Force a regeneration if it is.
         if not os.path.isfile(makefile) or os.path.getsize(makefile)==0:
+            if perl is None:
+                print("Perl is required to build the makefiles!")
+                sys.exit(1)
+
             print("Creating the makefiles...")
             sys.stdout.flush()
             # Put our working Perl at the front of our path
@@ -149,13 +210,31 @@
                                           os.pathsep + \
                                           os.environ["PATH"]
             run_configure(configure, do_script)
-            if arch=="x86" and debug:
-                # the do_masm script in openssl doesn't generate a debug
-                # build makefile so we generate it here:
-                os.system("perl util\mk1mf.pl debug "+configure+" >"+makefile)
+            if debug:
+                print("OpenSSL debug builds aren't supported.")
+            #if arch=="x86" and debug:
+            #    # the do_masm script in openssl doesn't generate a debug
+            #    # build makefile so we generate it here:
+            #    os.system("perl util\mk1mf.pl debug "+configure+" >"+makefile)
+
+            if arch == "amd64":
+                create_makefile64(makefile, m32)
+            fix_makefile(makefile)
+            shutil.copy(r"crypto\buildinf.h", r"crypto\buildinf_%s.h" % arch)
+            shutil.copy(r"crypto\opensslconf.h", r"crypto\opensslconf_%s.h" % arch)
 
         # Now run make.
-        makeCommand = "nmake /nologo PERL=\"%s\" -f \"%s\"" %(perl, makefile)
+        if arch == "amd64":
+            rc = os.system(r"ml64 -c -Foms\uptable.obj ms\uptable.asm")
+            if rc:
+                print("ml64 assembler has failed.")
+                sys.exit(rc)
+
+        shutil.copy(r"crypto\buildinf_%s.h" % arch, r"crypto\buildinf.h")
+        shutil.copy(r"crypto\opensslconf_%s.h" % arch, r"crypto\opensslconf.h")
+
+        #makeCommand = "nmake /nologo PERL=\"%s\" -f \"%s\"" %(perl, makefile)
+        makeCommand = "nmake /nologo -f \"%s\"" % makefile
         print("Executing ssl makefiles:", makeCommand)
         sys.stdout.flush()
         rc = os.system(makeCommand)
@@ -165,16 +244,6 @@
             sys.exit(rc)
     finally:
         os.chdir(old_cd)
-    # And finally, we can build the _ssl module itself for Python.
-    defs = "SSL_DIR=\"%s\"" % (ssl_dir,)
-    if debug:
-        defs = defs + " " + "DEBUG=1"
-    if arch in ('amd64', 'ia64'):
-        defs = defs + " EXTRA_CFLAGS=/GS- EXTRA_LIBS=bufferoverflowU.lib"
-    makeCommand = 'nmake /nologo -f _ssl.mak ' + defs + " " + make_flags
-    print("Executing:", makeCommand)
-    sys.stdout.flush()
-    rc = os.system(makeCommand)
     sys.exit(rc)
 
 if __name__=='__main__':