R for Mac OS X Developer's Page - Building R

This page contains details that didn't make it to the FAQ or are too recent to make it to the release.

R on Mac OS X 10.5 (Leopard)

Leoaprd build (32-bit and 64-bit) are now available from the R for Mac OS X Developer's Page and package binaries are on CRAN, so most users should find no need to compile R for Leopard themselves. If you still do, read on. Now for the development part.

Fixing X11 on Leopard

X11 is broken on Leopard (still as of 10.5.2 release), it is impossible to compile programs against it (more precisely whenever libGL is touched - directly or indirectly). The easiest way to fix it is as follows:
cd /usr/X11/lib
sudo bash
# enter your password
mv libGL.dylib libGL.dylib.apple
ln -s /System/Library/Frameworks/OpenGL.framework/Libraries/libGL.dylib .

Compiling R

Due to a bug in /bin/sh it is necessary to specify another, compliant shell. SHELL=/bin/ksh and SHELL='/bin/bash' are known to work (when passed to configure). (R-devel and R 2.6.2 provide a work-around)
Also note that the default locale in Terminal is now UTF-8 (see its Preferences), which triggers bugs in tools like sed, so it is highly recommended to use the C locale instead (either by changing the preferences or setting LANG to C).

Bulidng of R itself does not require any special flags (other than the above). A simple configure && make && make install is known to work. However, for a proper 64-bit support, read on.

Apple gcc 4.2

If you have access to Apple's gcc 4.2 compilers (they are public now), you may want to use them instead. We have compiled a GNU Fortran specifically for Apple's gcc 4.2 that simply adds Fortran capability to the system compilers. Get it from the tools page (Alternative tools section further down the page) instead of the Fortran that comes with R.

Universal 32- and 64-bit

Leopard supports 64-bit throughout, including in the R GUI and Quartz from R 2.7.0 on. Use compiler flags to specify the target architecture as well as r_arch to tag it. For example:
r_arch=x86_64 \
CC="gcc -arch x86_64 -std=gnu99" \
CXX="g++ -arch x86_64" \
OBJC="gcc -arch x86_64" \
F77="gfortran -arch x86_64" \
FC="gfortran -arch x86_64"
Replace x86_64 with i386, ppc or ppc64 to build the other architectures. Each make install will merge the current architecture with the others. On an Intel-based Mac, it is possible to build all but the ppc64 architecture.

Copy/paste guide

The is just an easy way to get started with R on a Leopard Intel-based machine. Make sure you have installed Xcode 3.1 and GNU Fortran from the tools page first. The script below assumes bash-like shell.

PATH=/usr/X11/bin:/usr/local/bin:$PATH
export PATH
LANG=C
export LANG
svn co https://svn.r-project.org/R/trunk R-devel
# you may have to accept a certificate here
cd R-devel
tools/rsync-recommended
cd ..
# got the sources, on to building 64-bit R
mkdir rd64
cd rd64
../R-devel/configure SHELL='/bin/bash' \
r_arch=x86_64 \
CC="gcc -arch x86_64 -std=gnu99" \
CXX="g++ -arch x86_64" \
OBJC="gcc -arch x86_64" \
F77="gfortran -arch x86_64" \
FC="gfortran -arch x86_64" \
--with-system-zlib \
--with-blas='-framework vecLib' --with-lapack && \
make -j4 && \
make check && \
make install
cd ..
# if you want a 32-bit build as well, continue here
mkdir rd32
cd rd32
../R-devel/configure SHELL='/bin/bash' \
r_arch=i386 \
CC="gcc-4.0 -arch i386 -std=gnu99" \
CXX="g++-4.0 -arch i386" \
OBJC="gcc-4.0 -arch i386" \
F77="gfortran-4.0 -arch i386" \
FC="gfortran-4.0 -arch i386" \
--with-system-zlib \
--with-blas='-framework vecLib' --with-lapack && \
make -j4 && \
make check && \
make install
cd ..
# done - you should have 32-bit and 64-bit R
# set r_arch on the command line to start the corresponding R
Note that your binary will require you to install all packages from sources. Also you will be missing some of the functionality that requires additional libraries (Cairo etc.) unless you have installed them previously (they are also available from the CRAN Mac Tools page).