TCLDIRDIR= $(TCLDIR)/unix
TKDIRDIR= $(TKDIR)/unix

XFLAGS = --x-includes=$(X11INCLUDE) --x-libraries=$(X11LIB)
XPAFLAGS = $(XFLAGS)
FUNTOOLSFLAGS =

all: 	dirs \
	tcl tk \
	tktable tkcon xmlrpc tkblt \
	tclxml tkimg tkmpeg tkhtml \
	xpa tcliis tclcheckdns signal funtools \
	ast wcssubs \
	rice hcompress plio \
	saotk zvfs ds9

tcl	: FORCE
	@echo "Installing Tcl..."
	cd $(TCLDIRDIR); CC='$(CC)' CFLAGS='$(OPTS)' \
	./configure $(XFLAGS) $(TCLFLAGS) \
	--prefix $(root) \
	--disable-shared \
	--enable-symbols
	$(MAKE) -C $(TCLDIRDIR) -j $(JOBS) install

tk	: FORCE
	@echo "Installing Tk..."
	cd $(TKDIRDIR); CC='$(CC)' CFLAGS='$(OPTS)' \
	./configure $(XFLAGS) $(TCLFLAGS) \
	--prefix $(root) \
	--disable-shared \
	--enable-symbols
	$(MAKE) -C $(TKDIRDIR) -j $(JOBS) install

tkblt	: FORCE
	@echo "Installing Tkblt..."
	cd $(TKBLTDIR); CC='$(CC)' CFLAGS='$(OPTS)' \
	./configure $(XFLAGS) \
	--prefix $(root) \
	--exec-prefix $(root) \
	--enable-symbols
	$(MAKE) -C $(TKBLTDIR) -j $(JOBS) install

tktable	: FORCE
	@echo "Installing Tktable..."
	cd $(TKTABLEDIR); CC='$(CC)' CFLAGS='$(OPTS)' \
	./configure $(XFLAGS) \
	--prefix $(root) \
	--disable-shared \
	--enable-symbols
	$(MAKE) -C $(TKTABLEDIR) -j $(JOBS)
	$(MAKE) -C $(TKTABLEDIR) -j $(JOBS) install

tclxml	: FORCE
	@echo "Installing Tclxml..."
	cd $(TCLXMLDIR); CC='$(CC)' CFLAGS='$(OPTS)' \
	./configure \
	--prefix $(root) \
	--disable-shared
	--with-xml-static=1
	$(MAKE) -C $(TCLXMLDIR) -j $(JOBS)
	$(MAKE) -C $(TCLXMLDIR) -j $(JOBS) install

tkimg	: libtiff
	@echo "Installing Tkimg..."
	cd $(TKIMGDIR); CC='$(CC)' CFLAGS='$(OPTS) -DPNG_NO_WRITE_gAMA' \
	./configure $(XFLAGS) \
	--with-tcl=$(root)/$(TCLDIRDIR) \
	--with-tk=$(root)/$(TKDIRDIR) \
	--prefix $(root) \
	--disable-shared
	$(MAKE) -C $(TKIMGDIR) -j $(JOBS) install

tkmpeg	: FORCE
	@echo "Installing Tkmpeg..."
	cd $(TKMPEGDIR); CC='$(CC)' CFLAGS='$(OPTS)' \
	./configure $(XFLAGS) \
	--prefix $(root) \
	--exec-prefix $(root) \
	--enable-symbols
	$(MAKE) -C $(TKMPEGDIR) -j $(JOBS) install

tkhtml	: $(HTMLDIR)
	@echo "Installing Tkhtml..."
	cd $(HTMLDIR); CC='$(CC)' CFLAGS='$(OPTS) -DUSE_INTERP_RESULT' \
	$(root)/htmlwidget/configure $(XFLAGS) \
	--with-tcl=$(root)/$(TCLDIR) \
	--with-tk=$(root)/$(TKDIR) \
	--prefix $(root) \
	--enable-shared=no
	$(MAKE) -C $(HTMLDIR) headers libtkhtml.a
	cp $(HTMLDIR)/libtkhtml.a lib/.

tcliis	: FORCE
	@echo "Installing Tcliis..."
	cd $(TCLIISDIR); CC='$(CC)' CFLAGS='$(OPTS)' \
	./configure \
	--prefix $(root) \
	--exec-prefix $(root) \
	--enable-symbols
	$(MAKE) -C $(TCLIISDIR) -j $(JOBS) install

tclcheckdns : FORCE
	@echo "Installing Tclcheckdns..."
	cd $(TCLCHECKDNSDIR); CC='$(CC)' CFLAGS='$(OPTS)' \
	./configure \
	--prefix $(root) \
	--exec-prefix $(root) \
	--enable-symbols
	$(MAKE) -C $(TCLCHECKDNSDIR) -j $(JOBS) install

distclean : tclclean tkclean \
	tktableclean tkbltclean \
	tclxmlclean tkimgclean tkmpegclean tkhtmlclean \
	xpaclean tcliisclean tclcheckdnsclean signalclean funtoolsclean \
	astclean wcssubsclean \
	riceclean hcompressclean plioclean \
	saotkclean zvfsclean ds9clean srcclean \
	filesclean dirsclean

#--------------------------distribution

ifdef CVS_SERVER

#--------------------------remote

dist : distds9 distxpa
	scp dist/ds9.$(ARCH).$(DS9VERSION).tar.gz $(USER)@$(DEST):build/$(ARCH)/.
	ssh $(USER)@$(DEST) 'cd build/$(ARCH); zcat ds9.$(ARCH).$(DS9VERSION).tar.gz | tar -xvf -'
	scp dist/xpa.$(ARCH).$(XPAVERSION).tar.gz $(USER)@$(DEST):build/$(ARCH)/.
	ssh $(USER)@$(DEST) 'cd build/$(ARCH); zcat xpa.$(ARCH).$(XPAVERSION).tar.gz | tar -xvf -'

#--------------------------remote

else

#--------------------------local

dist : distds9 distxpa
	cp dist/ds9.$(ARCH).$(DS9VERSION).tar.gz $(HOME)/build/$(ARCH)/.
	cd $(HOME)/build/$(ARCH); $(ZCAT) ds9.$(ARCH).$(DS9VERSION).tar.gz | tar -xvf -
	cp dist/xpa.$(ARCH).$(XPAVERSION).tar.gz $(HOME)/build/$(ARCH)/.
	cd $(HOME)/build/$(ARCH); $(ZCAT) xpa.$(ARCH).$(XPAVERSION).tar.gz | tar -xvf -

#--------------------------local

endif

distds9 : FORCE
	@echo "Creating SAODS9 Distribution"
	cd bin; tar cvf - ds9$(EXE) $(ZIPFILE) | gzip > ../dist/ds9.$(ARCH).$(DS9VERSION).tar.gz

distxpa : FORCE
	@echo "Creating XPA Distribution"
	cd bin; tar cvf - xpa*$(EXE) |gzip > ../dist/xpa.$(ARCH).$(XPAVERSION).tar.gz
