#
# ${R_HOME}/doc/Makefile

VPATH = @srcdir@
srcdir = @srcdir@
top_srcdir = @top_srcdir@

top_builddir = ..
subdir = doc

include $(top_builddir)/Makeconf

distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir)
INSTFILES = AUTHORS COPYING COPYING.LIB COPYRIGHTS CRAN_mirrors.csv \
	KEYWORDS KEYWORDS.db THANKS
DISTFILES = Makefile.in $(INSTFILES) R.aux Rscript.1
NON_SVN_INSTFILES = FAQ RESOURCES
SUBDIRS = html manual

HELP2MAN = $(PERL) $(top_srcdir)/tools/help2man.pl

all: Makefile R docs
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
	@cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@

R: Makefile svnonly
	@for d in $(SUBDIRS); do \
	  (cd $${d} && $(MAKE) $@) || exit 1; \
	done
	@if test "$(BUILDDIR_IS_SRCDIR)" = no ; then \
	  $(MAKE) rdocdir=$(top_builddir)/doc install-sources; \
	fi

docs: R.1
	@(cd manual && $(MAKE) $@)

R.1:
	@$(HELP2MAN) --include=$(srcdir)/R.aux --no-info --output=R.1 \
	  --name="a language for data analysis and graphics" \
	  $(top_builddir)/bin/R

install: install-message installdirs install-sources install-sources2 install-man
	@for d in $(SUBDIRS); do \
	  (cd $${d} && $(MAKE) $@) || exit 1; \
	done
installdirs:
	@$(MKINSTALLDIRS) "$(DESTDIR)$(rdocdir)"
	@$(MKINSTALLDIRS) $(DESTDIR)$(mandir)/man1
install-man: installdirs R.1 Rscript.1
	@rm -f $(DESTDIR)$(mandir)/man1/R.1
	@$(INSTALL_DATA) R.1 $(DESTDIR)$(mandir)/man1
	@rm -f $(DESTDIR)$(mandir)/man1/Rscript.1
	@@$(INSTALL_DATA) ${srcdir}/Rscript.1 $(DESTDIR)$(mandir)/man1
install-message:
	@$(ECHO) "installing $(subdir) ..."
install-sources:
	@$(MKINSTALLDIRS) "$(DESTDIR)$(rdocdir)"
	@for f in $(INSTFILES); do \
	  $(INSTALL_DATA) $(srcdir)/$${f} "$(DESTDIR)$(rdocdir)"; \
	done
install-sources2: installdirs
	@for f in $(NON_SVN_INSTFILES); do \
	  $(INSTALL_DATA) $${f} "$(DESTDIR)$(rdocdir)"; \
	done
	$(INSTALL_DATA) $(top_srcdir)/NEWS "$(DESTDIR)$(rdocdir)"
install-strip: install

uninstall:
	@$(ECHO) "uninstalling $(subdir) ..."
	@if test -d "$(DESTDIR)$(rdocdir)" \
	  && test "`cd \"$(DESTDIR)$(rhome)\"; $(GETWD)`" \
	       != "`cd $(top_builddir); $(GETWD)`"; then \
	  for d in $(SUBDIRS); do \
	    (cd $${d} && $(MAKE) $@) || exit 1; \
	  done; \
	  for f in $(INSTFILES) $(NON_SVN_INSTFILES) NEWS; do \
	    rm -f "$(DESTDIR)$(rdocdir)"/$${f}; \
	  done; \
	  rmdir "$(DESTDIR)$(rdocdir)" 2>/dev/null \
	    || $(ECHO) "  subdir $(DESTDIR)$(subdir) not removed"; \
	fi
	@rm -f $(DESTDIR)$(mandir)/man1/R.1 $(DESTDIR)$(mandir)/man1/Rscript.1

dvi info pdf::
	@(cd manual && $(MAKE) $@)

mostlyclean:
clean:
	@for d in $(SUBDIRS); do \
	  (cd $${d} && $(MAKE) $@); \
	done
	@if test "$(BUILDDIR_IS_SRCDIR)" = no ; then \
	  rm -f $(INSTFILES) R.1; \
	fi
distclean: clean
	@for d in $(SUBDIRS); do \
	  (cd $${d} && $(MAKE) $@) || exit 1; \
	done
	@if test "$(BUILDDIR_IS_SRCDIR)" = no ; then \
	  rm -f $(NON_SVN_INSTFILES); \
	fi
	-@rm -f Makefile R.1
maintainer-clean: distclean


svnonly:
	@if test -f "$(srcdir)/FAQ" ; then \
	  if test "$(BUILDDIR_IS_SRCDIR)" = no ; then \
	    for f in $(NON_SVN_INSTFILES); do \
	      $(INSTALL_DATA) $(srcdir)/$${f} .; \
	    done \
	  fi \
	fi

distdir: $(DISTFILES)
	@for f in $(DISTFILES); do \
	  test -f $(distdir)/$${f} \
	    || ln $(srcdir)/$${f} $(distdir)/$${f} 2>/dev/null \
	    || cp -p $(srcdir)/$${f} $(distdir)/$${f}; \
	done
	@for f in FAQ RESOURCES ; do \
	  cp -p $${f} $(distdir)/$${f}; \
	done
	@for d in $(SUBDIRS); do \
	  test -d $(distdir)/$${d} \
	    || mkdir $(distdir)/$${d} \
	    || exit 1; \
	  chmod 755 $(distdir)/$${d}; \
	  (cd $${d} && $(MAKE) distdir) \
	    || exit 1; \
	done
