#!/bin/bash
#
# https://www.tcl.tk
#
P=tcl
V=${TCL_VERSION:-8.6.13}
FNAME="$P$V-src.tar.gz"
DOWNLOAD_URL="https://prdownloads.sourceforge.net/tcl/${FNAME}"

source "$(dirname "$0")/librecipes.bash"

#---
# download
test -r "${SRC_FILE}" || curl -L --output "$_" "${DOWNLOAD_URL}" || exit ${PB_ERR_DOWNLOAD}

#---
# unpack
mkdir -p "${SRC_DIR}" && cd "$_" || exit ${PB_ERR_SYSTEM}
tar --directory "${SRC_DIR}" --strip-components 1 -xv -f "${SRC_FILE}" || exit ${PB_ERR_UNTAR}

#---
# configure
mkdir -p "${BUILD_DIR}" && cd "$_" || exit ${PB_ERR_SYSTEM}
case $(uname -s) in
Linux )
	srcdir="${SRC_DIR}/unix"
	;;
Darwin )
	srcdir="${SRC_DIR}/macosx"
	;;
* )
	echo "Oops: unsupported OS!" 1>&2
	exit ${PB_ERR_SYSTEM}
	;;
esac
"${srcdir}"/configure \
	--prefix="${PREFIX}" \
	--bindir="${PREFIX}/${UTILBIN_DIR}" \
	--mandir="${PREFIX}/share/man" \
	--enable-shared=no \
        || exit ${PB_ERR_CONFIGURE}

#---
# compile & install
make -j ${NJOBS} || exit ${PB_ERR_MAKE}
make install || exit ${PB_ERR_INSTALL}

#---
# post-install
{ cd "${PREFIX}/${UTILBIN_DIR}" && rm -f tclsh && ln -fs tclsh${V%.*} tclsh; };

rm -rf "${PREFIX}/share/man/man1/tclsh.1"
rm -rf "${PREFIX}/share/man/man3"
rm -rf "${PREFIX}/share/man/mann"

#---
# Local Variables:
# mode: shell-script-mode
# sh-basic-offset: 8
# End:
