thrillhouse
thrillhouse

Reputation: 121

Change build options for Mac vs. Linux in R package

I'm creating an R package that uses a third-party (closed-source) API for importing .edf files into R (from SR Research Eyelink eye trackers). Someone who has already gotten this to work in Linux has shared his code, and I was able to get it to work on Mac. It was a matter of changing the src/Makevars files to point to the API as it's installed on the mac:

PKG_LIBS=-framework edfapi -F/Library/Frameworks/

To make it work in linux, Makevars needs to have:

PKG_LIBS=-L/usr/local/lib -ledfapi -lm

I know that for windows-specific options, I need to create a Makevars.win file, but how do I have the build options change for Mac versus Linux? I would like to do something like:

if [[ `uname` -eq Darwin ]] ; then

  PKG_LIBS=-framework edfapi -F/Library/Frameworks/

fi

if [[ `uname` -eq Linux ]] ;then

  PKG_LIBS=-L/usr/local/lib -ledfapi -lm

fi

but putting this into Makevars doesn't work. From researching this it seems that I need a combination of setting options in configure and Makevars, but I haven't quite figured it out. I am comfortable with R programming and know just enough C++ to make some basic functions, but I still don't understand all the nuances involved in the building process. If someone could explain the main purpose of configure/configure.ac versus Makevars/Makevars.in that would be helpful as well.

Ideally I would like to bundle the API along with the R package and have the different versions in a platform-specific folder. The API consists of just 3 header files and a binary (and it rarely changes). I realize this would prevent me from putting the package on CRAN but that is fine. I've managed to successfully build the package with the API files in a different folder, but at runtime it still looks for it in the standard spot (/Library/Frameworks). I realize this is a more loaded question and I can create a separate post as well.

Upvotes: 3

Views: 469

Answers (1)

thrillhouse
thrillhouse

Reputation: 121

This post helped me figure it out: stackoverflow.com/a/32590600/1457051

configure (in the package root directory) looks like this:

#!/bin/bash

#make the Makevars file
if [ ! -e "./src/Makevars" ]; then
touch ./src/Makevars
fi

#if mac
if [[ `uname` -eq Darwin ]] ; then

echo "PKG_LIBS=-framework edfapi -F/Library/Frameworks/" > ./src/Makevars
#if linux
elif [[ `uname` -eq Linux ]] ;then

echo "PKG_LIBS=-L/usr/local/lib -ledfapi -lm" > ./src/Makevars

fi

Makevars is created and the appropriate options are added based on the platform. There may be a more direct solution, but this works for my purposes.

Upvotes: 1

Related Questions