title: Linux/Makefile: Creating a binary that executes as if it were in a specific directory
body: <p>I had the following folder structure:</p>
  
  <pre><code>include/
  src/
  data/
  binary-file
  makefile
  </code></pre>
  
  <p>I would execute the binary like so: ./binary-file</p>
  
  <p>But now I want my binary in it's own folder like so:</p>
  
  <pre><code>bin/ &lt;- binary-file is in here now
  include/
  src/
  data/
  makefile
  </code></pre>
  
  <p>Everything goes fine when I execute it from the main folder like so: bin/binary-file</p>
  
  <p>But if I am in another folder other than the main folder, the program will be ill-behaved and will not be able to locate the paths to #include's. For example, if I were in the bin/ folder, the program will be ill-behaved if I execute it like so: ./binary-file</p>
  
  <p>My question is: How can I tell my makefile or binary file to execute like it was in the main folder, from anywhere on my system?</p>
  
  <p>In my makefile, all I changed was:</p>
  
  <pre><code>$(CC) $(CFLAGS) -I$(IDIR) -I$(BDIR) -I$(DDIR) -o $(PROG) $^ $(LFLAGS)
  </code></pre>
  
  <p>to</p>
  
  <pre><code>$(CC) $(CFLAGS) -I$(IDIR) -I$(BDIR) -I$(DDIR) -o $(BDIR)/$(PROG) $^ $(LFLAGS)
  </code></pre>