首先准备以下软件:

如果 安装 activePerl, 需要额外安装patch

将上述软件分别安装到以下目录

  • Vs2010 -> d:\apps\vs2010\
  • 7zip -> d:\apps\7zip\
  • nasm -> d:\apps\nasm\
  • strawberryperl -> d:\apps\strawberry\
  • ActivePerl -> d:\apps\perl\
  • patch -> d:\apps\msbin\

下面的操作我们假定需要编译的文件都放在d:\build 文件夹下

set build_dir=d:\build

编译openssl 参考: http://developer.covenanteyes.com/building-openssl-for-visual-studio/

下载并解压openssl, 在cmd下运行以下命令:

d:\apps\vs2010\Common7\Tools\vsvars32.bat
d:
cd %build_dir%
set PATH=%PATH%;d:\apps\strawberry\perl\bin;d:\apps\nasm
cd openssl-1.0.1i
perl Configure VC-WIN32
ms\do_nasm.bat
nmake -f ms\nt.mak

下载 bzip2-1.0.6, 解压到 %build_dir%\bzip2-1.0.6

下载 zlib-1.2.8, 解压到 %build_dir%\zlib-1.2.8

下载 sqlcipher, 并解压, 创建 %build_dir%\sqlite-3.8.0.2, 将以下文件拷贝到此文件夹下

crypto.c
crypto_cc.c
crypto_impl.c
crypto_libtomcrypt.c
crypto_openssl.c
sqlite3.c
crypto.h
sqlcipher.h
sqlite3.h
sqlite3ext.h

解压Python-2.7.8 到 %build_dir% 文件夹下,至此,%build_dir% 下有如下结构

bzip2-1.0.6\
openssl-1.0.1i\
Python-2.7.8\
sqlite-3.8.0.2\
zlib-1.2.8\

进入Python-2.7.8, 双击打开 PCbuild\pcbuild.sln, VS2010会自动转换,转换完后 关闭,修改pyproject.props,

<sqlite3Dir>$(externalsDir)\sqlite-3.8.0.2</sqlite3Dir>
<zlibDir>$(externalsDir)\zlib-1.2.8</zlibDir>

<opensslDir>$(externalsDir)\openssl-1.0.1i</opensslDir>

重新双击打开 PCbuild\pcbuild.sln, 修改编译 debugrelease,

点击工具栏 Build -> Configuration Manager, 除了以下以外的都去掉勾选

kill_python
make_buildinfo
make_versioninfo
python
pythoncore

修改 PCbuild\pythoncore.vcxproj, 补丁

patch --binary pythoncore.vcxproj < pythoncore.vcxproj.patch

修改 PC\config.c, 补丁

patch --binary config.c < config.c.patch

dynamic build

修改 Modules_ctypes\callbacks.c, 补丁

patch --binary callbacks.c < ctypes_callbacks.c.patch

static build

修改 Lib\ctypes\__init__.py, 补丁

patch --binary __init__.py < ctypes__init__.py.patch

修改 PC\dl_nt.c, 补丁

patch --binary dl_nt.c < dl_nt.c.patch

修改pythoncore project, "Configuration Properties"

  • "General" -> "Configuration Type" to "Static Library (.lib)"
  • "General" -> "Target Name" to "python27"
  • "C/C++" -> "Preprocessor", "Py_ENABLE_SHARED" to "Py_NO_ENABLE_SHARED"
  • "C/C++" -> "Code Generation" -> "Runtime Library", "Multi-threaded DLL (/MD)" to "Multi-threaded (/MT)"

修改python project, "Configuration Properties"

  • "C/C++" -> "Preprocessor", add "Py_NO_ENABLE_SHARED"
  • "C/C++" -> "Code Generation" -> "Runtime Library", "Multi-threaded DLL (/MD)" to "Multi-threaded (/MT)"
  • "Linker" -> "Input" -> "Additional Dependencies": getbuildinfo.o;ws2_32.lib;$(opensslDir)\out32\libeay32.lib;$(opensslDir)\out32\ssleay32.lib
  • "Linker" -> "Command Line" -> "Additional Options": /NODEFAULTLIB:MSVCRT

参考文章:

  • https://github.com/zeha/python-superstatic