# Copyright (C) 2002-2020 Free Software Foundation, Inc.
#      Written by Werner Lemberg <wl@gnu.org>
#      Automake migration by Bertrand Garrigues
#        <bertrand.garrigues@laposte.net>
#
# 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 3 of the License, 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 this program.  If not, see <http://www.gnu.org/licenses/>.

mom_srcdir = $(top_srcdir)/contrib/mom

# pdfmom command used to generate .pdf
#
# Use '-K utf8', not '-k', in case 'configure' didn't find uchardet.
MOMPDFMOM = \
  GROFF_COMMAND_PREFIX= \
  GROFF_BIN_PATH="$(GROFF_BIN_PATH)" \
  PDFMOM_BIN_PATH="$(top_builddir)" \
  $(PDFMOMBIN) $(FFLAG) $(MFLAG) -M$(mom_srcdir) -K utf8 -p -e -t

man7_MANS += contrib/mom/groff_mom.7

# Files installed in $(tmacdir).
# MOMNORMALFILES are located in the source tree.
MOMNORMALFILES = \
  contrib/mom/mom.tmac \
  contrib/mom/om.tmac
momtmacdir = $(tmacdir)
dist_momtmac_DATA = $(MOMNORMALFILES)

# Files installed in htmldocdir/mom
MOMHTMLDOCFILES=\
  contrib/mom/momdoc/stylesheet.css \
  contrib/mom/momdoc/appendices.html \
  contrib/mom/momdoc/color.html \
  contrib/mom/momdoc/cover.html \
  contrib/mom/momdoc/definitions.html \
  contrib/mom/momdoc/docelement.html \
  contrib/mom/momdoc/docprocessing.html \
  contrib/mom/momdoc/goodies.html \
  contrib/mom/momdoc/graphical.html \
  contrib/mom/momdoc/headfootpage.html \
  contrib/mom/momdoc/images.html \
  contrib/mom/momdoc/inlines.html \
  contrib/mom/momdoc/intro.html \
  contrib/mom/momdoc/letters.html \
  contrib/mom/momdoc/macrolist.html \
  contrib/mom/momdoc/rectoverso.html \
  contrib/mom/momdoc/refer.html \
  contrib/mom/momdoc/reserved.html \
  contrib/mom/momdoc/tables-of-contents.html \
  contrib/mom/momdoc/toc.html \
  contrib/mom/momdoc/typesetting.html \
  contrib/mom/momdoc/using.html \
  contrib/mom/momdoc/version-2.html
momhtmldir = $(htmldocdir)/mom
momhtml_DATA = $(MOMHTMLDOCFILES)

# Files installed in $(examplesdir)/mom.  MOMEXAMPLEFILES are located
# in the source tree, while MOMPROCESSEDEXAMPLEFILES are generated in
# the build tree.
MOMEXAMPLEFILES=\
  contrib/mom/examples/letter.mom \
  contrib/mom/examples/mom-pdf.mom \
  contrib/mom/examples/mon_premier_doc.mom \
  contrib/mom/examples/sample_docs.mom \
  contrib/mom/examples/typesetting.mom \
  contrib/mom/examples/README.txt \
  contrib/mom/examples/README-fr.txt \
  contrib/mom/examples/elvis_syntax \
  contrib/mom/examples/elvis_syntax.new \
  contrib/mom/examples/penguin.ps \
  contrib/mom/examples/penguin.pdf \
  contrib/mom/examples/mom.vim \
  contrib/mom/examples/slide-demo.mom \
  contrib/mom/examples/copyright-default.mom \
  contrib/mom/examples/copyright-chapter.mom
momexampledir = $(exampledir)/mom
dist_momexample_DATA = $(MOMEXAMPLEFILES)

if USE_GROPDF
MOMPROCESSEDEXAMPLEFILES = \
  contrib/mom/examples/letter.pdf \
  contrib/mom/examples/mom-pdf.pdf \
  contrib/mom/examples/mon_premier_doc.pdf \
  contrib/mom/examples/sample_docs.pdf \
  contrib/mom/examples/slide-demo.pdf \
  contrib/mom/examples/copyright-default.pdf \
  contrib/mom/examples/copyright-chapter.pdf
if HAVE_URW_FONTS
MOMPROCESSEDEXAMPLEFILES += contrib/mom/examples/typesetting.pdf
endif
momprocessedexampledir = $(exampledir)/mom
nodist_momprocessedexample_DATA = $(MOMPROCESSEDEXAMPLEFILES)
endif

mom_test_template = contrib/mom/examples/test-mom.sh.in

# Small test suite on mom examples
mom_TESTS = contrib/mom/examples/tests-mom.sh
TESTS += $(mom_TESTS)
contrib/mom/examples/tests-mom.sh: \
  $(top_builddir)/config.status \
  $(MOMPROCESSEDEXAMPLEFILES) \
  $(top_srcdir)/$(mom_test_template)
	$(AM_V_GEN)sed \
	  -e "s|[@]abs_top_builddir[@]|$(abs_top_builddir)|g" \
	  -e "s|[@]groff_have_urw_fonts[@]|$(groff_have_urw_fonts)|g" \
	  $(top_srcdir)/$(mom_test_template) > $@ \
	&& chmod +x $@
MOSTLYCLEANFILES += $(mom_TESTS)
EXTRA_DIST += $(mom_test_template)

# For this list of files we add a symlink from $(exampledir)/mom to $(pdfdocdir)
PDFDOCFILE = mom-pdf.pdf

EXTRA_DIST += $(MOMHTMLDOCFILES) $(MOMEXAMPLEFILES) \
  contrib/mom/BUGS \
  contrib/mom/ChangeLog \
  contrib/mom/NEWS \
  contrib/mom/TODO \
  contrib/mom/copyright \
  contrib/mom/groff_mom.7.man

MOSTLYCLEANFILES += \
  $(MOMPROCESSEDEXAMPLEFILES) \
  penguin.ps \
  penguin.pdf

# rule to generate .pdf files from .mom files
SUFFIXES += .mom .pdf
.mom.pdf:
	$(GROFF_V)$(MKDIR_P) `dirname $@` \
	&& LC_ALL=C $(MOMPDFMOM) $< >$@

$(MOMPROCESSEDEXAMPLEFILES): $(MOMNORMALFILES) \
  groff troff gropdf pdfmom penguin.ps penguin.pdf font/devpdf/stamp

penguin.ps:
	$(AM_V_at)cp $(mom_srcdir)/examples/penguin.ps $@
penguin.pdf:
	$(AM_V_at)cp $(mom_srcdir)/examples/penguin.pdf $@

install-data-hook: install_mom
install_mom:
if USE_GROPDF
	for f in $(PDFDOCFILE); do \
	  $(RM) $(DESTDIR)$(pdfdocdir)/$$f; \
	  ln -s $(exampledir)/mom/$$f $(DESTDIR)$(pdfdocdir)/$$f; \
	done
endif

uninstall_groffdirs: uninstall_mom
uninstall_mom:
	for f in $(PDFDOCFILE); do \
	  $(RM) $(DESTDIR)$(pdfdocdir)/$$f; \
	done
	-rmdir $(DESTDIR)$(pdfdocdir)
	if test -d $(DESTDIR)$(exampledir)/mom; then \
	  rmdir $(DESTDIR)$(exampledir)/mom; \
	fi
	if test -d $(DESTDIR)$(htmldocdir)/mom; then \
	  rmdir $(DESTDIR)$(htmldocdir)/mom; \
	fi


# Local Variables:
# fill-column: 72
# mode: makefile-automake
# End:
# vim: set autoindent filetype=automake textwidth=72:
