#--------------------------defines

CFLAGS= $(CCOPT) -I. -I../include -I$(X11INCLUDE)
CXXFLAGS = $(CXXOPT) -I. -I../include -I$(X11INCLUDE)

MAINDIR	= ../$(TKDIR)/win
MAIN	= winMain
RES	= ds9.res.o

OBJS	= ds9.o $(MAIN).o $(RES)

ZDIR	= zipdir/zvfsmntpt
FFILES	= \
	$(ZDIR)/$(TCLVER) \
	$(ZDIR)/tcl8 \
	$(ZDIR)/$(TKVER) \
	$(ZDIR)/$(TKBLTDIR) \
	$(ZDIR)/$(TCLLIBVER) \
	$(ZDIR)/$(TKCONVER) \
	$(ZDIR)/$(XMLRPCVER) \
	$(ZDIR)/src \
	$(ZDIR)/msgs \
	$(ZDIR)/doc \
	$(ZDIR)/cmaps \
	$(ZDIR)/template

ifdef FILTERCOMPILER
	FILES = $(FFILES) $(ZDIR)/$(FILTERCOMPILER)
else
	FILES = $(FFILES)
endif

LIBS	= \
	../lib/libsaotk.a \
	../lib/libtkhtml.a \
	../lib/$(TKMPEGDIR)/libtkmpeg10.a \
	../lib/$(TCLXMLVER)/Tclxml32.a \
	../lib/$(TKTABLEVER)/Tktable210.a \
	../lib/$(TKIMGVER)/tkimgpng14.a \
	../lib/$(TKIMGVER)/pngtcl143.a \
	../lib/$(TKIMGVER)/tkimgtiff14.a \
	../lib/$(TKIMGVER)/tifftcl394.a \
	../lib/$(TKIMGVER)/tkimgjpeg14.a \
	../lib/$(TKIMGVER)/jpegtcl82.a \
	../lib/$(TKIMGVER)/tkimggif14.a \
	../lib/$(TKIMGVER)/tkimgwindow14.a \
	../lib/$(TKIMGVER)/zlibtcl125.a \
	../lib/$(TKIMGVER)/tkimg14.a \
	../lib/libtiff.a \
	../lib/libfuntools.a \
	../lib/librice.a \
	../lib/libhcomp.a \
	../lib/libplio.a \
	../lib/libast.a \
	../lib/libast_err.a \
	../lib/libast_pal.a \
	../lib/libwcs.a \
	../lib/libzvfs.a \
	../lib/libz.a \
	../lib/libxpa.a \
	../lib/$(TCLIISDIR)/libiis10.a \
	../lib/$(TCLCHECKDNSDIR)/libtclcheckdns11.a \
	../lib/libxxlib.a \
	../lib/libtk86sg.a \
	../lib/libtkstub86sg.a \
	../lib/libtcl86sg.a \
	../lib/libtclstub86sg.a

#--------------------------main

all: ds9.exe

ds9.exe	: ds9Base.exe ds9.zip ../bin/tcc
	$(RM) $@
	strip ds9Base.exe
	cp ds9Base.exe ds9.exe
	cp ds9.exe ../bin/.
	cp ds9.zip ../bin/.
	cp /bin/cygwin1.dll ../bin/.
	cp /bin/cygxml2-2.dll ../bin/.
	cp /bin/cygstdc++-6.dll ../bin/.
	cp /bin/cygiconv-2.dll ../bin/.
	cp /bin/cygz.dll ../bin/.
	cp /bin/cyggcc_s-1.dll ../bin/.
	cp /bin/cygjbig-2.dll ../bin/.
	cp /bin/cyglzma-5.dll ../bin/.

debug	: ds9Base.exe ds9.zip ../bin/tcc
	$(RM) $@
	cp ds9Base.exe ds9.exe

ds9app	: ds9.exe
	$(RM) -r ../bin/ds9app
	mkdir ../bin/ds9app
	cp ds9.exe ../bin/ds9app/.
	cp ds9.zip ../bin/ds9app/.
	cp /bin/cygwin1.dll ../bin/ds9app/.
	cp /bin/cygxml2-2.dll ../bin/ds9app/.
	cp /bin/cygstdc++-6.dll ../bin/ds9app/.
	cp /bin/cygiconv-2.dll ../bin/ds9app/.
	cp /bin/cygz.dll ../bin/ds9app/.
	cp /bin/cyggcc_s-1.dll ../bin/ds9app/.
	cp /bin/cygjbig-2.dll ../bin/ds9app/.
	cp /bin/cyglzma-5.dll ../bin/ds9app/.
	cp -rp ../bin/tcc ../bin/ds9app/.
	cp ../ds9/win/install.vbs ../bin/ds9app/.

ds9Base.exe: $(OBJS) $(LIBS)
	$(RM) $@
	$(CXX) ${OPTS} \
	-o $@ $(OBJS) $(LIBS) \
	-lxml2 -ljbig \
	-lws2_32 -limm32 -lcomctl32 -mwindows 

$(RES)	: win/ds9.rc win/ds9.ico
	windres -o $@ --define STATIC_BUILD --include ../$(TKDIR)/generic \
	--include ../$(TCLDIR)/generic --include ../$(TKDIR)/win/rc \
	--include win win/ds9.rc

../bin/tcc: ../compilers/$(TCC)
	$(RM) -r $@
	cd ../bin; unzip ../compilers/$(TCC)
	chmod +x ../bin/tcc/tcc.exe
	touch $@

#--------------------------cleanup

distclean: FORCE
	$(RM) core *~ *# ds9Base.exe ds9.exe *.zip *.o
	$(RM) -r zipdir bin/tcc
