Rev 78938 | Rev 82190 | 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}/Makeconfshare/make/winshlib.mkincluded in that order. Some settings in Makeconf are substituted inetc/Makeconf by fixed/Makefile, taken from MkRules.2) Everything else, where the primary Makefile is MkRules which iswhere all the customization is done. This is included by allMakefile.win files in directories above this one and./Makefile./cran/Makefile./fixed/Makefile./front-ends/Makefile./getline/Makefile./installer/Makefileand replaces Unix's top-level Makeconf.The largest difference from Unix (even a R-shlib build) is the use ofDLLs, 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 thereremains provision for import libraries via lib%.dll.a: %.def rules.Making executables has a number of Windows-specific features, done infront-ends/Makefile:- A resource compiler is used to compile in version information, anicon and a manifest. Also done for version information in all theother DLLs under bin and modules (R.dll Rblas.dll Rgraphapp.dllRiconv.dll Rlapack.dll internet.dll lapack.dll).- LINKFLAGS includes flags for the stack size and to allow addressingover 2GB for 32-bit executables.A resource compiler is used to add version information to the DLLsunder directories bin and modules.The default is to compile without debug info: this can be enabled byusing 'make DEBUG=T' from this directory, or install add-on packageswith Rcmd INSTALL --debug. Otherwise DLLs and executables arestripped.Link-Time Optimization======================To enable LTO for building R set the LTO macro in MkRules.local, to-flto or e.g. -flto=8 to use 8 threads.Checking of packages with LTO can be performed by setting the LTO_OPTmacro to -flto in MkRules.local and using Rcmd INSTALL --use-LTO.For an installed version of R it should suffice to edit the value ofLTO_OPT in the etc/*/Makeconf files or to set it in a personal or siteMakevars file.[Unlike a Unix-alike, LTO/LTO_OPT are used for Fortran as well as C/C++.]Cross-compilation=================Linux distributions including Fedora, Debian and Ubuntu providecross-compilers and many cross-compiled libraries for both 32- and64-bit Windows. For example, on Fedora 32 for a 64-bit build onemight install the RPMsmingw64-binutilsmingw64-bzip2mingw64-cairomingw64-cppmingw64-crtmingw64-filesystemmingw64-gccmingw64-gcc-c++ (not needed for R, but needed for cairo, icu and libtiff)mingw64-gcc-gfortranmingw64-headersmingw64-libgompmingw64-libpngmingw64-libjpeg-turbomingw64-libtiffmingw64-pcre2mingw64-pkg-configmingw64-readlinemingw64-tclmingw64-termcapmingw64-tkmingw64-winpthreadsmingw64-xz-libsmingw64-zlibor install the mingw32- variants for a 32-bit build. At the time ofwriting this used GCC 9.2.1.To build all the compiled code, set BINPREF in MkRules.local, e.g. toWIN = 64BINPREF64 = /usr/bin/x86_64-w64-mingw32-orWIN = 32BINPREF = /usr/bin/i686-w64-mingw32-Setting LTO is supported.Then in this directorymake MkRules rbuild rpackages-crossTo make the cairo devices, set something likeUSE_CAIRO = TRUECAIRO_CPPFLAGS = -I/usr/x86_64-w64-mingw32/sys-root/mingw/include/cairoCAIRO_LIBS = "-lcairo -lpixman-1 -lpng -lz -lgdi32 -lmsimg32"in MkRules.local and runmake cairodevicesThis will link to the DLLs of external software and for libgomp andpthreads (for OpenMP).For a more static build, installmingw64-bzip2-staticmingw64-libpng-staticmingw64-libjpeg-turbo-staticmingw64-libtiff-staticmingw64-pcre2-staticmingw64-winpthreads-staticmingw64-xz-libs-staticmingw64-zlib-staticand remove the corresponding libfoo.dll.a files from/usr/x86_64-w64-mingw32/sys-root/mingw/lib, and libgomp.dll.a. (Thebuild still uses DLLs for libgcc_s_seh and Tcl/Tk). For a staticbuild of the Cairo devices one would need other RPMs likemingw64-cairo-staticmingw64-fontconfig-staticmingw64-freetype-staticmingw64-pixman-staticRather than remove the .dll.a files, one could experiment with -Wl,-Bstatic.There are curl and ICU libraries for optional features. Settings forFedora's libs (DLL versions):USE_LIBCURL = YESCURL_LIBS = -lcurlUSE_ICU = YESICU_LIBS = -licuuc -licui18n -licudataThere is a static version for curl but not ICU.Cross-building packages=======================There is experimental minimal support for cross-building packages.Copy {bin,etc}/{i386,x64} from this build to a standard Linux build.Edit the copy of etc/*/Makeconf to haveR_WIN = /path/to/top/directory/of/this/buildR_XTRA_CPPFLAGS = -I"$(R_WIN)/include" -DNDEBUGSet the environment variable R_CROSS_BUILD to i386 or x64.Use R CMD INSTALL as usual. (This does not do a staged install nortest loading.) --use-LTO is supported if LTO_OPT was set.R CMD INSTALL --build will produce a zipped installation.Should a package require external libraries, these can be placed underLOCAL_SOFT as defined in etc/*/Makeconf in the copy.