Faheem Mitha
2002-Jun-13 17:57 UTC
[R] using MAKEFLAGS in compiling C code as a shared library using R CMD SHLIB
Dear R People,
in the R FAQ (in the R Programming section) it says
**********************************************************************
How can I change compilation flags?
==================================
Suppose you have C code file for dynloading into R, but you want to
use `R CMD SHLIB' with compilation flags other than the default ones
(which were determined when R was built). You could change the file
``R_HOME'/etc/Makeconf' to reflect your preferences. If you are a
Bourne shell user, you can also pass the desired flags to Make (which
is used for controlling compilation) via the Make variable `MAKEFLAGS',
as in
MAKEFLAGS="CFLAGS=-O3" R CMD SHLIB *.c
**********************************************************************
Now, something like
MAKEFLAGS="CC=gcc-3.0" R CMD SHLIB rc.c -o rc.so
works fine, and something like
MAKEFLAGS="CC=gcc-3.0 PKG_CFLAGS= -Wall" R CMD SHLIB rc.c -o rc.so
also works fine.
However,
MAKEFLAGS="CC=gcc-3.0 PKG_CFLAGS= -Wall -pedantic" R CMD SHLIB rc.c -o
rc.so
does not work fine. Make throws a fit and spews forth gibberish.
My understanding of MAKEFLAGS is that it is for passing flags to some
submake process, in this case R CMD SHLIB. The documentation (make manual)
says that
"Words in the value of `MAKEFLAGS' that contain `=', `make'
treats as
variable definitions just as if they appeared on the command line."
However, there seems to be a problem when the variable definition contains
blanks, as PKG_CFLAGS does above. Can anyone advise on what is the correct
syntax for this? I tried various possibilities and none of them worked,
and I cannot find any documentation that is helpful.
I realise that this is more a question about make, but I thought someone
here might know, and since I am using it in the context of R...
It would probably be a good idea if the answer to this was added to the
above section of the FAQ, since it doesn't seem immediately obvious, at
least to me.
Sincerely, Faheem Mitha.
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at
stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Faheem Mitha
2002-Jun-14 03:50 UTC
[R] SOLVED (was Re: using MAKEFLAGS in compiling C code as a shared library using R CMD SHLIB)
Dear R People,
I'm replying to my own question here. The maintainer of GNU
Make, Paul Smith, kindly replied to a message I posted to the GNU Make
help list, help-make at gnu.org.
I suggest that an example be added to the appropriate section of the FAQ
to reflect this issue, or perhaps the current example could be expanded.
Granted, this is just a shell quoting issue, but it might save someone,
sometime, from some head scratching.
Sincerely, Faheem Mitha.
*******************************************************************
%% Faheem Mitha <faheem at email.unc.edu> writes:
fm> MAKEFLAGS="CC=gcc-3.0 PKG_CFLAGS= -Wall -pedantic" R CMD
SHLIB rc.c
-o rc.so
fm> does not work fine. Make throws a fit and spews forth gibberish.
Make is interpreting the -Wall and -pedantic as lists of make options,
rather than as the value of PKG_CFLAGS, which is entirely correct given
that command string.
fm> My understanding of MAKEFLAGS is that it is for passing flags to
some
fm> submake process, in this case R CMD SHLIB. The documentation (make
fm> manual) says that
fm> "Words in the value of `MAKEFLAGS' that contain `=',
`make' treats
as
fm> variable definitions just as if they appeared on the command
line."
fm> However, there seems to be a problem when the variable definition
fm> contains blanks, as PKG_CFLAGS does above.
That's because the ''PKG_CFLAGS= -Wall -pedantic'' above is
not _one_
word containing an =, it's three words, only the first of which contains
an =. So only the first word is considered to be a variable definition.
fm> Can anyone advise on what is the correct syntax for this?
The simplest solution is to use backslashes to quote the spaces:
MAKEFLAGS='CC=gcc-3.0 PKG_CFLAGS=\ -Wall\ -pedantic' R CMD SHLIB rc.c
-o
rc.so
will work (note the change to single quotes: if you must use double
quotes you'll have to type two backslashes to get one--see the
documentation for your shell).
************************************************************************
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at
stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._