Reputation: 5789
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)
Upvotes: 3
Views: 3714
Reputation: 368251
There are two to three things here:
As you note, R itself uses the options encoded from its run of configure
, ie built-time. See the file $RHOME/etc/Makeconf
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
.
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.
Upvotes: 6
Reputation: 5789
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
Upvotes: 5