TCL_SUBDIR=			@VENDOR_TCL_SUBDIR@
TCL_TARGETS=		@VENDOR_TCL_INSTALL@

TCLTHREAD_SUBDIR=	@VENDOR_TCLTHREAD_SUBDIR@
TCLTREHAD_TARGETS=	@VENDOR_TCLTHREAD_INSTALL@

TCLX_SUBDIR=		@VENDOR_TCLX_SUBDIR@
TCLX_TARGETS=		@VENDOR_TCLX_INSTALL@

TCLLIB_SUBDIR=		@VENDOR_TCLLIB_SUBDIR@
TCLLIB_TARGETS= 	@VENDOR_TCLLIB_INSTALL@

DESTROOT=   		@abs_top_builddir@/vendor/vendor-destroot

.PHONY: all clean distclean install destroot test
.PHONY: destroot-tcl destroot-tcllthread destroot-tclx destroot-tcllib
.PHONY: install-tcl install-tcllthread install-tclx install-tcllib
.PHONY: %-tcl %-tcllthread %-tclx %-tcllib

# for make all, run destroot (where destroot will depend on all of each
# subpackage)
all: destroot

%-tcl:
	@echo ===\> making $(@:%-tcl=%) in ${DIRPRFX}@VENDOR_TCL_SUBDIR@
	@umask 0022; $(MAKE) -C @VENDOR_TCL_SUBDIR@ $(@:%-tcl=%)

%-tclthread:
	@echo ===\> making $(@:%-tclthread=%) in ${DIRPRFX}@VENDOR_TCLTHREAD_SUBDIR@
	@umask 0022; $(MAKE) -C @VENDOR_TCLTHREAD_SUBDIR@ $(@:%-tclthread=%)

# thread links against libtclstub
all-tclthread: all-tcl

%-tclx:
	@echo ===\> making $(@:%-tclx=%) in ${DIRPRFX}@VENDOR_TCLX_SUBDIR@
	@umask 0022; $(MAKE) -C @VENDOR_TCLX_SUBDIR@ $(@:%-tclx=%)

# tclx also links against libtclstub
all-tclx: all-tcl

%-tcllib:
	@echo ===\> making $(@:%-tcllib=%) in ${DIRPRFX}@VENDOR_TCLLIB_SUBDIR@
	@umask 0022; $(MAKE) -C @VENDOR_TCLLIB_SUBDIR@ TCLSH_PROG=@INTREE_TCLSH@ $(@:%-tcllib=%)

# tcllib requires a working tclsh
all-tcllib: all-tcl

destroot: destroot-tcl destroot-tclthread destroot-tclx destroot-tcllib
destroot-tcl: all-tcl
	@echo ===\> staging to destroot in ${DIRPRFX}@VENDOR_TCL_SUBDIR@
	@umask 0022; $(MAKE) -C @VENDOR_TCL_SUBDIR@ DESTDIR=${DESTROOT} @VENDOR_TCL_INSTALL@

destroot-tclthread: all-tclthread
	@echo ===\> staging to destroot in ${DIRPRFX}@VENDOR_TCLTHREAD_SUBDIR@
	@umask 0022; $(MAKE) -C @VENDOR_TCLTHREAD_SUBDIR@ DESTDIR=${DESTROOT} @VENDOR_TCLTHREAD_INSTALL@

destroot-tclx: all-tclx
	@echo ===\> staging to destroot in ${DIRPRFX}@VENDOR_TCLX_SUBDIR@
	@umask 0022; $(MAKE) -C @VENDOR_TCLX_SUBDIR@ DESTDIR=${DESTROOT} @VENDOR_TCLX_INSTALL@

destroot-tcllib: all-tcllib
	@echo ===\> staging to destroot in ${DIRPRFX}@VENDOR_TCLLIB_SUBDIR@
	@umask 0022; $(MAKE) -C @VENDOR_TCLLIB_SUBDIR@ DESTDIR=${DESTROOT} TCLSH_PROG=@INTREE_TCLSH@ @VENDOR_TCLLIB_INSTALL@

install: install-tcl install-tclthread install-tclx install-tcllib

TCL_PACKAGE_PATH=@TCL_PACKAGE_PATH@
OLD_TCL_FILES=  $(DESTDIR)$(TCL_PACKAGE_PATH)/tcl8/8.4/http-2.7.12.tm \
                $(DESTDIR)$(TCL_PACKAGE_PATH)/tcl8/8.4/platform-1.0.12.tm \
                $(DESTDIR)$(TCL_PACKAGE_PATH)/tcl8/8.4/platform-1.0.13.tm \
                $(DESTDIR)$(TCL_PACKAGE_PATH)/tcl8/8.5/tcltest-2.3.5.tm
install-tcl:
	rm -rf $(OLD_TCL_FILES)
	@echo ===\> making $(@:%-tcl=%) in ${DIRPRFX}@VENDOR_TCL_SUBDIR@
	@umask 0022; $(MAKE) -C @VENDOR_TCL_SUBDIR@ @VENDOR_TCL_INSTALL@

install-tclthread:
	rm -rf $(DESTDIR)$(TCL_PACKAGE_PATH)/thread2.7.{0,2}
	@echo ===\> making $(@:%-tclthrad=%) in ${DIRPRFX}@VENDOR_TCLTHREAD_SUBDIR@
	@umask 0022; $(MAKE) -C @VENDOR_TCLTHREAD_SUBDIR@ @VENDOR_TCLTHREAD_INSTALL@

install-tclx:
	@echo ===\> making $(@:%-tclx=%) in ${DIRPRFX}@VENDOR_TCLX_SUBDIR@
	@umask 0022; $(MAKE) -C @VENDOR_TCLX_SUBDIR@ @VENDOR_TCLX_INSTALL@

install-tcllib:
	rm -rf $(DESTDIR)$(TCL_PACKAGE_PATH)/tcllib1.1{5,7}
	@echo ===\> making $(@:%-tcllib=%) in ${DIRPRFX}@VENDOR_TCLLIB_SUBDIR@
	@umask 0022; $(MAKE) -C @VENDOR_TCLLIB_SUBDIR@ @VENDOR_TCLLIB_INSTALL@

test:

clean: clean-tcl clean-tcllib clean-tclx clean-tclthread
	rm -rf ${DESTROOT}

distclean: distclean-tcl distclean-tcllib distclean-tclx distclean-tclthread
	rm -f Makefile
	rm -rf vendor-destroot
