I am writing an r package which provides a wrapper around the libSBML
C library.
I am using the rcppgsl
package as a reference, which looks for the location of header files and the library files for GNU Scientific Library GSL
and uses that information to write the configure
script and Makevars
and Makevars.in
. I am not building for Windows currently. On my machine (macOS), libsbml
(SBML C library) is installed in usual locations, i.e.
header files are at - /usr/local/include/sbml
and library files at - /usr/local/lib
. Indeed, if in my package Makevars
file I use the following, I can build my package.
CXX=clang++
PKG_CPPFLAGS= -I/usr/local/include
PKG_LIBS= $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS) /usr/local/lib/libsbml-static.a
However, I want to learn how to use the configure
script to find the library and use that information to build the package. The relevant portion of configure.ac
from rcppgsl
is
## Check for non-standard programs: gsl-config(1)
AC_PATH_PROG([GSL_CONFIG], [gsl-config])
## If gsl-config was found, let's use it
if test "${GSL_CONFIG}" != ""; then
# Use gsl-config for header and linker arguments
GSL_CFLAGS=`${GSL_CONFIG} --cflags`
GSL_LIBS=`${GSL_CONFIG} --libs`
else
AC_MSG_ERROR([gsl-config not found, is GSL installed?])
fi
I replaced GSL_CONFIG
with LIB_SBML
at relevant places, i.e., the entire configure.ac
file I am using is pasted below (at the end).
However, I don't see configure
, Makevars
and Makevars.in
being generated (which I see in rcppgsl
). Any help here would be highly appreciated!
For the sake of completion, the output of
ls -l | grep sbml
(in usr/local/include
) is
drwxrwxr-x 58 root admin 1856 Aug 1 2016 sbml
and ls -l | grep sbml
(in usr/local/lib
) is
-rw-r--r-- 1 root wheel 7970584 Aug 2 2016 libsbml-static.a
-rwxr-xr-x 1 arcadmin staff 10453624 Nov 25 2014 libsbml.5.11.0.dylib
-rwxr-xr-x 1 root wheel 3813572 Aug 2 2016 libsbml.5.13.0.dylib
lrwxr-xr-x 1 root wheel 20 Aug 1 2016 libsbml.5.dylib -> libsbml.5.13.0.dylib
-rw-r--r-- 1 root wheel 13907656 Feb 26 2015 libsbml.a
lrwxr-xr-x 1 arcadmin staff 15 Mar 27 2015 libsbml.dylib -> libsbml.5.dylib
-rwxr-xr-x 1 root wheel 828 Feb 26 2015 libsbml.la
-rwxrwxr-x 1 root admin 13362732 Nov 25 2014 libsbmlj.jnilib
My configure.ac
file --
## Process this file with autoconf to produce a configure script.
##
## Configure.ac for RcppSBML
##
## Copyright (C) 2010 Romain Francois and Dirk Eddelbuettel
## Copyright (C) 2014 - 2015 Dirk Eddelbuettel
##
## Licensed under GNU GPL 2 or later
# The version set here will propagate to other files from here
AC_INIT([Rcppsbml], 0.1.0)
# Checks for common programs using default macros
AC_PROG_CC
## Use gsl-config to find arguments for compiler and linker flags
##
## Check for non-standard programs: gsl-config(1)
AC_PATH_PROG([LIB_SBML], [libsbml])
## If gsl-config was found, let's use it
if test "${LIB_SBML}" != ""; then
# Use gsl-config for header and linker arguments
SBML_CFLAGS=`${LIB_SBML} --cflags`
SBML_LIBS=`${LIB_SBML} --libs`
else
AC_MSG_ERROR([libsbml not found, is SBML installed?])
fi
# Now substitute these variables in src/Makevars.in to create src/Makevars
AC_SUBST(LIB_SBML)
AC_SUBST(LIB_SBML)
AC_OUTPUT(src/Makevars)
The config package makes it easy to manage environment specific configuration values. For example, you might want to use distinct values for development, testing, and production environments. You can install the config package from CRAN as follows: install.packages("config")
The packages. config file is used in some project types to maintain the list of packages referenced by the project. This allows NuGet to easily restore the project's dependencies when the project is to be transported to a different machine, such as a build server, without all those packages.
To manually submit your package to CRAN, you create a package bundle (with devtools::build() ) then upload it to https://cran.r-project.org/submit.html, along with some comments which describe the process you followed.
Every package must have a DESCRIPTION file and an R directory containing code. These are created by us. A NAMESPACE file is needed as well, and a man directory containing documentation, but both can be autogenerated.
Here a minimal setup:
Remove src/Makevars
and create src/Makevars.in
with content
PKG_CPPFLAGS= @SBML_INCLUDE@
PKG_LIBS= $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS) @SBML_LIBS@
I am not setting CXX
since you cannot change that in src/Makevars
, c.f. Package build ignores Makevars flags.
Create a minimal configure.ac
file:
AC_INIT([Rcppsbml], 0.1.0)
AC_LANG(C++)
AC_REQUIRE_CPP
AC_PROG_CXX
# default values
AC_SUBST([SMBL_INCLUDE], "-I/usr/local/include")
AC_SUBST([SMBL_LIBS], "/usr/local/lib/libsbml-static.a")
# allow for override
AC_ARG_WITH([smbl],
AC_HELP_STRING([--with-smbl=PREFIX],
[path to where smbl is installed]),
[
SMBL_INCLUDE="-I${with_smbl}/include"
SMBL_LIBS="${with_smbl}/lib/libsbml-static.a"
],
[])
# create and report output
AC_CONFIG_FILES([src/Makevars])
AC_OUTPUT
echo
echo "Final src/Makevars"
cat src/Makevars
Call autoconf
to create a configure
file from your configure.ac
template. You might want to check the script with ./configure
and ./configure --with-smbl=/some/path
.
Call
R CMD build ...
R CMD check [--install-args=--configure-args=--with-smbl=/some/path] ...
R CMD INSTALL [--configure-args=--with-smbl=/some/path]...
to build, check and install the package.
Possible extensions:
I see three issues here:
The generation of configure
from configure.ac
is not automatic. You have to call autoconf
.
Similarly, Makevars.in
is not generated by the system. You have to provide it as template from which Makevars
is generated by configure
.
The GSL ships with gsl-config
, other libraries make use of the general pkg-config
. If your library does not support this, you can use the more traditional way to use default locations or those provided with --with-...
arguments. For example in RcppArrayFire I use:
AC_SUBST([AF_INCLUDE], "")
AC_SUBST([AF_LIBS], "-laf")
AS_IF([test -e "${with_arrayfire}"],
[
AF_INCLUDE="-I${with_arrayfire}/include ${AF_INCLUDE}"
AF_LIBS="-L${with_arrayfire}/lib ${AF_LIBS} -Wl,-rpath,${with_arrayfire}/lib"
])
If a directory is supplied as --with-arrayfire=/relevant/path
, then appropriate sub directories are searched for headers and dynamic libraries.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With