#!/usr/bin/make -f
#
#  Copyright (C) 2007 xxx
#

include version.mk

DESTDIR =
PREFIX = /usr/local


install:
	mkdir -p $(DESTDIR)$(PREFIX)/bin

	sed "s|@xslt_prefix@|${PREFIX}|g" \
		bin/xgridfit > $(DESTDIR)$(PREFIX)/bin/xgridfit; \
	sed "s|@xslt_prefix@|${PREFIX}|g" \
		bin/xgfupdate > $(DESTDIR)$(PREFIX)/bin/xgfupdate; \
	sed "s|@xslt_prefix@|${PREFIX}|g" \
		bin/ttx2xgf > $(DESTDIR)$(PREFIX)/bin/ttx2xgf; \

	chmod 0755 $(DESTDIR)$(PREFIX)/bin/xgridfit
	chmod 0755 $(DESTDIR)$(PREFIX)/bin/xgfupdate
	chmod 0755 $(DESTDIR)$(PREFIX)/bin/ttx2xgf

	mkdir -p $(DESTDIR)$(PREFIX)/share/$(PACKAGE)/lib
	cp lib/* $(DESTDIR)$(PREFIX)/share/$(PACKAGE)/lib

	mkdir -p $(DESTDIR)$(PREFIX)/share/$(PACKAGE)/schemas
	cp schemas/* $(DESTDIR)$(PREFIX)/share/$(PACKAGE)/schemas

	mkdir -p $(DESTDIR)$(PREFIX)/share/$(PACKAGE)/utils
	cp utils/* $(DESTDIR)$(PREFIX)/share/$(PACKAGE)/utils

	mkdir -p $(DESTDIR)$(PREFIX)/share/man/man1
	cp man/*.1 $(DESTDIR)$(PREFIX)/share/man/man1

# If replacing an older version of Xgridfit, these are obsolete.
	rm -f  $(DESTDIR)$(PREFIX)/share/man/man1/xgridfit-ttx.1
	rm -f $(DESTDIR)$(PREFIX)/share/$(PACKAGE)/lib/xgridfit-ttx.xsl
	rm -f $(DESTDIR)$(PREFIX)/bin/xgridfit-ttx


install-docs:
	mkdir -p $(DESTDIR)$(PREFIX)/share/doc/$(PACKAGE)/html
	cp docs/* $(DESTDIR)$(PREFIX)/share/doc/$(PACKAGE)/html


install-all:
	$(MAKE) -f Makefile install
	$(MAKE) -f Makefile install-docs


uninstall:
	rm -f $(DESTDIR)$(PREFIX)/share/$(PACKAGE)/lib/*
	rmdir $(DESTDIR)$(PREFIX)/share/$(PACKAGE)/lib
	rm -f $(DESTDIR)$(PREFIX)/share/$(PACKAGE)/schemas/*
	rmdir $(DESTDIR)$(PREFIX)/share/$(PACKAGE)/schemas
	rm -f $(DESTDIR)$(PREFIX)/share/$(PACKAGE)/utils/*
	rmdir $(DESTDIR)$(PREFIX)/share/$(PACKAGE)/utils
	rmdir $(DESTDIR)$(PREFIX)/share/$(PACKAGE)
	rm -f $(DESTDIR)$(PREFIX)/share/man/man1/xgridfit.1*
	rm -f $(DESTDIR)$(PREFIX)/share/man/man1/xgfupdate.1*
	rm -f $(DESTDIR)$(PREFIX)/share/man/man1/ttx2xgf.1*
	rm -f $(DESTDIR)$(PREFIX)/bin/xgridfit
	rm -f $(DESTDIR)$(PREFIX)/bin/xgfupdate
	rm -f $(DESTDIR)$(PREFIX)/bin/ttx2xgf


uninstall-docs:
	rm -f $(DESTDIR)$(PREFIX)/share/doc/$(PACKAGE)/html/*
	rmdir $(DESTDIR)$(PREFIX)/share/doc/$(PACKAGE)/html
	rmdir $(DESTDIR)$(PREFIX)/share/doc/$(PACKAGE)


uninstall-all:
	$(MAKE) -f Makefile uninstall
	$(MAKE) -f Makefile uninstall-docs


dist:
	$(MAKE) -f Makefile clean
	tar -C .. -zcvf $(PACKAGE)-$(VERSION).tar.gz \
		--exclude=CVS --exclude=*.tar.bz2 --exclude=.*  --exclude=*.*~ \
                --exclude=*~ --exclude=*.tar.gz xgridfit

clean:
	rm -f *.tar.gz *.*~ *~
	rm -f bin/*~
	rm -f docs/*.*~
	rm -f lib/*.*~
	rm -f schemas/*.*~
	rm -f utils/*.*~


.PHONY:	install install-docs install-all uninstall \
        uninstall-docs uninstall-all dist clean

