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

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

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

include $(top_builddir)/Makeconf
distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir)
DISTFILES = LICENSE INDEX TITLE DESCRIPTION.in Makefile.in

pkg = methods

all: Makefile DESCRIPTION
	@echo "building package \`$(pkg)'"
	@$(MKINSTALLDIRS) $(top_builddir)/library/$(pkg)/R
	@(f=$${TMPDIR:-/tmp}/R$$$$; \
	  cat `ls $(srcdir)/R/*.R` > $${f}; \
	  $(top_srcdir)/tools/move-if-change $${f} all.R)
	@for f in COPYRIGHTS INDEX TITLE; do \
	if test -f $(srcdir)/$${f}; then \
	  $(INSTALL_DATA) $(srcdir)/$${f} \
	    $(top_builddir)/library/$(pkg); \
	fi; \
	done
	@if test -f $(top_builddir)/$(subdir)/DESCRIPTION; then \
	  $(INSTALL_DATA) $(top_builddir)/$(subdir)/DESCRIPTION \
	    $(top_builddir)/library/$(pkg); \
	fi
	@if test -d $(srcdir)/data; then \
	  $(MKINSTALLDIRS) $(top_builddir)/library/$(pkg)/data; \
	  for f in `ls -d $(srcdir)/data/* | sed '/CVS/d'`; do \
	    $(INSTALL_DATA) $${f} $(top_builddir)/library/$(pkg)/data; \
	  done; \
	fi
	@if test -d src; then \
	  (cd src && $(MAKE)) || exit 1; \
	fi
	@$(MAKE) Rfiles

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

Rfiles: $(top_builddir)/library/$(pkg)/R/$(pkg) \
  $(top_builddir)/library/$(pkg)/R/all.rda

$(top_builddir)/library/$(pkg)/R/$(pkg): $(top_srcdir)/share/R/firstlib.R
	@cp $(top_srcdir)/share/R/firstlib.R $@

$(top_builddir)/library/$(pkg)/R/all.rda: all.R
	@echo "dumping R code in package \`$(pkg)'"
	@$(top_builddir)/bin/R --vanilla --slave < all.R

mostlyclean: clean
clean:
	@if test -d src; then (cd src && $(MAKE) $@); fi
	@rm -f all.R
distclean:
	@if test -d src; then (cd src && $(MAKE) $@); fi
	@rm -f Makefile DESCRIPTION
maintainer-clean: distclean

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 R data exec man src; do \
	  if test -d $(srcdir)/$${d}; then \
	    ((cd $(srcdir); \
	          $(TAR) -c -f - $(DISTDIR_TAR_EXCLUDE) $${d}) \
	        | (cd $(distdir); $(TAR) -x -f -)) \
	      || exit 1; \
	  fi; \
	done
