openssl linux編譯及android版編譯
阿新 • • 發佈:2018-12-14
前言
目前本人由於工作原因,需要編譯linux及android版的openssl庫,由於之前沒有做個這個工作,且網上也沒有找到合適的文章,所以覺定記錄一下。以便大家參考,同時也可以記錄一下,以備不時之需。
系統環境
- Ubuntu 16.04
- openssl 1.1.0-stable git地址
- android-sdk-linux
- android-ndk-r14b
linux庫編譯
使用使用git命令下載原始碼,並切換至1.1.0-stable版本。
git clone https://github.com/openssl/openssl.git cd openssl git checkout git checkout OpenSSL_1_1_0-stable
配置編譯引數
./config enable-ssl2 no-comp no-hw enable-egd \
--openssldir=/home/liupeng/workspace/git-project/openssl/ssl \
--prefix=/home/liupeng/workspace/git-project/openssl/build/linux
- enable-ssl2及其它引數用於配置openssl的相關功能
--openssldir
用於配置openssl的相關引用路徑,為openssl原始碼下的ssl資料夾,一定要有--prefix
用於配置庫的安裝路徑,預設安裝於/usr/下,本人由於需要編譯靜態庫及android版本,故指定到其它目錄命令成功如下
Operating system: x86_64-whatever-linux2
Configuring for linux-x86_64
Configuring OpenSSL version 1.1.0g-dev (0x10100070L)
no-asan [default] OPENSSL_NO_ASAN
no-comp [option] OPENSSL_NO_COMP (skip dir)
no-crypto-mdebug [default] OPENSSL_NO_CRYPTO_MDEBUG
no-crypto-mdebug-backtrace [default ] OPENSSL_NO_CRYPTO_MDEBUG_BACKTRACE
no-ec_nistp_64_gcc_128 [default] OPENSSL_NO_EC_NISTP_64_GCC_128
no-egd [default] OPENSSL_NO_EGD
no-fuzz-afl [default] OPENSSL_NO_FUZZ_AFL
no-fuzz-libfuzzer [default] OPENSSL_NO_FUZZ_LIBFUZZER
no-heartbeats [default] OPENSSL_NO_HEARTBEATS
no-hw [option] OPENSSL_NO_HW
no-md2 [default] OPENSSL_NO_MD2 (skip dir)
no-msan [default] OPENSSL_NO_MSAN
no-rc5 [default] OPENSSL_NO_RC5 (skip dir)
no-sctp [default] OPENSSL_NO_SCTP
no-ssl-trace [default] OPENSSL_NO_SSL_TRACE
no-ssl3 [default] OPENSSL_NO_SSL3
no-ssl3-method [default] OPENSSL_NO_SSL3_METHOD
no-ubsan [default] OPENSSL_NO_UBSAN
no-unit-test [default] OPENSSL_NO_UNIT_TEST
no-weak-ssl-ciphers [default] OPENSSL_NO_WEAK_SSL_CIPHERS
no-zlib [default]
no-zlib-dynamic [default]
Configuring for linux-x86_64
CC =gcc
CFLAG =-Wall -O3 -pthread -m64 -DL_ENDIAN -Wa,--noexecstack
SHARED_CFLAG =-fPIC -DOPENSSL_USE_NODELETE
DEFINES =DSO_DLFCN HAVE_DLFCN_H NDEBUG OPENSSL_THREADS OPENSSL_NO_STATIC_ENGINE OPENSSL_PIC OPENSSL_IA32_SSE2 OPENSSL_BN_ASM_MONT OPENSSL_BN_ASM_MONT5 OPENSSL_BN_ASM_GF2m SHA1_ASM SHA256_ASM SHA512_ASM RC4_ASM MD5_ASM AES_ASM VPAES_ASM BSAES_ASM GHASH_ASM ECP_NISTZ256_ASM PADLOCK_ASM POLY1305_ASM
LFLAG =
PLIB_LFLAG =
EX_LIBS =-ldl
APPS_OBJ =
CPUID_OBJ =x86_64cpuid.o
UPLINK_OBJ =
BN_ASM =asm/x86_64-gcc.o x86_64-mont.o x86_64-mont5.o x86_64-gf2m.o rsaz_exp.o rsaz-x86_64.o rsaz-avx2.o
EC_ASM =ecp_nistz256.o ecp_nistz256-x86_64.o
DES_ENC =des_enc.o fcrypt_b.o
AES_ENC =aes-x86_64.o vpaes-x86_64.o bsaes-x86_64.o aesni-x86_64.o aesni-sha1-x86_64.o aesni-sha256-x86_64.o aesni-mb-x86_64.o
BF_ENC =bf_enc.o
CAST_ENC =c_enc.o
RC4_ENC =rc4-x86_64.o rc4-md5-x86_64.o
RC5_ENC =rc5_enc.o
MD5_OBJ_ASM =md5-x86_64.o
SHA1_OBJ_ASM =sha1-x86_64.o sha256-x86_64.o sha512-x86_64.o sha1-mb-x86_64.o sha256-mb-x86_64.o
RMD160_OBJ_ASM=
CMLL_ENC =cmll-x86_64.o cmll_misc.o
MODES_OBJ =ghash-x86_64.o aesni-gcm-x86_64.o
PADLOCK_OBJ =e_padlock-x86_64.o
CHACHA_ENC =chacha-x86_64.o
POLY1305_OBJ =poly1305-x86_64.o
BLAKE2_OBJ =
PROCESSOR =
RANLIB =ranlib
ARFLAGS =
PERL =/usr/bin/perl
SIXTY_FOUR_BIT_LONG mode
Configured for linux-x86_64.
編譯並安裝
make -j8 && make install -j8
編譯成功後可以在 --prefix
配置的目錄下看見lib及include目錄,編譯發的庫就在此目錄下。
Android庫編譯
配置環境變數
export ANDROID_NDK_HOME=/home/liupeng/develop/tools/android-ndk-r14b
export ANDROID_NDK_ROOT=/home/liupeng/develop/tools/android-ndk-r14b
export ANDROID_SDK_HOME=/home/liupeng/develop/tools/android-sdk-linux
export ANDROID_SDK_ROOT=/home/liupeng/develop/tools/android-sdk-linux
下載配置指令碼
wget https://wiki.openssl.org/images/7/70/Setenv-android.sh
修改Setenv-android.sh相關配置
找到如下配置並修改
_ANDROID_NDK="android-ndk-r14b"
_ANDROID_EABI="arm-linux-androideabi-4.9"
_ANDROID_API="android-14"
執行指令碼
#這裡可能會報錯,可以不用管
source Setenv-android.sh
#配置編譯引數
./config enable-ssl2 no-comp no-hw enable-egd \
--openssldir=/home/liupeng/workspace/git-project/openssl/ssl/$ANDROID_API \
--prefix=/home/liupeng/workspace/git-project/openssl/build/android
編譯原始碼
make -j8
make install CC=$ANDROID_TOOLCHAIN/arm-linux-androideabi-gcc \
RANLIB=$ANDROID_TOOLCHAIN/arm-linux-androideabi-ranlib -j8
以就是完成編譯openssl android版的相步驟