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

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

top_builddir = ../..
subdir = src/scripts

include $(top_builddir)/Makeconf

SCRIPTS_S = BATCH Rd2dvi check filename help help.links \
	massage-Examples pager
SCRIPTS_B_IN = COMPILE.in INSTALL.in REMOVE.in Rd2contents.in Rd2txt.in \
	Rdconv.in Rdindex.in Rman2Rd.in SHLIB.in Sd2Rd.in build-help.in \
	fwf2table.in help.pretty.in html2dos.in
SCRIPTS_B = $(SCRIPTS_B_IN:.in=)

distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir)
DISTFILES = Makefile.in $(SCRIPTS_S) $(SCRIPTS_B_IN) R.sh.in

.SUFFIXES:
.SUFFIXES: .in

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

all: Makefile R

Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status

R: $(SCRIPTS_B) R.sh
	@$(MKINSTALLDIRS) $(top_builddir)/bin
	@sed "s@R_HOME_DIR*@`cd $(top_builddir); pwd`@" < R.sh \
	  > $(top_builddir)/bin/R
	@chmod +x $(top_builddir)/bin/R
	@for f in $(SCRIPTS_S); do \
	  $(INSTALL) $(srcdir)/$$f $(top_builddir)/bin; \
	done
	@for f in $(SCRIPTS_B); do \
	  $(INSTALL) $$f $(top_builddir)/bin; \
	done

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

mostlyclean: clean
clean:
distclean:
	@rm -f Makefile R.sh $(SCRIPTS_B)
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
