开篇提示:本文为本人原创,本文欢迎转载,但必须注明本文出处,例如:
注1:本文基于Win x64位平台来讲解,x86基本相同
注2:ActivePerl、dmake、nasm、nmake编译OpenSSL(1.1.0系列) :http://blog.youkuaiyun.com/fksec/article/details/52667055
“该文引用自 CruiseYoung的:“ActivePerl、nmake编译OpenSSL(1.0.x系列)”
http://blog.youkuaiyun.com/fksec/article/details/25969257”
否则说明阁下愿意支付以100元人民币每字计的稿费,敬请留意。
注1:本文基于Win x64位平台来讲解,x86基本相同
注2:ActivePerl、dmake、nasm、nmake编译OpenSSL(1.1.0系列) :http://blog.youkuaiyun.com/fksec/article/details/52667055
1 下载软件包
1.1 ActivePerl(x64): http://www.activestate.com/activeperl/downloads
1.2 nasm(x64): http://www.nasm.us/
1.3 OpenSSL: http://www.openssl.org/source/
代码托管地址: https://github.com/openssl/openssl(在Tags中选对应版本进行下载,否则静态版本能编译通过,而动态版本编译不能通过)
2 准备工作
2.1 阅读:
2.1.1 编译方法
openssl-1.0.1k\INSTALL.W32
openssl-1.0.1k\INSTALL.W64
openssl-fips-2.0.7\README.FIPS(openssl-fips编译一定要读该文件)
2.1.2 编译选项
openssl-1.0.1k\Makefile
注意以下内容# KRB5 stuff KRB5_INCLUDES= LIBKRB5= # Zlib stuff ZLIB_INCLUDE= LIBZLIB=
2.1.3 编译配置(方式)
openssl-1.0.1k\Configure注意以下内容my $usage="Usage: Configure [no-<cipher> ...] [enable-<cipher> ...] [experimental-<cipher> ...] [-Dxxx] [-lxxx] [-Lxxx] [-fxxx] [-Kxxx] [no-hw-xxx|no-hw] [[no-]threads] [[no-]shared] [[no-]zlib|zlib-dynamic] [no-asm] [no-dso] [no-krb5] [sctp] [386] [--prefix=DIR] [--openssldir=OPENSSLDIR] [--with-xxx[=vvv]] [--test-sanity] os/compiler[:flags]\n"; my @MK1MF_Builds=qw(VC-WIN64I VC-WIN64A debug-VC-WIN64I debug-VC-WIN64A VC-NT VC-CE VC-WIN32 debug-VC-WIN32 BC-32 netware-clib netware-clib-bsdsock netware-libc netware-libc-bsdsock);
2.2 安装nasm,下载链接http://www.nasm.us/
安装后,右击“我的电脑”-->属性-->高级-->环境变量-->系统变量-->path项添加:D:\Tools\NASM
2.3 编译环境:点击“开始”-->"所有程序"-->"Visual Studio 2013"-->"Visual Studio Tools"-->"VS2013 x64 本机工具命令提示"
2.4 解压“openssl-1.0.1k.tar.gz”到当前文件夹,如得到“openssl-1.0.1k.tar”文件则再次解压“openssl-1.0.1k.tar”到当前文件夹,用以下命令切换到“openssl-1.0.1k”目录
2.5 zlib编译见“nmake、cmake、Visual Studio编译zlib”:
http://blog.youkuaiyun.com/fksec/article/details/25906419
2.6 用以下命令切换到“openssl-1.0.1k”目录(openssl-1.0.1系列):
cd /d E:\Projects\compile\openssl-1.0.1k copy crypto\opensslconf.h crypto\opensslconf.h.bak
3 Release编译
3.1 如果编译“openssl-fips-2.0.7”,请先执行以下命令:cd /d E:\Projects\compile\openssl-fips-2.0.7 ms\do_fips
3.2 运行configure:
如果编译“openssl-1.0.1k”,执行:如果编译“openssl-fips-2.0.7”,即增加“fips”参数,执行:cd /d E:\Projects\compile\openssl-1.0.1k perl Configure VC-WIN64A --prefix=D:\comm\openssl\release_x64 perl Configure VC-WIN64A --prefix=D:\comm\openssl\release_x64 zlib --with-zlib-include=D:\comm\zlib\release_x64\include --with-zlib-lib=D:\comm\zlib\release_x64\lib\zlib.lib perl Configure VC-WIN64A --prefix=D:\comm\openssl\release_x64 zlib-dynamic --with-zlib-include=D:\comm\zlib\release_x64\include --with-zlib-lib=D:\comm\zlib\release_x64\lib\zdll.lib
E:\Projects\compile\openssl-fips-2.0.7 perl Configure VC-WIN64A fips --prefix=D:\comm\openssl_fips\release_x64 perl Configure VC-WIN64A fips --prefix=D:\comm\openssl_fips\release_x64 zlib --with-zlib-include=D:\comm\zlib\release_x64\include --with-zlib-lib=D:\comm\zlib\release_x64\lib\zlib.lib perl Configure VC-WIN64A fips --prefix=D:\comm\openssl_fips\release_x64 zlib-dynamic --with-zlib-include=D:\comm\zlib\release_x64\include --with-zlib-lib=D:\comm\zlib\release_x64\lib\zdll.lib
注1:如果不需引入“zlib”库,则请用第1条perl命令;
注2:如果引入“zlib”静态库,则请用第2条perl命令;此方式适用于“zlib”一个工程内只有“OpenSSL”库用到或通过“OpenSSL”库用到“zlib”库的功能;这种方式编译需要修改“.mak”文件;
注3:如果引入“zlib”动态库,则请用第3条perl命令;此方式适用于所有情况;
注4:约定:本文“OpenSSL”静态库库引入“zlib”静态库,“OpenSSL”动态库引入“zlib”动态库;
3.3 创建Makefile文件:3.4 将“ms\nt.mak”中“CFLAGS”中的“/MT”选项去掉:将“ms\ntdll.mak”中“CFLAGS”中的“/MD”选项去掉:ms\do_win64a
3.5 编译、测试、安装、清除上次的编译以便重新编译:
3.5.1 静态库:nmake -f ms\nt.mak nmake -f ms\nt.mak test nmake -f ms\nt.mak install rename D:\comm\openssl\release_x64 release_x64_static 或 rename D:\comm\openssl_fips\release_x64 release_x64_static nmake -f ms\nt.mak clean
3.5.2 动态库:nmake -f ms\ntdll.mak nmake -f ms\ntdll.mak test nmake -f ms\ntdll.mak install nmake -f ms\ntdll.mak clean
4 Debug编译
4.1 如果编译“openssl-fips-2.0.7”,请先执行以下命令:cd /d E:\Projects\compile\openssl-fips-2.0.7 ms\do_fips
4.2 运行configure:
如果编译“openssl-1.0.1k”,执行:如果编译“openssl-fips-2.0.7”,即增加“fips”参数,执行:cd /d E:\Projects\compile\openssl-1.0.1k perl Configure debug-VC-WIN64A --prefix=D:\comm\openssl\debug_x64 perl Configure debug-VC-WIN64A --prefix=D:\comm\openssl\debug_x64 zlib --with-zlib-include=D:\comm\zlib\debug_x64\include --with-zlib-lib=D:\comm\zlib\debug_x64\lib\zlib.lib perl Configure debug-VC-WIN64A --prefix=D:\comm\openssl\debug_x64 zlib-dynamic --with-zlib-include=D:\comm\zlib\debug_x64\include --with-zlib-lib=D:\comm\zlib\debug_x64\lib\zdll.lib
E:\Projects\compile\openssl-fips-2.0.7 perl Configure debug-VC-WIN64A fips --prefix=D:\comm\openssl_fips\debug_x64 perl Configure debug-VC-WIN64A fips --prefix=D:\comm\openssl_fips\debug_x64 zlib --with-zlib-include=D:\comm\zlib\debug_x64\include --with-zlib-lib=D:\comm\zlib\debug_x64\lib\zlib.lib perl Configure debug-VC-WIN64A fips --prefix=D:\comm\openssl_fips\debug_x64 zlib-dynamic --with-zlib-include=D:\comm\zlib\debug_x64\include --with-zlib-lib=D:\comm\zlib\debug_x64\lib\zdll.lib
4.3 创建Makefile文件:注1:如果不需引入“zlib”库,则请用第1条perl命令;
注2:如果引入“zlib”静态库,则请用第2条perl命令;此方式适用于“zlib”一个工程内只有“OpenSSL”库用到或通过“OpenSSL”库用到“zlib”库的功能;这种方式编译需要修改“.mak”文件;
注3:如果引入“zlib”动态库,则请用第3条perl命令;此方式适用于所有情况;
注4:约定:本文“OpenSSL”静态库库引入“zlib”静态库,“OpenSSL”动态库引入“zlib”动态库;4.4 将“ms\nt.mak”中“CFLAGS”中的“/MTd”选项去掉:将“ms\ntdll.mak”中“CFLAGS”中的“/MDd”选项去掉:ms\do_win64a
4.5 编译、测试、安装、清除上次的编译以便重新编译:
4.5.1 静态库:nmake -f ms\nt.mak nmake -f ms\nt.mak test nmake -f ms\nt.mak install rename D:\comm\openssl\debug_x64 debug_x64_static 或 rename D:\comm\openssl_fips\debug_x64 debug_x64_static nmake -f ms\nt.mak clean
4.5.2 动态库:nmake -f ms\ntdll.mak nmake -f ms\ntdll.mak test nmake -f ms\ntdll.mak install nmake -f ms\ntdll.mak clean
5 再次“运行configure”时的清除工作
cd /d E:\Projects\compile\openssl-1.0.1k del MINFO del Makefile copy Makefile.bak Makefile del crypto\buildinf.h del crypto\opensslconf.h copy crypto\opensslconf.h.bak crypto\opensslconf.h del ms\libeay32.def del ms\nt.mak del ms\ntdll.mak del ms\ssleay32.def del ms\uptable.asm del ms\uptable.obj del ms\version32.rc erase /q/a/f/s inc32\*.* del /q/a/f/s inc32
6 如果不想编译,直接下载OpenSSL安装包
Binary Distributions: http://www.openssl.org/related/binaries.html
OpenSSL for Windows: http://www.slproweb.com/products/Win32OpenSSL.html