pkg_name=curl
version=8.23.0
revision=1
build_style=gnu-configure
short_desc="Command line URL transfer tool"
home_page="https://curl.se"
license="curl"
dist_files="https://curl.haxx.se/download/curl-${version}.tar.xz"
checksum="c048df2e61382c619b609f94156ea73d29c96f536ff2de5abb8e9a1a871c63ac"

# man: generate the curl(1)/libcurl(3) manpages from md sources, needs perl
# manual: built in `curl --manual`, generated from the same sources as ^
#         so needs man as well
use_flags="man -manual -completions ipv6 ssl -ldap -ares -psl -idn -brotli -zstd static"

depends="zlib
 $(use_if ssl libressl)
 $(use_if ldap openldap)
 $(use_if ares c-ares)
 $(use_if psl libpsl)
 $(use_if idn libidn2)
 $(use_if brotli brotli)
 $(use_if zstd zstd)"

# curl only needs perl at buildtime for scripts/managen, scripts/cdn2roff
# and scripts/completion.pl
make_depends="zlib
 $(use_if ssl libressl)
 $(use_if ldap openldap)
 $(use_if ares c-ares)
 $(use_if psl libpsl)
 $(use_if idn libidn2)
 $(use_if brotli brotli)
 $(use_if zstd zstd)
 $(use_if man perl)
 $(use_if completions perl)"

configure_args="
    $(use_enable ipv6)
    --enable-unix-sockets
    --enable-symbol-hiding
    $(use_enable man docs)
    $(use_enable manual)
    $(use_enable ldap)
    $(use_enable ares)
    $(use_if ssl --with-openssl --without-ssl)
    --with-pic
    --with-ca-fallback
    --without-librtmp
    $(use_with psl libpsl)
    $(use_with idn libidn2)
    $(use_with brotli)
    $(use_with zstd)
    $(use_with completions zsh-functions-dir)
    $(use_with completions fish-functions-dir)"

pre_configure() {
    if use manual && ! use man; then
        die "curl: the manual use flag needs the man use flag"
    fi

    # upstream broke static linking of the curl binary, keep the shared
    # library intact and force -all-static for the command only
    # https://github.com/curl/curl/issues/7475
    use static && bsed 's/\(curl_LDADD =\)/\1 -all-static/' src/Makefile.in
}
