curl 的 http2 特性需要在编译时加入第三方库 nghttp2 才能开启,而 nghttp2 又依赖 openssl/boringssl。
编译 OpenSSL
cd ./openssl
./Configure darwin64-x86_64-cc --prefix=/tmp/openssl no-shared
clean_make
make install
编译 nghttp2
cd ./nghttp2
autoreconf -i
automake
autoconf
./configure --prefix=/tmp/nghttp2 --disable-shared --enable-static
clean_make
make install
编译 CURL
cd ./curl
./configure --prefix=/tmp/curl --disable-shared --enable-static --with-ssl=/tmp/openssl --with-nghttp2=/tmp/nghttp2
clean_make
make install
查看一下编译后的 curl -V,输出内容如下
curl 7.66.0-DEV (x86_64-apple-darwin18.7.0) libcurl/7.66.0-DEV OpenSSL/3.0.0 zlib/1.2.11 nghttp2/1.40.0-DEV
Release-Date: [unreleased]
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtsp smb smbs smtp smtps telnet tftp
Features: AsynchDNS HTTP2 HTTPS-proxy IPv6 Largefile libz NTLM NTLM_WB SSL TLS-SRP UnixSockets
clean_make 是一个工具方法,用于加快 make 的速度,代码如下
CPUNUM=`sysctl -n hw.logicalcpu_max`
clean_make() {
make clean
make -j ${CPUNUM}
}