# Copyright (C) 1989-2000, 2002-2004, 2006-2011
#   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/>.
#
# Makefile.comm
#
INCLUDES=-I. -I$(srcdir) \
  -I$(top_builddir)/src/include -I$(top_srcdir)/src/include \
  -I$(top_builddir)/src/libs/gnulib/lib
ALL_CCFLAGS=$(INCLUDES) $(CCDEFINES) $(CCFLAGS) $(CPPFLAGS)
COMPILE.cpp=$(CCC) $(ALL_CCFLAGS) -c
ALL_CFLAGS=$(INCLUDES) $(CDEFINES) $(CFLAGS) $(CPPFLAGS)
COMPILE.c=$(CC) $(ALL_CFLAGS) -c
LINK.cpp=$(CCC) $(CCFLAGS) $(LDFLAGS)
LINK.c=$(CC) $(CFLAGS) $(LDFLAGS)
LIBGROFF=$(top_builddir)/src/libs/libgroff/libgroff.$(LIBEXT)
LIBBIB=$(top_builddir)/src/libs/libbib/libbib.$(LIBEXT)
LIBDRIVER=$(top_builddir)/src/libs/libdriver/libdriver.$(LIBEXT)
LIBXUTIL=$(top_builddir)/src/libs/libxutil/libxutil.$(LIBEXT)
LIBGNU=$(top_builddir)/src/libs/gnulib/lib/libgnu.$(LIBEXT)
MLIB=
XLIBS=
YTABH=
YTABC=
GRAM=
LIBCLEAN=
MOSTLYCLEANADD=
MOSTLYCLEANDIRADD=
MOSTLYCLEANNOTSRCDIRADD=
MOSTLYCLEANFILES=$(MANCLEAN) $(PROG) $(OBJS) $(GENSRCS) $(GENHDRS) \
  depend.temp core y.output $(MOSTLYCLEANADD)
CLEANFILES=$(LIBCLEAN)
DISTCLEANFILES=TAGS Makefile Makefile.dep
REALCLEANFILES=$(YTABC) $(YTABH)
NAMEPREFIX=
HDRS=
MANPAGES=$(MAN1) $(MAN5) $(MAN7)
MANCLEAN=$(MANPAGES)
fontsubdir=$(fontdir)/dev$(DEV)
oldfontsubdir=$(oldfontdir)/dev$(DEV)

all do_install install_bin install_data TAGS depend distfiles uninstall_sub:

do_install: install_bin install_data
uninstall: uninstall_sub
pure:
fonts:

.PHONY: all clean distclean mostlyclean realclean extraclean depend distfiles
.PHONY: install install_bin install_data
.PHONY: uninstall uninstall_sub
.PHONY: pure fonts

mostlyclean:
	-rm -f $(MOSTLYCLEANFILES)
	-rm -rf $(MOSTLYCLEANDIRADD)
	-@if test `cd $(srcdir); pwd` = `pwd`; then \
	  :; \
	else \
	  rm -f $(MOSTLYCLEANNOTSRCDIRADD); \
	fi

clean: mostlyclean
	-rm -f $(CLEANFILES)

distclean: clean
	-rm -f $(DISTCLEANFILES)
	-@if test `cd $(srcdir); pwd` = `pwd`; then \
	  :; \
	else \
	  rm -f $(YTABC) $(YTABH); \
	fi

realclean: distclean
	-rm -f $(REALCLEANFILES)

extraclean: distclean
	-rm -f \#* *~ =* core junk grot old temp tmp tem *.new *.old *.orig

.SUFFIXES:
.SUFFIXES: .o .obj .cpp .c .y .man .n

.cpp.o:
	$(COMPILE.cpp) $(EXTRA_CCFLAGS) $<

.c.o:
	$(COMPILE.c) $(EXTRA_CFLAGS) $<

.cpp.obj:
	$(COMPILE.cpp) $(EXTRA_CCFLAGS) $<

.c.obj:
	$(COMPILE.c) $(EXTRA_CFLAGS) $<

.y.cpp:
	if test -n "$(YTABH)"; then \
	  $(YACC) $(YACCFLAGS) -d $<; \
	else \
	  $(YACC) $(YACCFLAGS) $<; \
	fi
	-test -f y.tab.h && mv y.tab.h y_tab.h
	-test -f y.tab.c && mv y.tab.c y_tab.c
	sed "s/^#line \(.*\) \"y.tab.c\"/#line \1 \"$(YTABC)\"/" \
	  < y_tab.c > $(YTABC)
	-rm -f y_tab.c
	test -z "$(YTABH)" || mv y_tab.h $(YTABH)

# The next rule is needed for make of Solaris 2.5.1 to override its
# built-in .y.o rule (which takes precedence over the .y.cpp rule above).
.y.o:
	if test -n "$(YTABH)"; then \
	  $(YACC) $(YACCFLAGS) -d $<; \
	else \
	  $(YACC) $(YACCFLAGS) $<; \
	fi
	-test -f y.tab.h && mv y.tab.h y_tab.h
	-test -f y.tab.c && mv y.tab.c y_tab.c
	mv y_tab.c $(YTABC)
	test -z "$(YTABH)" || mv y_tab.h $(YTABH)
	$(COMPILE.cpp) $(EXTRA_CCFLAGS) $(YTABC)

.man.n:
	@echo Making $@ from $<
	@-rm -f $@
	@sed -e "s|@APPRESDIR@|$(appresdir)|g" \
	-e "s|@BINDIR@|$(bindir)|g" \
	-e "s|@BROKEN_SPOOLER_FLAGS@|$(BROKEN_SPOOLER_FLAGS)|g" \
	-e "s|@COMMON_WORDS_FILE@|$(common_words_file)|g" \
	-e "s|@DATASUBDIR@|$(datasubdir)|g" \
	-e "s|@DEFAULT_INDEX@|$(indexdir)/$(indexname)|g" \
	-e "s|@DEFAULT_INDEX_NAME@|$(indexname)|g" \
	-e "s|@DEVICE@|$(DEVICE)|g" \
	-e "s|@DOCDIR@|$(docdir)|g" \
	-e "s|@EXAMPLEDIR@|$(exampledir)|g" \
	-e "s|@FONTDIR@|$(fontdir)|g" \
	-e "s|@g@|$(g)|g" \
	-e "s!@G@!`echo $(g) | tr [a-z] [A-Z]`!g" \
	-e "s|@HTMLDOCDIR@|$(htmldocdir)|g" \
	-e "s|@INDEX_SUFFIX@|$(indexext)|g" \
	-e "s|@LEGACYFONTDIR@|$(legacyfontdir)|g" \
	-e "s|@LOCALFONTDIR@|$(localfontdir)|g" \
	-e "s|@LOCALMACRODIR@|$(localtmacdir)|g" \
	-e "s|@MACRODIR@|$(tmacdir)|g" \
	-e "s|@MAN1EXT@|$(man1ext)|g" \
	-e "s|@MAN5EXT@|$(man5ext)|g" \
	-e "s|@MAN7EXT@|$(man7ext)|g" \
	-e "s|@MDATE@|`$(SHELL) $(top_srcdir)/mdate.sh $<`|g" \
	-e "s|@OLDFONTDIR@|$(oldfontdir)|g" \
	-e "s|@PDFDOCDIR@|$(pdfdocdir)|g" \
	-e "s|@SYSTEMMACRODIR@|$(systemtmacdir)|g" \
	-e "s|@TMAC_AN_PREFIX@|$(tmac_an_prefix)|g" \
	-e "s|@TMAC_M_PREFIX@|$(tmac_m_prefix)|g" \
	-e "s|@TMAC_MDIR@|$(tmacdir)/mm|g" \
	-e "s|@TMAC_S_PREFIX@|$(tmac_s_prefix)|g" \
	-e "s|@VERSION@|$(version)$(revision)|g" \
	$< >$@

.PHONY: install_man
install_man:
	-test -d $(DESTDIR)$(manroot) || $(mkinstalldirs) $(DESTDIR)$(manroot)
	-test -d $(DESTDIR)$(man1dir) || $(mkinstalldirs) $(DESTDIR)$(man1dir)
	@-pages="$(MAN1)"; \
	for p in $$pages; do \
	 prog=`basename $$p .n`; \
	 target=$(DESTDIR)$(man1dir)/$(NAMEPREFIX)$$prog.$(man1ext); \
	 rm -f $$target; \
	 echo $(INSTALL_DATA) $$p $$target; \
	 $(INSTALL_DATA) $$p $$target; \
	done
	-test -d $(DESTDIR)$(man5dir) || $(mkinstalldirs) $(DESTDIR)$(man5dir)
	@-pages="$(MAN5)"; \
	for p in $$pages; do \
	 target=$(DESTDIR)$(man5dir)/`basename $$p .n`.$(man5ext); \
	 rm -f $$target; \
	 echo $(INSTALL_DATA) $$p $$target; \
	 $(INSTALL_DATA) $$p $$target; \
	done
	-test -d $(DESTDIR)$(man7dir) || $(mkinstalldirs) $(DESTDIR)$(man7dir)
	@-pages="$(MAN7)"; \
	for p in $$pages; do \
	 target=$(DESTDIR)$(man7dir)/`basename $$p .n`.$(man7ext); \
	 rm -f $$target; \
	 echo $(INSTALL_DATA) $$p $$target; \
	 $(INSTALL_DATA) $$p $$target; \
	done

.PHONY: uninstall_man
uninstall_man:
	@-pages="$(MAN1)"; \
	for p in $$pages; do \
	 target=$(DESTDIR)$(man1dir)/$(NAMEPREFIX)`basename $$p .n`.$(man1ext); \
	 echo rm -f $$target; \
	 rm -f $$target; \
	done
	@-pages="$(MAN5)"; \
	for p in $$pages; do \
	 target=$(DESTDIR)$(man5dir)/`basename $$p .n`.$(man5ext); \
	 echo rm -f $$target; \
	 rm -f $$target; \
	done
	@-pages="$(MAN7)"; \
	for p in $$pages; do \
	 target=$(DESTDIR)$(man7dir)/`basename $$p .n`.$(man7ext); \
	 echo rm -f $$target; \
	 rm -f $$target; \
	done

.PHONY: install_prog
install_prog:
	-test -d $(DESTDIR)$(bindir) || $(mkinstalldirs) $(DESTDIR)$(bindir)
	rm -f $(DESTDIR)$(bindir)/$(NAMEPREFIX)$(PROG)
	$(INSTALL_PROGRAM) $(PROG) $(DESTDIR)$(bindir)/$(NAMEPREFIX)$(PROG)

.PHONY: uninstall_prog
uninstall_prog:
	-rm -f $(DESTDIR)$(bindir)/$(NAMEPREFIX)$(PROG)	

.PHONY: install_dev
install_dev:
	-test -d $(DESTDIR)$(datadir) \
	  || $(mkinstalldirs) $(DESTDIR)$(datadir)
	-test -d $(DESTDIR)$(dataprogramdir) \
	  || $(mkinstalldirs) $(DESTDIR)$(dataprogramdir)
	-test -d $(DESTDIR)$(datasubdir) \
	  || $(mkinstalldirs) $(DESTDIR)$(datasubdir)
	-test -d $(DESTDIR)$(fontdir) \
	  || $(mkinstalldirs) $(DESTDIR)$(fontdir)
	-test -d $(DESTDIR)$(fontsubdir) \
	  || $(mkinstalldirs) $(DESTDIR)$(fontsubdir)
	-if test -d $(srcdir)/generate; then \
	  test -d $(DESTDIR)$(fontsubdir)/generate \
	    || $(mkinstalldirs) $(DESTDIR)$(fontsubdir)/generate; \
	fi
	-if test -d $(srcdir)/enc; then \
	  test -d $(DESTDIR)$(fontsubdir)/enc \
	    || $(mkinstalldirs) $(DESTDIR)$(fontsubdir)/enc; \
	fi
	-if test -d $(srcdir)/map; then \
	  test -d $(DESTDIR)$(fontsubdir)/map \
	    || $(mkinstalldirs) $(DESTDIR)$(fontsubdir)/map; \
	fi
	-if test -d $(srcdir)/util; then \
	  test -d $(DESTDIR)$(fontsubdir)/util \
	    || $(mkinstalldirs) $(DESTDIR)$(fontsubdir)/util; \
	fi
	-if test -d $(srcdir)/old; then \
	  test -d $(DESTDIR)$(oldfontdir) \
	    || $(mkinstalldirs) $(DESTDIR)$(oldfontdir); \
	  test -d $(DESTDIR)$(oldfontsubdir) \
	    || $(mkinstalldirs) $(DESTDIR)$(oldfontsubdir); \
	fi
	-test -z "$(DEVFILES)" \
	  || for f in ""$(DEVFILES); do \
	       rm -f $(DESTDIR)$(fontsubdir)/$$f; \
	       if test -f $$f; then \
		 $(INSTALL_DATA) $$f $(DESTDIR)$(fontsubdir)/$$f; \
	       else \
		 $(INSTALL_DATA) $(srcdir)/$$f $(DESTDIR)$(fontsubdir)/$$f; \
	       fi; \
	     done
	-test -z "$(OLDDEVFILES)" \
	  || for f in ""$(OLDDEVFILES); do \
	       rm -f $(DESTDIR)$(oldfontsubdir)/$$f; \
	       $(INSTALL_DATA) $(srcdir)/old/$$f $(DESTDIR)$(oldfontsubdir)/$$f; \
	     done
	-test -z "$(DEVSCRIPTS)" \
	  || for f in ""$(DEVSCRIPTS); do \
	       rm -f $(DESTDIR)$(fontsubdir)/$$f; \
	       if test -f $$f; then \
		 $(INSTALL_SCRIPT) $$f $(DESTDIR)$(fontsubdir)/$$f; \
	       else \
		 $(INSTALL_SCRIPT) $(srcdir)/$$f $(DESTDIR)$(fontsubdir)/$$f; \
	       fi; \
	     done

.PHONY: uninstall_dev
uninstall_dev:
	-test -z "$(DEVFILES)$(DEVSCRIPTS)" \
	  || for f in ""$(DEVFILES) $(DEVSCRIPTS); do \
	       rm -f $(DESTDIR)$(fontsubdir)/$$f; \
	     done
	-test -z "$(OLDDEVFILES)" \
	  || for f in ""$(OLDDEVFILES); do \
	       rm -f $(DESTDIR)$(oldfontsubdir)/$$f; \
	     done
	-test -d $(DESTDIR)$(fontsubdir)/generate \
	  && rmdir $(DESTDIR)$(fontsubdir)/generate
	-test -d $(DESTDIR)$(fontsubdir)/enc \
	  && rmdir $(DESTDIR)$(fontsubdir)/enc
	-test -d $(DESTDIR)$(fontsubdir)/map \
	  && rmdir $(DESTDIR)$(fontsubdir)/map
	-test -d $(DESTDIR)$(fontsubdir)/util \
	  && rmdir $(DESTDIR)$(fontsubdir)/util
	-rmdir $(DESTDIR)$(fontsubdir)
	-rmdir $(DESTDIR)$(oldfontsubdir)

.PHONY: depend_src
depend_src: depend.temp
	mv depend.temp Makefile.dep

depend.temp: FORCE
	> depend.temp;
	if test -f "$(srcdir)/$(YTABC)"; then \
	  ytabc="$(srcdir)/$(YTABC)"; \
	else \
	  ytabc="$(YTABC)"; \
	fi; \
	test -z "$(CCSRCS)$(YTABC)" \
	  || $(CCC) $(ALL_CCFLAGS) $(EXTRA_CCFLAGS) -MM $(CCSRCS) $$ytabc >>depend.temp
	test -z "$(CSRCS)" \
	  || $(CC) $(ALL_CFLAGS) $(EXTRA_CFLAGS) -MM $(CSRCS) >>depend.temp
	test -z "$(YTABH)" \
	  || (sed -e 's|$(YTABH)|$(YTABC)|g' depend.temp >depend1.temp; \
	      mv depend1.temp depend.temp)

.PHONY: TAGS_src
TAGS_src:
	$(ETAGS) $(ETAGSFLAGS) $(CCSRCS) $(CSRCS)
	test -z "$(GRAM)$(HDRS)" \
	  || $(ETAGS) $(ETAGSFLAGS) -a $(ETAGSCCFLAG) $(GRAM) $(HDRS)

# This rule is only considered for the subdir_Makefile target.
Makefile:
	-rm -f Makefile
	echo srcdir=$(srcdir) >>Makefile
	echo VPATH=$(VPATH) >>Makefile
	cat $(MAKEFILEPARTS) /dev/null >>Makefile

FORCE:

.NOEXPORT:
