include make.include
include make.pkgs

.NOTPARALLEL :

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

export root := $(shell pwd)

USER	= joye
DEST	= bokhara

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

SRCDIR	= src
DOCDIR	= doc
DS9DIR	= ds9
DIRS = bin lib include man share dist

#--------------------------dist

DS9APP=SAOImage\ DS9\ $(DS9VERSION)
XPAAPP=XPA\ $(XPAVERSION)

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

CVSFILES = admin \
	COPYING \
	copyright \
	make.arm \
	make.cygwin \
	make.cygwin64 \
	make.darwinmavericks \
	make.darwinmountainlion \
	make.darwinlion \
	make.linux \
	make.linux64 \
	make.macosxmavericks \
	make.macosxmountainlion \
	make.macosxlion \
	make.source \
	make.pkgs \
	Makefile \
	Makefile.unix \
	Makefile.macosx \
	Makefile.windows \
	mods \
	notes.txt \
	README \
	saotk \
	tclcheckdns1.1 \
	tcliis1.0 \
	tkblt3.0 \
	tkmacosx1.0 \
	tkmpeg1.0 \
	win \
	tests \
	doc \
	cmaps \
	template \
	src \
	msgs \
	ds9 \
	util \
	compilers \
	$(ZVFSDIR)/Makefile \
	$(WCSSUBSDIR)/Makefile \
	$(RICEDIR)/Makefile \
	$(HCOMPRESSDIR)/Makefile \
	$(PLIODIR)/Makefile

#--------------------------build

include Makefile.$(OS)

doc	: FORCE
	@echo "Making Documentation..."
	cd $(DOCDIR); $(MAKE)

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

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

#--------------------------items

dirs	: FORCE
	@echo "Installing Directories..."
	@for d in $(DIRS); do if [ ! -d $$d ]; then mkdir $$d; fi done

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

xmlrpc	: FORCE
	@echo "Installing XMLRPC..."
	$(RM) -r lib/$(XMLRPCVER)
	mkdir lib/$(XMLRPCVER)
	cp $(XMLRPCDIR)/xmlrpc.tcl lib/$(XMLRPCVER)

zlib  : FORCE
	@echo "Installing zlib..."
	cd $(ZLIBDIR); CC='$(CC)' CFLAGS='$(OPTS)' \
	./configure --prefix $(root) --static
	$(MAKE) -C $(ZLIBDIR) -j $(JOBS) install

libtiff	: FORCE
	@echo "Installing LIBTIFF..."
	cd $(TKIMGDIR)/compat/libtiff; CC='$(CC)' CFLAGS='$(OPTS)' CXX='$(CC)' \
	CXXFLAGS='$(OPTS)' \
	./configure --prefix $(root) --disable-shared
	$(MAKE) -C $(TKIMGDIR)/compat/libtiff -j $(JOBS) install

$(HTMLDIR) : FORCE
	mkdir $(HTMLDIR)

xpa	: FORCE
	@echo "Installing XPA..."
	cd $(XPADIR); CC='$(CC)' CFLAGS='$(OPTS)' \
	./configure \
	--prefix $(root) \
	--disable-shared \
	--with-tcl=$(root)/$(TCLDIRDIR) \
	$(XPAFLAGS)
	$(MAKE) -C $(XPADIR) -j $(JOBS) install
	cd bin; strip xpa*

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

funtools: FORCE
	@echo "Installing Funtools..."
	cd $(FUNTOOLSDIR); CC='$(CC)' CFLAGS='$(OPTS)' \
	./configure \
	--prefix $(root) \
	--with-wcslib=../lib/libwcs.a \
	--enable-mainlib $(FUNTOOLSFLAGS)
	$(MAKE) -C $(FUNTOOLSDIR) lib
	cp $(FUNTOOLSDIR)/libfuntools.a lib/.

ast	: FORCE
	@echo "Installing AST..."
	cd $(ASTDIR); CC='$(CC)' CFLAGS='$(OPTS) -I.' \
	./configure \
	--enable-shared=no \
	--prefix=$(root) \
	$(ASTFLAGS)
	$(MAKE) -C $(ASTDIR) -j $(JOBS) ast.h install-libLTLIBRARIES \
	install-nodist_includeHEADERS install-includeHEADERS

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

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

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

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

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

zvfs	: FORCE
	@echo "Installing ZVFS..."
	$(MAKE) -C $(ZVFSDIR) install

ds9	: scrub
	@echo "Making DS9..."
	$(MAKE) -C $(DS9DIR)

debug	: FORCE
	@echo "Making DS9..."
	$(MAKE) -C $(DS9DIR) debug

distsource : FORCE
	@echo "Creating Source Distribution"
	rm -rf dist/saods9
	cd dist; cvs export -Dtoday saods9
	cd dist/saods9; rm -rf notes mods admin
	cd dist; tar cvf - saods9 | gzip > ds9.$(DS9VERSION).tar.gz
	rm -rf dist/saods9
	scp dist/ds9.$(DS9VERSION).tar.gz $(USER)@$(DEST):build/source/.

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

scrub : FORCE
	find . -name "*[~#]" -exec rm {} \;
ifeq ($(OS),windows)
	find . -name "*stackdump*" -exec rm {} \;
endif

clean: FORCE

filesclean: FORCE
	$(RM) core *~ *#

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

tclclean : FORCE
	$(MAKE) -C $(TCLDIRDIR) distclean

tkclean : FORCE
	$(MAKE) -C $(TKDIRDIR) distclean

tktableclean: FORCE
	$(MAKE) -C $(TKTABLEDIR) distclean

tkbltclean: FORCE
	$(MAKE) -C $(TKBLTDIR) distclean

zlibclean: FORCE
	$(MAKE) -C $(ZLIBDIR) distclean

tclxmlclean: FORCE
	$(MAKE) -C $(TCLXMLDIR) distclean

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

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

tkmpegclean: FORCE
	$(MAKE) -C $(TKMPEGDIR) distclean

tkhtmlclean: FORCE
#	cd $(HTMLDIR); $(MAKE) distclean
	rm -rf $(HTMLDIR)

xpaclean : FORCE
	$(MAKE) -C $(XPADIR) distclean

tcliisclean : FORCE
	$(MAKE) -C $(TCLIISDIR) distclean

tclcheckdnsclean : FORCE
	$(MAKE) -C $(TCLCHECKDNSDIR) distclean

signalclean : FORCE
	$(MAKE) -C $(SIGNALDIR) distclean

funtoolsclean: FORCE
	$(MAKE) -C $(FUNTOOLSDIR) distclean

astclean: FORCE
	$(MAKE) -C $(ASTDIR) distclean

wcssubsclean: FORCE
	$(MAKE) -C $(WCSSUBSDIR) distclean

riceclean: FORCE
	$(MAKE) -C $(RICEDIR) distclean

hcompressclean: FORCE
	$(MAKE) -C $(HCOMPRESSDIR) distclean

plioclean: FORCE
	$(MAKE) -C $(PLIODIR) distclean

saotkclean : FORCE
	$(MAKE) -C $(SAOTKDIR) distclean

zvfsclean: FORCE
	$(MAKE) -C $(ZVFSDIR) distclean

ds9clean : FORCE
	$(MAKE) -C $(DS9DIR) distclean

srcclean : FORCE
	$(MAKE) -C $(SRCDIR) distclean

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

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

update : FORCE
	cvs update $(CVSFILES)

FORCE	:
