Prepare environment
docker run -i -t --rm -v ${PWD}:/mnt \
  --name=buildenv alpine:latest \
    sh -c 'apk add bash; bash'Install build tools:
apk update
apk add build-base
apk add autoconf automake libtool pkgconfig
apk add clang openssl-dev nghttp2-dev nghttp2-static libssh2-dev libssh2-static openssl-libs-static zlib-static perl
apk add curl lddtreeDownload curl source code:
curl -fsSLO https://curl.se/download/curl-8.16.0.tar.gz
tar -zxf curl-8.16.0.tar.gz
cd curl-8.16.0Prepare build configuration and compile:
LDFLAGS="-static" PKG_CONFIG="pkg-config --static" ./configure --disable-shared --enable-static --with-openssl --with-libssh2 --without-libpsl --disable-docs --disable-manual
make LDFLAGS="-static -all-static"
strip src/curl
lddtree src/curl
tar -zcf /mnt/curl-static.tgz --strip-components 1 src/curl
exit$ file curl
Optionally, a static openssl can be build as follows (and used as --with-openssl=/opt/openssl-static):
# needed for secure-memory feature, otherwise add no-secure-memory to config below
apk add linux-headers
# compile
curl -fsSLO https://www.openssl.org/source/openssl-3.5.4.tar.gz
tar -xzf openssl-3.5.4.tar.gz
cd openssl-3.5.4
export LDFLAGS="-static"
./config no-shared --prefix=/opt/openssl-static
make install_sw
strip /opt/openssl-static/bin/openssl
lddtree /opt/openssl-static/bin/openssl
tar -zcf /mnt/openssl-static.tgz --strip-components 2 /opt/openssl-static