diff -urN R-3.3.1.orig/configure R-3.3.1/configure
--- R-3.3.1.orig/configure	2016-10-21 11:27:17.943440572 +0100
+++ R-3.3.1/configure	2016-10-21 12:17:32.000000000 +0100
@@ -777,6 +777,7 @@
 USE_EXPORTFILES_TRUE
 SHLIB_EXT
 SHLIB_LIBADD
+RPATH_LDFLAGS
 DYLIB_UNDEFINED_ALLOWED_FALSE
 DYLIB_UNDEFINED_ALLOWED_TRUE
 INTERNET_LIBS
@@ -3829,7 +3830,9 @@
       ;;
   esac
 fi
- if test "x${want_R_framework}" = xyes; then
+
+
+if test "x${want_R_framework}" = xyes; then
   WANT_R_FRAMEWORK_TRUE=
   WANT_R_FRAMEWORK_FALSE='#'
 else
@@ -3853,7 +3856,9 @@
   want_R_shlib="${want_R_framework}"
 fi
 
- if test "x${want_R_shlib}" = xyes; then
+
+
+if test "x${want_R_shlib}" = xyes; then
   WANT_R_SHLIB_TRUE=
   WANT_R_SHLIB_FALSE='#'
 else
@@ -3876,7 +3881,9 @@
     want_R_static=no
   fi
 fi
- if test "x${want_R_static}" = xyes; then
+
+
+if test "x${want_R_static}" = xyes; then
   WANT_R_STATIC_TRUE=
   WANT_R_STATIC_FALSE='#'
 else
@@ -3911,7 +3918,9 @@
   use_maintainer_mode=no
 fi
 
- if test "x${use_maintainer_mode}" = xyes; then
+
+
+if test "x${use_maintainer_mode}" = xyes; then
   MAINTAINER_MODE_TRUE=
   MAINTAINER_MODE_FALSE='#'
 else
@@ -3941,7 +3950,9 @@
   want_prebuilt_html=no
 fi
 
- if test "x${want_prebuilt_html}" = xyes; then
+
+
+if test "x${want_prebuilt_html}" = xyes; then
   BUILD_HTML_TRUE=
   BUILD_HTML_FALSE='#'
 else
@@ -3966,7 +3977,9 @@
 fi
 
 
- if test "x${want_lto}" != xno; then
+
+
+if test "x${want_lto}" != xno; then
   BUILD_LTO_TRUE=
   BUILD_LTO_FALSE='#'
 else
@@ -3982,7 +3995,9 @@
   want_java=yes
 fi
 
- if test "x${want_java}" = xyes; then
+
+
+if test "x${want_java}" = xyes; then
   WANT_JAVA_TRUE=
   WANT_JAVA_FALSE='#'
 else
@@ -4238,7 +4253,9 @@
   want_byte_compiled_packages=yes
 fi
 
- if test "x${want_byte_compiled_packages}" = xyes; then
+
+
+if test "x${want_byte_compiled_packages}" = xyes; then
   BYTE_COMPILE_PACKAGES_TRUE=
   BYTE_COMPILE_PACKAGES_FALSE='#'
 else
@@ -22344,7 +22361,9 @@
 
 
 
- if test "${cross_compiling}" = yes; then
+
+
+if test "${cross_compiling}" = yes; then
   CROSS_COMPILING_TRUE=
   CROSS_COMPILING_FALSE='#'
 else
@@ -22355,7 +22374,7 @@
 
 ### * Checks for libraries.
 
-## Set up LD_LIBRARY_PATH or equivalent.
+## Add -Wl,-rpath, entries to LDFLAGS.
 ## <FIXME>
 ## What is this doing *HERE*?
 ## Should be needed for tests using AC_RUN_IFELSE()?
@@ -22388,6 +22407,13 @@
 else
   R_LD_LIBRARY_PATH="${R_LD_LIBRARY_PATH}${separator}${lib}"
 fi
+          separator=""
+test -z "${separator}" && separator=" "
+if test -z "${RPATH_LDFLAGS}"; then
+  RPATH_LDFLAGS="-Wl,-rpath,${lib}"
+else
+  RPATH_LDFLAGS="${RPATH_LDFLAGS}${separator}-Wl,-rpath,${lib}"
+fi
 	  ;;
       esac
     done
@@ -22407,13 +22433,20 @@
     Rshlibpath_var=${shlibpath_var}
 esac
 
-## Export LD_LIBRARY_PATH or equivalent.
+## Export LD_LIBRARY_PATH or equivalent (except we do not want to do that
+## instead we want to use -Wl,-rpath .. only doing this for Linux for now).
 if eval "test -z \"\${${Rshlibpath_var}}\""; then
   eval "${Rshlibpath_var}=\"${R_LD_LIBRARY_PATH}\""
 else
   eval "${Rshlibpath_var}=\"${R_LD_LIBRARY_PATH}${PATH_SEPARATOR}\${${Rshlibpath_var}}\""
 fi
-eval "export ${Rshlibpath_var}"
+case "${host_os}" in
+  linux*)
+    ;;
+  *)
+    eval "export ${Rshlibpath_var}"
+    ;;
+esac
 
 
 ## record how to strip shared/dynamic libraries.
@@ -25074,7 +25107,7 @@
 # flags.
 r_save_CFLAGS=$CFLAGS
 CFLAGS="$CFLAGS $r_verb"
-(eval echo $as_me:25077: \"$ac_link\") >&5
+(eval echo $as_me:25109: \"$ac_link\") >&5
 r_c_v_output=`eval $ac_link 5>&1 2>&1 | grep -v 'Driving:'`
 echo "$r_c_v_output" >&5
 CFLAGS=$r_save_CFLAGS
@@ -25149,7 +25182,7 @@
 # flags.
 r_save_CFLAGS=$CFLAGS
 CFLAGS="$CFLAGS $r_cv_prog_c_v"
-(eval echo $as_me:25152: \"$ac_link\") >&5
+(eval echo $as_me:25184: \"$ac_link\") >&5
 r_c_v_output=`eval $ac_link 5>&1 2>&1 | grep -v 'Driving:'`
 echo "$r_c_v_output" >&5
 CFLAGS=$r_save_CFLAGS
@@ -26089,7 +26122,9 @@
 
 
 
- if test "x${HAVE_FORTRAN_DOUBLE_COMPLEX}" != x; then
+
+
+if test "x${HAVE_FORTRAN_DOUBLE_COMPLEX}" != x; then
   COMPILE_FORTRAN_DOUBLE_COMPLEX_TRUE=
   COMPILE_FORTRAN_DOUBLE_COMPLEX_FALSE='#'
 else
@@ -28555,7 +28590,9 @@
 : ${INTERNET_LIBS="${internet_libs}"}
 
 
- if test "x${dylib_undefined_allowed}" = xyes; then
+
+
+if test "x${dylib_undefined_allowed}" = xyes; then
   DYLIB_UNDEFINED_ALLOWED_TRUE=
   DYLIB_UNDEFINED_ALLOWED_FALSE='#'
 else
@@ -28579,11 +28616,14 @@
 
 
 
+
 cat >>confdefs.h <<_ACEOF
 #define SHLIB_EXT "${SHLIB_EXT}"
 _ACEOF
 
- if test "x${use_exportfiles}" = xyes; then
+
+
+if test "x${use_exportfiles}" = xyes; then
   USE_EXPORTFILES_TRUE=
   USE_EXPORTFILES_FALSE='#'
 else
@@ -32307,7 +32347,9 @@
   esac
 fi
 
- if test "x${use_blas_shlib}" = xyes; then
+
+
+if test "x${use_blas_shlib}" = xyes; then
   BLAS_SHLIB_TRUE=
   BLAS_SHLIB_FALSE='#'
 else
@@ -32431,7 +32473,9 @@
   BLAS_LIBS="-L\$(R_HOME)/lib\$(R_ARCH) -lRblas"
 fi
 
- if test "x${use_veclib_g95fix}" = xyes; then
+
+
+if test "x${use_veclib_g95fix}" = xyes; then
   USE_VECLIB_G95FIX_TRUE=
   USE_VECLIB_G95FIX_FALSE='#'
 else
@@ -32439,7 +32483,9 @@
   USE_VECLIB_G95FIX_FALSE=
 fi
 
- if test "${acx_blas_ok}" = "yes"; then
+
+
+if test "${acx_blas_ok}" = "yes"; then
   USE_EXTERNAL_BLAS_TRUE=
   USE_EXTERNAL_BLAS_FALSE='#'
 else
@@ -32601,7 +32647,9 @@
   LAPACK_LIBS="-L\$(R_HOME)/lib\$(R_ARCH) -lRlapack"
 fi
 
- if test "${acx_lapack_ok}" = "yes"; then
+
+
+if test "${acx_lapack_ok}" = "yes"; then
   USE_EXTERNAL_LAPACK_TRUE=
   USE_EXTERNAL_LAPACK_FALSE='#'
 else
@@ -34244,7 +34292,9 @@
   { $as_echo "$as_me:${as_lineno-$LINENO}: result: using X11 ... ${use_X11}" >&5
 $as_echo "using X11 ... ${use_X11}" >&6; }
 
- if test "x${use_X11}" = "xyes"; then
+
+
+if test "x${use_X11}" = "xyes"; then
   BUILD_X11_TRUE=
   BUILD_X11_FALSE='#'
 else
@@ -34566,7 +34616,9 @@
 
 
 fi
- if test "x${r_cv_cairo_works}" = xyes; then
+
+
+if test "x${r_cv_cairo_works}" = xyes; then
   BUILD_DEVCAIRO_TRUE=
   BUILD_DEVCAIRO_FALSE='#'
 else
@@ -34672,7 +34724,9 @@
 ## - to compile src/unix/aqua.c
 ## - in etc/Renviron to set the personal library,
 ## - in grDevices to select building quartz()
- if test "x${use_aqua}" = xyes; then
+
+
+if test "x${use_aqua}" = xyes; then
   BUILD_AQUA_TRUE=
   BUILD_AQUA_FALSE='#'
 else
@@ -35425,7 +35479,9 @@
 $as_echo_n "checking for XDR support... " >&6; }
 { $as_echo "$as_me:${as_lineno-$LINENO}: result: ${r_xdr}" >&5
 $as_echo "${r_xdr}" >&6; }
- if test "x${r_xdr}" = xno; then
+
+
+if test "x${r_xdr}" = xno; then
   BUILD_XDR_TRUE=
   BUILD_XDR_FALSE='#'
 else
@@ -35580,7 +35636,9 @@
 $as_echo "$r_cv_zlib_mmap" >&6; }
 
 fi
- if test "x${have_zlib}" = xno && test "x${r_cv_zlib_mmap}" = xyes; then
+
+
+if test "x${have_zlib}" = xno && test "x${r_cv_zlib_mmap}" = xyes; then
   USE_MMAP_ZLIB_TRUE=
   USE_MMAP_ZLIB_FALSE='#'
 else
@@ -36112,7 +36170,9 @@
 else
   have_tre="no"
 fi
- if test x${have_tre} != xyes; then
+
+
+if test x${have_tre} != xyes; then
   BUILD_TRE_TRUE=
   BUILD_TRE_FALSE='#'
 else
@@ -37651,7 +37711,9 @@
 $as_echo "#define USE_INTERNAL_MKTIME 1" >>confdefs.h
 
 fi
- if test "x${use_internal_tzcode}" = xyes; then
+
+
+if test "x${use_internal_tzcode}" = xyes; then
   BUILD_TZONE_TRUE=
   BUILD_TZONE_FALSE='#'
 else
@@ -41610,7 +41672,9 @@
 fi
 
 fi
- if test "x${use_recommended_packages}" = xyes; then
+
+
+if test "x${use_recommended_packages}" = xyes; then
   USE_RECOMMENDED_PACKAGES_TRUE=
   USE_RECOMMENDED_PACKAGES_FALSE='#'
 else
@@ -41638,53 +41702,38 @@
   echo
   echo "Configuring src/extra/intl directory"
 
-  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for a thread-safe mkdir -p" >&5
-$as_echo_n "checking for a thread-safe mkdir -p... " >&6; }
-if test -z "$MKDIR_P"; then
-  if ${ac_cv_path_mkdir+:} false; then :
-  $as_echo_n "(cached) " >&6
-else
-  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
-for as_dir in $PATH$PATH_SEPARATOR/opt/sfw/bin
-do
-  IFS=$as_save_IFS
-  test -z "$as_dir" && as_dir=.
-    for ac_prog in mkdir gmkdir; do
-	 for ac_exec_ext in '' $ac_executable_extensions; do
-	   as_fn_executable_p "$as_dir/$ac_prog$ac_exec_ext" || continue
-	   case `"$as_dir/$ac_prog$ac_exec_ext" --version 2>&1` in #(
-	     'mkdir (GNU coreutils) '* | \
-	     'mkdir (coreutils) '* | \
-	     'mkdir (fileutils) '4.1*)
-	       ac_cv_path_mkdir=$as_dir/$ac_prog$ac_exec_ext
-	       break 3;;
-	   esac
-	 done
-       done
+  if mkdir -p --version . >/dev/null 2>&1 && test ! -d ./--version; then
+  # We used to keeping the `.' as first argument, in order to
+  # allow $(mkdir_p) to be used without argument.  As in
+  #   $(mkdir_p) $(somedir)
+  # where $(somedir) is conditionally defined.  However this is wrong
+  # for two reasons:
+  #  1. if the package is installed by a user who cannot write `.'
+  #     make install will fail,
+  #  2. the above comment should most certainly read
+  #     $(mkdir_p) $(DESTDIR)$(somedir)
+  #     so it does not work when $(somedir) is undefined and
+  #     $(DESTDIR) is not.
+  #  To support the latter case, we have to write
+  #     test -z "$(somedir)" || $(mkdir_p) $(DESTDIR)$(somedir),
+  #  so the `.' trick is pointless.
+  mkdir_p='mkdir -p --'
+else
+  # On NextStep and OpenStep, the `mkdir' command does not
+  # recognize any option.  It will interpret all options as
+  # directories to create, and then abort because `.' already
+  # exists.
+  for d in ./-p ./--version;
+  do
+    test -d $d && rmdir $d
   done
-IFS=$as_save_IFS
-
-fi
-
-  test -d ./--version && rmdir ./--version
-  if test "${ac_cv_path_mkdir+set}" = set; then
-    MKDIR_P="$ac_cv_path_mkdir -p"
+  # $(mkinstalldirs) is defined by Automake if mkinstalldirs exists.
+  if test -f "$ac_aux_dir/mkinstalldirs"; then
+    mkdir_p='$(mkinstalldirs)'
   else
-    # As a last resort, use the slow shell script.  Don't cache a
-    # value for MKDIR_P within a source directory, because that will
-    # break other packages using the cache if that directory is
-    # removed, or if the value is a relative name.
-    MKDIR_P="$ac_install_sh -d"
+    mkdir_p='$(install_sh) -d'
   fi
 fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $MKDIR_P" >&5
-$as_echo "$MKDIR_P" >&6; }
-
-mkdir_p="$MKDIR_P"
-case $mkdir_p in
-  [\\/$]* | ?:[\\/]*) ;;
-  */*) mkdir_p="\$(top_builddir)/$mkdir_p" ;;
-esac
 
 
     { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are using the GNU C Library 2 or newer" >&5
@@ -45796,7 +45845,9 @@
 fi
 
 
- if test "x${USE_NLS}" = xyes; then
+
+
+if test "x${USE_NLS}" = xyes; then
   USE_NLS_TRUE=
   USE_NLS_FALSE='#'
 else
@@ -45804,7 +45855,9 @@
   USE_NLS_FALSE=
 fi
 
- if test "x${USE_INCLUDED_LIBINTL}" = xyes; then
+
+
+if test "x${USE_INCLUDED_LIBINTL}" = xyes; then
   BUILD_LIBINTL_TRUE=
   BUILD_LIBINTL_FALSE='#'
 else
@@ -46575,7 +46628,6 @@
 ac_pwd='$ac_pwd'
 srcdir='$srcdir'
 INSTALL='$INSTALL'
-MKDIR_P='$MKDIR_P'
 AWK='$AWK'
 test -n "\$AWK" || AWK=awk
 _ACEOF
@@ -47818,11 +47870,6 @@
   [\\/$]* | ?:[\\/]* ) ac_INSTALL=$INSTALL ;;
   *) ac_INSTALL=$ac_top_build_prefix$INSTALL ;;
   esac
-  ac_MKDIR_P=$MKDIR_P
-  case $MKDIR_P in
-  [\\/$]* | ?:[\\/]* ) ;;
-  */*) ac_MKDIR_P=$ac_top_build_prefix$MKDIR_P ;;
-  esac
 _ACEOF
 
 cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
@@ -47877,7 +47924,6 @@
 s&@abs_builddir@&$ac_abs_builddir&;t t
 s&@abs_top_builddir@&$ac_abs_top_builddir&;t t
 s&@INSTALL@&$ac_INSTALL&;t t
-s&@MKDIR_P@&$ac_MKDIR_P&;t t
 $ac_datarootdir_hack
 "
 eval sed \"\$ac_sed_extra\" "$ac_file_inputs" |
diff -urN R-3.3.1.orig/configure.ac R-3.3.1/configure.ac
--- R-3.3.1.orig/configure.ac	2016-10-21 11:27:17.943440572 +0100
+++ R-3.3.1/configure.ac	2016-10-21 12:19:22.000000000 +0100
@@ -663,7 +663,7 @@
 
 ### * Checks for libraries.
 
-## Set up LD_LIBRARY_PATH or equivalent.
+## Add -Wl,-rpath, entries to LDFLAGS.
 ## <FIXME>
 ## What is this doing *HERE*?
 ## Should be needed for tests using AC_RUN_IFELSE()?
@@ -690,6 +690,7 @@
         -L*)
 	  lib=`echo ${arg} | sed "s/^-L//"`
 	  R_SH_VAR_ADD(R_LD_LIBRARY_PATH, [${lib}], [${PATH_SEPARATOR}])
+          R_SH_VAR_ADD(RPATH_LDFLAGS, [-Wl,-rpath,${lib}])
 	  ;;
       esac
     done
@@ -709,13 +710,20 @@
     Rshlibpath_var=${shlibpath_var}
 esac
 AC_SUBST(shlibpath_var)
-## Export LD_LIBRARY_PATH or equivalent.
+## Export LD_LIBRARY_PATH or equivalent (except we do not want to do that
+## instead we want to use -Wl,-rpath .. only doing this for Linux for now).
 if eval "test -z \"\${${Rshlibpath_var}}\""; then
   eval "${Rshlibpath_var}=\"${R_LD_LIBRARY_PATH}\""
 else
   eval "${Rshlibpath_var}=\"${R_LD_LIBRARY_PATH}${PATH_SEPARATOR}\${${Rshlibpath_var}}\""
 fi
-eval "export ${Rshlibpath_var}"
+case "${host_os}" in
+  linux*)
+    ;;
+  *)
+    eval "export ${Rshlibpath_var}"
+    ;;
+esac
 AC_SUBST(Rshlibpath_var)
 
 ## record how to strip shared/dynamic libraries.
@@ -1706,6 +1714,7 @@
 
 AC_SUBST(MAIN_LD)
 AC_SUBST(MAIN_LDFLAGS)
+AC_SUBST(RPATH_LDFLAGS)
 AC_SUBST(CPICFLAGS)
 AC_SUBST(CXXPICFLAGS)
 AC_SUBST(DYLIB_LD)
diff -urN R-3.3.1.orig/etc/ldpaths.in R-3.3.1/etc/ldpaths.in
--- R-3.3.1.orig/etc/ldpaths.in	2016-10-21 11:27:17.953440879 +0100
+++ R-3.3.1/etc/ldpaths.in	2016-10-21 12:14:56.582275399 +0100
@@ -1,3 +1,17 @@
+# https://github.com/conda/conda/issues/1679:
+#  Internally R_system() calls system() which
+# uses /bin/sh to launch various programs. If
+# /bin/sh is called with LD_LIBRARY_PATH that
+# loads condas shared libraries things break.
+#  It may be that not setting LD_LIBRARY_PATH
+# causes other things to break, in which case
+# R_system() will need to be modified so that
+# it calls execve() with an environment which
+# has these modifications to LD_LIBRARY_PATH
+# removed which may be tricky to orchestrate
+if [ "$(uname -s)" == "Linux" ]; then
+  return 0
+fi
 : ${JAVA_HOME=@JAVA_HOME@}
 : ${R_JAVA_LD_LIBRARY_PATH=@R_JAVA_LD_LIBRARY_PATH@}
 if test -n "@R_LD_LIBRARY_PATH@"; then
diff -urN R-3.3.1.orig/etc/Makeconf.in R-3.3.1/etc/Makeconf.in
--- R-3.3.1.orig/etc/Makeconf.in	2016-10-21 11:27:17.953440879 +0100
+++ R-3.3.1/etc/Makeconf.in	2016-10-21 12:16:05.000000000 +0100
@@ -71,7 +71,8 @@
 ## needed to build applications linking to static libR
 MAIN_LD = @MAIN_LD@
 MAIN_LDFLAGS = @MAIN_LDFLAGS@
-MAIN_LINK = $(MAIN_LD) $(MAIN_LDFLAGS) $(LDFLAGS)
+RPATH_LDFLAGS = -Wl,-rpath,$(abs_top_builddir)/lib @RPATH_LDFLAGS@
+MAIN_LINK = $(MAIN_LD) $(MAIN_LDFLAGS) $(LDFLAGS) $(RPATH_LDFLAGS)
 MKINSTALLDIRS = $(R_HOME)/bin/mkinstalldirs
 OBJC = @OBJC@
 OBJCFLAGS = @OBJCFLAGS@ $(LTO)
diff -urN R-3.3.1.orig/Makeconf.in R-3.3.1/Makeconf.in
--- R-3.3.1.orig/Makeconf.in	2016-10-21 12:30:36.328023364 +0100
+++ R-3.3.1/Makeconf.in	2016-10-21 12:32:10.000000000 +0100
@@ -63,7 +63,8 @@
 MAIN_FFLAGS = @MAIN_FFLAGS@
 MAIN_LD = @MAIN_LD@@BUILD_LTO_TRUE@ $(CFLAGS)
 MAIN_LDFLAGS = @MAIN_LDFLAGS@ @WANT_R_SHLIB_FALSE@ @USE_EXPORTFILES_TRUE@ -Wl,-bE:$(top_builddir)/etc/R.exp
-MAIN_LINK = $(MAIN_LD) $(MAIN_LDFLAGS) $(LIBR0) $(LDFLAGS)
+RPATH_LDFLAGS = -Wl,-rpath,$(abs_top_builddir)/lib @RPATH_LDFLAGS@
+MAIN_LINK = $(MAIN_LD) $(MAIN_LDFLAGS) $(LIBR0) $(LDFLAGS) $(RPATH_LDFLAGS)
 ## need this for bootstrapping
 MKINSTALLDIRS = @R_SHELL@ $(top_srcdir)/src/scripts/mkinstalldirs.in
 NOTANGLE = @NOTANGLE@
