Skip to content

[R-pkg-devel] Subarchitectures

6 messages · Balasubramanian Narasimhan, Dirk Eddelbuettel, Duncan Murdoch

#
I think the WRE manual says that an R_ARCH environment variable will be 
set when subarchitectures are involved, but environment variables aren't 
accessible in Makevars.

Is there a standard way to get a value in Makevars which will match 
.Platform$r_arch once R is running?

Duncan Murdoch
#
On 09/02/2021 11:01 a.m., Duncan Murdoch wrote:
Actually, I probably misread the section about environment variables.

Duncan
2 days later
#
If GNU make is acceptable as a system requirement, you can get any R 
configuration/runtime variable in Makevars, e.g.

R_ARCH=$(shell $(R_HOME)/bin/Rscript -e 'cat(.Platform$r_arch)')

-Naras
On 2/9/21 9:45 AM, Duncan Murdoch wrote:
#
On 11/02/2021 2:30 p.m., Balasubramanian Narasimhan wrote:
I wanted to avoid it, since WRE discourages it so strongly.  What I 
ended up doing is putting the following into src/Makevars.in:

all: $(SHLIB) @HIDE_IF_NO_OPENGL@ ../inst/useNULL$(R_ARCH)/$(SHLIB)

../inst/useNULL$(R_ARCH)/$(SHLIB): $(SHLIB)
	cp -R *.cpp *.c *.h OpenGL useNULL
	cd useNULL;$(R_HOME)/bin/R CMD SHLIB -o $(SHLIB);rm *.cpp *.c *.h 
OpenGL/*; cd ..
	mkdir -p ../inst/useNULL$(R_ARCH)
	mv useNULL/$(SHLIB) ../inst/useNULL$(R_ARCH)/


The $(SHLIB) target should already have the subarchitecture in it. 
@HIDE_IF_NO_OPENGL@ is set by configure to "#" if OpenGL is not 
available for the build, so the second make target would be commented 
out.  If it's not commented out, then I copy all the source files into 
src/useNULL, and in that directory, I make $(SHLIB) again.  (There's 
another Makevars.in in that directory that has different compiler and 
linker options than the main one.)  Then I move the result to 
inst/useNULL$(R_ARCH)/, which will be inst/useNULL in most cases, but 
will have a subarchitecture directory added on if necessary.

This is complicated, partly because  R CMD check  has a bug 
(https://bugs.r-project.org/bugzilla/show_bug.cgi?id=18054) which means 
you will get check warnings if you try to register entry points in a DLL 
with any name except the same as the name of the package.  So to get a 
modified version of the main DLL, it has to have the same name but be 
stored somewhere else.

The version above passes checks, but it's pretty unusual, so I'm not 
certain it doesn't violate the intention of some rule or other.

Duncan Murdoch
1 day later
#
On 11 February 2021 at 11:30, Balasubramanian Narasimhan wrote:
| If GNU make is acceptable as a system requirement, you can get any R 
| configuration/runtime variable in Makevars, e.g.
| 
| R_ARCH=$(shell $(R_HOME)/bin/Rscript -e 'cat(.Platform$r_arch)')

You can switch to backticks to not depend on bash so this

   R_ARCH=`"${R_HOME}/bin/Rscript" -e 'cat(.Platform$r_arch)'`

should work too.

Dirk
#
On 12/02/2021 3:51 p.m., Dirk Eddelbuettel wrote:
It didn't work for me, but I gave up on that approach pretty quickly so 
I might have made some other error that caused the failure.

Duncan Murdoch