Question

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)

Was it helpful?

Solution 2

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

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top