title: How to pass a value to Make, which gets passed to C code
body: <p>I'm looking for help getting my Makefile to do what I want it to do.</p>
  
  <p>I have figured out how to add preprocessing code to my C source which will compile only if I'm compiling for debug:</p>
  
  <pre><code>#if DEBUG
    printf("main()\n");
  
    {
      /* Pauses execution so gdb can attach. */
      int i=9;
      pid_t PID;
      char hostname[256];
      gethostname(hostname, sizeof(hostname));
      printf("PID %d on %s ready for attach.\n", PID=getpid(), hostname);
      fflush(stdout);
      while (i&gt;0) {
        sleep(5);
        i--;
      }
    }
  #endif
  </code></pre>
  
  <p>And I've figured out that if I add <code>-DDEBUG=1</code> to my compile statement, that the above code will be compiled (otherwise it's not compiled).</p>
  
  <p>Next, I want to pass a flag to my Makefile which will either include, or not include the <code>-D</code> option. Currently, I have two separate compile lines which I comment and uncomment as appropriate. Here is my Makefile (which I inherited from someone and am having a difficult time understanding). See the lines that say <code>CFLAGS</code>?:</p>
  
  <pre><code>SHELL = /bin/sh
  
  prefix       = /home/schwarz/sundials/instdir
  exec_prefix  = ${prefix}
  includedir   = ${prefix}/include
  libdir       = ${exec_prefix}/lib
  
  CPP         = cc -E
  CPPFLAGS    =
  CC          = cc
  # CFLAGS      = -Wall -g
  CFLAGS      = -Wall -g -DDEBUG=1
  # CFLAGS      = -g -O2
  LDFLAGS     =
  LIBS        = -lm
  MPICC       = /usr/local/mpi/bin/mpicc
  MPI_INC_DIR = /usr/local/mpi/bin/../include
  MPI_LIB_DIR = /usr/local/mpi/bin/../lib
  MPI_LIBS    =
  MPI_FLAGS   =
  
  INCLUDES = -I${includedir} -I${MPI_INC_DIR}
  LIBRARIES = -lsundials_cvode -lsundials_nvecparallel ${LIBS}
  LIBRARIES_BL =
  
  EXAMPLES = FPU          # cvAdvDiff_non_p cvDiurnal_kry_bbd_p cvDiurnal_kry_p
  
  
  OBJECTS = ${EXAMPLES:=.o}
  
  # -----------------------------------------------------------------------------------------
  
  .SUFFIXES : .o .c
  
  .c.o :
          ${MPICC} ${CPPFLAGS} ${CFLAGS} ${MPI_FLAGS} ${INCLUDES} -c $&lt;
  
  # -----------------------------------------------------------------------------------------
  
  all: ${OBJECTS}
          @for i in ${EXAMPLES} ; do \
            echo "${MPICC} -o $${i} $${i}.o ${MPI_FLAGS} ${CFLAGS} ${LDFLAGS} -L${libdir} ${LIBRARIES} -L${MPI_LIB_DIR} ${MPI_LIBS} ${LIBRARIES_BL}" ; \
            ${MPICC} -o $${i} $${i}.o ${MPI_FLAGS} ${CFLAGS} ${LDFLAGS} -L${libdir} ${LIBRARIES} -L${MPI_LIB_DIR} ${MPI_LIBS} ${LIBRARIES_BL}; \
          done
  
  clean:
          rm -f ${OBJECTS}
          rm -f ${EXAMPLES}
  </code></pre>
  
  <p>I have searched the web - I swear! - but cannot figure out how to pass a parameter into the makefile. <em>How can I set up my Makefile so that it does different types of compiles of the same code for different compile needs?</em> Even better would be if I could pass a specific value to the Makefile, which would pass a specific value to the compile, which I could use to initialize <code>i</code> in the code. (IOW, I compile as <code>make 8</code> and the C is compiled as <code>int i=8;</code>). Is any of that even possible in Make?</p>
  
  <p>As an aside, I've read about Makefiles and how they work by listing files with labels (colons), followed by their dependencies. But I can't understand how this Makefile works or why it issues two compile statements. So a brief explanation would also be helpful.</p>