## This is a -*- makefile -*-

# What the Emacs 19 binary is called on your system
EMACS = @EMACS@
EMACSFLAGS = @EMACSFLAGS@

# Prefix for constructing installation directory paths
prefix = @prefix@
exec_prefix = @exec_prefix@

# Shared directory for read-only data files
datadir = $(prefix)/share

# Where to put the .el and .elc files
lispdir=$(datadir)/emacs/site-lisp

# Where to put the Info files
infodir=$(prefix)/info
INFOFILES  = mailcrypt.info mailcrypt.info-1 mailcrypt.info-2

# Where to put the helper scripts
bindir=$(prefix)/bin

# Installation command
INSTALL = @INSTALL@
INSTALL_DATA = @INSTALL_DATA@
INSTALL_INFO = @INSTALL_INFO@

# Various auxiliary programs
MAKEINFO=makeinfo
DVIPS=dvips
TEXI2DVI=texi2dvi
TEXI2HTML=texi2html
TAR=tar

srcdir = @srcdir@
VPATH = @srcdir@

SOURCES = @EXTRA_SRCS@ \
	mailcrypt.el mc-toplev.el mc-pgp.el mc-remail.el \
	mc-pgp5.el mc-gpg.el expect.el mc-setversion.el

OBJECTS = @EXTRA_OBJS@ \
	mailcrypt.elc mc-toplev.elc mc-pgp.elc mc-remail.elc \
	mc-pgp5.elc mc-gpg.elc expect.elc mc-setversion.elc

DISTFILES = $(SOURCES) ANNOUNCE ChangeLog INSTALL LCD-entry Makefile.in \
	NEWS ONEWS README configure configure.in install-sh load-path.hack \
	mailcrypt.texi mkinstalldirs texi2html.ext FSF-timer.el \
	$(INFOFILES) mailcrypt.dvi README.gpg

SHELL = /bin/sh
#.PHONY: all clean dist distclean dvi html info install \
#	installdirs ps uninstall
.SUFFIXES:
.SUFFIXES: .elc .el

.el.elc:
	$(EMACS) -batch $(EMACSFLAGS) -l $(srcdir)/load-path.hack \
	  -f batch-byte-compile $<

all: $(OBJECTS)

install: all installdirs install-info $(bindir)
	for f in $(SOURCES); do \
	  $(INSTALL_DATA) $(srcdir)/$$f $(lispdir); \
	done;
	for f in $(OBJECTS); do \
	  $(INSTALL_DATA) $$f $(lispdir); \
	done;

# Make sure all installation directories actually exist
# by making them if necessary.
installdirs: mkinstalldirs
	$(srcdir)/mkinstalldirs $(lispdir) $(infodir) $(bindir)

install-info: info
	# There may be a newer info file in . than in srcdir.
	-if test -f mailcrypt.info; then d=.; \
	 else d=$(srcdir); fi; \
	for file in $(INFOFILES); do\
	  $(INSTALL_DATA) $$d/$$file $(infodir)/$$file; \
	done;
	$(INSTALL_INFO) --info-dir=$(infodir) \
	--entry="* Mailcrypt: (mailcrypt).       An Emacs/PGP interface" \
	mailcrypt.info 

uninstall:
	-cd $(lispdir) && rm -f $(SOURCES) $(OBJECTS)
	-cd $(infodir) && rm -f $(INFOFILES)
	$(INSTALL_INFO) --remove --info-dir=$(infodir) mailcrypt.info

info: $(INFOFILES)

$(INFOFILES): mailcrypt.texi
	$(MAKEINFO) $(srcdir)/mailcrypt.texi

timer.el: FSF-timer.el
	cp FSF-timer.el timer.el

dvi: mailcrypt.dvi

mailcrypt.dvi: mailcrypt.texi
	$(TEXI2DVI) $(srcdir)/mailcrypt.texi

ps: mailcrypt.ps

mailcrypt.ps: mailcrypt.dvi
	$(DVIPS) $(srcdir)/mailcrypt.dvi

html: mailcrypt_toc.html

mailcrypt_toc.html: mailcrypt.texi
	$(TEXI2HTML) -split_chapter $(srcdir)/mailcrypt.texi

TAGS: $(SOURCES)
	cd $(srcdir) && etags $(SOURCES)

clean:
	rm -f $(OBJECTS)
	-rm -f *.aux *.cp *.cps *.fn *.ky *.log *.pg *.toc *.tp *.vr
	-rm -f *.html
	rm -f TAGS

distclean: clean
	-rm -f *~ *.tar.gz
	-rm -f Makefile config.status config.cache config.log timer.el

${srcdir}/configure: configure.in
	cd ${srcdir} && autoconf

Makefile: Makefile.in config.status
	./config.status

config.status: ${srcdir}/configure
	./config.status --recheck

dist: $(DISTFILES)
	version=`perl -ne 'print $$1 if /defconst mc-version \"(.*)\"/' \
		 mailcrypt.el`; \
	distname=mailcrypt-$$version; \
	rm -rf $$distname; \
	mkdir $$distname; \
	for file in $(DISTFILES); do \
	  ln $$file $$distname/$$file; \
	done; \
	$(TAR) -chz -f $$distname.tar.gz $$distname; \
	rm -rf $$distname
