#!/bin/bash
# Build script for GNU wget

set -e
cd "$SRCDIR"

# Fix illumos gnulib compatibility issues
for f in lib/localename.c gnulib-tests/localename.c; do
    if [ -f "$f" ]; then
        sed -i 's/extern char \* getlocalename_l/extern const char * getlocalename_l/' "$f"
    fi
done

./configure \
    --prefix=$PREFIX \
    --sysconfdir=$SYSCONFDIR \
    --with-ssl=openssl \
    --disable-nls \
    --disable-pcre2

# Fix illumos memset_s false detection if present
for config in lib/config.h gnulib-tests/config.h config.h; do
    if [ -f "$config" ]; then
        sed -i 's/#define HAVE_MEMSET_S 1/\/* #undef HAVE_MEMSET_S - illumos has it as macro only *\//' "$config"
    fi
done

gmake -j${JOBS:-1}
gmake install DESTDIR="$PKGDIR"
