# SPDX-FileCopyrightText: 2022 Dor Askayo <dor.askayo@gmail.com>
# SPDX-FileCopyrightText: 2021 Andrius Štikonas <andrius@stikonas.eu>
# SPDX-FileCopyrightText: 2022 Samuel Tyler <samuel@samuelt.me>
#
# SPDX-License-Identifier: GPL-3.0-or-later


src_prepare() {
    default

    rm -f build-aux/ltmain.sh
    rm -f doc/*.info doc/*.1
    rm -f bootstrap
    rm -f tests/testsuite tests/package.m4

    ../../import-gnulib.sh

    LIBTOOLIZE=true AUTOPOINT=true ../../bootstrap-helper.sh

    LIBTOOLIZE=true AUTOPOINT=true AUTOMAKE=automake-1.15 ACLOCAL=aclocal-1.15 AUTOCONF=autoconf-2.69 AUTOHEADER=autoheader-2.69 autoreconf-2.69 -fi
    LIBTOOLIZE=true AUTOPOINT=true AUTOMAKE=automake-1.15 ACLOCAL=aclocal-1.15 AUTOCONF=autoconf-2.69 AUTOHEADER=autoheader-2.69 autoreconf-2.69 -fi libltdl
}

src_configure() {
    ./configure \
        --prefix="${PREFIX}" \
        --libdir="${LIBDIR}" \
        --disable-shared \
        --host="${TARGET}" \
        --target="${TARGET}" \
        --build="${TARGET}" \
        ac_path_EGREP="egrep" \
        ac_path_FGREP="fgrep" \
        ac_path_GREP="grep" \
        ac_path_SED="sed"
}

src_compile() {
    make "${MAKEJOBS}" AUTOM4TE=autom4te-2.69 MAKEINFO=true
}

src_install() {
    make install MAKEINFO=true DESTDIR="${DESTDIR}"

    sed -i -e "s/{EGREP=.*/{EGREP='egrep'}/" \
        -e "s/{FGREP=.*/{FREGP='fgrep'}/" \
        -e "s/{GREP=.*/{GREP='grep'}/" \
        -e "s/{SED=.*/{SED='sed'}/" \
        "${DESTDIR}/usr/bin/libtool"
}
