#
# ${R_HOME}/etc/Makefile

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

top_builddir = ..
subdir = etc

include $(top_builddir)/Makeconf

SOURCES = Makeconf.in Makeconf-tests.in Renviron.in
OBJECTS = $(SOURCES:.in=)
distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir)
DISTFILES = \
	Makefile.in $(SOURCES) \
	colors.big colors.small test-things.Rd \
	gnome-interface.glade

EXPORTFILE = @EXPORTFILE@
GNOME_IF_FILES = @GNOME_IF_FILES@

all: Makefile R

.SUFFIXES:
.SUFFIXES: .in

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

Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
	@cd $(top_builddir) && \
	  CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= \
	  $(SHELL) ./config.status
	@(for f in $(OBJECTS); do \
	    echo "$${f}: $(srcdir)/$${f}.in"; \
	  done) >> $@

R: $(OBJECTS)
## FIXME:
## We currently look for gnome-interface.glade in R_HOME/gnome, but we 
## should have it in R_HOME/etc (and the shlibs in Rexeclibdir).
## In this case, only do `install-gnome' if not building in srcdir.
	@$(MAKE) rhome=$(top_builddir) install-gnome

$(OBJECTS): $(top_builddir)/config.status

install: installdirs install-gnome
	@echo "installing etc ..."
	@for f in $(OBJECTS) $(EXPORTFILE); do \
	  $(INSTALL_DATA) $${f} $(rhome)/etc; \
	done
installdirs:
	@$(MKINSTALLDIRS) $(rhome)/etc
install-gnome:
	@if test -n "$(GNOME_IF_FILES)"; then \
	  $(MKINSTALLDIRS) $(rhome)/gnome ;\
	  for f in "$(GNOME_IF_FILES)"; do \
	    $(INSTALL_DATA) $(srcdir)/$${f} $(rhome)/gnome; \
	  done; \
	fi
install-strip: install
uninstall:
	@echo "uninstalling etc ..."
	@if test -d $(rhome)/etc -a \
	  "`cd $(rhome); pwd`" != "`cd $(top_builddir); pwd`"; then \
	  (cd $(rhome)/etc && \
	    rm -f *.pl $(OBJECTS) $(EXPORTFILE) $(GNOME_IF_FILES)); \
	  rmdir $(rhome)/etc 2> /dev/null \
	    || echo "  subdir etc not removed"; \
	fi

mostlyclean: clean
clean:
	@if [ "$(srcdir)" != "." ]; then \
	  rm -f *.pl $(GNOME_IF_FILES); \
	fi
	@rm -f $(EXPORTFILE)
distclean: clean
	@rm -f $(OBJECTS) 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

## Automagically generated dependencies: