# Copyright 1991-2020 Free Software Foundation, Inc.
#
# 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/>.
#
# mm.am
#

mm_srcdir = $(top_srcdir)/contrib/mm
mm_builddir = $(top_builddir)/contrib/mm

bin_SCRIPTS += mmroff

man1_MANS += contrib/mm/mmroff.1
man7_MANS += \
  contrib/mm/groff_mm.7 \
  contrib/mm/groff_mmse.7

# Files installed in $(tmacdir)/mm
MMFILES = \
  contrib/mm/mm/0.MT \
  contrib/mm/mm/5.MT \
  contrib/mm/mm/4.MT \
  contrib/mm/mm/ms.cov \
  contrib/mm/mm/se_ms.cov
mmdir = $(tmacdir)/mm
dist_mm_DATA = $(MMFILES)

# Files installed in $(tmacdir)
tmacmmdir = $(tmacdir)
dist_tmacmm_DATA = contrib/mm/refer-mm.tmac

MMEXAMPLEFILES=\
  contrib/mm/examples/letter.mm

mmexampledir=$(exampledir)/mm
dist_mmexample_DATA = $(MMEXAMPLEFILES)

EXTRA_DIST += \
  contrib/mm/ChangeLog \
  contrib/mm/examples \
  contrib/mm/Makefile.sim \
  contrib/mm/mm \
  contrib/mm/NOTES \
  contrib/mm/README \
  contrib/mm/groff_mm.7.man \
  contrib/mm/groff_mmse.7.man \
  contrib/mm/mmroff.1.man \
  contrib/mm/mmroff.pl

mm_TESTS = \
  contrib/mm/tests/LT_SP_AU_without_AT_works.sh \
  contrib/mm/tests/LT_SP_multi-word_LO_SJ_works.sh \
  contrib/mm/tests/MT-1-reports-all-TM-numbers.sh \
  contrib/mm/tests/MT_5_includes_AT_in_SG.sh \
  contrib/mm/tests/P-indentation-works.sh \
  contrib/mm/tests/ms_cover_sheet_robust_to_missing_AF.sh \
  contrib/mm/tests/mse_has-sufficient-footnote-space.sh \
  contrib/mm/tests/place-equation-labels-correctly-in-displays.sh \
  contrib/mm/tests/remove-stale-bib-entry-data.sh \
  contrib/mm/tests/short-pages-do-not-overflow-stack.sh
TESTS += $(mm_TESTS)
EXTRA_DIST += \
  $(mm_TESTS) \
  contrib/mm/tests/artifacts/60657.ref

mmroff: $(mm_srcdir)/mmroff.pl
	$(AM_V_GEN)$(SED) \
	  -e 's;[@]PERL[@];$(PERL);' \
	  -e 's;[@]VERSION[@];$(VERSION);' \
	  $(mm_srcdir)/mmroff.pl \
	  >$@.tmp \
	  && chmod +x $@.tmp \
	  && mv $@.tmp $@

# special installation rules for m.tmac, mse.tmac, mmse.tmac, mm.tmac
install-data-local: install_mm
install_mm:
	-test -d $(DESTDIR)$(tmacdir) || $(mkinstalldirs) $(DESTDIR)$(tmacdir)
	-test -d $(DESTDIR)$(mmdir) || $(mkinstalldirs) $(DESTDIR)$(mmdir)
	$(RM) $(DESTDIR)$(tmacdir)/tmac.$(tmac_m_prefix)m
	$(RM) $(DESTDIR)$(tmacdir)/$(tmac_m_prefix)m.tmac
	$(INSTALL_DATA) $(mm_srcdir)/m.tmac \
	  $(DESTDIR)$(tmacdir)/$(tmac_m_prefix)m.tmac
	$(SED) -e "s;^.mso m.tmac;.mso $(tmac_m_prefix)m.tmac;g" \
	  $(mm_srcdir)/mse.tmac > $(DESTDIR)$(tmacdir)/$(tmac_m_prefix)mse.tmac
	@$(SED) -e "s;^.mso mse.tmac;.mso $(tmac_m_prefix)mse.tmac;g" \
	  $(mm_srcdir)/mmse.tmac > $(DESTDIR)$(tmacdir)/$(tmac_m_prefix)mmse.tmac
	@$(SED) -e "s;^.mso m.tmac;.mso $(tmac_m_prefix)m.tmac;g" \
	  $(mm_srcdir)/mm.tmac > $(DESTDIR)$(tmacdir)/$(tmac_m_prefix)mm.tmac
uninstall-local: uninstall_mm
uninstall_mm:
	if test -d $(DESTDIR)$(mmexampledir); then \
	  rmdir $(DESTDIR)$(mmexampledir); \
	fi
	$(RM) $(DESTDIR)$(tmacdir)/tmac.$(tmac_m_prefix)m
	$(RM) $(DESTDIR)$(tmacdir)/$(tmac_m_prefix)m.tmac
	$(RM) $(DESTDIR)$(tmacdir)/$(tmac_m_prefix)mm.tmac
	$(RM) $(DESTDIR)$(tmacdir)/$(tmac_m_prefix)mse.tmac
	$(RM) $(DESTDIR)$(tmacdir)/$(tmac_m_prefix)mmse.tmac
	-rmdir $(DESTDIR)$(tmacdir)/mm

# Special distribution rule: we copy all .tmac files from contrib/mm
dist-hook: dist_mm
dist_mm:
	chmod u+w $(distdir)/contrib/mm/
	for i in $(mm_srcdir)/*.tmac; do \
	  cp -f $$i $(distdir)/contrib/mm/; \
	done


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