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

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

top_builddir = ../..
subdir = src/include

include $(top_builddir)/Makeconf

SRC_HEADERS = Mathlib.h Rdefines.h Rinternals.h R.h S.h S_compat.h f2c.h
OBJ_HEADERS = Rconfig.h Rversion.h
R_EXT_HEADERS = Arith.h Complex.h Constants.h Error.h Errormsg.h \
	F77.h Memory.h Print.h Random.h Scompat.h Sort.h \
	Linpack.h Blas.h
R_EXT_HEADERS2 = Applic.h Fortran.h PrtUtil.h Utils.h
R_EXT_OBJ_HEADERS = Rver.h

distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir)
DISTFILES = Makefile.in README \
	Defn.h Fileio.h Graphics.h IOStuff.h Parse.h Print.h \
	Statdecl.h Startup.h Stattab.h \
	$(SRC_HEADERS) \
	Rconfig.h.in

all: Makefile R

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

R: Makefile Rconfig.h Rversion.h FFDecl.h FFTab.h R_ext/Rver.h # R_ext/F77.h 
	@$(MKINSTALLDIRS) $(top_builddir)/include $(top_builddir)/include/R_ext
	@for f in $(SRC_HEADERS); do \
	  $(INSTALL_DATA) $(srcdir)/$$f $(top_builddir)/include; \
	done
	@for f in $(R_EXT_HEADERS); do \
	  $(INSTALL_DATA) $(srcdir)/R_ext/$$f $(top_builddir)/include/R_ext; \
	done
	@for f in $(R_EXT_HEADERS2); do \
	  $(INSTALL_DATA) $(srcdir)/$$f $(top_builddir)/include/R_ext; \
	done
	@for f in $(OBJ_HEADERS); do \
	  $(INSTALL_DATA) $$f $(top_builddir)/include; \
	done
	@for f in $(R_EXT_OBJ_HEADERS); do \
	  $(INSTALL_DATA) R_ext/$$f $(top_builddir)/include/R_ext; \
	done

Rconfig.h: $(top_srcdir)/configure $(srcdir)/Rconfig.h.in
	@cd $(top_builddir) && $(MAKE) src/include/Rconfig.h
	@touch $@

Rversion.h: $(top_srcdir)/VERSION $(top_srcdir)/date-stamp
	@$(top_srcdir)/tools/GETVERSION > $@

R_ext/Rver.h: $(top_srcdir)/VERSION Rconfig.h
	@mkdir -p R_ext
	@$(top_srcdir)/tools/GETRVERSION > $@


FFDecl.h FFTab.h:: $(top_srcdir)/src/appl/ROUTINES
	@$(top_srcdir)/tools/GETSYMBOLS

mostlyclean:
clean:
distclean:
	@rm -f GETSYMBOLS Makefile Rconfig.h Rversion.h FFDecl.h FFTab.h
maintainer-clean: distclean

install install-strip uninstall::

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
