R Makevars: how to evaluate command for preprocessor flags?

Viewed 75

When I am creating an R package with compiled code, the Makevars file which sets additional compilation flags is able to execute arbitrary commands within the build process in order to pass compile-time variable flags to the linker - example Makevars:

MY_FLAGS = `${R_HOME}/bin${R_ARCH_BIN}/Rscript -e "cat('-lmylib')"`
PKG_LIBS = $(MY_FLAGS)

However, if I try the same trick for the pre-processor flags instead, it will not work:

MY_FLAGS = `${R_HOME}/bin${R_ARCH_BIN}/Rscript -e "cat(1)"`
PKG_CPPFLAGS = -DMyFlag=$(MY_FLAGS)

Will instead issue the full command without evaluating it, unless I change it to use shell:

MY_FLAGS = ${shell ${R_HOME}/bin${R_ARCH_BIN}/Rscript -e "cat(1)"}
PKG_CPPFLAGS = -DMyFlag=$(MY_FLAGS)

... however, according to the R extensions manual, packages are not supposed to use shell like that due to non-portability.

How can I pass preprocessor flags that involve running R itself to evaluate some command?

I realize it's possible to instead create a Makevars.in and put the code that needs execution in the configure.ac, but is there some other way it could be achieved without a configure script?

0 Answers
Related