# Copyright (C) 2005-2021 Free Software Foundation, Inc.
#      Written by Keith Marshall (keith.d.marshall@ntlworld.com)
#      Automake migration by Bertrand Garrigues
#
# 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/>.

pdfmark_srcdir = $(top_srcdir)/contrib/pdfmark
pdfmark_builddir = $(top_builddir)/contrib/pdfmark

man1_MANS += contrib/pdfmark/pdfroff.1

bin_SCRIPTS += pdfroff

# Files installed in $(tmacdir)
TMACFILES = \
  contrib/pdfmark/pdfmark.tmac \
  contrib/pdfmark/sanitize.tmac \
  contrib/pdfmark/spdf.tmac
pdfmarktmacdir = $(tmacdir)
dist_pdfmarktmac_DATA = $(TMACFILES)

# Files installed in $(pdfdocdir)
PDFDOCFILES = \
  contrib/pdfmark/pdfmark.pdf
if USE_PDFROFF
pdfmarkpdfdocdir = $(pdfdocdir)
nodist_pdfmarkpdfdoc_DATA = $(PDFDOCFILES)
MOSTLYCLEANFILES += $(PDFDOCFILES)
else
EXTRA_DIST += $(PDFDOCFILES)
endif

EXTRA_DIST += \
  contrib/pdfmark/cover.ms \
  contrib/pdfmark/pdfmark.ms \
  contrib/pdfmark/ChangeLog \
  contrib/pdfmark/README \
  contrib/pdfmark/PROBLEMS \
  contrib/pdfmark/TODO \
  contrib/pdfmark/pdfroff.1.man \
  contrib/pdfmark/pdfroff.sh

PDFROFF=\
  GROFF_TMPDIR=. \
  GROFF_COMMAND_PREFIX= \
  GROFF_BIN_DIR="$(GROFF_BIN_DIR)" \
  GROFF_BIN_PATH="$(GROFF_BIN_PATH)" \
  ./pdfroff \
  $(FFLAG) $(MFLAG) -dpaper=$(PAGE) -P-p$(PAGE) -M$(pdfmark_srcdir)

contrib/pdfmark/pdfmark.pdf: contrib/pdfmark/pdfmark.ms
	$(GROFF_V)$(MKDIR_P) `dirname $@` \
	&& $(PDFROFF) -I $(doc_builddir) -I $(doc_srcdir) -mspdf \
	  --stylesheet=$(pdfmark_srcdir)/cover.ms \
	  $(top_srcdir)/contrib/pdfmark/pdfmark.ms >$@

# The pdf files use the local script to generate.
$(PDFDOCFILES): pdfroff groff troff gropdf
$(PDFDOCFILES): $(dist_devpsfont_DATA) $(nodist_devpsfont_DATA) \
  $(DOC_GNU_EPS)

pdfroff: contrib/pdfmark/pdfroff.sh $(SH_DEPS_SED_SCRIPT)
	$(AM_V_GEN)sed -f $(SH_DEPS_SED_SCRIPT) \
	    -e "s|[@]VERSION[@]|$(VERSION)|" \
	    -e "s|[@]GROFF_AWK_INTERPRETERS[@]|$(ALT_AWK_PROGS)|" \
	    -e "s|[@]GROFF_GHOSTSCRIPT_INTERPRETERS[@]|$(ALT_GHOSTSCRIPT_PROGS)|" \
	    -e "s|[@]GROFF_BIN_DIR[@]|$(bindir)|" $(pdfmark_srcdir)/pdfroff.sh \
	    >$@ \
	&& chmod +x $@

mostlyclean-local: mostlyclean_pdfmark
mostlyclean_pdfmark:
	rm -rf $(top_builddir)/pdfroff-*

uninstall_groffdirs: uninstall-pdfmark-hook
uninstall-pdfmark-hook:
if USE_PDFROFF
	-rmdir $(DESTDIR)$(pdfmarkpdfdocdir)
endif


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