title: How do you conditionally call a target based on a target variable (Makefile)?
body: <p>I want a different version of the clean target to run based on whether <code>make dev</code> or <code>make prod</code> are run on a makefile.</p>
  
  <p>I'm not compiling anything per se, just want to conditionally call a particular target or set of targets based on a variable, for example:</p>
  
  <pre><code>ifeq ($(BUILD_ENV),"development")
  clean: -clean
  else
  clean: -clean-info
  endif
  
  #---------------------------------
  dev: BUILD_ENV = development
  dev: dev-setup which-env
  
  #---------------------------------
  prod: BUILD_ENV = production
  prod: prod-setup which-env
  
  #---------------------------------
  
  
  which-env: clean
      @echo -e "$(GREEN)$(BUILD_ENV)!$(CLEAR)"
  
  -clean: -clean-info -clean-logs | silent
      @echo -e "$(GREEN)&lt;/CLEAN&gt;$(CLEAR)"
  
  -clean-info:
      @echo -e "$(GREEN)&lt;CLEAN&gt;...$(CLEAR)"
  
  -clean-logs:
      @echo -e " $(GREY)Removing log and status files $(CLEAR)";
      @if [ -d .stat ]; then rm -rf .stat; fi
      @rm -f *.log || true
  </code></pre>
  
  <p>Is there a way to do this with Makefiles? I havent found anything yet that illustrates this use-case.</p>
  
  <p>I'm not trying to specifically clean anything or build anything this is just an example of me trying to conditionally call a set of targets. The actual targets could be anything else.</p>