Saturday, April 28, 2012

Build R

I downloaded the latest version of R this morning and played a bit.

Just for fun, I decided to see if I could build it from source. I ran into only one hiccup, related to gfortran. The gfortran compiler is a new one I got the other day to build Julia.

> gfortran -v
Target: x86_64-apple-darwin11
gcc version 4.6.2 20111019 (prerelease) (GCC) 

Here are the build instructions for R:

# download R
curl -O
# unpack R
tar fxz R-2.15.0.tar.gz
# choose the architecture (x86_64, i386, ppc or ppc64)
# create a build directory
mkdir R-$arch
cd R-$arch
# configure R
../R-2.15.0/configure r_arch=$arch  CC="gcc -arch $arch" \
  CXX="g++ -arch $arch" F77="gfortran -arch $arch" \
  FC="gfortran -arch $arch" OBJC="gcc -arch $arch" \
  --x-includes=/usr/X11/include --x-libraries=/usr/X11/lib \
  --with-blas='-framework vecLib' --with-lapack
# build R
make -j8
# At this point you can run R as `bin/R' even without installing

# install R
make install
# in some cases you may need to use ``sudo make install'' instead

The configure step fails with a complaint about the options to gfortran. The config.log file reads:

configure:7007: result: defining F77 to be gfortran -arch x86_64
configure:7179: checking for Fortran 77 compiler version
configure:7188: gfortran -arch x86_64 --version >&5
GNU Fortran (GCC) 4.6.2 20111019 (prerelease)
Copyright (C) 2011 Free Software Foundation, Inc.

GNU Fortran comes with NO WARRANTY, to the extent permitted by law.
You may redistribute copies of GNU Fortran
under the terms of the GNU General Public License.
For more information about these matters, see the file named COPYING

configure:7199: $? = 0
configure:7188: gfortran -arch x86_64 -v >&5
Driving: gfortran -mmacosx-version-min=10.7.3 -arch x86_64 -v -l gfortran -shared-libgcc
gfortran: error: x86_64: No such file or directory
Using built-in specs.
gfortran: error: unrecognized option '-arch'

Removing "-arch $arch" from F77 and FC above, fixed it. R builds pretty quickly, then this works:

It even gives a Quartz window from which I can save the figure.

I don't have any real reason to do this, just thought I'd try it. Also, an important question is whether shared libraries like /usr/X11/lib/libpng.dylib are linked in properly. This works (but I'm not sure where it's getting libpng from):

> png('~/Desktop/x.png')
> plot(1:10)
null device