# Maintainer: Martell Malone <martellmalone@gmail.com>

pkgname=inetutils
pkgver=2.6
pkgrel=2
pkgdesc="A collection of common network programs."
arch=('i686' 'x86_64')
url="https://www.gnu.org/software/inetutils/"
msys2_repository_url="https://cgit.git.savannah.gnu.org/cgit/inetutils.git"
msys2_references=(
  "cpe: cpe:/a:gnu:inetutils"
)
license=('spdx:GPL-3.0-or-later')
depends=('gcc-libs' 'libintl' 'libreadline' 'ncurses')
makedepends=('gettext-devel' 'libreadline-devel' 'ncurses-devel' 'autotools' 'gcc' 'tftp-hpa' 'help2man')
options=('!emptydirs')
source=(https://ftp.gnu.org/gnu/inetutils/${pkgname}-${pkgver}.tar.xz
        inetutils-2.6-1.src.patch
        icmp6.h
        osockaddr.h
        talkd.h)
sha256sums=('68bedbfeaf73f7d86be2a7d99bcfbd4093d829f52770893919ae174c0b2357ca'
            '7898c2ae17f74e9462da7faf5599ad82a02e687054d50bfc779f09e44a39b15b'
            'efad23dea555319c503c0b6ed7ec6b46c8faa48c138c763749686fc66e98c4b8'
            'e19596afff3b2ed163cf1a5c8a8d034208f9f996ace1ac76fd877a2d16aa448d'
            'b9e2401b0756c9bebcb0b0835d3c8f218198a121013f4990637ed1b9af0c72fd')

prepare() {
  cd ${srcdir}/${pkgname}-${pkgver}

  # from cygwin
  mkdir -p headers/protocols
  cp ${srcdir}/osockaddr.h headers/protocols/osockaddr.h
  cp ${srcdir}/talkd.h     headers/protocols/talkd.h
  mkdir -p headers/netinet
  cp ${srcdir}/icmp6.h     headers/netinet/icmp6.h
  patch -p2 -i ${srcdir}/inetutils-2.6-1.src.patch

  autoreconf -fiv
}

build() {
  cd ${srcdir}/${pkgname}-${pkgver}

  mkdir -p "${srcdir}/build-${MSYSTEM}" && cd "${srcdir}/build-${MSYSTEM}"

  # copied from cygwin
  export ac_cv_func_mmap_fixed_mapped=no
  export CPPFLAGS+=" -I${srcdir}/${pkgname}-${pkgver}/headers"

  # this isn't set in ./configure but needed to get a valid Makefile -- don't ask me...
  export EXEEXT=.exe
  
  CFLAGS+=" -std=gnu17"

  ../${pkgbase}-${pkgver}/configure --prefix=/usr \
    --build=${CHOST} \
    --libexec=/usr/bin \
    --localstatedir=/var \
    --sysconfdir=/etc \
    --infodir=/usr/share/info \
    --mandir=/usr/share/man \
    --datarootdir=/usr/share \
    --docdir=/usr/share/doc/${pkgname} \
    --with-wrap \
    --without-pam \
    --enable-ftp --disable-ftpd \
    --enable-telnet --disable-telnetd \
    --enable-talk --disable-talkd \
    --enable-rlogin --disable-rlogind \
    --enable-rsh --disable-rshd \
    --enable-rcp --disable-hostname \
    --disable-rexec --disable-rexecd \
    --disable-tftp --disable-tftpd \
    --disable-ping --disable-ping6 \
    --disable-logger --disable-syslogd \
    --disable-inetd --disable-whois \
    --disable-uucpd --disable-ifconfig \
    --enable-dnsdomainname \
    --disable-traceroute \
	gl_cv_clean_version_stddef=yes

  make
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"

  make DESTDIR="${pkgdir}" install
}
