title: Conditional Compilation in Makefile
body: <p>I currently have a make file, part of which looks like the following.</p>
  
  <pre><code>####################################################################
  # Files                                                            #
  ####################################################################
  
  C_SRC +=  \
  CMSIS/CM3/CoreSupport/core_cm3.c \
  CMSIS/CM3/DeviceSupport/EnergyMicro/EFM32/system_efm32.c \
  efm32lib/src/efm32_assert.c \
  efm32lib/src/efm32_system.c \
  efm32lib/src/efm32_gpio.c \
  efm32lib/src/efm32_cmu.c \
  efm32lib/src/efm32_usart.c \
  efm32lib/src/efm32_i2c.c \
  efm32lib/src/efm32_dma.c \
  efm32lib/src/efm32_timer.c \
  efm32lib/src/efm32_int.c \
  efm32lib/src/efm32_emu.c \
  efm32lib/src/efm32_adc.c \
  efm32lib/src/efm32_rtc.c \
  radio.c \
  led.c \
  trace.c \
      main.c
  
  
  S_SRC +=  \
  CMSIS/CM3/DeviceSupport/EnergyMicro/EFM32/startup/cs3/startup_efm32.s
  
  ####################################################################
  # Rules                                                            #
  ####################################################################
  
  C_FILES = $(notdir $(C_SRC) )
  S_FILES = $(notdir $(S_SRC) )
  #make list of source paths, sort also removes duplicates
  C_PATHS = $(sort $(dir $(C_SRC) ) )
  S_PATHS = $(sort $(dir $(S_SRC) ) )
  
  C_OBJS = $(addprefix $(OBJ_DIR)/, $(C_FILES:.c=.o))
  S_OBJS = $(addprefix $(OBJ_DIR)/, $(S_FILES:.s=.o))
  C_DEPS = $(addprefix $(OBJ_DIR)/, $(C_FILES:.c=.d))
  
  vpath %.c $(C_PATHS)
  vpath %.s $(S_PATHS)
  
  # Default build is debug build
  all:    debug
  
  
  debug:    CFLAGS += -DDEBUG -O0 -g3
  debug:    $(OBJ_DIR) $(LST_DIR) $(EXE_DIR) $(EXE_DIR)/$(PROJECTNAME).bin
  
  release:  CFLAGS += -DNDEBUG -O3
  release:  $(OBJ_DIR) $(LST_DIR) $(EXE_DIR) $(EXE_DIR)/$(PROJECTNAME).bin
  
  base:     CFLAGS += -DDEBUG -O0 -g3
  base:     $(OBJ_DIR) $(LST_DIR) $(EXE_DIR) $(EXE_DIR)/$(PROJECTNAME).bin
  </code></pre>
  
  <p>Essentially what I want to do is if it is run with the base target then I want to change the main.c file in <code>C_SRC</code> with mainbase.c</p>
  
  <p>I have tried for hours and hours now and have gotten no where with it. Any advice?</p>
  
  <p>Thanks!</p>