[R] source package build/installation with subdirectory-lib

Murat Tasan mmuurr at gmail.com
Mon Oct 4 22:52:41 CEST 2010


hi all - i have a source package i'm writing that i'd like to be able
to install with a special library that my R src files rely on.
to be more precise, i have a normal R package directory structure
(i.e. src/ R/ man/ DESCRIPTION NAMESPACE etc.).
i also have another directory here called depPkg, and it has it's own
configure file for the canonical './configure && make && make install'
installation.

so myPkg looks like so (only showing the relevant pieces):

+ myPkg
|--- DESCRIPTION
|--- NAMESPACE
|--- R/   (with R files in here)
|--- src/   (with my .c files in here)
|--- depPkg/   (with all of the package contents (e.g. src, docs,
configure script, etc)


if i switch into and build depPkg by hand it works just fine, and i
set a configure option to locate the .a library file it creates into
the depPkg/lib/ directory, like so:
bash$ ./configure --prefix=./lib --with-pic --disable-shared
this builds depPkglib.a and puts it in the lib directory under depPkg.

now when i compile *my* shared library in testing, it also works just
fine:
bash$ cd src
bash$ gcc -std=gnu99 -I/usr/share/R/include -I../depPkg/include -fpic -
g -O2 -c mycode.c -o mycode.o
bash$ gcc -std=gnu99 -shared -o mycode.so mycode.o -L/usr/lib64/R/lib -
lR -L../depPgk/lib -ldepPkg

when in R, i can now use dyn.load("mycode.so") and .Call(...) with my
C functions perfectly.

now i want to build the package so i can install it easily on my
colleagues' machines.
so i use the normal R build mechanism (R CMD build), but first create
a Makevars file that looks like so:


PKG_CPPFLAGS = -I../depPkg/include
PKG_LIBS = ../depPkg/lib

.PHONY: all mylibs

all: $(SHLIB)

$(SHLIB): mylibs

mylibs:
        (cd ..; gunzip depPgk.tar.gz; tar -xf depPkg.tar; cd depPkg; ./
configure --prefix=./lib --with-pic --disable-shared; make; make
install)


finally, when i try R CMD INSTALL, i know it sees the Makevars file,
because the first build step shows the added include path (from the
PKG_CPPFLAGS variable), but it never seems to execute the commands for
the mylibs target, thus the compiling step of my code fails.

sorry for the long-winded description, but without it i think this
would have made no sense (and likely still doesn't).

i have also tried moving depPgk INTO the src directory and updating
the necessary ../ to ./ in the Makevars, but target mylibs never seems
to be built first.

anyone ever try something like this and have some pointers on how to
debug?

thanks much for any help,

-murat



More information about the R-help mailing list