[Rcpp-devel] Makevars flags that get evaluated

Dirk Eddelbuettel edd at debian.org
Tue Oct 1 23:51:41 CEST 2013


On 1 October 2013 at 09:02, Dirk Eddelbuettel wrote:
| On 1 October 2013 at 22:37, Gad Abraham wrote:
| | Is there a list of which of the Makevars variables are evaluated, i.e., ones
| | that I can declare as backticks for conditional results. For example, I'd like
| | to be able to declare an environment variable during package installation,
| | e.g.:
| | 
| | USE_OPENCL=yes R CMD INSTALL package
| | 
| | 
| | but neither
| | PKG_CPPFLAGS += `if ! [ -z $(USE_OPENCL) ]; then echo '-DUSE_OPENCL'; fi`
| | nor
| | PKG_CXXFLAGS += `if ! [ -z $(USE_OPENCL) ]; then echo '-DUSE_OPENCL'; fi`
| | 
| | seems to work.
| 
| That seems a little fragile.  I would try this in src/Makevars, which use the
| Make language (which also inherits environment variables as I dimly recall)
| but can also execute shell snippets.

Upon a second look, I suspect all you really want is to prefix 'R CMD INSTAL ...'
with a direct argument to, say, PKG_CXXFLAGS.  

Here is a quick example from one of my smaller packages:

  edd at max:~/svn/rcpp/pkg$ R CMD INSTALL RcppXts_0.0.4.1.tar.gz 
  * installing to library ‘/usr/local/lib/R/site-library’
  * installing *source* package ‘RcppXts’ ...
  ** libs
  ccache g++-4.7 -I/usr/share/R/include -DNDEBUG
  -I"/usr/local/lib/R/site-library/Rcpp/include"
  -I"/usr/local/lib/R/site-library/xts/include"   -fpic  -g -O3 -Wall -pipe
  -Wno-unused -pedantic  -c xtsMod.cpp -o xtsMod.o
  g++-4.7 -shared -o RcppXts.so xtsMod.o
  -L/usr/local/lib/R/site-library/Rcpp/lib -lRcpp
  -Wl,-rpath,/usr/local/lib/R/site-library/Rcpp/lib -L/usr/lib/R/lib -lR
  installing to /usr/local/lib/R/site-library/RcppXts/libs
  ** R
  ** inst
  ** preparing package for lazy loading
  ** help
  *** installing help indices
  ** building package indices
  ** testing if installed package can be loaded
  * DONE (RcppXts)
  edd at max:~/svn/rcpp/pkg$ PKG_CXXFLAGS=-DUSE_OPENCL R CMD INSTALL
  RcppXts_0.0.4.1.tar.gz                                                                                                                                                      
  * installing to library ‘/usr/local/lib/R/site-library’
  * installing *source* package ‘RcppXts’ ...
  ** libs
  ccache g++-4.7 -I/usr/share/R/include -DNDEBUG
  -I"/usr/local/lib/R/site-library/Rcpp/include"
  -I"/usr/local/lib/R/site-library/xts/include"  -DUSE_OPENCL -fpic  -g -O3
  -Wall -pipe -Wno-unused -pedantic  -c xtsMod.cpp -o xtsMod.o
  g++-4.7 -shared -o RcppXts.so xtsMod.o
  -L/usr/local/lib/R/site-library/Rcpp/lib -lRcpp
  -Wl,-rpath,/usr/local/lib/R/site-library/Rcpp/lib -L/usr/lib/R/lib -lR
  installing to /usr/local/lib/R/site-library/RcppXts/libs
  ** R
  ** inst
  ** preparing package for lazy loading
  ** help
  *** installing help indices
  ** building package indices
  ** testing if installed package can be loaded
  * DONE (RcppXts)
  edd at max:~/svn/rcpp/pkg$ 

See how the -DUSE_OPENCL carries through? (It doesn't do anything for my
package, but your get the idea.)  R even strips quotes, so you can also say

   $ PKG_CXXFLAGS="-DUSE_OPENCL" R CMD INSTALL

instead of 

   $ PKG_CXXFLAGS=-DUSE_OPENCL R CMD INSTALL

You can glance at the file $(R_HOME)/etc/Makeconf to see the other PKG_* variables.

Hth, Dirk

-- 
Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com


More information about the Rcpp-devel mailing list