## Makefile.maintainer
## ======================================================================

PACKAGE_NAME_cmd=	grep '^AC_INIT' configure.in |sed 's/.*(//;s/,.*//'
PACKAGE_NAME=		$(shell $(PACKAGE_NAME_cmd))$(PACKAGE_NAME_cmd:sh)
PACKAGE_VERSION_cmd=	grep '^AC_INIT' configure.in |sed 's/.*, *//;s/)$$//'
PACKAGE_VERSION=	$(shell $(PACKAGE_VERSION_cmd))$(PACKAGE_VERSION_cmd:sh)
PACKAGE_DIST=		$(PACKAGE_NAME)-$(PACKAGE_VERSION)

ARCHIVE_DIR=		..
ARCHIVE_NAME=		$(PACKAGE_DIST).tar.gz
ARCHIVE_COMPRESS=	$(GZIP)

TAR=			tar
GZIP=			gzip -9
GPG_cmd=		type gpg >/dev/null 2>&1 && echo gpg || echo :
GPG=			$(shell $(GPG_cmd))$(GPG_CMD:sh)
RPMBUILD_cmd=		type gpg >/dev/null 2>&1 && echo rpmbuild --sign || echo rpmbuild
RPMBUILD=		$(shell $(RPMBUILD_cmd))$(RPMBUILD_CMD:sh)

## ----------------------------------------------------------------------

default:
	@echo "Please read file 'INSTALL' and run ./configure && make."

## ----------------------------------------------------------------------

dist: dist-conf dist-archive dist-rpm

dist-conf:
	[ -f Makefile ] && $(MAKE) distclean || :
	build/autogen.sh

dist-archive:
	rm -rf .dist.tmp $(PACKAGE_DIST)
	mkdir .dist.tmp
	cp -rp * .dist.tmp
	find .dist.tmp -type d -name .svn -exec rm -rf {} \; -prune
	rm -rf .dist.tmp/vendor/rails .dist.tmp/tags
	mv .dist.tmp $(PACKAGE_DIST)
	$(TAR) cf - $(PACKAGE_DIST) |$(ARCHIVE_COMPRESS) >$(ARCHIVE_DIR)/$(ARCHIVE_NAME)
	rm -rf $(PACKAGE_DIST)
	$(GPG) --sign --detach-sign $(ARCHIVE_DIR)/$(ARCHIVE_NAME)
	ls -l $(ARCHIVE_DIR)/$(ARCHIVE_NAME)
	ls -l $(ARCHIVE_DIR)/$(ARCHIVE_NAME).sig 2>/dev/null || :

dist-rpm:
	$(RPMBUILD) -ta $(ARCHIVE_DIR)/$(ARCHIVE_NAME)

configure: configure.in
	autoconf

distclean:

