# Copyright (C) 2021 Free Software Foundation, Inc.
#      Written 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/>.

sboxes_srcdir = $(top_srcdir)/contrib/sboxes
sboxes_builddir = $(top_builddir)/contrib/sboxes
sboxesnotquine = $(sboxes_srcdir)/notquine.sed

sboxestmacdir = $(tmacdir)
dist_sboxestmac_DATA = contrib/sboxes/sboxes.tmac

EXTRA_DIST += \
    contrib/sboxes/ChangeLog \
    contrib/sboxes/msboxes.ms.in \
    contrib/sboxes/notquine.sed

SBOXES_EXAMPLEFILES = $(sboxes_srcdir)/msboxes.ms.in

sboxesotherdocdir = $(docdir)
nodist_sboxesotherdoc_DATA = $(sboxes_builddir)/msboxes.ms

if USE_GROPDF
sboxespdfdocdir = $(pdfdocdir)
nodist_sboxespdfdoc_DATA = $(sboxes_builddir)/msboxes.pdf
endif

MOSTLYCLEANFILES += msboxes.ms \
	$(nodist_sboxesotherdoc_DATA) \
	$(nodist_sboxespdfdoc_DATA)

# The ordering of the sed -e expressions is important.
$(sboxes_builddir)/msboxes.ms: $(SBOXES_EXAMPLEFILES) $(sboxesnotquine)
	$(AM_V_at)mkdir -p $(sboxes_builddir)
	$(AM_V_at)$(SED) -n -e '1,/REPLACEME/p' \
	    $(SBOXES_EXAMPLEFILES) > $@.tmp
	$(AM_V_at)$(SED) -f $(sboxesnotquine) \
	    $(SBOXES_EXAMPLEFILES) >> $@.tmp
	$(AM_V_at)$(SED) -n -e '/REPLACEME/,$$p' \
	    $(SBOXES_EXAMPLEFILES) >> $@.tmp
	$(AM_V_GEN)mv $@.tmp $@

$(sboxes_builddir)/msboxes.pdf: $(sboxes_builddir)/msboxes.ms \
  $(dist_sboxestmac_DATA) groff troff gropdf font/devpdf/stamp
	$(GROFF_V)$(DOC_GROFF) -M$(sboxes_srcdir) -ms -msboxes -Tpdf \
	  $(sboxes_builddir)/msboxes.ms > $@

uninstall_groffdirs: uninstall_sboxes
uninstall_sboxes:
	if test -d $(DESTDIR)$(exampledir)/sboxes; then \
	  rmdir $(DESTDIR)$(exampledir)/sboxes; \
	fi
if USE_GROPDF
	-rmdir $(DESTDIR)$(sboxespdfdocdir)
endif

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