include ./make.pkgs

#--------------------------dirs

DIRS = bin lib include man share dist

#--------------------------cvs stuff

CVSFILES = admin \
	compilers \
	COPYING \
	copyright \
	ds9 \
	macosx \
	make.include \
	make.pkgs \
	mods \
	notes.txt \
	README \
	tclcheckdns1.1 \
	tcliis1.0 \
	tclsignal1.4 \
	tclzvfs1.0 \
	tests \
	tkblt3.0 \
	tkhtml1.0 \
	tkmacosx1.0 \
	tkmpeg1.0 \
	tksao1.0 \
	tkwin1.0 \
	unix \
	win

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

.NOTPARALLEL :
.PHONY	: all dirs ds9 tclcheckdns tcliis tclsignal tclxml tclzvfs 
.PHONY	: tkblt tkcon tkhtml tkimg libtiff tkmpeg tksao tktable xmlrpc xpa

all	: saods9

dirs	:
	@echo ""
	@echo "*** Install $@ ***"
	@for d in $(DIRS); do if [ ! -d $$d ]; then mkdir $$d; fi done

ds9	: scrub $(DS9DIR)/$(OS)/Makefile
	@echo ""
	@echo "*** Installing $(DS9DIR) ***"
	$(MAKE) -C $(DS9DIR)/$(OS)

debug	: scrub $(DS9DIR)/$(OS)/Makefile
	@echo ""
	@echo "*** Installing $(DS9DIR) ***"
	$(MAKE) -C $(DS9DIR)/$(OS) debug

$(DS9DIR)/$(OS)/Makefile :
	@echo ""
	@echo "*** Configure $(DS9DIR) ***"
	cd $(DS9DIR)/$(OS); \
	./configure \
	$(WITHTK) \
	--prefix $(ROOT) --exec-prefix $(ROOT) \
	--enable-symbols \
	--config-cache --cache-file=../../config.cache

tclcheckdns : $(TCLCHECKDNSDIR)/Makefile
	@echo ""
	@echo "*** Install $(TCLCHECKDNSDIR) ***"
	$(MAKE) -C $(TCLCHECKDNSDIR) -j $(JOBS) install

$(TCLCHECKDNSDIR)/Makefile :
	@echo ""
	@echo "*** Configure $(TCLCHECKDNSDIR) ***"
	cd $(TCLCHECKDNSDIR); \
	./configure \
	$(WITHTCL) \
	--prefix $(ROOT) --exec-prefix $(ROOT) \
	--disable-shared --enable-symbols \
	--config-cache --cache-file=../config.cache

tcliis	: $(TCLIISDIR)/Makefile
	@echo ""
	@echo "*** Install $(TCLIISDIR) ***"
	$(MAKE) -C $(TCLIISDIR) -j $(JOBS) install

$(TCLIISDIR)/Makefile :
	@echo ""
	@echo "*** Configure $(TCLIISDIR) ***"
	cd $(TCLIISDIR); \
	./configure \
	$(WITHTCL) \
	--prefix $(ROOT) --exec-prefix $(ROOT) \
	--disable-shared --enable-symbols \
	--config-cache --cache-file=../config.cache

tclsignal: $(TCLSIGNALDIR)/Makefile
	@echo ""
	@echo "*** Install $(TCLSIGNALDIR) ***"
	$(MAKE) -C $(TCLSIGNALDIR) install

$(TCLSIGNALDIR)/Makefile :
	@echo ""
	@echo "*** Configure $(TCLSIGNALDIR) ***"
	cd $(TCLSIGNALDIR); \
	./configure \
	$(WITHTCL) \
	--prefix $(ROOT) --exec-prefix $(ROOT) \
	--disable-shared --enable-symbols \
	--config-cache --cache-file=../config.cache

# no parallel
tclxml	: $(TCLXMLDIR)/Makefile
	@echo ""
	@echo "*** Install $(TCLXMLDIR) ***"
	$(MAKE) -C $(TCLXMLDIR) install

$(TCLXMLDIR)/Makefile :
	@echo ""
	@echo "*** Configure $(TCLXMLDIR) ***"
	cd $(TCLXMLDIR); \
	./configure \
	$(WITHTCL) \
	--prefix $(ROOT) --exec-prefix $(ROOT) \
	--disable-shared --enable-symbols \
	--config-cache --cache-file=../config.cache

tclzvfs	: $(TCLZVFSDIR)/Makefile
	@echo ""
	@echo "*** Install $(TCLZVFSDIR) ***"
	$(MAKE) -C $(TCLZVFSDIR) install

$(TCLZVFSDIR)/Makefile :
	@echo ""
	@echo "*** Configure $(TCLZVFSDIR) ***"
	cd $(TCLZVFSDIR); \
	./configure \
	$(WITHTCL) \
	--prefix $(ROOT) --exec-prefix $(ROOT) \
	--disable-shared --enable-symbols \
	--config-cache --cache-file=../config.cache

tkblt	: $(TKBLTDIR)/Makefile
	@echo ""
	@echo "*** Install $(TKBLTDIR) ***"
	$(MAKE) -C $(TKBLTDIR) -j $(JOBS) install

$(TKBLTDIR)/Makefile :
	@echo ""
	@echo "*** Configure $(TKBLTDIR) ***"
	cd $(TKBLTDIR); \
	./configure \
	$(WITHTK) \
	--prefix $(ROOT) --exec-prefix $(ROOT) \
	--disable-shared --enable-symbols \
	--config-cache --cache-file=../config.cache

tkcon	:
	@echo ""
	@echo "*** Install $@ ***"
	$(RM) -r lib/$(TKCONVER)
	mkdir lib/$(TKCONVER)
	cp $(TKCONDIR)/*.tcl lib/$(TKCONVER)

# no parallel
tkhtml	: $(TKHTMLDIR)/Makefile
	@echo ""
	@echo "*** Install $(TKHTMLDIR) ***"
	$(MAKE) -C $(TKHTMLDIR) install

$(TKHTMLDIR)/Makefile :
	@echo ""
	@echo "*** Configure $(TKHTMLDIR) ***"
	cd $(TKHTMLDIR); \
	./configure \
	$(WITHTK) \
	--prefix $(ROOT) --exec-prefix $(ROOT) \
	--disable-shared --enable-symbols \
	--config-cache --cache-file=../config.cache

tkimg	: libtiff $(TKIMGDIR)/Makefile
	@echo ""
	@echo "*** Install $(TKIMGDIR) ***"
	$(MAKE) -C $(TKIMGDIR) -j $(JOBS) install

# no config.cache
$(TKIMGDIR)/Makefile :
	@echo ""
	@echo "*** Configure $(TKIMGDIR) ***"
	cd $(TKIMGDIR); \
	./configure CFLAGS='-DPNG_NO_WRITE_gAMA' \
	$(WITHTK) $(TKIMGFLAGS) \
	--prefix $(ROOT) --exec-prefix $(ROOT) \
	--disable-shared --enable-symbols

libtiff	: $(TKIMGDIR)/compat/libtiff/Makefile
	@echo ""
	@echo "*** Install $(TKIMGDIR)/compat/libtiff ***"
	$(MAKE) -C $(TKIMGDIR)/compat/libtiff -j $(JOBS) install

# no enable-symbols
$(TKIMGDIR)/compat/libtiff/Makefile :
	@echo ""
	@echo "*** Configure $(TKIMGDIR)/compat/libtiff ***"
	cd $(TKIMGDIR)/compat/libtiff; \
	./configure \
	$(WITHTK) \
	--prefix $(ROOT) --exec-prefix $(ROOT) \
	--disable-shared

tkmpeg	: $(TKMPEGDIR)/Makefile
	@echo ""
	@echo "*** Install $(TKMPEGDIR) ***"
	$(MAKE) -C $(TKMPEGDIR) -j $(JOBS) install

$(TKMPEGDIR)/Makefile :
	@echo ""
	@echo "*** Configure $(TKMPEGDIR) ***"
	cd $(TKMPEGDIR); \
	./configure \
	$(WITHTK) \
	--prefix $(ROOT) --exec-prefix $(ROOT) \
	--disable-shared --enable-symbols \
	--config-cache --cache-file=../config.cache

tksao	: $(TKSAODIR)/Makefile
	@echo ""
	@echo "*** Install $(TKSAODIR) ***"
	$(MAKE) -C $(TKSAODIR) -j $(JOBS) install

$(TKSAODIR)/Makefile :
	@echo ""
	@echo "*** Configure $(TKSAODIR) ***"
	cd $(TKSAODIR); \
	./configure \
	$(WITHTK) \
	--prefix $(ROOT) --exec-prefix $(ROOT) \
	--disable-shared --enable-symbols \
	--config-cache --cache-file=../config.cache \
	ASTDIR=$(ASTDIR) FUNTOOLSDIR=$(FUNTOOLSDIR)

# no parallel
tktable	: $(TKTABLEDIR)/Makefile
	@echo ""
	@echo "*** Install $(TKTABLEDIR) ***"
	$(MAKE) -C $(TKTABLEDIR) install

$(TKTABLEDIR)/Makefile :
	@echo ""
	@echo "*** Configure $(TKTABLEDIR) ***"
	cd $(TKTABLEDIR); \
	./configure \
	$(WITHTK) $(TKTABLEFLAGS) \
	--prefix $(ROOT) --exec-prefix $(ROOT) \
	--disable-shared --enable-symbols \
	--config-cache --cache-file=../config.cache

xmlrpc	: 
	@echo ""
	@echo "*** Install $@ ***"
	$(RM) -r lib/$(XMLRPCVER)
	mkdir lib/$(XMLRPCVER)
	cp $(XMLRPCDIR)/xmlrpc.tcl lib/$(XMLRPCVER)

# no config.cache
xpa	: $(XPADIR)/Makefile
	@echo ""
	@echo "*** Install $(XPADIR) ***"
	$(MAKE) -C $(XPADIR) -j $(JOBS) install

$(XPADIR)/Makefile :
	@echo ""
	@echo "*** Configure $(XPADIR) ***"
	cd $(XPADIR); \
	./configure \
	$(WITHTCL) $(XPAFLAGS) \
	--prefix $(ROOT) --exec-prefix $(ROOT) \
	--disable-shared --enable-symbols \
	--with-x=disabled --enable-posix_spawn

#--------------------------language

.PHONY	: language

language:
	cd ds9; \
	grep 'msgcat::mc' library/*.tcl | tclsh8.6 util/mergedict.tcl da iso8859-1; \
	grep 'msgcat::mc' library/*.tcl | tclsh8.6 util/mergedict.tcl de iso8859-1; \
	grep 'msgcat::mc' library/*.tcl | tclsh8.6 util/mergedict.tcl es iso8859-1; \
	grep 'msgcat::mc' library/*.tcl | tclsh8.6 util/mergedict.tcl fr iso8859-1; \
	grep 'msgcat::mc' library/*.tcl | tclsh8.6 util/mergedict.tcl pt iso8859-1; \
	grep 'msgcat::mc' library/*.tcl | tclsh8.6 util/mergedict.tcl cs iso8859-2; \
	grep 'msgcat::mc' library/*.tcl | tclsh8.6 util/mergedict.tcl ja euc-jp; \
	grep 'msgcat::mc' library/*.tcl | tclsh8.6 util/mergedict.tcl zh big5


#--------------------------scrub

.PHONY	: scrub

scrub :
	find . -name "*[~#]" -exec rm {} \;

#--------------------------clean

.PHONY	: clean
.PHONY	: dirsclean ds9clean localclean
.PHONY	: tclclean tclcheckdnsclean tcliisclean tclsignalclean 
.PHONY	: tclxmlclean tclzvfsclean
.PHONY	: tkclean tkbltclean tkhtmlclean tkimgclean libtiffclean 
.PHONY	: tkmpegclean tksaoclean tktableclean xpaclean

clean	: dirsclean tclclean tkclean \
	tclcheckdnsclean tcliisclean tclsignalclean \
	tclzvfsclean tclxmlclean xpaclean \
	tkbltclean tktableclean tkimgclean \
	tkmpegclean tkhtmlclean \
	tk$(OS)clean \
	tksaoclean ds9clean \
	localclean

dirsclean :
	@for d in $(DIRS); do rm -rf $$d; done

ds9clean :
	$(MAKE) -C $(DS9DIR)/$(OS) clean

localclean :
	-rm -f core *~ *#

tclclean :
	$(MAKE) -C $(TCLDIR)/$(OS) clean

tclcheckdnsclean :
	$(MAKE) -C $(TCLCHECKDNSDIR) clean

tcliisclean :
	$(MAKE) -C $(TCLIISDIR) clean

tclsignalclean :
	$(MAKE) -C $(TCLSIGNALDIR) clean

tclxmlclean:
	$(MAKE) -C $(TCLXMLDIR) clean

tclzvfsclean:
	$(MAKE) -C $(TCLZVFSDIR) clean

tkclean :
	$(MAKE) -C $(TKDIR)/$(OS) clean

tkbltclean:
	$(MAKE) -C $(TKBLTDIR) clean

tkhtmlclean:
	$(MAKE) -C $(TKHTMLDIR) clean

tkimgclean: libtiffclean
	rm -fr $(TKIMGDIR)/Img/*
	rm -fr lib/Img1.*
	$(MAKE) -C $(TKIMGDIR) clean

libtiffclean:
	$(MAKE) -C $(TKIMGDIR)/compat/libtiff clean

tkmpegclean:
	$(MAKE) -C $(TKMPEGDIR) clean

tksaoclean :
	$(MAKE) -C $(TKSAODIR) clean

tktableclean:
	$(MAKE) -C $(TKTABLEDIR) clean

xpaclean :
	$(MAKE) -C $(XPADIR) clean

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

.PHONY	: dirsdistclean ds9distclean localdistclean 
.PHONY	: tcldistclean tclcheckdnsdistclean tcliisdistclean tclsignaldistclean 
.PHONY	: tclxmldistclean tclzvfsdistclean
.PHONY	: tkdistclean tkbltdistclean tkhtmldistclean tkimgdistclean
.PHONY	: libtiffdistclean tkmpegdistclean tksaodistclean
.PHONY	: tktabledistclean xpadistclean

distclean : tcldistclean tkdistclean \
	tclcheckdnsdistclean tcliisdistclean tclsignaldistclean \
	tclzvfsdistclean tclxmldistclean xpadistclean \
	tkbltdistclean tktabledistclean tkimgdistclean \
	tkmpegdistclean tkhtmldistclean \
	tk$(OS)distclean \
	tksaodistclean ds9distclean \
	dirsdistclean localdistclean

dirsdistclean:
	@for d in $(DIRS); do rm -rf $$d; done

ds9distclean :
	$(MAKE) -C $(DS9DIR)/$(OS) distclean

localdistclean : localclean
	-rm -f config.log config.status config.cache Makefile 

tcldistclean :
	$(MAKE) -C $(TCLDIR)/$(OS) distclean

tclcheckdnsdistclean :
	$(MAKE) -C $(TCLCHECKDNSDIR) distclean

tcliisdistclean :
	$(MAKE) -C $(TCLIISDIR) distclean

tclsignaldistclean :
	$(MAKE) -C $(TCLSIGNALDIR) distclean

tclxmldistclean:
	$(MAKE) -C $(TCLXMLDIR) distclean

tclzvfsdistclean:
	$(MAKE) -C $(TCLZVFSDIR) distclean

tkdistclean :
	$(MAKE) -C $(TKDIR)/$(OS) distclean

tkbltdistclean:
	$(MAKE) -C $(TKBLTDIR) distclean

tkhtmldistclean:
	$(MAKE) -C $(TKHTMLDIR) distclean

tkimgdistclean: libtiffdistclean
	rm -fr $(TKIMGDIR)/Img/*
	rm -fr lib/Img1.*
	$(MAKE) -C $(TKIMGDIR) distclean

libtiffdistclean:
	$(MAKE) -C $(TKIMGDIR)/compat/libtiff distclean

tkmpegdistclean:
	$(MAKE) -C $(TKMPEGDIR) distclean

tksaodistclean :
	$(MAKE) -C $(TKSAODIR) distclean

tktabledistclean:
	$(MAKE) -C $(TKTABLEDIR) distclean

xpadistclean :
	$(MAKE) -C $(XPADIR) distclean

#--------------------------cvs

.PHONY	: commit update

commit : scrub
	cvs commit -m "" $(CVSFILES)

update : scrub
	cvs update $(CVSFILES)
