diff -rN -U 0 -x CVS pkgsrc-2017Q1/math/R/distinfo pkgsrc/math/R/distinfo
--- pkgsrc-2017Q1/math/R/distinfo	2017-03-11 10:50:34.000000000 +0100
+++ pkgsrc/math/R/distinfo	2017-04-07 22:00:58.676649855 +0200
@@ -7 +7 @@
-SHA1 (patch-ac) = 68c1943a352e6f8b2842331578ed746b1ac27bea
+SHA1 (patch-ac) = f25e5a45dbddf06df2ebb1d34772e9aa2f406c23
diff -ruN -x CVS pkgsrc-2017Q1/math/R/Makefile pkgsrc/math/R/Makefile
--- pkgsrc-2017Q1/math/R/Makefile	2017-03-11 10:50:34.000000000 +0100
+++ pkgsrc/math/R/Makefile	2017-04-07 22:00:58.676649855 +0200
@@ -9,6 +9,8 @@
 COMMENT=		Statistical language for data analysis and graphics
 LICENSE=		gnu-gpl-v2
 
+PLIST_SRC=              PLIST
+
 #needs FPC code not found in older versions of NetBSD
 NOT_FOR_PLATFORM=	NetBSD-1.[0-4]*-alpha NetBSD-1.5-alpha \
 			NetBSD-1.5.*-alpha NetBSD-1.5[A-U]-alpha
@@ -40,6 +42,8 @@
 CONFIGURE_ARGS+=	--with-system-pcre
 CONFIGURE_ARGS+=	--with-system-xz
 
+.include "options.mk"
+
 .include "../../mk/bsd.prefs.mk"
 .if ${OPSYS} == "NetBSD" || ${OPSYS} == "FreeBSD"
 CONFIGURE_ARGS+=	--enable-long-double=no
@@ -53,20 +57,6 @@
 CONFIGURE_ARGS+=	--disable-R-framework
 CONFIGURE_ARGS+=	--without-aqua
 
-# Use BLAS (math/blas)
-CONFIGURE_ARGS+=	--without-atlas
-CONFIGURE_ARGS+=	--disable-BLAS-shlib
-CONFIGURE_ARGS+=	--with-blas
-CONFIGURE_ARGS+=	--without-blas_risc
-CONFIGURE_ARGS+=	--without-dxml
-CONFIGURE_ARGS+=	--without-libmoto
-
-# Work around missing MAIN__() definition used in -lF77 by AC_CHECK_LIB.
-# and other failures due to not linking to support libs during testing
-CONFIGURE_ENV+=		ac_cv_lib_blas_dgemm=yes
-CONFIGURE_ENV+=		ac_cv_lib_blas_dgemm_=yes
-CONFIGURE_ENV+=		r_cv_complete_blas=yes
-
 # Broken test for bzlib >= 1.0.5 in R 2.7.0
 CONFIGURE_ENV+=		r_cv_have_bzlib=yes
 # Override zlib 1.2.5 requirement
diff -ruN -x CVS pkgsrc-2017Q1/math/R/options.mk pkgsrc/math/R/options.mk
--- pkgsrc-2017Q1/math/R/options.mk	1970-01-01 01:00:00.000000000 +0100
+++ pkgsrc/math/R/options.mk	2017-04-08 10:21:54.766773614 +0200
@@ -0,0 +1,30 @@
+PKG_OPTIONS_VAR=        PKG_OPTIONS.R
+PKG_SUPPORTED_OPTIONS=  openblas
+PKG_SUGGESTED_OPTIONS=
+
+.include "../../mk/bsd.options.mk"
+
+.if !empty(PKG_OPTIONS:Mopenblas)
+.include "../../wip/OpenBLAS/buildlink3.mk"
+# We use the LAPACK inside libopenblas, if present.
+CONFIGURE_ARGS+= --with-blas=openblas --with-lapack
+CONFIGURE_ARGS+= --enable-BLAS-shlib
+# This still creates a libRblas.so which links to openblas.
+PLIST_SRC+=       PLIST.libRblas
+# Trying to hack the additional rpath into the binaries now.
+# The R wrapper script sets LD_LIBRARY_PATH anyway, but this
+# here makes the pkgsrc library check happy.
+LDFLAGS+= ${COMPILER_RPATH_FLAG}${PREFIX}/lib/R/lib
+BUILDLINK_PASSTHRU_RPATHDIRS+=  ${PREFIX}/lib/R/lib
+.else
+CONFIGURE_ARGS+= --with-blas
+CONFIGURE_ARGS+= --disable-BLAS-shlib
+.include "../../math/blas/buildlink3.mk"
+.endif
+
+# Not sure if that is needed anywhere. Not on my CentOS system. --ThOr
+# Work around missing MAIN__() definition used in -lF77 by AC_CHECK_LIB.
+# and other failures due to not linking to support libs during testing
+CONFIGURE_ENV+= ac_cv_lib_blas_dgemm=yes
+CONFIGURE_ENV+= ac_cv_lib_blas_dgemm_=yes
+CONFIGURE_ENV+= r_cv_complete_blas=yes
diff -ruN -x CVS pkgsrc-2017Q1/math/R/patches/patch-ac pkgsrc/math/R/patches/patch-ac
--- pkgsrc-2017Q1/math/R/patches/patch-ac	2016-07-26 06:53:33.000000000 +0200
+++ pkgsrc/math/R/patches/patch-ac	2017-04-07 22:00:58.676649855 +0200
@@ -183,7 +183,7 @@
  # define F77_SYMBOL(x)   x
  #endif
  extern void F77_SYMBOL(test1)(int *iflag);
-+ifdef F77_DUMMY_MAIN
++#ifdef F77_DUMMY_MAIN
 +
 +#  ifdef __cplusplus
 +     extern "C"
diff -ruN -x CVS pkgsrc-2017Q1/math/R/PLIST.libRblas pkgsrc/math/R/PLIST.libRblas
--- pkgsrc-2017Q1/math/R/PLIST.libRblas	1970-01-01 01:00:00.000000000 +0100
+++ pkgsrc/math/R/PLIST.libRblas	2017-04-07 22:00:58.676649855 +0200
@@ -0,0 +1 @@
+lib/R/lib/libRblas.so
