The R Project SVN R

Rev

Rev 78879 | Rev 78892 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

The R for Windows Build Process
===============================

from the point of view of a Unix installer of R.

Compilation of C/Fortran code is done in two pathways.

1) standard and add-on packages, the most similar to Unix.

The primary Makefiles are
$(R_HOME)/etc${R_ARCH}/Makeconf
share/make/winshlib.mk

included in that order.  Some settings in Makeconf are substituted in
etc/Makeconf by fixed/Makefile, taken from MkRules.


2) Everything else, where the primary Makefile is MkRules which is
where all the customization is done.  This is included by all
Makefile.win files under directories above this one and

./Makefile
./cran/Makefile
./fixed/Makefile
./front-ends/Makefile
./getline/Makefile
./installer/Makefile

and replaces Unix's top-level Makeconf.


The largest difference from Unix (even a R-shlib build) is the use of
DLLs, which require the exported symbols to be listed (via nm) in a
.def file and fed to the compiler with the object files for linking.

In recent years DLLs are linked to directly as libraries, but there
remains provision for import libraries via lib%.dll.a: %.def rules.

Making executables has a number of Windows-specific features, done in
front-ends/Makefile:

- A resource compiler is used to compile in a manifest, which in turn
  includes an icon.

- LINKFLAGS includes flags for the stack size and to allow addressing
  over 2GB for 32-bit executables.

The default is to compile without debug info: this can be enabled by
using 'make DEBUG=T' from this directory, or install add-on packages
with Rcmd INSTALL --debug.  Otherwise DLLs and executables are
stripped.


Link-Time Optimization
======================

To enable LTO, set the LTO macro in MkRules.local, to -flto or e.g. -flto=8.


Cross-compilation
=================

Linux distributions including Fedora, Debian and Ubuntu provide
cross-compilers and many cross-compiled librarues for both 32- and
64-bit Windows.  For example, on Fedora 32 for a 64-bit build one
might install RPMs

mingw-binutils-generic
mingw-filesystem-base
mingw64-binutils
mingw64-bzip2-
mingw64-bzip2-static
mingw64-cpp
mingw64-crt
mingw64-curl
mingw64-curl
mingw64-filesystem
mingw64-gcc
mingw64-gcc-c++- (not needed for R itself)
mingw64-gcc-gfortran
mingw64-headers
mingw64-libgomp
mingw64-libidn2
mingw64-libssh2
mingw64-openssl
mingw64-pcre2
mingw64-pcre2-static
mingw64-pkg-config
mingw64-readline
mingw64-termcap
mingw64-winpthreads
mingw64-xz-libs
mingw64-xz-libs-static
mingw64-zlib
mingw64-zlib-static

(for packages grDevices and tcltk)
mingw64-libpng.noarch
mingw64-libpng-static.noarch
mingw64-libjpeg-turbo.noarch
mingw64-libjpeg-turbo-static.noarch
mingw64-libtiff.noarch
mingw64-libtiff-static.noarch
mingw64-cairo.noarch
mingw64-cairo-static.noarch
mingw64-tcl.noarch
mingw64-tk.noarch

or install the mingw32- variants for a 32-bit build.  At the time of
writing this used GCC 9.2.1.

To build almost all the compiled code, set BINPREF in MkRules.local, e.g. to

WIN = 64
BINPREF64 = /usr/bin/x86_64-w64-mingw32-

or

WIN = 32
BINPREF = /usr/bin/i686-w64-mingw32-

Setting LTO is supported.

Then in this directory

make MkRules rbuild rpackages-cross

(Currently it does not build grDevices which need additional
libraries.)

To make the cairo devices, install the appropriate RPMs, set

USE_CAIRO = TRUE
CAIRO_CPPFLAGS = -I/usr/x86_64-w64-mingw32/sys-root/mingw/include/cairo
CAIRO_LIBS = "-lcairo -lpixman-1 -lpng -lz -lgdi32 -lmsimg32"

in MkRules.local and run

make cairodevices