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

XPAFLAGS = --without-x
FUNTOOLSFLAGS =

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

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

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

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

tkblt	: FORCE
	@echo "Installing TKBLT..."
	cd $(TKBLTDIR); CC='$(CC)' CFLAGS='$(OPTS) -DUSE_INTERP_RESULT' \
	 ./configure --prefix $(root) --with-tcl=$(root)/$(TCLDIRDIR) --with-tk=$(root)/$(TKDIRDIR) --without-x $(TKBLTWITHOUT) --without-xftincdir --without-xftlibdir --disable-shared
	cd $(TKBLTDIR)/src; $(MAKE) -j $(JOBS) build_static
	cp $(TKBLTDIR)/src/*.a lib/.
	cd $(TKBLTDIR)/src; cp $(TKBLTINCL) ../../include/.

tclxml	: FORCE
	@echo "Installing TCLXML..."
	cd $(TCLXMLDIR); CC='$(CC)' CFLAGS='$(OPTS)' \
	./configure --prefix $(root) --disable-shared --disable-threads --with-xml-static=1 $(TCLXMLFLAGS)
	$(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 --prefix $(root) --with-tcl=$(root)/$(TCLDIRDIR) --with-tk=$(root)/$(TKDIRDIR) $(XFLAGS) --disable-shared --disable-threads
	$(MAKE) -C $(TKIMGDIR) -j $(JOBS) install

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

win : FORCE
	@echo "Installing win..."
	$(MAKE) -C win -j $(JOBS) install

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

winclean : FORCE
	$(MAKE) -C win distclean

ds9app	: ds9
	$(MAKE) -C $(DS9DIR) ds9app

ds9winzip : FORCE
	$(RM) -f dist/$(DS9APP)\ Install.*
	/cygdrive/c/Program\ Files\ \(x86\)/WinZip/wzzip -p -r dist/$(DS9APP)\ Install.zip bin/ds9app
#	/cygdrive/c/Program\ Files\ \(x86\)/WinZip\ Self-Extractor/WINZIPSE.EXE  dist/$(DS9APP)\ Install.zip -setup -i ds9/win/ds9.ico -le -runasuser -t ds9/win/message.txt -a ds9/win/about.txt -c cscript install.vbs 
	/cygdrive/c/Program\ Files\ \(x86\)/WinZip\ Self-Extractor/WINZIPSE.EXE  dist/$(DS9APP)\ Install.zip -d C:\\ds9 -i ds9/win/ds9.ico -le -overwrite -runasuser -c cscript install.vbs

xpawinzip : FORCE
	$(RM) -f dist/$(XPAAPP)\ Install.*
	/cygdrive/c/Program\ Files\ \(x86\)/WinZip/wzzip dist/$(XPAAPP)\ Install.zip bin/xpa* bin/cygwin1.dll
	/cygdrive/c/Program\ Files\ \(x86\)/WinZip\ Self-Extractor/WINZIPSE.EXE  dist/$(XPAAPP)\ Install.zip -d C:\\ds9 -le -overwrite -runasuser

distapp	: distds9app distxpaapp

ifdef CVS_SERVER

distds9app : ds9winzip
	scp dist/$(DS9APP)\ Install.exe $(USER)@$(DEST):build/$(ARCH)/.

distxpaapp : xpawinzip
	@echo "Creating XPA Distribution"
	scp dist/$(XPAAPP)\ Install.exe $(USER)@$(DEST):build/$(ARCH)/.

else

distds9app : ds9winzip
	cp dist/ds9.$(ARCH).$(DS9VERSION).exe $(HOME)/build/$(ARCH)/.

distxpaapp : xpawinzip
	cp dist/xpa.$(ARCH).$(XPAVERSION).exe $(HOME)/build/$(ARCH)/.

endif

FORCE	:
