#!/usr/bin/env modbuild

pbuild::set_download_url "ftp://ftp.tcl.tk/pub/tcl/tcl8_6/tcl${V_PKG}-src.tar.gz"

pbuild::add_to_group 'Programming'
pbuild::install_docfiles 'license.terms' 'README'

pbuild::configure_Darwin() {
	export CXX=/usr/bin/clang++
	export CC=/usr/bin/clang
	PATH+=":/opt/X11/bin"
	export PKG_CONFIG_PATH="/opt/X11/share/pkgconfig:/opt/X11/lib/pkgconfig:$PKG_CONFIG_PATH"
	"${SRC_DIR}/macosx/configure" \
		--prefix="${PREFIX}" \
		--enable-threads \
		--disable-symbols \
		|| exit 1
}

pbuild::configure_Linux() {
	"${SRC_DIR}/unix/configure" \
		--prefix="${PREFIX}" \
		|| exit 1
}

pbuild::post_install() {
	{ cd "${PREFIX}"/bin && rm -f tclsh && ln -fs tclsh${V%.*} tclsh; };
}

pbuild::post_install_Darwin() {
	local -r libtcl="libtcl${V_MAJOR}.${V_MINOR}.dylib"
	install_name_tool \
			-id @executable_path/../lib/${libtcl} \
			"${PREFIX}/lib/${libtcl}"
}
