From ripley at stats.ox.ac.uk  Wed Dec 29 20:24:41 2004
From: ripley at stats.ox.ac.uk (Prof Brian Ripley)
Date: Wed Dec 29 20:24:44 2004
Subject: [Rd] Makefile vs Makevars vs configure
In-Reply-To: <7669F018DC9DD711AEC500065B3D5ABF042B3E2E@tudor.com>
References: <7669F018DC9DD711AEC500065B3D5ABF042B3E2E@tudor.com>
Message-ID: <Pine.LNX.4.61.0412291917080.24187@gannet.stats>

On Wed, 29 Dec 2004, Whit Armstrong wrote:

> Apologies in advance for the long post.
>
> I'm currently using a Makefile to build my shared library. Pursuant to the
> R-exts manual, I'd like to switch to a Makevars file or a configure file if
> necessary.
>
> Having never used these types of make utilities before, I'm a bit lost.
>
> My package is quite simple.  It only has one source file and one header:
> excelpoi.cpp
> excelpoi.h
>
> The reason I need help with Makevars is because it needs jni.h from the
> user's JAVA_HOME/include and jni_md.h from the user's
> JAVA_HOME/include/OS_TYPE directory.
>
> In addition, it needs libjvm.so from the user's
> JAVA_HOME/jre/lib/ARCH/client directory.
>
> I've looked at the SJava package with the idea of using a similar configure
> script, but I was hoping I could just get by with a Makevars file rather
> than a configure script.
>
> I would appreciate any pointers, as I'm not really sure exactly where to
> begin.
>
> I suppose if I can find the values of JAVA_HOME, ARCH, and OS_TYPE, then I
> can fill in the values I need using PKG_LIBS and PKG_INCLUDE in the Makevars
> file.

Right.  So you need Makevars.in and a configure script to fathom out 
JAVA_HOME and ARCH. Not so sure about OS_TYPE, as your include directories 
will depend on whose JRE this is, I think.  Something like

JAVA_HOME=@JAVA_HOME@

PKG_CFLAGS=-I$(JAVA_HOME)/include -D_REENTRANT -D_GNU_SOURCE
PKG_LIBS=-L$(JAVA_HOME)/jre/lib/@ARCH@/client -ljvm

*However* as your libjvm is shared then you will need to ensure
$(JAVA_HOME)/jre/lib/$(ARCH)/client is in the LD_LIBRARY_PATH and then you 
don't need the -L.


> below is the makefile I'm currently using for your reference.
>
> Thanks in advance,
> Whit
>
> <Makefile>
> archExpr = case "`uname -m`" in  \
>                i[3-6]86 | ia32) \
>                    echo i386 \
>                    ;; \
>                sparc*)  \
>                    echo sparc \
>                    ;; \
>                *) \
>                    uname -m  \
>                    ;; \
>        esac
>
> ARCH = $(shell $(archExpr) )
>
> JAVA_HOME=/opt/blackdown-jdk-1.4.1/
>
> INCLUDES=-I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/linux
> -I/usr/local/lib/R/include
>
> LIBS=-L$(JAVA_HOME)/jre/lib/$(ARCH)/client -ljvm
>
> # The recommended c compiler flags
> CFLAGS=-D_REENTRANT -D_GNU_SOURCE
>
> all: excelpoi.so
>
> excelpoi.so: excelpoi.cpp excelpoi.h
>  $(CXX) -O2 $(CFLAGS) $(INCLUDES) $(LIBS) -shared -fPIC -o $@ $<
>
> </Makefile>

-- 
Brian D. Ripley,                  ripley@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595


[Rd] Makefile vs Makevars vs configure
Prof Brian Ripley