# $Id: Makefile.in,v 1.42 2001/11/06 19:12:31 roessler Exp $

SHELL = /bin/sh

PACKAGE = @PACKAGE@
VERSION = @VERSION@

prefix = @prefix@
exec_prefix = @exec_prefix@
bindir = @bindir@
libdir = @libdir@
mandir = @mandir@
srcdir = @srcdir@
docdir = @docdir@
includedir  =  @includedir@
top_srcdir=@top_srcdir@
top_builddir = ..
VPATH = @srcdir@
@SET_MAKE@

INSTALL = @INSTALL@
CC = @CC@
CPP = @CPP@
XCPPFLAGS = -I. @CPPFLAGS@
CFLAGS = @CFLAGS@ $(XCPPFLAGS)
LDFLAGS = @LDFLAGS@
subdir = doc

CPPFLAGS = @CPPFLAGS@

DEFS = -DSYSCONFDIR=\"$(sysconfdir)\" -DBINDIR=\"$(bindir)\" -DHAVE_CONFIG_H=1
INCLUDES = -I. -I.. -I$(includedir) -I$(top_srcdir)

MAKEDOC_CPP = $(CPP) $(INCLUDES) $(DEFS) $(CPPFLAGS) -D_MAKEDOC -C 

DISTFILES = Makefile.in dotlock.man  	\
	muttbug.man			\
	mutt.man			\
	PGP-Notes.txt			\
	applying-patches.txt		\
	devel-notes.txt			\
	manual.txt			\
	muttrc.man.head			\
	muttrc.man.tail			\
	muttrc.man			\
	mbox.man			\
	manual.sgml.head		\
	manual.sgml.tail		\
	manual.sgml			\
	manual.html			\
	stamp-doc-sgml			\
	stamp-doc-man			\
	instdoc.sh.in			\
	patch-notes.txt

srcdir_DOCFILES = PGP-Notes.txt applying-patches.txt	\
	devel-notes.txt patch-notes.txt


topsrcdir_DOCFILES = COPYRIGHT GPL INSTALL ChangeLog	\
	README NEWS TODO README.SECURITY README.SSL 

all: muttrc.man try-html try-txt

try-html: ../makedoc
	test -f manual.html || $(MAKE) manual.html || cp $(srcdir)/manual*.html ./

try-txt: ../makedoc
	test -f manual.txt || $(MAKE) manual.txt || cp $(srcdir)/manual.txt ./

install: all instdoc
	$(top_srcdir)/mkinstalldirs $(DESTDIR)$(mandir)/man1
	$(top_srcdir)/mkinstalldirs $(DESTDIR)$(mandir)/man5
	./instdoc $(srcdir)/mutt.man $(DESTDIR)$(mandir)/man1/mutt.1
	./instdoc $(srcdir)/muttbug.man $(DESTDIR)$(mandir)/man1/flea.1
	echo ".so $(mandir)/man1/flea.1" > $(DESTDIR)$(mandir)/man1/muttbug.1
	./instdoc $(srcdir)/dotlock.man \
		$(DESTDIR)$(mandir)/man1/mutt_dotlock.1
	./instdoc muttrc.man $(DESTDIR)$(mandir)/man5/muttrc.5
	./instdoc $(srcdir)/mbox.man $(DESTDIR)$(mandir)/man5/mbox.5
	$(top_srcdir)/mkinstalldirs $(DESTDIR)$(docdir)
	for f in $(srcdir_DOCFILES) ; do \
		$(INSTALL) -m 644 $(srcdir)/$$f $(DESTDIR)$(docdir) ; \
	done
	for f in $(topsrcdir_DOCFILES) ; do \
		$(INSTALL) -m 644 $(top_srcdir)/$$f $(DESTDIR)$(docdir) ; \
	done
	$(INSTALL) -m 644 manual.txt $(DESTDIR)$(docdir) || true
	$(top_srcdir)/mkinstalldirs $(DESTDIR)$(docdir)/html
	for file in manual*.html ; do	\
		$(INSTALL) -m 644 $$file $(DESTDIR)$(docdir)/html/ || true ;\
	done

uninstall:
	-rm -f $(DESTDIR)$(mandir)/man1/mutt.1
	-rm -f $(DESTDIR)$(mandir)/man1/mutt_dotlock.1
	-rm -f $(DESTDIR)$(mandir)/man5/muttrc.5
	-rm -rf $(DESTDIR)$(docdir)

check:
manual.txt: manual.sgml
	if sgml2txt -c latin manual ; then \
		uniq < manual.txt | expand > _manual.txt ; \
		rm manual.txt ; \
		mv _manual.txt manual.txt ;\
	fi

manual.html: manual.sgml
	sgml2html manual  || true

manual.ps: manual.sgml
	sgml2latex --output=ps manual || true

clean: 
	rm -f *~ *.html *.orig *.rej  stamp-doc-sgml stamp-doc-man *.ps

clean-real:
	rm -f manual.txt

maintainer-clean: clean clean-real distclean

distclean: clean
	rm -f Makefile

Makefile: Makefile.in ../config.status
	cd .. \
	  && CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status

instdoc: instdoc.sh
	cat instdoc.sh > instdoc
	chmod a+x instdoc

instdoc.sh: instdoc.sh.in ../config.status
	cd .. \
	  && CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status

distdir = ../$(PACKAGE)-$(VERSION)/$(subdir)
dist distdir: Makefile $(DISTFILES)
	for file in $(DISTFILES) ; do				\
		ln $(srcdir)/$$file $(distdir) 2> /dev/null 	\
			|| cp -p $(srcdir)/$$file $(distdir); 	\
	done
	for file in $(srcdir)/manual-*.html ; do		\
		ln $$file $(distdir) 2> /dev/null 		\
		|| cp -p $$file $(distdir) ;			\
	done

../makedoc: $(top_srcdir)/makedoc.c
	(cd .. && $(MAKE) makedoc)

# hack around autoconf mixing up patterns.
at = @

update-doc:  ../makedoc stamp-doc-sgml stamp-doc-man manual.txt manual.html

muttrc.man stamp-doc-man: ../makedoc $(top_srcdir)/init.h muttrc.man.head muttrc.man.tail
	$(MAKEDOC_CPP) $(top_srcdir)/init.h | ../makedoc -m | 	    \
		cat $(srcdir)/muttrc.man.head - $(srcdir)/muttrc.man.tail\
		> muttrc.man
	touch stamp-doc-man

manual.sgml stamp-doc-sgml: ../makedoc $(top_srcdir)/init.h manual.sgml.head manual.sgml.tail $(top_srcdir)/VERSION
	( sed -e "s/$(at)VERSION$(at)/`cat $(top_srcdir)/VERSION`/" $(srcdir)/manual.sgml.head ;\
	  $(MAKEDOC_CPP) $(top_srcdir)/init.h | ../makedoc -s ) |      \
		cat - $(srcdir)/manual.sgml.tail > manual.sgml
	touch stamp-doc-sgml

