#
# ${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
PKGS = $(R_PKGS)

SUBDIRS = profile $(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 $(PKGS) profile; do \
	  (cd $${pkg} && $(MAKE)) || exit 1; \
	done
	@(cd $(top_builddir)/library; \
	  cat */TITLE > LibIndex 2> /dev/null)

docs:
	@echo "Building ALL documentation (help, HTML, LaTeX, examples)"
	@$(MAKE) DOCS
	@R_HOME=`cd $(top_builddir); pwd`; export R_HOME; \
	  $${R_HOME}/bin/build-help --htmllists
	@touch stamp-docs
help:
	@OPTS="--nroff"   $(MAKE) DOCS
html:
	@OPTS="--html"    $(MAKE) DOCS
	@R_HOME=`cd $(top_builddir); pwd`; export R_HOME; \
	  $${R_HOME}/bin/build-help --htmllists
latex:
	@OPTS="--latex"   $(MAKE) DOCS
examples:
	@OPTS="--example" $(MAKE) DOCS

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

DOCS:
	@for pkg in $(PKGS); do \
	  R_HOME=`cd $(top_builddir); pwd`; export R_HOME; \
	  $${R_HOME}/bin/build-help $${OPTS} $(srcdir)/$${pkg}; \
	  $${R_HOME}/bin/Rd2contents $(srcdir)/$${pkg} \
	    > $${R_HOME}/library/$${pkg}/CONTENTS; \
	done; \
	cat $${R_HOME}/library/*/CONTENTS \
	  > $${R_HOME}/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
