# Maintainer: Levente Polyak <anthraxx[at]archlinux[dot]org>
# Maintainer: T.J. Townsend <blakkheim@archlinux.org>
# Maintainer: Robin Candau <antiz@archlinux.org>
# Contributor: Eric Bélanger <eric@archlinux.org>

pkgname=wget
pkgver=1.25.0
pkgrel=3
pkgdesc='Network utility to retrieve files from the web'
url='https://www.gnu.org/software/wget/wget.html'
arch=('x86_64' 'aarch64')
license=('GPL-3.0-or-later')
depends=('glibc' 'zlib' 'gnutls' 'libidn2' 'libidn2.so' 'util-linux-libs' 'libuuid.so'
         'libpsl' 'libpsl.so' 'pcre2' 'nettle' 'libnettle.so')
checkdepends=('perl-http-daemon' 'perl-io-socket-ssl' 'python')
makedepends=('autoconf-archive' 'git' 'gperf' 'perl')
optdepends=('ca-certificates: HTTPS downloads')
backup=('etc/wgetrc')
source=("git+https://https.git.savannah.gnu.org/git/wget.git?signed#tag=v${pkgver}"
        "git+https://https.git.savannah.gnu.org/git/gnulib.git"
        "https://ftpmirror.gnu.org/gnu/${pkgname}/${pkgname}-${pkgver}.tar.lz"{,.sig})
sha256sums=('c63fd5c082a3a7ecf9309c2334df95e61abfc413cbefe81e5ed5d40a4301344e'
            'SKIP'
            '19225cc756b0a088fc81148dc6a40a0c8f329af7fd8483f1c7b2fe50f4e08a1f'
            'SKIP')
b2sums=('d4f747bd505a5b482013dfc20c307a34ce505833120ff2b77ba4d94b7476d1407e64eab862d6fd5490e96e5e9b8a7e3cf742404634a287996a7a702c8efd6304'
        'SKIP'
        '58edd7393b5109804d7a6ce77466d30e1fba3c5ae4b5b8634758c9ebd7fa95cf106d35ad0b4f9151833d88b0221fc488a1005ec0b98417766bf2092309744954'
        'SKIP')
validpgpkeys=(
  'AC404C1C0BF735C63FF4D562263D6DF2E163E1EA' # Giuseppe Scrivano <gscrivano@gnu.org>
  '7845120B07CBD8D6ECE5FF2B2A1743EDA91A35B6' # Darshit Shah <darnir@gnu.org>
  '1CB27DBC98614B2D5841646D08302DB6A2670428' # Tim Rühsen <tim.ruehsen@gmx.de>
)

prepare() {
  cd ${pkgname}

  # Skip downloading po files in bootstrap scripts
  # to avoid non-deterministic builds
  # and to avoid wget (make-)depending on itself
  export SKIP_PO="1"
  # The $SKIP_PO environment variable is only honored by
  # the gnulib submodule if using its "sh" implementation
  export GNULIB_TOOL_IMPL="sh"

  git submodule init
  git config submodule.gnulib.url "${srcdir}/gnulib"
  git -c protocol.file.allow=always submodule update

  sh bootstrap
  autoreconf -fiv

  cat >> doc/sample.wgetrc <<EOF

# default root certs location
ca_certificate=/etc/ssl/certs/ca-certificates.crt
EOF
}

build() {
  cd ${pkgname}
  ./configure \
    --prefix=/usr \
    --sysconfdir=/etc \
    --disable-rpath \
    --enable-nls \
    --with-ssl=gnutls
  make

  # Generate wget mo files from dist tarball
  cd "${srcdir}/${pkgname}-${pkgver}/po"
  for po in *.po; do
    msgfmt "${po}" -o "${po%.po}.mo"
  done
}

check() {
  cd ${pkgname}
  make check < /dev/null
}

package() {
  cd ${pkgname}
  make DESTDIR="${pkgdir}" install

  # Install wget and wget-gnulib mo files from dist tarball
  cd "${srcdir}/${pkgname}-${pkgver}/po"
  for wget_mo in *.mo; do
    install -Dm 644 "${wget_mo}" "${pkgdir}/usr/share/locale/${wget_mo%.mo}/LC_MESSAGES/${pkgname}.mo"
  done

  for wget_gnulib_mo in *.gmo; do
    install -Dm 644 "${wget_gnulib_mo}" "${pkgdir}/usr/share/locale/${wget_gnulib_mo%.gmo}/LC_MESSAGES/${pkgname}-gnulib.mo"
  done
}

# vim: ts=2 sw=2 et:
