title: How can I show the value of a particular gcc Makefile target variable?
body: <p>I'm trying to debug a problem in my gcc Makefile that came from the ChatScript open source chat-bot project:</p>
  
  <p><a href="http://chatscript.sourceforge.net/" rel="nofollow noreferrer">http://chatscript.sourceforge.net/</a></p>
  
  <p>Here are my relevant version numbers:</p>
  
  <pre><code>Ubuntu 14.04
  make version 3.81
  gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5)
  </code></pre>
  
  <p>I can't seem to get it to find a source file in another directory that is along-side the current working directory.  If I move the source file into the current directory, it works fine, but if I put the file back in the old directory, it complains it can't find it:</p>
  
  <pre><code>make: *** No rule to make target `privatesrc.cpp', needed by `all'.  Stop.
  </code></pre>
  
  <p>The current directory I am in when executing <em>make</em> is SRC, the directory where <em>Makefile</em> is located.  <em>privatesrc.cpp</em> resides in a sibling directory that <strong>should</strong> be reachable from SRC with this relative path:</p>
  
  <p>../privatecode/privatesrc.cpp</p>
  
  <p>To debug this problem I want to see exactly what the files are for each of the make target's variables.  I used these two SO posts to try and dump those values:</p>
  
  <p><a href="https://stackoverflow.com/questions/16467718/how-to-print-out-a-variable-in-makefile">How to print out a variable in makefile</a></p>
  
  <p>Jim Nisby's answer.  And:</p>
  
  <p><a href="https://stackoverflow.com/questions/7117978/gnu-make-list-the-values-of-all-variables-or-macros-in-a-particular-run/7144684">gnu make: list the values of all variables (or &quot;macros&quot;) in a particular run</a></p>
  
  <p>The accepted answer.</p>
  
  <p>I created this new make target called <em>server_dry_run</em> to facilitate this:</p>
  
  <pre><code>server_dry_run: DEFINES+= -DPRIVATE_CODE -DLOCKUSERFILE=1 -DEVSERVER=1 -DEVSERVER_FORK=1 -DDISCARDDATABASE=1
  server_dry_run: PGLOAD= -pthread
  server_dry_run: INCLUDEDIRS=-Ievserver
  server_dry_run: all
  server_dry_run: EXECUTABLE=../BINARIES/ChatScript
  server_dry_run: CFLAGS=-c -Wall  -funsigned-char  -Wno-write-strings -Wno-char-subscripts -Wno-strict-aliasing 
  # Uncomment this line if you want to filter out variables already defined.
  # VARS_OLD := $(.VARIABLES)
  CUR-DIR := $(shell pwd)
  LOG-DIR := $(CUR-DIR)/make-logs
  $(info INCLUDEDIRS="$(INCLUDEDIRS)")
  $(foreach v,$(filter-out $(VARS_OLD) VARS_OLD,$(.VARIABLES)),$(info $(v) = $($(v))))
  </code></pre>
  
  <p>However, INCLUDEDIRS always shows as empty:</p>
  
  <pre><code>INCLUDEDIRS=""
  </code></pre>
  
  <p>How can I see the value of INCLUDEDIRS so I can fix this problem?</p>
  
  <p>Below is the entire content of my Makefile.  Note, <em>I did try removing the quotes I added around the value assigned to INCLUDEDIRS</em>, but that didn't help.  One other bit of data.  If I do "make clean"  I get the error "<em>rm: cannot remove `../': Is a directory</em>", <strong>which seems to indicate the EXECUTABLE target variable may not be right</strong>.</p>
  
  <p>MAKEFILE:</p>
  
  <pre><code>debugserver: DEFINES+= -DPRIVATE_CODE -DLOCKUSERFILE=1 -DEVSERVER=1 -DEVSERVER_FORK=1 -DDISCARDDATABASE=1 -DDEBUG
  debugserver: PGLOAD= -pthread
  debugserver: INCLUDEDIRS="-Ievserver -I../privatecode"
  debugserver: all
  debugserver: EXECUTABLE=../BINARIES/ChatScriptDebug
  debugserver: CFLAGS=-c -Wall  -funsigned-char  -Wno-write-strings -Wno-char-subscripts -Wno-strict-aliasing -g
  
  debugpgserver: DEFINES+= -DPRIVATE_CODE -DLOCKUSERFILE=1 -DEVSERVER=1 -DEVSERVER_FORK=1  -DDEBUG
  debugpgserver: PGLOAD= -lpq -pthread
  debugpgserver: INCLUDEDIRS="-Ievserver -I../privatecode"
  debugpgserver: all
  debugpgserver: EXECUTABLE=../BINARIES/ChatScriptpgDebug
  debugpgserver: CFLAGS=-c -Wall  -funsigned-char  -Wno-write-strings -Wno-char-subscripts -Wno-strict-aliasing -g
  
  server: DEFINES+= -DPRIVATE_CODE -DLOCKUSERFILE=1 -DEVSERVER=1 -DEVSERVER_FORK=1 -DDISCARDDATABASE=1
  server: PGLOAD= -pthread
  server: INCLUDEDIRS="-Ievserver -I../privatecode"
  server: all
  server: EXECUTABLE=../BINARIES/ChatScript
  server: CFLAGS=-c -Wall  -funsigned-char  -Wno-write-strings -Wno-char-subscripts -Wno-strict-aliasing 
  
  standalone: DEFINES+= -DPRIVATE_CODE  -DDISCARDSERVER=1 -DDISCARDDATABASE=1 
  standalone: PGLOAD= -pthread
  standalone: INCLUDEDIRS="-Ievserver -I../privatecode"
  standalone: all
  standalone: EXECUTABLE=../BINARIES/ChatScript
  standalone: CFLAGS=-c -Wall  -funsigned-char  -Wno-write-strings -Wno-char-subscripts -Wno-strict-aliasing 
  
  pgserver: DEFINES+= -DPRIVATE_CODE -DLOCKUSERFILE=1 -DEVSERVER=1 -DEVSERVER_FORK=1 
  pgserver: PGLOAD= -lpq -pthread
  pgserver: all
  pgserver: EXECUTABLE=../BINARIES/ChatScriptpg
  pgserver: INCLUDEDIRS="-Ievserver -Ipostgres -I../privatecode"
  pgserver: CFLAGS=-c -Wall  -funsigned-char  -Wno-write-strings -Wno-char-subscripts -Wno-strict-aliasing 
  
  
  mongoserver: DEFINES+= -DPRIVATE_CODE -DLOCKUSERFILE=1 -DEVSERVER=1 -DEVSERVER_FORK=1 
  mongoserver: PGLOAD= -lpq -pthread
  mongoserver: all
  mongoserver: EXECUTABLE=../BINARIES/ChatScriptmongo
  mongoserver: INCLUDEDIRS="-Ievserver -I../privatecode"
  mongoserver: CFLAGS=-c -Wall  -funsigned-char  -Wno-write-strings -Wno-char-subscripts -Wno-strict-aliasing 
  
  server_dry_run: DEFINES+= -DPRIVATE_CODE -DLOCKUSERFILE=1 -DEVSERVER=1 -DEVSERVER_FORK=1 -DDISCARDDATABASE=1
  server_dry_run: PGLOAD= -pthread
  server_dry_run: INCLUDEDIRS=-Ievserver -I../privatecode
  server_dry_run: all
  server_dry_run: EXECUTABLE=../BINARIES/ChatScript
  server_dry_run: CFLAGS=-c -Wall  -funsigned-char  -Wno-write-strings -Wno-char-subscripts -Wno-strict-aliasing 
  # Uncomment this line if you want to filter out variables already defined.
  # VARS_OLD := $(.VARIABLES)
  CUR-DIR := $(shell pwd)
  LOG-DIR := $(CUR-DIR)/make-logs
  $(info INCLUDEDIRS="$(INCLUDEDIRS)")
  $(foreach v,$(filter-out $(VARS_OLD) VARS_OLD,$(.VARIABLES)),$(info $(v) = $($(v))))
  
  UNAME := $(shell uname)
  
  CC=g++
  
  ifeq ($(UNAME), Linux)
  $(info ************ LINUX VERSION ************)
  LDFLAGS= -lrt -lcurl --verbose $(PGLOAD) 
  endif
  
  ifeq ($(UNAME), Darwin)
  $(info ************ MAC VERSION ************)
  LDFLAGS=-mmacosx-version-min=10.7 $(PGLOAD)  
  CFLAGS=-mmacosx-version-min=10.7 -c -Wall  -funsigned-char -Wno-write-strings -Wno-char-subscripts 
  endif
  
  SOURCES=constructCode.cpp evserver.cpp csocket.cpp cs_ev.c dictionarySystem.cpp englishTagger.cpp factSystem.cpp  functionExecute.cpp english.cpp infer.cpp javascript.cpp jsmn.cpp markSystem.cpp os.cpp outputSystem.cpp patternSystem.cpp privatesrc.cpp scriptCompile.cpp spellcheck.cpp secure.cpp systemVariables.cpp tagger.cpp testing.cpp textUtilities.cpp tokenSystem.cpp topicSystem.cpp userCache.cpp userSystem.cpp variableSystem.cpp mainSystem.cpp 
  OBJECTS=$(SOURCES:.cpp=.o)
  
  all: $(SOURCES) binary
  
  clean:
      -rm -f $(EXECUTABLE)
      -rm -f ../$(EXECUTABLE)
      -rm -f *.o
  
  binary: $(OBJECTS)
      $(CC) $(OBJECTS) $(LDFLAGS) $(DEFINES) $(INCLUDEDIRS) -o $(EXECUTABLE)
  
  .cpp.o:
      $(CC) $(CFLAGS) $(DEFINES) $(INCLUDEDIRS) $&lt; -o $@
  </code></pre>