title: R package with C/C++ and openMP: how to make "Makevars" file under "mypackage/src/" folder?
body: <p>I am developing an R package on Mac OSX with some low level <code>C/C++</code> code and <code>openMP</code> support. The <code>C++</code> code is written using <code>Rcpp</code> package. My global ''Makevars'' file is placed under <code>~/.R/</code> folder. The file looks like following.</p>
  
  <pre><code>CC=clang-omp
  CXX=clang-omp++
  
  PKG_CFLAGS=Wall -pedantic
  PKG_CFLAGS= -fopenmp
  PKG_CXXFLAGS= -fopenmp
  PKG_LIBS= -fopenmp -lgomp
  </code></pre>
  
  <p>Everything works great under this configuration! </p>
  
  <p>However, now I want to build package-specific <code>Makevars</code> file for its own compilation to make the package portable. What I tried was simply move the global <code>Makevars</code> file into my R pakcage <code>src</code> folder. However, the compiler complained about that it cannot find the openMP header file <code>omp.h</code>:</p>
  
  <pre><code>** libs
  clang++ -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG  -I/usr/local/include -I/usr/local/include/freetype2 -I/opt/X11/include -I"/Library/Frameworks/R.framework/Versions/3.2/Resources/library/Rcpp/include" -I"/Library/Frameworks/R.framework/Versions/3.2/Resources/library/bigmemory/include" -I"/Library/Frameworks/R.framework/Versions/3.2/Resources/library/BH/include"  -fopenmp -fPIC  -Wall -mtune=core2 -g -O2  -c RcppExports.cpp -o RcppExports.o
  RcppExports.cpp:12:10: fatal error: 'omp.h' file not found
  #include &lt;omp.h&gt;
           ^
  1 error generated.
  make: *** [RcppExports.o] Error 1
  clang++ -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG  -I/usr/local/include -I/usr/local/include/freetype2 -I/opt/X11/include -I"/Library/Frameworks/R.framework/Versions/3.2/Resources/library/Rcpp/include" -I"/Library/Frameworks/R.framework/Versions/3.2/Resources/library/bigmemory/include" -I"/Library/Frameworks/R.framework/Versions/3.2/Resources/library/BH/include"  -fopenmp -fPIC  -Wall -mtune=core2 -g -O2  -c RcppExports.cpp -o RcppExports.o
  RcppExports.cpp:12:10: fatal error: 'omp.h' file not found
  #include &lt;omp.h&gt;
           ^
  1 error generated.
  make: *** [RcppExports.o] Error 1
  </code></pre>
  
  <p>As you can see, the compilers become <code>clang</code> and <code>clang++</code>, but not what specified in the <code>Makevars</code> files: <code>CC=clang-omp</code> and <code>CXX=clang-omp++</code>.</p>
  
  <p><strong>Question 1:</strong> So how could I fix this issue and build a <code>Makevars</code> file within the R package?</p>
  
  <p>Another thing is that, I noticed from <a href="https://cran.r-project.org/doc/manuals/r-release/R-exts.html#OpenMP-support" rel="noreferrer">Writing R extensions</a> that,</p>
  
  <pre><code>For example, a package with C code written for OpenMP should have in src/Makevars the lines
  
  PKG_CFLAGS = $(SHLIB_OPENMP_CFLAGS)
  PKG_LIBS = $(SHLIB_OPENMP_CFLAGS)
  </code></pre>
  
  <p><strong>Question 2:</strong> What is the difference between, for example, macro <code>$(SHLIB_OPENMP_CFLAGS)</code> and flag <code>-fopenmp</code>? which one under which circumstance should I use? I tried to replace the flags with the macros, but still cannot fix the issue.</p>