# Copyright (C) 1989-2007, 2009-2012
#   Free Software Foundation, Inc.
#      Written by James Clark (jjc@jclark.com)
# 
# 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/>.

MAN7=\
  groff_ms.n \
  groff_man.n \
  groff_me.n \
  groff_mdoc.n \
  groff_trace.n \
  groff_www.n

NORMALFILES=\
  man.tmac mandoc.tmac andoc.tmac an-old.tmac an-ext.tmac \
  ms.tmac \
  me.tmac \
  mdoc.tmac \
  pic.tmac \
  a4.tmac papersize.tmac \
  62bit.tmac \
  ec.tmac \
  safer.tmac \
  trace.tmac \
  ps.tmac psold.tmac pspic.tmac psatk.tmac \
  pdf.tmac \
  dvi.tmac \
  tty.tmac tty-char.tmac \
  latin1.tmac latin2.tmac latin5.tmac latin9.tmac cp1047.tmac \
  unicode.tmac \
  X.tmac Xps.tmac \
  lj4.tmac \
  lbp.tmac \
  html.tmac html-end.tmac \
  devtag.tmac \
  europs.tmac \
  composite.tmac fallbacks.tmac \
  eqnrc \
  refer.tmac refer-me.tmac refer-ms.tmac \
  troffrc troffrc-end \
  trans.tmac \
  hyphen.us hyphenex.us \
  fr.tmac hyphen.fr \
  sv.tmac hyphen.sv \
  de.tmac den.tmac hyphen.det hyphen.den hyphenex.det \
  cs.tmac hyphen.cs hyphenex.cs \
  ja.tmac

# These files are handled specially during installation and deinstallation.
SPECIALFILES=an.tmac s.tmac www.tmac

# These files are processed with `strip.sed'.
STRIPFILES=e.tmac doc.tmac doc-old.tmac
MDOCFILES=doc-common doc-ditroff doc-nroff doc-syms
mdocdir=$(tmacdir)/mdoc

MOSTLYCLEANADD=\
  stamp-wrap stamp-sed *-wrap www.tmac-sed \
  stamp-strip e.tmac-s doc.tmac-s doc-old.tmac-s \
  doc-common-s doc-ditroff-s doc-nroff-s doc-syms-s mdoc.local-s
tmac_s_prefix=
tmac_an_prefix=
tmac_wrap=
sys_tmac_prefix=
pnmtops_nosetpage="pnmtops"

all: stamp-strip stamp-wrap stamp-sed

install_data: $(NORMALFILES) $(SPECIALFILES) man.local \
              stamp-strip stamp-wrap stamp-sed
	-test -d $(DESTDIR)$(tmacdir) \
	  || $(mkinstalldirs) $(DESTDIR)$(tmacdir)
	-test -d $(DESTDIR)$(systemtmacdir) \
	  || $(mkinstalldirs) $(DESTDIR)$(systemtmacdir)
	-test -d $(DESTDIR)$(localtmacdir) \
	  || $(mkinstalldirs) $(DESTDIR)$(localtmacdir)
	if test -n "$(tmac_wrap)"; then \
	  for m in ""$(tmac_wrap); do \
	    $(INSTALL_DATA) $$m-wrap $(DESTDIR)$(systemtmacdir)/$$m.tmac; \
	  done; \
	fi
	for f in $(NORMALFILES); do \
	  rm -f $(DESTDIR)$(tmacdir)/$$f; \
	  $(INSTALL_DATA) $(srcdir)/$$f $(DESTDIR)$(tmacdir)/$$f; \
	done
	-rm -f $(DESTDIR)$(tmacdir)/$(tmac_s_prefix)s.tmac
	$(INSTALL_DATA) $(srcdir)/s.tmac \
	  $(DESTDIR)$(tmacdir)/$(tmac_s_prefix)s.tmac
	-rm -f $(DESTDIR)$(tmacdir)/$(tmac_an_prefix)an.tmac
	$(INSTALL_DATA) $(srcdir)/an.tmac \
	  $(DESTDIR)$(tmacdir)/$(tmac_an_prefix)an.tmac
	-rm -f $(DESTDIR)$(tmacdir)/www.tmac
	$(INSTALL_DATA) www.tmac-sed $(DESTDIR)$(tmacdir)/www.tmac
	for f in $(STRIPFILES); do \
	  rm -f $(DESTDIR)$(tmacdir)/$$f; \
	  $(INSTALL_DATA) $$f-s $(DESTDIR)$(tmacdir)/$$f; \
	done
	-test -d $(DESTDIR)$(mdocdir) || $(mkinstalldirs) $(DESTDIR)$(mdocdir)
	for f in $(MDOCFILES); do \
	  rm -f $(DESTDIR)$(mdocdir)/$$f; \
	  $(INSTALL_DATA) $$f-s $(DESTDIR)$(mdocdir)/$$f; \
	done
	-test -f $(DESTDIR)$(localtmacdir)/man.local || \
	  $(INSTALL_DATA) $(srcdir)/man.local \
	    $(DESTDIR)$(localtmacdir)/man.local
	-test -f $(DESTDIR)$(localtmacdir)/mdoc.local || \
	  $(INSTALL_DATA) mdoc.local-s $(DESTDIR)$(localtmacdir)/mdoc.local

stamp-strip: $(STRIPFILES) $(MDOCFILES) mdoc.local
	for f in $(STRIPFILES) $(MDOCFILES) mdoc.local; do \
	  rm -f $$f-s; \
	  sed -f $(srcdir)/strip.sed $(srcdir)/$$f >$$f-s; \
	done
	touch $@

stamp-wrap:
	if test -n "$(tmac_wrap)"; then \
	  for m in ""$(tmac_wrap); do \
	    rm -f $$m-wrap; \
	    if test "$$m" = an; then \
	      echo .do mso andoc.tmac >>$$m-wrap; \
	    fi; \
	    echo .cp 1 >>$$m-wrap; \
	    echo .so $(sys_tmac_prefix)$$m >>$$m-wrap; \
	  done; \
	fi
	touch $@

stamp-sed: www.tmac
	rm -f www.tmac-sed; \
	sed -e "s;@PNMTOPS_NOSETPAGE@;$(pnmtops_nosetpage);g" \
	  $(srcdir)/www.tmac > www.tmac-sed;
	touch $@

uninstall_sub:
	-if test -n "$(tmac_wrap)"; then \
	  for m in ""$(tmac_wrap); do \
	    rm -f $(DESTDIR)$(systemtmacdir)/$$m.tmac; \
	  done; \
	fi
	-for f in $(NORMALFILES) $(STRIPFILES); do \
	  rm -f $(DESTDIR)$(tmacdir)/$$f; \
	done
	-rm -f $(DESTDIR)$(tmacdir)/$(tmac_s_prefix)s.tmac
	-rm -f $(DESTDIR)$(tmacdir)/$(tmac_an_prefix)an.tmac
	-rm -f $(DESTDIR)$(tmacdir)/www.tmac
	-if cmp -s $(DESTDIR)$(localtmacdir)/man.local \
	           $(srcdir)/man.local; then \
	  rm -f $(DESTDIR)$(localtmacdir)/man.local; \
	fi
	-if cmp -s $(DESTDIR)$(localtmacdir)/mdoc.local \
	           $(srcdir)/mdoc.local; then \
	  rm -f $(DESTDIR)$(localtmacdir)/mdoc.local; \
	fi
	-for f in $(MDOCFILES); do rm -f $(DESTDIR)$(mdocdir)/$$f; done
	-rmdir $(DESTDIR)$(mdocdir)
