From khansen at stat.Berkeley.EDU  Tue Mar 20 22:32:08 2007
From: khansen at stat.Berkeley.EDU (Kasper Daniel Hansen)
Date: Tue, 20 Mar 2007 22:32:08 +0100
Subject: [Rd] PKG_CFLAGS/CFLAGS and PKG_CXXFLAGS/CXXFLAGS
In-Reply-To: <438FA5BB-AA84-4E61-8D3F-FDCA637CDD53@ic.ac.uk>
References: <438FA5BB-AA84-4E61-8D3F-FDCA637CDD53@ic.ac.uk>
Message-ID: <F2257117-F22F-4FA4-A74D-59C1D5E6C252@stat.berkeley.edu>


On Mar 20, 2007, at 7:58 PM, Ernest Turro wrote:

> Why is it that R places CFLAGS after PKG_CFLAGS and not before when
> compiling a package (e.g. through R CMD build pkg)? This can be
> problematic if, for instance, you want to use -O3, but -O2 is in
> R_HOME/etc/Makeconf. If -O2 (in CFLAGS) appears after -O3 (in
> PKG_CFLAGS), you are left with what you didn't want: -O2.
>
> In R-exts, it says that "Flags which are set in file etc/Makeconf can
> be overridden by the environment variable MAKEFLAGS (at least for
> systems using GNU make), as in (Bourne shell syntax)" but this
> doesn't work if I set either MAKEFLAGS or CFLAGS/CXXFLAGS in my
> configure.ac script or package Makevars.

In you example above you want to force the user to use a higher  
optimization flag. But (s)he may have very valid reasons for not  
doing so - and are you really sure that you are comfortable setting - 
O3 on _all_ platforms? Also -O. is GCC specific so it does not work  
for all compilers.

If a user really wants a super fast R (s)he will (should) compile it  
with -O3.

Having said that, I think it is problematic that one cannot   
_downgrade_ the optimization. I am maintaining a package including an  
external library (outside of my control) which does not work with -O2  
on some platforms, due to alignment problems.

> Does anyone have any ideas on how to reliably override the default
> CFLAGS/CXXFLAGS given in Makeconf?

I was given the following code some while ago by Simon Urbanek:

all: $(SHLIB)

MYCXXFLAGS=-O0

%.o: %.cpp
         $(CXX) $(ALL_CPPFLAGS) $(ALL_CXXFLAGS) $(MYCXXFLAGS) -c $< - 
o $@

(this is for C++, I imagine the syntax is straightforward for C). Put  
it in src/Makevars.

But as I said above, I think it is a bad idea to raise the  
optimization level for all users.

Kasper

> Many thanks,
>
> Ernest
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel



[Rd] PKG_CFLAGS/CFLAGS and PKG_CXXFLAGS/CXXFLAGS
Kasper Daniel Hansen