# Copyright (C) 2002 Free Software Foundation, Inc.
#      Written by Werner Lemberg (wl@gnu.org)
# 
# This file is part of groff.
# 
# groff is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 2, or (at your option) any later
# version.
# 
# groff is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
# for more details.
# 
# You should have received a copy of the GNU General Public License along
# with groff; see the file COPYING.  If not, write to the Free Software
# Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

groff_bin_dirs=\
  $(top_builddir)/src/roff/groff \
  $(top_builddir)/src/roff/troff \
  $(top_builddir)/src/devices/grops
groff_bin_path=`echo $(groff_bin_dirs) | sed -e 's|  *|:|g'`

FFLAG=-F$(top_builddir)/font -F$(top_srcdir)/font
TFLAG=-M$(top_builddir)/tmac -M$(top_srcdir)/tmac -M$(srcdir)

GROFF=GROFF_COMMAND_PREFIX=''; \
      export GROFF_COMMAND_PREFIX; \
      GROFF_BIN_PATH=$(groff_bin_path); \
      export GROFF_BIN_PATH; \
      $(top_builddir)/src/roff/groff/groff $(FFLAG) $(TFLAG)

MAN7=\
  groff_mom.n

NORMALFILES=\
  mom.tmac \
  om.tmac

HTMLDOCFILES=\
  momdoc/appendices.html \
  momdoc/cover.html \
  momdoc/definitions.html \
  momdoc/docelement.html \
  momdoc/docprocessing.html \
  momdoc/goodies.html \
  momdoc/headfootpage.html \
  momdoc/inlines.html \
  momdoc/intro.html \
  momdoc/letters.html \
  momdoc/rectoverso.html \
  momdoc/reserved.html \
  momdoc/toc.html \
  momdoc/typemacdoc.html \
  momdoc/typesetting.html \
  momdoc/using.html

EXAMPLEFILES=\
  examples/letter.mom \
  examples/macros.mom \
  examples/typeset.mom \
  examples/typewrite.mom \
  examples/README.mom \
  examples/elvis_syntax \
  examples/penguin.ps

PROCESSEDEXAMPLEFILES=\
  examples/letter.ps \
  examples/macros.ps \
  examples/typeset.ps \
  examples/typewrite.ps

CLEANADD=\
  penguin.ps \
  $(PROCESSEDEXAMPLEFILES)

.SUFFIXES: .mom .ps
.mom.ps:
	$(GROFF) -Tps -mom $< >$@


all: make_examples

.PHONY: make_examples
make_examples: prepare_make_examples $(PROCESSEDEXAMPLEFILES)

prepare_make_examples: examples/penguin.ps
	test -d examples || $(mkinstalldirs) examples
	test -f penguin.ps || cp $(srcdir)/examples/penguin.ps .

install_data: $(NORMALFILES) $(HTMLDOCFILES) \
              $(EXAMPLEFILES) $(PROCESSEDEXAMPLEFILES)
	-test -d $(tmacdir) || $(mkinstalldirs) $(tmacdir)
	for f in $(NORMALFILES); do \
	  rm -f $(tmacdir)/$$f; \
	  $(INSTALL_DATA) $(srcdir)/$$f $(tmacdir)/$$f; \
	done
	-test -d $(htmldocdir)/momdoc || $(mkinstalldirs) $(htmldocdir)/momdoc
	for f in $(HTMLDOCFILES); do \
	  rm -f $(htmldocdir)/$$f; \
	  $(INSTALL_DATA) $(srcdir)/$$f $(htmldocdir)/$$f; \
	done
	-test -d $(exampledir) || $(mkinstalldirs) $(exampledir)
	for f in $(EXAMPLEFILES); do \
	  rm -f $(exampledir)/$$f; \
	  $(INSTALL_DATA) $(srcdir)/$$f $(docdir)/$$f; \
	done
	for f in $(PROCESSEDEXAMPLEFILES); do \
	  rm -f $(exampledir)/$$f; \
	  $(INSTALL_DATA) $$f $(docdir)/$$f; \
	done

uninstall_sub:
	-for f in $(NORMALFILES); do \
	  rm -f $(tmacdir)/$$f; \
	done
	-for f in $(HTMLDOCFILES); do \
	  rm -f $(htmldocdir)/$$f; \
	done
	-rmdir $(htmldocdir)/momdoc
	-for f in $(EXAMPLEFILES) $(PROCESSEDEXAMPLEFILES); do \
	  rm -f $(docdir)/$$f; \
	done
