#
# ${R_HOME}/tests/Embedding/Makefile

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

top_builddir = ../..
subdir = tests/Embedding

include $(top_builddir)/Makeconf

distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir)

SOURCES_R = error.R foo.R
SOURCES_C = \
  RNamedCall.c \
  RParseEval.c \
  Rerror.c \
  Rpackage.c \
  Rplot.c \
  Rpostscript.c \
  Rtest.c \
  embeddedRCall.c \
  tryEval.c

HEADERS = embeddedRCall.h
PROGRAMS = Rtest Rplot Rpostscript Rerror RNamedCall RParseEval Rpackage tryEval

## <FIXME>
## Currently Rshutdown.c is not used.
DISTFILES = Makefile.in index.html \
  $(SOURCES_R) $(SOURCES_C) $(HEADERS) \
  Rshutdown.c
## </FIXME>

R_CMD_LINK = $(top_builddir)/bin/R CMD LINK $(CC)
LIBR = -L`cd $(top_builddir) && $(GETWD)`/bin -lR

all: Makefile R-sources tests

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

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

tests: $(PROGRAMS)
	(R_HOME=$(top_builddir); export R_HOME; ./Rtest --silent)
	(R_HOME=$(top_builddir); export R_HOME; ./RNamedCall --silent)
	(R_HOME=$(top_builddir); export R_HOME; ./RParseEval --silent)
	(R_HOME=$(top_builddir); export R_HOME; ./Rpackage --silent)
	(R_HOME=$(top_builddir); export R_HOME; ./Rerror --silent)
	(R_HOME=$(top_builddir); export R_HOME; ./Rplot --silent)
	(R_HOME=$(top_builddir); export R_HOME; \
	  ./Rpostscript --silent --gui=none --no-save)
	(R_HOME=$(top_builddir); export R_HOME; ./tryEval --silent)

Rtest: Rtest.o embeddedRCall.o
	$(R_CMD_LINK) -o $@ Rtest.o embeddedRCall.o $(LIBR)
Rplot: Rplot.o embeddedRCall.o
	$(R_CMD_LINK) -o $@ Rplot.o embeddedRCall.o $(LIBR)
Rpostscript: Rpostscript.o embeddedRCall.o
	$(R_CMD_LINK) -o $@ Rpostscript.o embeddedRCall.o $(LIBR)
Rerror: Rerror.o embeddedRCall.o
	$(R_CMD_LINK) -o $@ Rerror.o embeddedRCall.o $(LIBR)
Rpackage: Rpackage.o  embeddedRCall.o
	$(R_CMD_LINK) -o $@ Rpackage.o embeddedRCall.o $(LIBR)
RNamedCall: RNamedCall.o embeddedRCall.o
	$(R_CMD_LINK) -o $@ RNamedCall.o embeddedRCall.o $(LIBR)
RParseEval: RParseEval.o embeddedRCall.o
	$(R_CMD_LINK) -o $@ RParseEval.o embeddedRCall.o $(LIBR)

tryEval: tryEval.o
	$(R_CMD_LINK) -o $@ tryEval.o $(LIBR)	

R.so: showArgs.o
	$(SHLIB_LINK) -o $@ showArgs.o

mostlyclean: clean
clean:
	@if test "$(BUILDDIR_IS_SRCDIR)" = no ; then \
	  rm -f $(SOURCES_R); \
	fi
	@-rm -rf .libs _libs
	@-rm -f *.o $(PROGRAMS) Rplots.ps
distclean: clean
	@-rm -f Makefile
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