There’s a lot of magic happening in the build process. It’s about damn near impossible to figure out which variables you need to set to affect the build commands that R automagically creates. I had to do a lot of experiementation, and a lot of “programming by accident” which I don’t really enjoy. Having never used GNU autoconf didn’t help, and only having a limited knowledge of automake (only enough to help in small projects). But here are a few things in no particular order:

  • R uses a default global Makefile located in $R_HOME/etc/Makeconf. This has several implications, one of which is if you have your own Makefile in the src directory, it stomps the default and probably doesn't do what you want it to. I think that I read that it's recommended to just generate a Makevars file in the src direcotry and automake will use that. That's what I had the best of luck with.
  • Linking to an external library was non-trival, simply because it took me a long time to figure out which LIB variable to write the lib string (in my case -ludunits2) to. Turns out that it's PKG_LIBS... modifying LIBS has no affect. I think that the magic line in the default Makeconf file is this:
    ALL_LIBS = $(PKG_LIBS) $(SHLIB_LIBADD) $(LIBR)# $(LIBINTL)
    which shows PKG_LIBS being used. But then again ALL_LIBS isn't mentioned in any of the make rules below that line. It must be pulled in by the R binary in the CMD build somewhere, but I can't figure it out.
  • PKG_CFLAGS seems to be PKG_LIBS's equivalent; a place to put all of the custom include flags (in case the prerequisite package is installed in a non-standard place.
  • GNU autoconf is a pain in the butt to figure out. That said, I have a 36 line configure.in file that seems to cover everything that I would need, which isn't that bad. It could be smaller, though. I wish they had some standard marcos for declaring non-standard library install paths. That would be a very common thing needed, I would assume.
  • GNU autoconf related: when the manual says that the AC_CHECK_LIB "defines HAVE_LIB<library_name>", they mean that it defines the C symbol as in the compiler flag -DHAVE_LIBUDUNITS2. It took me way too long to figure out that they didn't mean that it defined an autoconf macro. I kept trying to use @HAVE_LIBUDUNITS@ and it didn't work. Noted. All of this makes complete sense after having figured it out, but I wish that it were documented somewhere. It must be one of those Unix common-sense things, that no one bothers to tell you, because everyone knows already. Anyways, I have my R extension package built and am pretty happy with it! -----


blog comments powered by Disqus

Published

19 August 2010

Category

work

Tags