include ../../make.pkgs

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

CFLAGS= -g -DSTATIC_BUILD -mnop-fun-dllimport -D_GNU_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -I. -I../../include -I../../include/X11
CXXFLAGS = $(CFLAGS)

OBJS	= ds9.o winMain.o ds9.res.o

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

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

LIBS	= \
	../../lib/$(TKSAODIR)/libtksao10.a \
	../../lib/$(TKSAODIR)/libfuntools.a \
	../../lib/$(TKSAODIR)/libast.a \
	../../lib/$(TKSAODIR)/libast_err.a \
	../../lib/$(TKSAODIR)/libast_pal.a \
	../../lib/$(TKHTMLDIR)/libtkhtml10.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/$(TCLZVFSDIR/libtclzvfs10.a \
	../../lib/libxpa.a \
	../../lib/$(TKBLTDIR)/libtkblt30.a \
	../../lib/libtk86.a \
	../../lib/libtkstub86.a \
	../../lib/libtcl86.a \
	../../lib/libtclstub86.a

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

all: ds9.exe

winMain.o : winMain.c
	$(CC) $(CFLAGS) -DTK_LOCAL_APPINIT=SAOAppInit \
	-DTK_LOCAL_MAIN_HOOK=SAOLocalMainHook -c winMain.c -o $@

winMain.c : ../../$(TKDIR)/winMain.c
	cp ../../$(TKDIR)/winMain.c .

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/.

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 -rp ../../bin/tcc ../../bin/ds9app/.
	cp ../../ds9/install.vbs ../../bin/ds9app/.

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

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

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

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

clean	: FORCE
	cd ../library; $(MAKE) clean
	$(RM) core *~ *# 

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

FORCE	: