# $Id: Makefile,v 1.26 2006/05/06 16:43:46 wohler Exp $
#
# Makefile for MH-E documentation.
#
# Note: most changes to this file should also be mirrored in the Makefiles in
# $(TOP)/src and $(TOP)/contrib.
#
TOP = ..

CVSROOT = cvs.savannah.gnu.org:/cvsroot/emacs

# Developers can use CVSLOGIN=$USER CVSMETHOD=ext.

CVSLOGIN = anoncvs

CVSMETHOD = pserver

MH_E_DOC = man/mh-e.texi

MH_E_ETC_EMACS = man/ChangeLog

MH_E_ETC = ChangeLog Makefile README

MH_E_DIST = $(MH_E_DOC) $(MH_E_ETC_EMACS) $(MH_E_ETC)

MAKEINFOINFOFLAGS =

MAKEINFOHTMLFLAGS = --html --output html

TEXI2PDFFLAGS = --quiet --clean

#
# User Targets
#

all: $(MH_E_DOC) clean info html pdf

# Check out manual if necessary.
emacs: $(MH_E_DOC)

$(MH_E_DOC): 
	(files=`echo $(MH_E_DOC) $(MH_E_ETC_EMACS) \
	        | sed 's/man\//emacs\/man\//g'`; \
	cvs -d :$(CVSMETHOD):$(CVSLOGIN)@$(CVSROOT) co $$files)
	mv emacs/man .
	$(RM) -r emacs

clean:
	$(RM) -r info html mh-e.html mh-e.pdf

info: info/mh-e

info/mh-e: $(MH_E_DOC)
	[ -d info ] || mkdir info
	(cd `dirname $<` \
	&& makeinfo $(MAKEINFOINFOFLAGS) `basename $<`)

html: html/index.html mh-e.html

html/index.html: $(MH_E_DOC)
	[ -d html ] || mkdir html
	$(RM) html/*
	makeinfo $(MAKEINFOHTMLFLAGS) $<
mh-e.html: $(MH_E_DOC)
	makeinfo --html --output $@ --no-split $<

pdf: mh-e.pdf

mh-e.pdf: $(MH_E_DOC)
	texi2pdf $(TEXI2PDFFLAGS) $<
	texi2pdf $(TEXI2PDFFLAGS) $<

#
# Maintainer Targets
#

# Tag the MH-E files that are checked out.
tag:
	@if [ "$(TAG)" = "" ]; then \
	    echo "No tag found. Set TAG environment variable."; \
	    exit 1; \
	fi
	cvs tag $(TAG) $(MH_E_ETC)
	(cd man; \
	files=`echo $(MH_E_DOC) $(MH_E_ETC_EMACS) | sed 's/man\///g'`; \
	cvs tag $(TAG) $$files)

# Create a distribution. 
dist:
	@echo "Determining release..."
	@TAG=`cvs stat Makefile | awk '/Sticky Tag/{print $$3}'`; \
        if [ "$$TAG" = "(none)" ]; then \
            echo "No sticky tags here. Do a 'cvs update -rmh-e-doc-M_N'."; \
            exit 1; \
        fi; \
        RELEASE=`echo $$TAG | sed 's/_/./g'`; \
	echo "Building $$RELEASE..."; \
        rm -rf $$RELEASE; \
        mkdir $$RELEASE; \
        cp --parents $(MH_E_DIST) $$RELEASE; \
        tar -czhf $$RELEASE.tgz $$RELEASE

# Back up MH-E CVS files at Savannah.
MH_BACKUP_DIR = ../backup
MH_FILES = $(MH_E_DOC) $(MH_E_ETC_EMACS)

backup:
	@[ -d $(MH_BACKUP_DIR) ] || mkdir $(MH_BACKUP_DIR)
	@(host=`echo $(CVSROOT) | awk -F: '{print $$1}'` \
	set $(MH_FILES); \
	files=`for i; do \
		    echo -n $$i|sed -e 's/^/sources\/emacs\/emacs\//' -e 's/$$/,v /';\
		done`; \
	set $$files; \
	for file; do \
	    rsync -aziR $$host::$$file $(MH_BACKUP_DIR); \
	done;)
