#!/usr/bin/env sh
# Get an updated config.sub and config.guess
cp $BUILD_PREFIX/share/libtool/build-aux/config.* ./build-aux
cp $BUILD_PREFIX/share/libtool/build-aux/config.* ./libcharset/build-aux
set -ex


./configure --prefix=${PREFIX}  \
            --host=${HOST}      \
            --build=${BUILD}    \
            --enable-static     \
            --disable-rpath     \
            --enable-relocatable

make -j${CPU_COUNT} ${VERBOSE_AT}
make install
if [[ "${CONDA_BUILD_CROSS_COMPILATION}" != "1" ]]; then
export LD_LIBRARY_PATH="$PREFIX/lib"
make check || true
fi

# TODO :: Only provide a static iconv executable for GNU/Linux.
# TODO :: glibc has iconv built-in. I am only providing it here
# TODO :: for legacy packages (and through gritted teeth).
if [[ ${HOST} =~ .*linux.* ]]; then
  chmod 755 ${PREFIX}/lib/libiconv.so.*
  chmod 755 ${PREFIX}/lib/libcharset.so.*
  chmod 755 ${PREFIX}/lib/preloadable_libiconv.so
fi

# remove libtool files
find $PREFIX -name '*.la' -delete
