Linux下交叉編譯openssl
1. 安裝交叉編譯器,這裡用的是gcc-linaro-arm-linux-gnueabihf-4.8,當然也可以使用更高版本
非官方下載地址:http://download.csdn.net/detail/huangchijun11/9828071
官方下載地址:https://www.linaro.org/downloads/
官方網站上根據你的CPU指令集選擇arm-linux-gnueabihf或者armv8l-linux-gnueabihf,這裡編譯的是32位,因此選擇arm-linux-gnueabihf。
另外,官方給出了種gcc版本,但最低版本是4.9-2016.02,系列下載地址:https://releases.linaro.org/components/toolchain/binaries/
解壓至/opt/arm-linux-gnueabihf-4.8,修改使用者目錄下面的.bashrc,追加export PATH=$PATH:/opt/arm-linux-gnueabihf-4.8/bin
然後重新開啟shell視窗即可,用arm-linux-gnueabihf-gcc --version檢查編譯器是否安裝成功
2. 獲取Git程式碼庫
$mkdir openssl-dir
$cd openssl-dir
$git clone https://github.com/openssl/openssl.git
3. 切換到最新發布版本,這裡使用的是FIPS版本的,當前最新版本是OpenSSL-fips-2_0_9。(通過git tag檢視當前版本)
$mkdir arm-openssl arm-ssl // 這兩個目錄用於之後編譯openssl
$cd openssl
$git checkout -b local/OpenSSL-fips-2_0_9
$setarch i386 ./config no-asm no-shared enable-ssl3 enable-ssl3-method enable-tls1_3 --prefix=<path to arm-openssl> --openssldir=<path to arm-ssl> --cross-compile-prefix=arm-linux-gnueabihf-
說明:具體配置引數請參考openssl程式碼目錄中的INSTALL文件,簡單說明以下引數:
setarch i386: 指編譯32位,如果不指定就會報錯,當然如果忘記指定也可以在生成的Makefile檔案中刪除-m64標誌來解決
no-shared: 指靜態編譯,只生成靜態庫
--cross-compile-prefix: 指定交叉編譯器字首
$make
$make install_sw// Use "make install_sw" to install the software without documentation
4. 在arm-openssl和arm-ssl目錄中即生成編譯之後的檔案。