title: Setting up "configure" for openMP in R
body: <p>I have an R package which is easily sped up by using OpenMP. If your compiler supports it then you get the win, if it doesn't then the pragmas are ignored and you get one core.</p>
  
  <p>My problem is how to get the package build system to use the right compiler options and libraries. Currently I have:</p>
  
  <pre><code>PKG_CPPFLAGS=-fopenmp
  PKG_LIBS=-fopenmp
  </code></pre>
  
  <p>hardcoded into src/Makevars on my machine, and this builds it with OpenMP support. But it produces a warning about non-standard compiler flags on check, and will probably fail hard on a machine with no openMP capabilities.</p>
  
  <p>The solution seems to be to use configure and autoconf. There's some information around here:</p>
  
  <p><a href="http://cran.r-project.org/doc/manuals/R-exts.html#Using-Makevars" rel="noreferrer">http://cran.r-project.org/doc/manuals/R-exts.html#Using-Makevars</a></p>
  
  <p>including a complex example to compile in odbc functionality. But I can't see how to begin tweaking that to check for openmp and libgomp. </p>
  
  <p>None of the R packages I've looked at that talk about using openMP seem to have this set up either.</p>
  
  <p>So does anyone have a walkthrough for setting up an R package with OpenMP?</p>
  
  <p>[EDIT]</p>
  
  <p>I may have cracked this now. I have a configure.ac script and a Makevars.in with @FOO@ substitutions for the compiler options. But now I'm not sure of the workflow. Is it:</p>
  
  <ul>
  <li>Run "autoconf configure.in > configure; chmod 755 configure" if I change the configure.in file.</li>
  <li>Do a package build.</li>
  <li>On package install, the system runs ./configure for me and creates Makevars from Makevars.in</li>
  </ul>
  
  <p>But just to be clear, "autoconf configure.in > configure" doesn't run on package install - its purely a developer process to create the configure script that <em>is</em> distributed - amirite?</p>