Simplify support for building on Windows; make sure to include all the necessary dlls when making binary distributions
diff --git a/INSTALL b/INSTALL
index 793b9bb..b650ba6 100644
--- a/INSTALL
+++ b/INSTALL
@@ -11,47 +11,59 @@
 pyOpenSSL uses distutils, so there really shouldn't be any problems. To build
 the library:
 
-    python setup.py build
+  $ python setup.py build
 
 If your OpenSSL header files aren't in /usr/include, you may need to supply
 the -I flag to let the setup script know where to look. The same goes for the
 libraries of course, use the -L flag. Note that build won't accept these
 flags, so you have to run first build_ext and then build! Example:
 
-    python setup.py build_ext -I/usr/local/ssl/include -L/usr/local/ssl/lib
-    python setup.py build
+  $ python setup.py build_ext -I/usr/local/ssl/include -L/usr/local/ssl/lib
+  $ python setup.py build
 
 Now you should have a directory called OpenSSL that contains e.g. SSL.so and
 __init__.py somewhere in the build dicrectory, so just:
 
-    python setup.py install
+  $ python setup.py install
 
 If you, for some arcane reason, don't want the module to appear in the
 site-packages directory, use the --prefix option.
 
 You can, of course, do
 
-    python setup.py --help
+  $ python setup.py --help
 
 to find out more about how to use the script.
 
 
 -- Building the Module on a Windows System --
 
-Big thanks to Itamar Shtull-Trauring and Oleg Orlov for their help with
-Windows build instructions. Same as for Unix systems, we have to separate
-the build_ext and the build.
+pyOpenSSL is known to build with mingw32 for Python 2.3 through Python 2.5. 
+For Python 2.6, the official Windows installer of which is built with
+Microsoft Visual Studio 2008 (version 9.0), Microsoft Visual Studio 2008
+(version 9.0) is required.  You can specify that mingw32 be used by passing
+the --compiler argument to build_ext.  You will also need to specify the
+location of the OpenSSL headers and libraries:
 
-Building the library:
+  C:\pyOpenSSL-X.Y> setup.py build_ext -c mingw32 -I C:\OpenSSL\include ^
+                      -L C:\OpenSSL bdist_msi
 
-    setup.py build_ext -I ...\openssl\inc32 -L ...\openssl\out32dll
-    setup.py build
+The correct header and library paths depend on how you have OpenSSL
+installed.  The above paths are correct for the default installation of
+(<http://www.slproweb.com/products/Win32OpenSSL.html>).
 
-Where ...\openssl is of course the location of your OpenSSL installation.
+The bdist_msi command will build an MSI installer.  It can be substituted
+with another bdist command if another kind of installer is desired.
 
-Installation is the same as for Unix systems:
+To build with MSVC instead, omit the -c option and pass a slightly different
+library directory:
 
-    setup.py install
+  C:\pyOpenSSL-X.Y> setup.py build_ext -I C:\OpenSSL\include ^
+                      -L C:\OpenSSL\lib bdist_msi
+
+The resulting binary distribution will be placed in the dist directory. To
+install it, dDepending on what kind of distribution you create, run it,
+unzip it, or copy it to Python installation's site-packages.
 
 And similarily, you can do
 
@@ -59,6 +71,9 @@
 
 to get more information.
 
+Big thanks to Itamar Shtull-Trauring, Oleg Orlov, Zooko O'Whielacronx, Chris
+Galvan, and #python and #distutils on FreeNode for their help with Windows
+build instructions.
 
 -- Documentation --
 
diff --git a/setup.py b/setup.py
index 06d477b..a6a446c 100755
--- a/setup.py
+++ b/setup.py
@@ -42,34 +42,27 @@
 
 # Add more platforms here when needed
 if os.name == 'nt' or sys.platform == 'win32':
-    Libraries = ['eay32', 'Ws2_32']
-    # Try to find it...
-    for path in ["C:\\OpenSSL\\lib\\MinGW", "C:\\Python23\\libs",
-                 "C:\\Python24\\libs", "C:\\Python25\\libs", "C:\\Python26\\libs"]:
-        # The .a is the "export library".  It's the thing we need to link
-        # against to let us use the .dll.
-        ssleay32 = os.path.join(path, "ssleay32.a")
-        if os.path.exists(ssleay32):
-            ExtraObjects = [ssleay32]
-            break
-    else:
-        raise SystemExit("Cannot find ssleay32.a, aborting")
+
+    Libraries = ['Ws2_32']
+    def makeTellMeIf(original, what):
+        class tellMeIf(original):
+            def __init__(*a, **kw):
+                Libraries.extend(what)
+                return original.__init__(*a, **kw)
+        return tellMeIf
+
+    from distutils import cygwinccompiler
+    cygwinccompiler.Mingw32CCompiler = makeTellMeIf(cygwinccompiler.Mingw32CCompiler, ['eay32', 'ssl32'])
+    from distutils import msvccompiler
+    msvccompiler.MSVCCompiler = makeTellMeIf(msvccompiler.MSVCCompiler, ['libeay32', 'ssleay32'])
+
+    import shutil
+    shutil.copy("C:\\OpenSSL\\ssleay32.dll", os.path.split(os.path.abspath(__file__))[0])
+    shutil.copy("C:\\OpenSSL\\libeay32.dll", os.path.split(os.path.abspath(__file__))[0])
+    package_data = {'': ['ssleay32.dll', 'libeay32.dll']}
 else:
     Libraries = ['ssl', 'crypto']
-    ExtraObjects = []
-
-if sys.platform == 'darwin':
-    IncludeDirs = ['/sw/include']
-    LibraryDirs = ['/sw/lib']
-
-# On Windows, make sure the necessary .dll's get added to the egg.
-data_files = []
-if sys.platform == 'win32':
-    import ctypes.util
-    libeay32 = ctypes.util.find_library("libeay32")
-    if libeay32 is None:
-        raise SystemExit("Cannot find libeay32.dll, aborting")
-    data_files = [("OpenSSL", [libeay32])]
+    package_data = {}
 
 
 def mkExtension(name):
@@ -77,10 +70,11 @@
     src = globals()[name.lower() + '_src']
     dep = globals()[name.lower() + '_dep']
     return Extension(modname, src, libraries=Libraries, depends=dep,
-                     include_dirs=IncludeDirs, library_dirs=LibraryDirs,
-                     extra_objects=ExtraObjects)
+                     include_dirs=IncludeDirs, library_dirs=LibraryDirs)
+
 
 setup(name='pyOpenSSL', version=__version__,
+      packages = ['OpenSSL'],
       package_dir = {'OpenSSL': '.'},
       ext_modules = [mkExtension('crypto'), mkExtension('rand'),
                      mkExtension('SSL')],
@@ -90,7 +84,8 @@
                      'OpenSSL.test.test_crypto',
                      'OpenSSL.test.test_rand',
                      'OpenSSL.test.test_ssl'],
-      data_files = data_files,
+      zip_safe = False,
+      package_data = package_data,
       description = 'Python wrapper module around the OpenSSL library',
       author = 'Martin Sjögren, AB Strakt',
       author_email = 'msjogren@gmail.com',