Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Customize package compilation option R

Tags:

r

cran

I'm building a package containing an old f77 code that should absolutely be build with the o0 optimization option.

In the /src/Makevars of my package I added this line:

FFLAGS=-O0 -pipe  -g $(LTO)

but when I compile my package, I see R is still using the default compiling options from the /usr/lib/R/etc/Makeconf file:

gfortran   -fpic  -O3 -pipe  -g  -c Babar.f -o Babar.o

How can I override the default compilation options for the FORTRAN files of my package in R?

(I intend to distribute that package through CRAN so the compilation option should be set from the Makevars file)

like image 956
user189035 Avatar asked Aug 08 '26 01:08

user189035


2 Answers

There are two to three things here:

  1. As you note, R itself uses the options encoded from its run of configure, ie built-time. See the file $RHOME/etc/Makeconf

  2. You can override things via src/Makevars on a per-package basis. That is what you probably want here. See R's Makeconf for the list of variables, and set eg FFLAGS.

  3. You can override things for all your builds via a per-user ~/.R/Makevars. Eg I set optimization and warning level for my builds in that file.

See the "Writing R Extensions" manual for details.

Edit: And there is 1.a) You can edit a local file $RHOME/etc/Makeconf.site too. On Debian/Ubuntu, I softlink the directory $RHOME/etc/ into /etc/R which makes that easier too.

like image 82
Dirk Eddelbuettel Avatar answered Aug 10 '26 16:08

Dirk Eddelbuettel


Ok, the best solution I found for this is to do it as is done in the quadprog package (ver 1.5-5). Here is what the relevant parts of the src/Makevars file look like:

mypackage_FFLAGS = $(FPICFLAGS) $(SHLIB_FFLAGS) 
all: $(SHLIB)
Babar.o: Babar.f
    $(F77) $(mypackage_FFLAGS) -O1 -pipe -g -c -o Babar.o Babar.f

So, for example when you send the package to the win-builder here is what the compiler output looks like (confirming that this solution does indeed work):

gfortran     -O1 -pipe -g -c -o Babar.o Babar.f
like image 32
user189035 Avatar answered Aug 10 '26 17:08

user189035



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!