获取来源。我使用 git 是因为我觉得它更容易,但下载源代码 tar.gz 也可以:
$ git clone git://git.openssl.org/openssl.git
Cloning into 'openssl'...
remote: Counting objects: 394745, done.
remote: Compressing objects: 100% (102341/102341), done.
remote: Total 394745 (delta 288534), reused 387444 (delta 281591)
Receiving objects: 100% (394745/394745), 92.39 MiB | 911.00 KiB/s, done.
Resolving deltas: 100% (288534/288534), done.
Updating files: 100% (24047/24047), done.
检查远程分支 (git branch -r) 或标签 (git tag) 并选择要构建的版本。我用的是最新的1.1.1j:
$ cd openssl
$ git checkout OpenSSL_1_1_1j
Note: switching to 'OpenSSL_1_1_1j'.
...
HEAD is now at 52c587d60b Prepare for 1.1.1j release
使用-static 参数运行./config。
$ ./config -static
Operating system: x86_64-whatever-linux2
Configuring OpenSSL version 1.1.1j (0x101010afL) for linux-x86_64
Using os-specific seed configuration
Creating configdata.pm
Creating Makefile
**********************************************************************
*** ***
*** OpenSSL has been successfully configured ***
*** ***
*** If you encounter a problem while building, please open an ***
*** issue on GitHub <https://github.com/openssl/openssl/issues> ***
*** and include the output from the following command: ***
*** ***
*** perl configdata.pm --dump ***
*** ***
*** (If you are new to OpenSSL, you might want to consult the ***
*** 'Troubleshooting' section in the INSTALL file first) ***
*** ***
**********************************************************************
我从INSTALL 文件中得到了这个-static 参数:
-Dxxx, -Ixxx, -Wp, -lxxx, -Lxxx, -Wl, -rpath, -R, -framework, -static
These system specific options will be recognised and
passed through to the compiler to allow you to define
preprocessor symbols, specify additional libraries, library
directories or other compiler options. It might be worth
noting that some compilers generate code specifically for
processor the compiler currently executes on. This is not
necessarily what you might have in mind, since it might be
unsuitable for execution on other, typically older,
processor. Consult your compiler documentation.
编译:
$ make -j`nproc`
...
检查它是否是静态二进制文件:
$ ldd apps/openssl
not a dynamic executable
$ file apps/openssl
apps/openssl: ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), statically linked, BuildID[sha1]=286e4615c57e3c21b8e566eb2a046353fe2308c0, for GNU/Linux 3.2.0, with debug_info, not stripped
无需手动编辑 Makefile。
不幸的是,我不知道如何在 Windows 上执行此操作。