suppressing "global" cppflags in an individual package

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

suppressing "global" cppflags in an individual package

Kasper Daniel Hansen
Hi

I can use PKG_CPPFLAGS in a Makevars file to add additional flags to  
the c++ compiler for a given package. Is it possible to remove flags  
passed to the packages from R. Eg: say R have been compiled with -O2  
and I want the package to be compiled with another optimization level?

/Kasper

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: suppressing "global" cppflags in an individual package

Hin-Tak Leung-2
Kasper Daniel Hansen wrote:
> Hi
>
> I can use PKG_CPPFLAGS in a Makevars file to add additional flags to  
> the c++ compiler for a given package. Is it possible to remove flags  
> passed to the packages from R. Eg: say R have been compiled with -O2  
> and I want the package to be compiled with another optimization level?

Do you mean the flags passed to the c++ compiler (CXXFLAGS) or
to the C proprocessor (CPPFLAGS)? Do not confuse the two.

I think the "proper" way would be to write a full makefile.
(there are plenty of examples on CRAN).

Now, out of curiosity - why would you want to do that? The actual
difference in CPU time usage is often small (10%?), so unless the
package triggers a compiler bug at specific optimization level and
gets mis-compiled, it is probably not worth the trouble. And if
the package is that sensitive to optimization level and can get
mis-compiled, one of them (the package or the compiler) needs fixing.

HTL

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: suppressing "global" cppflags in an individual package

Kasper Daniel Hansen

On May 9, 2006, at 9:49 AM, Hin-Tak Leung wrote:

> Kasper Daniel Hansen wrote:
>> Hi
>> I can use PKG_CPPFLAGS in a Makevars file to add additional flags  
>> to  the c++ compiler for a given package. Is it possible to remove  
>> flags  passed to the packages from R. Eg: say R have been compiled  
>> with -O2  and I want the package to be compiled with another  
>> optimization level?
>
> Do you mean the flags passed to the c++ compiler (CXXFLAGS) or
> to the C proprocessor (CPPFLAGS)? Do not confuse the two.

Hmm good point. I think I have indeed confused the two.

> I think the "proper" way would be to write a full makefile.
> (there are plenty of examples on CRAN).

I would like to avoid this, see below.

> Now, out of curiosity - why would you want to do that? The actual  
> difference in CPU time usage is often small (10%?), so unless the
> package triggers a compiler bug at specific optimization level and
> gets mis-compiled, it is probably not worth the trouble. And if
> the package is that sensitive to optimization level and can get mis-
> compiled, one of them (the package or the compiler) needs fixing.

It is indeed the case that after updating to GCC 4 the package gets  
broken using -O2. I agree this needs to be fixed, but the error  
(which I believe I have kind of localized, but not really understood)  
stems from a C++ library we have little control over, so it would be  
nice to have a fix for the time being that does not require a  
reinstallation of R - especially since we actually have users who  
currently (or soon will be) testing it. I was thus looking for a  
temporary quick fix allowing me to disable the optimization level,  
while I take the time to fix it properly.

Kurt Hornik have replied of-list that it is possible to do so using a  
~/.R/Makevars file (which I have not had the time to test  
unfortunately), but reading your comment about CPPFLAGS and CXXFLAGS  
makes me think I can indeed override it using the package Makevars  
file. The flags I was passing to the compiler were library locations  
anyway which was for the preprocessor.

Thanks for the help, Kasper


> HTL

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: suppressing "global" cppflags in an individual package

Simon Urbanek
On May 9, 2006, at 1:11 PM, Kasper Daniel Hansen wrote:

> It is indeed the case that after updating to GCC 4 the package  
> gets  broken using -O2. I agree this needs to be fixed, but the error
> [...]
> unfortunately), but reading your comment about CPPFLAGS and  
> CXXFLAGS makes me think I can indeed override it using the package  
> Makevars file. The flags I was passing to the compiler were library  
> locations anyway which was for the preprocessor.
>

AFAIR you cannot override CPPFLAGS/CXXFLAGS in Makevars, because it  
gets included first. You can, however, use something like this:

all: $(SHLIB)

MYCFLAGS=-O0

%.o: %.c
         $(CC) $(ALL_CPPFLAGS) $(ALL_CFLAGS) $(MYCFLAGS) -c $< -o $@

for C, or for C++ accordingly:

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

However, don't ask me how portable this is ;). It exploits the fact  
that old-style rules .c.o used by Makeconf are overridden by the new-
style rules regardless of their position. Nevertheless, you could  
still use specific rules if desired without a full-blown Makefile. (I  
always recommend the use of Makevars as far as possible, because most  
writers of Makefiles get the shlib compilation wrong).

Cheers,
Simon

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: suppressing "global" cppflags in an individual package

Hin-Tak Leung-2
In reply to this post by Kasper Daniel Hansen
Kasper Daniel Hansen wrote:
<snipped>

> It is indeed the case that after updating to GCC 4 the package gets
> broken using -O2. I agree this needs to be fixed, but the error (which I
> believe I have kind of localized, but not really understood) stems from
> a C++ library we have little control over, so it would be nice to have a
> fix for the time being that does not require a reinstallation of R -
> especially since we actually have users who currently (or soon will be)
> testing it. I was thus looking for a temporary quick fix allowing me to
> disable the optimization level, while I take the time to fix it properly.
>
> Kurt Hornik have replied of-list that it is possible to do so using a
> ~/.R/Makevars file (which I have not had the time to test
> unfortunately), but reading your comment about CPPFLAGS and CXXFLAGS
> makes me think I can indeed override it using the package Makevars file.
> The flags I was passing to the compiler were library locations anyway
> which was for the preprocessor.

Can't do that with Makevars, because its defines are included first (and
get overriden by R's built-time flags later in the command line), as
Simon on the list has pointed out.

If it is a one-off operation, you can be slightly barbaric and just
record all the operations done by R CMD SHLIB/INSTALL
e.g. piping them to a file with >& , edit the file manually and exec
the operations by "sh file", then copy the differently-built shared
library over by hand, over-writing the broken one. Not very elegant,
but it will buy you some time until either the compiler or the package
get fixed.

Hin-Tak Leung

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: suppressing "global" cppflags in an individual package

Kasper Daniel Hansen
In reply to this post by Simon Urbanek
Thank you Simon, a little comment below

On May 9, 2006, at 2:49 PM, Simon Urbanek wrote:

> On May 9, 2006, at 1:11 PM, Kasper Daniel Hansen wrote:
>
>> It is indeed the case that after updating to GCC 4 the package  
>> gets  broken using -O2. I agree this needs to be fixed, but the error
>> [...]
>> unfortunately), but reading your comment about CPPFLAGS and  
>> CXXFLAGS makes me think I can indeed override it using the package  
>> Makevars file. The flags I was passing to the compiler were  
>> library locations anyway which was for the preprocessor.
>>
>
> AFAIR you cannot override CPPFLAGS/CXXFLAGS in Makevars, because it  
> gets included first. You can, however, use something like this:
>
> all: $(SHLIB)
>
> MYCFLAGS=-O0
>
> %.o: %.c
>         $(CC) $(ALL_CPPFLAGS) $(ALL_CFLAGS) $(MYCFLAGS) -c $< -o $@
>
> for C, or for C++ accordingly:
>
> %.o: %.cc
>         $(CXX) $(ALL_CPPFLAGS) $(ALL_CXXFLAGS) $(MYCXXFLAGS) -c $< -
> o $@

Actually you do not need the all: line, and since I use .cpp as C++  
extension, all I needed was

%.o: %.cpp
<TAB>$(CXX) $(ALL_CPPFLAGS) -O0 -c $< -o $@

Note that I needed to delete the $(ALL_CXXFLAGS) which basically  
reads R's flags.

Now, is there any way to (in the Makevars file) operate on $
(ALL_CXXFLAGS), since all I want is to delete any -O* flag? Or is  
defining rules and variables all I can do?

Actually, where do I read about the Makevars syntax. Is it from  
autoconf (of which I only now the name). The section on it in R-exts  
is useful (hey, I managed to make one in the first place), but not  
comprehensive.

/Kasper


> However, don't ask me how portable this is ;). It exploits the fact  
> that old-style rules .c.o used by Makeconf are overridden by the  
> new-style rules regardless of their position. Nevertheless, you  
> could still use specific rules if desired without a full-blown  
> Makefile. (I always recommend the use of Makevars as far as  
> possible, because most writers of Makefiles get the shlib  
> compilation wrong).
>
> Cheers,
> Simon

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: suppressing "global" cppflags in an individual package

Simon Urbanek
Kasper,

On May 11, 2006, at 12:37 AM, Kasper Daniel Hansen wrote:

> Thank you Simon, a little comment below
>
> On May 9, 2006, at 2:49 PM, Simon Urbanek wrote:
>
>> On May 9, 2006, at 1:11 PM, Kasper Daniel Hansen wrote:
>>
>>> It is indeed the case that after updating to GCC 4 the package  
>>> gets  broken using -O2. I agree this needs to be fixed, but the  
>>> error
>>> [...]
>>> unfortunately), but reading your comment about CPPFLAGS and  
>>> CXXFLAGS makes me think I can indeed override it using the  
>>> package Makevars file. The flags I was passing to the compiler  
>>> were library locations anyway which was for the preprocessor.
>>>
>>
>> AFAIR you cannot override CPPFLAGS/CXXFLAGS in Makevars, because  
>> it gets included first. You can, however, use something like this:
>>
>> all: $(SHLIB)
>>
>> MYCFLAGS=-O0
>>
>> %.o: %.c
>>         $(CC) $(ALL_CPPFLAGS) $(ALL_CFLAGS) $(MYCFLAGS) -c $< -o $@
>>
>> for C, or for C++ accordingly:
>>
>> %.o: %.cc
>>         $(CXX) $(ALL_CPPFLAGS) $(ALL_CXXFLAGS) $(MYCXXFLAGS) -c $<  
>> -o $@
>
> Actually you do not need the all: line, and since I use .cpp as C++  
> extension, all I needed was
>
> %.o: %.cpp
> <TAB>$(CXX) $(ALL_CPPFLAGS) -O0 -c $< -o $@
>

If it worked for you, fine ... but it doesn't for me (using plain  
SHLIB), because you're replacing the first target, the .so doesn't  
get built.

> Note that I needed to delete the $(ALL_CXXFLAGS) which basically  
> reads R's flags.
>

Well actually the point was that you *don't* need to do that and you  
should not. Most compilers (including gcc) ignore preceding  
conflicting flags, so -O3 -O0 will give you simply -O0 and that's  
what you wanted.

> Now, is there any way to (in the Makevars file) operate on $
> (ALL_CXXFLAGS), since all I want is to delete any -O* flag? Or is  
> defining rules and variables all I can do?
>

Yes. Again, I'm talking GNU make now, so I suspect this is not  
portable (so kids, don't do this at home), but you should be able to use

MYCXXFLAGS=$(filter-out -O3,$(ALL_CXXFLAGS))

However as stated above I don't think you want to do that - just  
append -O0 and you're safe.

Cheers,
Simon

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel