#--------------------------parsers

vpath %.tac $(prefix)/ds9/parsers
vpath %.fcl $(prefix)/ds9/parsers

# -v generate output file
# -w generate warnings
# -d generate lexer table
$(prefix)/ds9/parsers/%parser.tcl : %parser.tac
	tclsh $(prefix)/taccle/taccle.tcl -p $* -d $<
#	tclsh $(prefix)/taccle/taccle.tcl -p $* -d -w -v $<
	echo "package provide DS9 1.0" | cat - $@ > tmp && mv tmp $@

# -d debug
$(prefix)/ds9/parsers/%lex.tcl : %lex.fcl
	tclsh $(prefix)/fickle/fickle.tcl -P $* $<
#	tclsh $(prefix)/fickle/fickle.tcl -P $* -d $<
	echo "package provide DS9 1.0" | cat - $@ > tmp && mv tmp $@

#--------------------------library

SRCP = $(wildcard $(prefix)/ds9/parsers/*.tac)
SRCL = $(wildcard $(prefix)/ds9/parsers/*.fcl)

$(LIBDIR)/library : $(SRCP:.tac=.tcl) $(SRCP:.tac=.tab.tcl) $(SRCL:.fcl=.tcl) $(prefix)/ds9/library/*.tcl
	mkdir -p "$@"
	cp -prf $? "$@"
# must do it this way for win
	cd "$@"; \
	echo "pkg_mkIndex . *.tcl; exit" | tclsh
	touch "$@"

#--------------------------support

$(LIBDIR)/msgs : $(prefix)/ds9/msgs
	cp -prf $? "$@"

$(LIBDIR)/doc : $(prefix)/ds9/doc
	cp -prf $? "$@"

$(LIBDIR)/cmaps : $(prefix)/ds9/cmaps
	cp -prf $? "$@"

$(LIBDIR)/template : $(prefix)/ds9/template
	cp -prf $? "$@"

#--------------------------tls

$(LIBDIR)/tls	: $(prefix)/tls/tls.tcl
	mkdir -p "$@"
	cp -prf $? "$@"
# must do it this way for win
	cd "$@"; \
	echo "pkg_mkIndex . *.tcl; exit" | tclsh

#--------------------------tkblt

$(LIBDIR)/tkblt	: $(prefix)/tkblt/library/*.tcl
	mkdir -p "$@"
	cp -p $? "$@"
# must do it this way for win
	cd "$@"; \
	echo "pkg_mkIndex . *.tcl; exit" | tclsh

#--------------------------tkcon

$(LIBDIR)/tkcon	: $(prefix)/tkcon
	cp -prf $? "$@"
# must do it this way for win
	cd "$@"; \
	echo "pkg_mkIndex . *.tcl; exit" | tclsh

#--------------------------tcllib

$(LIBDIR)/base64: $(prefix)/tcllib/modules/base64
	cp -prf $? "$@"

$(LIBDIR)/ftp	: $(prefix)/tcllib/modules/ftp
	cp -prf $? "$@"

$(LIBDIR)/log	: $(prefix)/tcllib/modules/log
	cp -prf $? "$@"

$(LIBDIR)/textutil: $(prefix)/tcllib/modules/textutil
	cp -prf $? "$@"

$(LIBDIR)/math	: $(prefix)/tcllib/modules/math
	cp -prf $? "$@"

#--------------------------distclean

.PHONY	: distclean parsersclean

distclean: clean
	-rm -f Makefile config.cache config.log config.status
	-rm -rf autom4te.cache

parsersclean:
	-rm -rf $(prefix)/ds9/parsers/*# \
	    $(prefix)/ds9/parsers/*~ \
	    $(prefix)/ds9/parsers/*.tcl \
	    $(prefix)/ds9/parsers/*.output
