title: Makefile leads to compilation error
body: <p>I'm trying to compile a program (which isn't mine):</p>
  
  <pre><code>make -f makefile
  </code></pre>
  
  <p>... using the following <code>makefile</code>:</p>
  
  <pre><code># Compiler for .cpp files
  CPP  = g++
  
  # Use nvcc to compile .cu files
  NVCC = nvcc
  NVCCFLAGS = -arch sm_20 # For fermi's in keeneland
  
  # Add CUDA Paths
  ICUDA = /usr/lib/nvidia-cuda-toolkit/include
  LCUDA = /usr/lib/nvidia-cuda-toolkit/lib64
  
  # Add CUDA libraries to the link line
  LFLAGS += -lcuda -lcudart -L$(LCUDA) -lgomp
  
  # Include standard optimization flags
  CPPFLAGS = -O3 -c -I $(ICUDA) -Xcompiler -fopenmp -DTHRUST_DEVICE_BACKEND=THRUST_DEVICE_BACKEND_OMP
  
  # List of all the objects you need
  OBJECTS  = timer.o ar1.o kGrid.o vfInit.o parameters.o
  
  # Rule that tells make how to make the program from the objects
  main :  main.o $(OBJECTS)
          $(CPP) -o main main.o $(OBJECTS) $(LFLAGS)
  
  # Rule that tells make how to turn a .cu file into a .o
  %.o: %.cu
                  $(NVCC) ${NVCCFLAGS} $(CPPFLAGS) -c $&lt;
  
  # How does make know how to turn a .cpp into a .o?  It's built-in!
  # but if you wanted to type it out it would look like:
  # %.o: %.cpp
  #       $(CPP) $(CPPFLAGS) -c $&lt;
  
  clean :
          rm -f *.o
          rm -f core core.*
  
  veryclean :
          rm -f *.o
          rm -f core core.*
          rm -f main
  </code></pre>
  
  <p>Which results in the following commands:</p>
  
  <pre><code>nvcc -arch sm_20  -O3 -c -I /usr/lib/nvidia-cuda-toolkit/include -Xcompiler -fopenmp -DTHRUST_DEVICE_BACKEND=THRUST_DEVICE_BACKEND_OMP -c main.cu
  g++  -O3 -c -I /usr/lib/nvidia-cuda-toolkit/include -Xcompiler -fopenmp -DTHRUST_DEVICE_BACKEND=THRUST_DEVICE_BACKEND_OMP  -c -o timer.o timer.cpp
  g++: error: unrecognized command line option â-Xcompilerâ
  make: *** [timer.o] Error 1
  </code></pre>
  
  <p>I don't understand the <code>makefile</code>: the <code>-xCompiler</code> flag (in the variable <code>CPPFLAGS</code>) should be used only by the <code>nvcc</code> compiler, not <code>g++</code>. Therefore, I understand why I am getting an error. However, I don't understand, from my basic understanding of the <code>makefile</code> above, why at some point the variable <code>CPPFLAGS</code> follows <code>g++</code> (variable <code>CPP</code>). I don't see any such sequence in the <code>makefile</code>.</p>