#!/bin/sh

if [[ `uname` = "Linux" ]]; then
  export LDFLAGS="${LDFLAGS} -lrt -Wl,-z,noexecstack,-z,relro,-z,now"
  export CFLAGS="${CFLAGS} -Wformat -Wformat-security -fstack-protector-all \
-D_FORTIFY_SOURCE=2 -fpic -fPIC -O3 -Wl,-z,noexecstack,-z,relro,-z,now"
fi

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

make -j${CPU_COUNT} ${VERBOSE_AT}
make check
make install

# 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.2.6.0
  chmod 755 ${PREFIX}/lib/libcharset.so.1.0.0
  chmod 755 ${PREFIX}/lib/preloadable_libiconv.so
fi
