autoconfr-packagesbml

Writing `configure` file for an r package


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)

Solution

  • 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: