#
# ${R_HOME}/src/library/Makefile

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

top_builddir = ../..
subdir = src/library

include $(top_builddir)/Makeconf

distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir)
DISTFILES = Makefile.in

SUBDIRS = profile $(R_PKGS)

PKGS = $(R_PKGS)

all: Makefile R

Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
	cd $(top_builddir) && \
	  CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= \
	  $(SHELL) ./config.status

R:
	@$(MKINSTALLDIRS) $(top_builddir)/library
	@for pkg in $(R_PKGS) profile; do \
	  (cd $${pkg} && $(MAKE)) || exit 1; \
	done
	@(cd $(top_builddir)/library; \
	  cat */TITLE > LibIndex 2> /dev/null)
	@cp $(top_srcdir)/doc/html/R.css $(top_builddir)/library/

docs:
	@echo "building all R object docs (help, HTML, LaTeX, examples)"
	@$(MAKE) DOCS
	@$(MAKE) indices
	@touch stamp-docs
help:
	@OPTS="--txt"   $(MAKE) DOCS
html:
	@OPTS="--html"    $(MAKE) DOCS
	@$(MAKE) indices
latex:
	@OPTS="--latex"   $(MAKE) DOCS
examples:
	@OPTS="--example" $(MAKE) DOCS

indices:
	@$(top_builddir)/bin/R CMD build-help --htmllists

$(top_builddir)/library/LibIndex:
	@if [ ! -f $@ ]; then touch $@; fi

DOCS:
	@if @NO_PERL5@; then \
	  echo "you need Perl version 5 to build the R object docs"; \
	  exit 1; \
	fi
	@for pkg in $(R_PKGS); do \
	  $(top_builddir)/bin/R CMD build-help $${OPTS} \
	    $(srcdir)/$${pkg}; \
	  $(top_builddir)/bin/R CMD Rd2contents $(srcdir)/$${pkg} \
	    > $(top_builddir)/library/$${pkg}/CONTENTS; \
	done; \
	cat $(top_builddir)/library/*/CONTENTS \
	  > $(top_builddir)/doc/html/search/index.txt

mostlyclean: clean
clean:
	@for d in $(SUBDIRS); do \
	  (cd $${d} && $(MAKE) $@); \
	done
	@rm -f stamp-*
distclean:
	@for d in $(SUBDIRS); do \
	  (cd $${d} && $(MAKE) $@); \
	done
	@rm -f Makefile

maintainer-clean: distclean

install install-strip uninstall TAGS info dvi check::

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 d in $(SUBDIRS); do \
	  test -d $(distdir)/$${d} \
	    || mkdir $(distdir)/$${d} \
	    || exit 1; \
	  chmod 755 $(distdir)/$${d}; \
	  (cd $${d} && $(MAKE) distdir) \
	    || exit 1; \
	done