tags:

views:

161

answers:

1

I'm building an R package and need to build a jni library for OSX (called myPackage.jnilib) as part of my build process and then have R's automatic installation mechanisms put it inside the libs directory of my package.

The problem is that R's default is to try and build an object called myPackage.so . I'd like to be able to customise this but can't see how.

I can get part of the way by subverting R's mechanisms using a phony "all" target in Makevars (described here http://stat.ethz.ch/R-manual/R-patched/doc/manual/R-exts.html#Using-Makevars ) and then copying the file to the "inst" directory of my package. This is OK for my own local uses but generates headaches when trying to build universal binaries and isn't very portable. I'm currently preparing the package for CRAN so this method isn't likely to work.

I can see two potential solutions but haven't got either to work yet

(1) Copy my library manually to the libs directory of my package during installation. Since this directory is created on the fly, how would I find out what it is from within Makevars or a configure script

(2) The best solution: Tell R CMD SHLIB the name of my output file so I can use R's normal package mechanisms and let it copy the file to the right directory.

A: 

In case anyone else encounters this problem I'm posting my own workaround here.

I define targets in my Makevars and copy the libraries directly (ie answer 1). The variable R_LIBRARY_DIR provides the temporary location where the package is being built.

My Makevars now looks something like this

OBJECTS = 

LIBSINSTDIR=$(R_LIBRARY_DIR)/myPackage/libs/

#ARCHFLAG is set in the configure script to i386 or ppc as appropriate
JNIINSTDIR=$(LIBSINSTDIR)/@ARCHFLAG@/

.PHONY: all

all: $(SHLIB) jnilib 

jnilib: object1.o object2.o
   $(CXX) -bundle $(JAVA_LIBS) $(JAVA_CPPFLAGS) -o libmyPackage.jnilib object1.o object2.o
   mkdir -p $(JNIINSTDIR)
   cp libmyPackage.jnilib $(JNIINSTDIR)
Ira Cooke