--- /MacPorts/var/macports/sources/rsync.macports.org/release/tarballs/ports/math/R/Portfile	2013-03-20 21:00:19.000000000 -0700
+++ Portfile	2013-04-09 13:53:28.000000000 -0700
@@ -1,17 +1,20 @@
-# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4
 # $Id: Portfile 104220 2013-03-21 03:37:44Z larryv@macports.org $
 
 PortSystem 1.0
 
-name             R
-conflicts        R-framework
-version          2.15.3
-categories       math science
-maintainers      me.com:kjell.konis
-license          {GPL-2 GPL-3}
-platforms        darwin
+set major 3
+set minor 0
+set point 0
+
+name                        R
+version                     ${major}.${minor}.${point}
+categories                  math science
+maintainers                 me.com:kjell.konis
+license                     {GPL-2 GPL-3}
+platforms                   macosx
 
-description      R is GNU S - an interpreted language for statistical computing
+description \
+    R is GNU S - an interpreted language for statistical computing
 
 long_description \
     R is a language and environment for statistical computing and graphics. \
@@ -19,158 +22,189 @@
     classical statistical tests, time-series analysis, classification, \
     clustering, ...) and graphical techniques, and is highly extensible.
 
-homepage         http://www.r-project.org/
+homepage                    http://www.r-project.org/
 
-master_sites     http://cran.us.r-project.org/src/base/R-2/ \
-                 http://cran.ms.unimelb.edu.au/src/base/R-2/ \
-                 http://cran.at.r-project.org/src/base/R-2/ \
-                 http://cran.hu.r-project.org/src/base/R-2/ \
-                 http://cran.r-project.org/src/base/R-2/
-
-checksums        rmd160  d588100f075e3a370a2cd6400e3c61dcc5b7a09e \
-                 sha256  c583a38f8dad3bc012c08116f4ba1eb2182cadfad4b0f8d7bd3cdba24bc255d6
-
-depends_build    port:pkgconfig
-
-depends_lib      port:gettext \
-                 port:icu \
-                 path:lib/pkgconfig/glib-2.0.pc:glib2 \
-                 port:jpeg \
-                 port:libiconv \
-                 path:lib/pkgconfig/cairo.pc:cairo \
-                 path:lib/pkgconfig/pango.pc:pango \
-                 port:readline \
-                 port:tcl \
-                 port:tk \
-                 port:tiff \
-                 port:xorg-libXmu \
-                 port:xorg-libXScrnSaver
+master_sites                http://cran.us.r-project.org/src/base/R-3/ \
+                            http://cran.ms.unimelb.edu.au/src/base/R-3/ \
+                            http://cran.at.r-project.org/src/base/R-3/ \
+                            http://cran.hu.r-project.org/src/base/R-3/ \
+                            http://cran.r-project.org/src/base/R-3/
 
-universal_variant no
+checksums                   rmd160  a2ad8818298cf29db4fe69df64d895769170694d \
+                            sha256  dd65c24f1497610f3ff16008da99b4f52286d6424fbd61f08037c4f10f57ff16
 
-variant recommended description {Install recommended R packages} {
-    configure.args-delete --without-recommended-packages
-    configure.args-append --with-recommended-packages
-}
+depends_build               port:pkgconfig
 
-variant gcc43 conflicts gcc44 gcc45 gcc46 gcc47 description {Build with gcc43} {
-    configure.compiler macports-gcc-4.3
-    depends_lib-append port:gcc43
-}
+depends_lib                 port:readline \
+                            port:icu \
+                            port:libiconv
+
+universal_variant           no
 
-variant gcc44 conflicts gcc43 gcc45 gcc46 gcc47 description {Build with gcc44} {
-    configure.compiler macports-gcc-4.4
-    depends_lib-append port:gcc44
+set resources ${frameworks_dir}/R.framework/Versions/${major}.${minor}/Resources
+
+post-patch {
+    reinplace "s|R_HOME|\"${resources}\"|" "${worksrcpath}/src/unix/Rscript.c"
 }
 
-variant gcc45 conflicts gcc43 gcc44 gcc46 gcc47 description {Build with gcc45} {
-    configure.compiler macports-gcc-4.5
-    depends_lib-append port:gcc45
+configure.pre_args          --prefix=${frameworks_dir}
+
+configure.cflags-append     -DOS_OBJECT_USE_OBJC=0
+
+configure.args              --enable-R-framework \
+                            --enable-R-shlib \
+                            --enable-BLAS-shlib \
+                            --enable-openmp \
+                            --with-readline \
+                            --with-aqua \
+                            --without-tcltk \
+                            --without-cairo \
+                            --with-libpng \
+                            --without-jpeglib \
+                            --without-recommended-packages \
+                            --with-ICU \
+                            --without-x \
+                            --with-included-gettext
+
+variant cairo requires x11 description {Use cairo and pango} {
+    depends_lib-append      path:lib/pkgconfig/cairo.pc:cairo \
+                            path:lib/pkgconfig/pango.pc:pango \
+                            path:lib/pkgconfig/glib-2.0.pc:glib2 \
+                            port:freetype \
+                            port:fontconfig \
+                            port:gettext
+    configure.args-delete   --without-cairo
+    configure.args-append   --with-cairo
 }
 
-variant gcc46 conflicts gcc43 gcc44 gcc45 gcc47 description {Build with gcc46} {
-    configure.compiler macports-gcc-4.6
-    depends_lib-append port:gcc46
+variant accelerate conflicts builtin_lapack description {build using the BLAS and Lapack in Apple's Accelerate framework} {
+    configure.args-append   --with-blas="-framework vecLib" \
+                            --with-lapack="-framework vecLib"
 }
 
-variant gcc47 conflicts gcc43 gcc44 gcc45 gcc46 description {Build with gcc46} {
-    configure.compiler macports-gcc-4.7
-    depends_lib-append port:gcc47
+variant builtin_lapack conflicts accelerate description {build using reference BLAS and Lapack} {
+    configure.args-append   --without-blas --without-lapack
 }
 
-variant debug description {Build with debug symbols} {
+variant debug description {build with debug symbols} {
     configure.optflags-append -g
 }
 
-variant aqua description {Enable quartz graphics device} {
-    if {${os.platform} == "darwin" && ${os.major} == 10} {
-        # This variant uses a hack in "CFString.h" that does not define the problematic CF_FORMAT_FUNCTION
-        # and CF_FORMAT_ARGUMENT macros if __INTEL_COMPILER is defined. Currently, that is the ONLY place
-        # in the 10.6 SDK where the __INTEL_COMPILER macro is checked, but that may change in the future.
-        # We also need to use Apple's ObjC compiler for the single "qdCocoa.m" file.
-        configure.args-delete   --without-aqua
-        configure.args-append   --with-aqua
-        patchfiles-append       patch-QuartzDevice_h.diff
-        configure.objc          /usr/bin/gcc-4.2
-    } else {
-        ui_error "The +aqua variant is for Snow Leopard (Mac OS X 10.6) only - for Aqua support on Lion (Mac OS X 10.7) use the R-framework port"
-        return -code error "incompatible variant"
-    }
+variant gcc45 conflicts gcc46 gcc47 description {build with gcc45} {
+    depends_lib-append      port:gcc45
+    configure.compiler      macports-gcc-4.5
+    configure.objc          /usr/bin/gcc
+    configure.env-append    "OBJCXX=/usr/bin/g++"
+}
+
+variant gcc46 conflicts gcc45 gcc47 description {build with gcc46} {
+    depends_lib-append      port:gcc46
+    configure.compiler      macports-gcc-4.6
+    configure.objc          /usr/bin/gcc
+    configure.env-append    "OBJCXX=/usr/bin/g++"
+}
+
+variant gcc47 conflicts gcc45 gcc46 description {build with gcc47} {
+    depends_lib-append      port:gcc47
+    configure.compiler      macports-gcc-4.7
+    configure.objc          /usr/bin/gcc
+    configure.env-append    "OBJCXX=/usr/bin/g++"
 }
 
-default_variants +recommended
+variant recommended description {Install recommended R packages} {
+    configure.args-delete   --without-recommended-packages
+    configure.args-append   --with-recommended-packages
+}
 
-if {![variant_isset gcc42] && ![variant_isset gcc43] && ![variant_isset gcc44] &&
-    ![variant_isset gcc45] && ![variant_isset gcc46] && ![variant_isset gcc47]} {
-    default_variants-append +gcc47
+variant tcltk requires x11 description {Use tcltk} {
+    depends_lib-append      port:tcl \
+                            port:tk \
+                            port:xorg-libXScrnSaver \
+                            port:xorg-libXext
+    configure.args-delete   --without-tcltk
+    configure.args-append   --with-tcltk \
+                            --with-tcl-config=${prefix}/lib/tclConfig.sh \
+                            --with-tk-config=${prefix}/lib/tkConfig.sh
+}
+
+variant x11 description {
+    depends_lib-append      port:xorg-libsm \
+                            port:xorg-libice \
+                            port:xorg-libX11 \
+                            port:xorg-libXt \
+                            port:tiff \
+                            port:jpeg \
+                            port:libpng \
+                            port:zlib
+    configure.args-delete   --without-x \
+                            --without-jpeglib
+    configure.args-append   --with-x \
+                            --with-jpeglib \
+                            --x-include=${prefix}/include/X11 \
+                            --x-lib=${prefix}/lib
 }
 
-post-patch {
-  reinplace "s|R_HOME|\"${prefix}/lib/R\"|" "${worksrcpath}/src/unix/Rscript.c"
+default_variants +cairo +recommended +x11
+
+if {![variant_isset accelerate] && ![variant_isset builtin_lapack]} {
+    default_variants-append +accelerate
 }
 
-configure.env-append r_arch=${build_arch}
+if {![variant_isset gcc45] && ![variant_isset gcc46] && ![variant_isset gcc47]} {
+    default_variants-append +gcc47
+}
 
-configure.args   --mandir=\\\${prefix}/share/man \
-                 --enable-BLAS-shlib \
-                 --enable-R-shlib \
-                 --disable-nls \
-                 --disable-R-framework \
-                 --without-aqua \
-                 --with-tcl-config=${prefix}/lib/tclConfig.sh \
-                 --with-tk-config=${prefix}/lib/tkConfig.sh \
-                 --x-include=${prefix}/include \
-                 --x-lib=${prefix}/lib \
-                 --without-recommended-packages
-
-test.run         yes
-test.target      check
-destroot.destdir prefix=${destroot}${prefix}
+destroot.destdir prefix=${destroot}${frameworks_dir}
 
 post-destroot {
-  foreach r { "/bin/R" "/lib/R/bin/R" } {
+    move ${destroot}${frameworks_dir}/lib/pkgconfig/libR.pc ${destroot}${prefix}/lib/pkgconfig/libR.pc
+
+    foreach v { "rhome" "rincludedir" } {
+        reinplace "s|${v}=${destroot}|${v}=|" "${destroot}${prefix}/lib/pkgconfig/libR.pc"
+    }
+
     foreach dir { "R_HOME_DIR" "R_SHARE_DIR" "R_INCLUDE_DIR" "R_DOC_DIR" } {
-      reinplace "s|${dir}=${destroot}|${dir}=|" "${destroot}${prefix}${r}"
+        reinplace "s|${dir}=${destroot}|${dir}=|" "${destroot}${resources}/bin/R"
+    }
+
+    reinplace "s|-F${destroot}|-F|" "${destroot}${resources}/etc/Makeconf"
+
+    foreach dylib [ exec find ${destroot}${frameworks_dir}/R.framework -name "\*.dylib" ] {
+        regsub ":$" ${dylib} "" destroot_dylib_path
+        regsub ${destroot} ${destroot_dylib_path} "" dylib_path
+        system "install_name_tool -id ${dylib_path} ${destroot_dylib_path}"
+        system "install_name_tool -change ${destroot}${resources}/lib/libR.dylib ${resources}/lib/libR.dylib \
+            ${destroot_dylib_path}"
+        system "install_name_tool -change ${destroot}${resources}/lib/libRblas.dylib ${resources}/lib/libRblas.dylib \
+            ${destroot_dylib_path}"
+        system "install_name_tool -change ${destroot}${resources}/lib/libRlapack.dylib ${resources}/lib/libRlapack.dylib \
+            ${destroot_dylib_path}"
+    }
+
+    foreach so [ exec find ${destroot}${frameworks_dir}/R.framework -name "\*.so" ] {
+        regsub ":$" ${so} "" destroot_so_path
+        regsub ${destroot} ${destroot_so_path} "" so_path
+        system "install_name_tool -id ${so_path} ${destroot_so_path}"
+        system "install_name_tool -change ${destroot}${resources}/lib/libR.dylib ${resources}/lib/libR.dylib \
+            ${destroot_so_path}"
+        system "install_name_tool -change ${destroot}${resources}/lib/libRblas.dylib ${resources}/lib/libRblas.dylib \
+            ${destroot_so_path}"
+        system "install_name_tool -change ${destroot}${resources}/lib/libRlapack.dylib ${resources}/lib/libRlapack.dylib \
+            ${destroot_so_path}"
     }
-  }
 
-  foreach v { "rhome" "rincludedir" } {
-    reinplace "s|${v}=${destroot}|${v}=|" "${destroot}${prefix}/lib/pkgconfig/libR.pc"
-  }
-
-  foreach dylib [ exec find ${destroot}${prefix}/lib/R/lib/${build_arch} -name "\*.dylib" ] {
-    regsub ":$" ${dylib} "" destroot_dylib_path
-    regsub ${destroot} ${destroot_dylib_path} "" dylib_path
-    system "install_name_tool -id ${dylib_path} ${destroot_dylib_path}"
-    system "install_name_tool -change libR.dylib ${prefix}/lib/R/lib/${build_arch}/libR.dylib \
-      ${destroot_dylib_path}"
-    system "install_name_tool -change libRblas.dylib ${prefix}/lib/R/lib/${build_arch}/libRblas.dylib \
-      ${destroot_dylib_path}"
-    system "install_name_tool -change libRlapack.dylib ${prefix}/lib/R/lib/${build_arch}/libRlapack.dylib \
-      ${destroot_dylib_path}"
-  }
-
-  foreach so [ exec find ${destroot}${prefix}/lib/R -name "\*.so" ] {
-    regsub ":$" ${so} "" destroot_so_path
-    regsub ${destroot} ${destroot_so_path} "" so_path
-    system "install_name_tool -id ${so_path} ${destroot_so_path}"
-    system "install_name_tool -change libR.dylib ${prefix}/lib/R/lib/${build_arch}/libR.dylib \
-      ${destroot_so_path}"
-    system "install_name_tool -change libRblas.dylib ${prefix}/lib/R/lib/${build_arch}/libRblas.dylib \
-      ${destroot_so_path}"
-    system "install_name_tool -change libRlapack.dylib ${prefix}/lib/R/lib/${build_arch}/libRlapack.dylib \
-      ${destroot_so_path}"
-  }
-
-  system "install_name_tool -change libR.dylib ${prefix}/lib/R/lib/${build_arch}/libR.dylib \
-    ${destroot}${prefix}/lib/R/bin/exec/${build_arch}/R"
-  system "install_name_tool -change libRblas.dylib ${prefix}/lib/R/lib/${build_arch}/libRblas.dylib \
-    ${destroot}${prefix}/lib/R/bin/exec/${build_arch}/R"
+    system "install_name_tool -change ${destroot}${resources}/lib/libR.dylib ${resources}/lib/libR.dylib \
+        ${destroot}${resources}/bin/exec/R"
+    system "install_name_tool -change ${destroot}${resources}/lib/libRblas.dylib ${resources}/lib/libRblas.dylib \
+        ${destroot}${resources}/bin/exec/R"
 
-  reinplace "s|-dylib_file libRblas\.dylib:\$\(R_HOME\)/lib\$\(R_ARCH\)/libRblas\.dylib| |" \
-            "${destroot}${prefix}/lib/R/etc/${build_arch}/Makeconf"
+    ln -s ${resources}/bin/R ${destroot}${prefix}/bin/R
+    ln -s ${resources}/bin/Rscript ${destroot}${prefix}/bin/Rscript
 }
 
 livecheck.type      regex
 livecheck.url       [lindex ${master_sites} 0]
 livecheck.regex     >${name}-(\[0-9.\]+)${extract.suffix}<
+
+
+
