# Makefile.sub for `chem' (integration into the `groff' source tree)

# File position: <groff-source>/contrib/chem/Makefile.sub

# Copyright (C) 2006, 2009 Free Software Foundation, Inc.
# Written by Bernd Warken.

# Last update: 5 Jan 2009

# This file is part of `chem' which 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/>.

########################################################################

MAN1=chem.n
CLEANADD=chem chem.n README examples/README

# not all make programs have $(RM) predefined.
RM=rm -f

all: README examples/README chem $(MAN1)

README: $(srcdir)/README.txt
	sed -e "s|@g@|$(g)|g" $? >$@

examples/README: $(srcdir)/examples/README.txt
	-test -d examples || $(mkinstalldirs) examples
	sed -e "s|@g@|$(g)|g" $? >$@

chem: $(srcdir)/chem.pl $(SH_DEPS_SED_SCRIPT)
	sed -f "$(SH_DEPS_SED_SCRIPT)" \
	  -e "s|@g@|$(g)|g" \
	  -e "s|@BINDIR@|$(DESTDIR)$(bindir)|g" \
	  -e "s|@MACRODIR@|$(DESTDIR)$(tmacdir)|g" \
	  -e "s|@PICDIR@|$(DESTDIR)$(datasubdir)/pic|g" \
	  -e "s|@VERSION@|$(version)$(revision)|g" \
	  -e "$(SH_SCRIPT_SED_CMD)" \
	  $(srcdir)/chem.pl >$@
	chmod +x $@

install_data: chem \
              README examples/README \
              $(srcdir)/chem.pic \
              $(srcdir)/examples/*.chem $(srcdir)/examples/122/*
	-test -d $(DESTDIR)$(bindir) || $(mkinstalldirs) $(DESTDIR)$(bindir)
	$(RM) $(DESTDIR)$(bindir)/$(g)chem
	$(INSTALL_SCRIPT) chem $(DESTDIR)$(bindir)/$(g)chem
	-test -d $(DESTDIR)$(datasubdir)/pic \
          || $(mkinstalldirs) $(DESTDIR)$(datasubdir)/pic
	$(RM) $(DESTDIR)$(datasubdir)/pic/chem.pic
	$(INSTALL_DATA) $(srcdir)/chem.pic \
          $(DESTDIR)$(datasubdir)/pic/chem.pic
	-test -d $(DESTDIR)$(exampledir)/chem \
          || $(mkinstalldirs) $(DESTDIR)$(exampledir)/chem/122
	-test -d $(DESTDIR)$(exampledir)/chem/122 \
          || $(mkinstalldirs) $(DESTDIR)$(exampledir)/chem/122
	-$(RM) $(DESTDIR)$(exampledir)/chem/*
	$(INSTALL_DATA) examples/README \
          $(DESTDIR)$(exampledir)/chem/README
	for i in $(srcdir)/examples/*.chem; do \
          n=`echo $$i | sed 's|$(srcdir)/examples/||g'`; \
          $(INSTALL_DATA) $$i $(DESTDIR)$(exampledir)/chem/$$n; \
        done
	-$(RM) $(DESTDIR)$(exampledir)/chem/122/*
	for i in $(srcdir)/examples/122/*; do \
          n=`echo $$i | sed 's|$(srcdir)/examples/122/||g'`; \
          $(INSTALL_DATA) $$i $(DESTDIR)$(exampledir)/chem/122/$$n; \
        done

uninstall_sub:
	$(RM) $(DESTDIR)$(bindir)/chem
	$(RM) $(DESTDIR)$(datasubdir)/pic/chem.pic
	-rmdir $(DESTDIR)$(datasubdir)/pic
	$(RM) $(DESTDIR)$(exampledir)/chem/122/*
	-rmdir $(DESTDIR)$(exampledir)/chem/122
	$(RM) $(DESTDIR)$(exampledir)/chem/*
	-rmdir $(DESTDIR)$(exampledir)/chem
	-rmdir $(DESTDIR)$(exampledir)

########################################################################
# Emacs settings
########################################################################
#
# Local Variables:
# mode: makefile
# End:
