#
# ${R_HOME}/Makefile

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

top_builddir = .

include $(top_builddir)/Makeconf

distdir = $(PACKAGE)-$(VERSION)
INSTFILES = AUTHORS COPYING COPYING.LIB COPYRIGHTS FAQ NEWS RESOURCES THANKS
DISTFILES = $(INSTFILES) \
	BUGS ChangeLog INSTALL ONEWS README VERSION Y2K \
	Makeconf.in Makefile.in \
	acinclude.m4 aclocal.m4 \
	config.site configure configure.ac \
	date-stamp
SUBDIRS = m4 tools afm doc etc share src tests
SUBDIRS_WITH_NO_BUILD = debian

GZIP = --best

all: Makefile Makeconf R docs @USE_RECOMMENDED_PACKAGES_TRUE@ stamp-recommended

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

ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
ACLOCAL_DEPENDENCIES = \
	configure.ac \
	acinclude.m4
ACINCLUDE_DEPENDENCIES = \
	m4/R.m4 \
	m4/codeset.m4 \
	m4/gnome-gnorba-check.m4 \
	m4/gnome-orbit-check.m4 \
	m4/gnome.m4 \
	m4/libglade.m4 \
	m4/libtool.m4
CONFIGURE_DEPENDENCIES = $(srcdir)/VERSION
config.status: $(srcdir)/configure
	@$(SHELL) ./config.status --recheck
$(srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(srcdir)/configure.ac $(ACLOCAL_M4) $(CONFIGURE_DEPENDENCIES)
	@cd $(srcdir) && $(AUTOCONF)
$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(srcdir)/configure.ac $(ACLOCAL_DEPENDENCIES)
	@cd $(srcdir) && $(ACLOCAL)
$(srcdir)/acinclude.m4: @MAINTAINER_MODE_TRUE@ $(ACINCLUDE_DEPENDENCIES)
	@cd $(srcdir) && cat $(ACINCLUDE_DEPENDENCIES) > $@

LIBTOOL_DEPS = @LIBTOOL_DEPS@
libtool: $(LIBTOOL_DEPS)
	$(SHELL) ./config.status --recheck

R: Makefile
	@if test "$(BUILDDIR_IS_SRCDIR)" = no ; then \
	  for f in $(INSTFILES); do \
	    $(INSTALL_DATA) $(srcdir)/$${f} $(top_builddir); \
	  done; \
	fi
	@for d in $(SUBDIRS); do \
	  (cd $${d} && $(MAKE) R) || exit 1; \
	done
	@test -f src/library/stamp-docs || \
	  echo "you should 'make docs' now ..."

docs: R FORCE
	-@(cd doc && $(MAKE) $@)
	-@(cd src/library && $(MAKE) $@)
help html latex examples: FORCE
	-@(cd src/library && $(MAKE) $@)
FORCE:

stamp-recommended: R docs
	@(cd src/library/Recommended && $(MAKE))

install: installdirs
	@for d in $(SUBDIRS); do \
	  (cd $${d} && $(MAKE) $@) || exit 1; \
	done
	@for f in $(INSTFILES); do \
	  $(INSTALL_DATA) $(srcdir)/$${f} $(rhome); \
	done
@WANT_R_FRAMEWORK_TRUE@		$(MAKE) install-R-framework
@WANT_R_FRAMEWORK_TRUE@		@(sed 's/^LIBR =.*/LIBR = -framework R/' \
@WANT_R_FRAMEWORK_TRUE@		  $(top_builddir)/etc/Makeconf > $(rhome)/etc/Makeconf)
@WANT_R_FRAMEWORK_TRUE@		@(sed 's/Versions\/$(VERSION)\/Resources/Resources/' \
@WANT_R_FRAMEWORK_TRUE@		  $(R_FRAMEWORK_DIR)/Resources/bin/R > \
@WANT_R_FRAMEWORK_TRUE@		  $(R_FRAMEWORK_DIR)/Resources/bin/RR)
@WANT_R_FRAMEWORK_TRUE@		@(mv $(R_FRAMEWORK_DIR)/Resources/bin/RR $(R_FRAMEWORK_DIR)/Resources/bin/R)
@WANT_R_FRAMEWORK_TRUE@		@(chmod 755 $(R_FRAMEWORK_DIR)/Resources/bin/R)
@WANT_R_FRAMEWORK_TRUE@		@(cp $(R_FRAMEWORK_DIR)/Resources/bin/R $(R_FRAMEWORK_DIR)/Resources/R)


installdirs:
	@$(MKINSTALLDIRS) $(rhome)
install-strip:
	$(MAKE) INSTALL_PROGRAM="${INSTALL_PROGRAM} -s" install
uninstall:
	@(for d in $(SUBDIRS); do rsd="$${d} $${rsd}"; done; \
	  for d in $${rsd}; do (cd $${d} && $(MAKE) $@); done)
	@for f in $(INSTFILES); do \
	  rm -f $(rhome)/$${f}; \
	done
	@rm -rf $(Rexecbindir)
	@rm -rf $(rhome)/demos
	@rm -rf $(rhome)/gnome


mostlyclean: clean
clean:
	@(for d in $(SUBDIRS); do rsd="$${d} $${rsd}"; done; \
	  for d in $${rsd}; do (cd $${d} && $(MAKE) $@); done)
	@if test "$(BUILDDIR_IS_SRCDIR)" = no ; then \
	  rm -f $(INSTFILES); \
	fi
distclean: clean
	@(for d in $(SUBDIRS); do rsd="$${d} $${rsd}"; done; \
	  for d in $${rsd}; do (cd $${d} && $(MAKE) $@); done)
	-@rm -rf bin include library modules gnome
	-@rm -f Makeconf Makefile Makefile.bak Makefrag.* \
	  config.cache config.log config.status libtool
maintainer-clean: distclean
	@echo "This command is intended for maintainers to use; it"
	@echo "deletes files that may need special rules to rebuild"
	@(for d in $(SUBDIRS); do rsd="$${d} $${rsd}"; done; \
	  for d in $${rsd}; do (cd $${d} && $(MAKE) $@); done)
	-@(cd $(srcdir) && rm -rf autom4te.cache)

dist: dist-unix
dist-unix: distdir
	-chmod -R a+r $(distdir)
	-chmod -R go-w $(distdir)
	GZIP=$(GZIP) $(TAR) czf $(distdir).tar.gz $(distdir)
	rm -rf $(distdir)
dist-win:
distdir: $(DISTFILES)
	@rm -rf $(distdir)
	@mkdir $(distdir)
	@-chmod 755 $(distdir)
	@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 $(SUBDIRS); do \
	  test -d $(distdir)/$${d} \
	    || mkdir $(distdir)/$${d} \
	    || exit 1; \
	  chmod 755 $(distdir)/$${d}; \
	  (cd $${d} && $(MAKE) distdir) \
	    || exit 1; \
	done
	@for d in $(SUBDIRS_WITH_NO_BUILD); do \
	  ((cd $(srcdir); $(TAR) -c -f - --exclude=CVS $${d}) \
	      | (cd $(distdir); $(TAR) -x -f -)) \
	    || exit 1; \
	done

dvi info pdf:
	-@(cd doc && $(MAKE) $@)
install-dvi install-info install-pdf:
	-@(cd doc/manual && $(MAKE) $@)
uninstall-dvi uninstall-info uninstall-pdf:
	-@(cd doc/manual && $(MAKE) $@)

check check-devel check-all:
	@(cd tests && $(MAKE) $@)

reset-recommended:
	@(cd src/library/Recommended && $(MAKE) clean)

install-R-framework:
	@(cd $(top_builddir)/src/modules/aqua && \
	  cp Info.plist "$(R_FRAMEWORK_DIR)/Versions/$(VERSION)/Resources")
	@(cd "$(R_FRAMEWORK_DIR)/Versions/$(VERSION)" && \
	  ln -f -s -n Resources/include Headers && \
	  ln -f -s -n Resources/bin/libR.dylib R && \
	  test -d "Resources/bin/Frameworks" || mkdir -p "Resources/bin/Frameworks")
	@(cd "$(R_FRAMEWORK_DIR)/Versions" && \
	  ln -f -s -n $(VERSION) Current)
	@(cd "$(R_FRAMEWORK_DIR)"  && \
	  ln -f -s -n Versions/Current/Headers Headers&& \
	  ln -f -s -n Versions/Current/R R && \
	  ln -f -s -n Versions/Current/Resources Resources)
	@(cd "$(srcdir)/src/modules/aqua/Contents/Resources" && \
	  cp -R * "$(R_FRAMEWORK_DIR)/Resources/bin")
	@(cd "$(R_FRAMEWORK_DIR)/Resources/bin" && \
	  sed 's/^args=/args=--gui=aqua/' < R > RAqua && \
	  chmod 755 RAqua && \
	  install_name_tool -id "$(R_FRAMEWORK_DIR)/Versions/$(VERSION)/Resources/bin/libR.dylib" libR.dylib)
	@(sed 's/Versions\/$(VERSION)\/Resources/Resources/' $(R_FRAMEWORK_DIR)/Resources/bin/RAqua > \
	  $(R_FRAMEWORK_DIR)/Resources/bin/RRAqua)
	@(mv $(R_FRAMEWORK_DIR)/Resources/bin/RRAqua $(R_FRAMEWORK_DIR)/Resources/bin/RAqua)
	@(chmod 755 $(R_FRAMEWORK_DIR)/Resources/bin/RAqua)
	@(cp $(srcdir)/src/modules/aqua/CHANGES "$(R_FRAMEWORK_DIR)/Resources/NEWS.aqua")
	@(cp $(srcdir)/src/modules/aqua/RMacOSX-FAQ.html "$(R_FRAMEWORK_DIR)/Resources/RMacOSX-FAQ.html")



install-aqua:
	@(rm -rf /Applications/R.app)
	@(mkdir -p /Applications/R.app/Contents/Resources)
	@(cd "$(srcdir)/src/modules/aqua/Contents" && \
	  cp PkgInfo /Applications/R.app/Contents)
	@(cd "$(top_builddir)/src/modules/aqua/Contents" && \
	  cp Info.plist  /Applications/R.app/Contents)
	@(cd "$(srcdir)/src/modules/aqua/Contents/Resources" && \
	  cp -R * /Applications/R.app/Contents/Resources)
	@(mkdir -p /Applications/R.app/Contents/MacOS)
	@test -f "$(R_FRAMEWORK_DIR)/Resources/bin/RAqua"  \
	  || (echo "please, make install-R-framework first" &&  exit 1)
	@(cd /Applications/R.app/Contents/MacOS && \
	  ln -f -n "$(R_FRAMEWORK_DIR)/Resources/bin/RAqua" R && \
	  chmod 755 R)
TAGS:
