#! /bin/sh

name=readline
version=8.2.13
revision=1
tarball_url="https://ftp.gnu.org/gnu/readline/readline-8.2.tar.gz"
tarball_blake2b="7974322b9c092a756a79e537df08e8532f8e0fcb598f77732e28287c33ebec9e9837ed88b43334c310892d56a871b423903f0f564def2fbe700a1004f2ae7b18"
source_allow_network="yes"
source_imagedeps="curl"
source_hostdeps="automake autoconf libtool pkg-config"
hostdeps="gcc autoconf automake libtool pkg-config"
deps="core-libs ncurses"

prepare() {
    for p in $(seq -w 13); do
        curl -L https://ftp.gnu.org/gnu/readline/readline-8.2-patches/readline82-0$p | patch -p0
    done

    cp -v /usr/local/share/autoconf/build-aux/{config.guess,config.sub} ./support/
    cp -v /usr/local/share/autoconf/build-aux/install-sh ./support/install.sh
}

configure() {
    autotools_configure \
        --enable-multibyte \
        --with-curses
}

build() {
    make SHLIB_LIBS="-lncursesw -ltinfow" -j${parallelism}
}

package() {
    make install DESTDIR="${dest_dir}"

    ln -s libreadline.so.8.2 "${dest_dir}${prefix}"/lib/libreadline.so.8
    ln -s libhistory.so.8.2 "${dest_dir}${prefix}"/lib/libhistory.so.8

    post_package_strip
}
