#! /bin/bash

# Define parameters
VERS=0.4
SRC="src/tcltcc${VERS}.zip"
SRCURL="http://tcltcc.googlecode.com/files/tcltcc${VERS}.zip"
BUILDDIR="tcltcc-${VERS}"
export VERS SRC SRCURL BUILDDIR

# Load common functions
source ../common.sh

# Do not build if the "tcl" platform has been requested
not_platforms 'tcl'

# Download source
download_src

# Build package
(
	rm -rf build
	mkdir -p "${PLATDIR}" >/dev/null 2>/dev/null
	mkdir build

	cd build/ || exit 1
	mkdir "${BUILDDIR}"
	cd "${BUILDDIR}" || exit 1

	unzip -q "../../${SRC}"

	# TCC ships with object files in the way
	${MAKE:-make} distclean >/dev/null 2>/dev/null

	bash ./configure --enable-shared --enable-threads --with-tcl="${TCLCONFIGDIR}" --prefix="${PLATDIR}" --libdir="${PLATDIR}" --bindir="${PLATDIR}" ${CONFIGUREEXTRA}

	${MAKE:-make} || exit 1

	${MAKE:-make} install-binaries PKG_DIR='' || exit 1

	rm -f "${PLATDIR}"/*.a
) || exit 1

# Create metadata
../create_teapot "${PLATDIR}/teapot.txt" "tcc" "${VERS}" "${SRCURL}" "${PLATFORM}" "Tcl 8.4" "Tcltcc provides a Tcl binding to the TinyCC compiler. It allows dynamic compilation of C code from within a Tcl interpreter."

exit 0
