From ripley at stats.ox.ac.uk  Mon Feb 21 11:17:46 2005
From: ripley at stats.ox.ac.uk (Prof Brian Ripley)
Date: Mon Feb 21 11:17:57 2005
Subject: [Rd] Re: [R] minus I and minus L flags
In-Reply-To: <20050220171208.GA13943@stat.umn.edu>
References: <200502201109.j1KB8jOX030138@hypatia.math.ethz.ch>
	<20050220171208.GA13943@stat.umn.edu>
Message-ID: <Pine.LNX.4.61.0502210936520.15731@gannet.stats>

[This is getting rather technical, so moved to R-devel.]

On Sun, 20 Feb 2005, Charles Geyer wrote:

> I have been RTFM/doc/www, but I'm still lost.
>
> How does one tell R CMD INSTALL and R CMD check (both) that libraries
> are installed in non-usual places and so -I/APPS/include (or whatever)
> is necessary in CPPFLAGS and -L/APPS/lib (similarly) is necessary
> in LDFLAGS?
>
> I know I can hardwire them in pkg/src/Makevars, but this requires hand
> editing of that file by each installer (yuck!)
>
> rgentlem suggested some tricks with configure, but after a lot of grovelling
> in autoconf manuals and books, I still don't get it.
>
> Surely this is a pre-solved problem (I hopefully assert).  Is there a standard
> solution, and if so where is the example I follow?

Configure helps if there is a well-known and exhaustive set of possible 
locations.  Otherwise src/Makevars saying

PKG_CPPFLAGS = -I$(FOO_INCLUDE)
PKG_LIBS = -L$(FOO_LDPATH)

and instructions to the user to set the environment variables FOO_INCLUDE 
amd FOO_LDPATH is a good compromise (except perhaps for the auto-builders 
and auto-testers at CRAN).

I looked at the examples on CRAN, and failed to find one that allowed 
users to specify the paths flexibly.  RQuantian mentioned by Dirk does 
allow the Boost paths to be set, but not the quantlib-config path (at 
least it is not mentioned in RQuantian/configure --help), and it appears 
not be make use of the Boost paths that can be set. (Dirk: surely they 
need to be appended to pkg_cxxflags and pkg_libs?)

Here is a working example planned for RODBC:

src/Makevars.in:
PKG_CPPFLAGS=@CPPFLAGS@
PKG_LIBS=@LIBS@

configure.ac:
AC_INIT(DESCRIPTION)

AC_ARG_WITH([odbc-include],
             AC_HELP_STRING([--with-odbc-include=INCLUDE_PATH],
                            [the location of ODBC header files]),
             [odbc_include_path=$withval])
if test [ -n "$odbc_include_path" ] ; then
    AC_SUBST([CPPFLAGS],["-I${odbc_include_path} ${CPPFLAGS}"])
else
   if test [ -n "${ODBC_INCLUDE}" ] ; then
      AC_SUBST([CPPFLAGS],["-I${ODBC_INCLUDE} ${CPPFLAGS}"])
   fi
fi

AC_ARG_WITH([odbc-lib],
             AC_HELP_STRING([--with-odbc-lib=LIB_PATH],
                            [the location of ODBC libraries]),
             [odbc_lib_path=$withval])
if test [ -n "$odbc_lib_path" ] ; then
    AC_SUBST([LIBS],[" -L${odbc_lib_path} ${LIBS}"])
else
   if test [ -n "${ODBC_LIB}" ] ; then
      AC_SUBST([LIBS],["-I${ODBC_LIB} ${LIBS}"])
   fi
fi

AC_SEARCH_LIBS(SQLTables, odbc odbc32 iodbc,,
 	AC_MSG_ERROR("no ODBC driver manager found"))

AC_SUBST(CPPFLAGS)
AC_SUBST(LIBS)
AC_OUTPUT(src/Makevars)


Then just running 'autoconf' in the top directory makes configure, and

configure --help

lists the options.


-- 
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] Re: [R] minus I and minus L flags
Prof Brian Ripley