<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>Object Mentor Blog: Tag makefile</title>
    <link>http://blog.objectmentor.com/articles/tag/makefile</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description></description>
    <item>
      <title>Makefiles, what are you doing with them?</title>
      <description>&lt;p&gt;Half a year ago, I took some exercises written in Java and ported them to C++. At that time I punted on writing makefiles and decided to reply on an &lt;span class="caps"&gt;IDE&lt;/span&gt; (Visual Studio). That worked fine but recently we almost had a customer that was going to take this class and, bless their heart, use the command line.&lt;/p&gt;


	&lt;p&gt;Turns out they are going to use visual studio, so I can shelve this, but I figured I&amp;#8217;d get feedback on what I have created for a makefile. Since I have not written a makefile for 12ish years, I figured things have changed. They have, but I suspect they have even more.&lt;/p&gt;


	&lt;p&gt;What follows are my environment assumptions and the makefile. I&amp;#8217;d appreciate any suggestions.&lt;/p&gt;


	&lt;p&gt;&lt;span class="caps"&gt;FWIW&lt;/span&gt;, I wrote this makefile because it turns out fully building all files takes longer than just building what has changed. I know this seems obvious, but it is not always the case with small projects like this. There is some point where the project becomes big enough to warrant dependency-based building. The exercise meets that criteria. Sometimes the time taken to evaluate build changes is enough overhead that it can be safely removed in lieu of a full build. This is a consideration when creating custom build files for legacy-based refactoring efforts.&lt;/p&gt;


&lt;b&gt;Environment&lt;/b&gt;
	&lt;ul&gt;
	&lt;li&gt;Generic Unix&lt;/li&gt;
		&lt;li&gt;zsh &amp;#8211; though any shell will do really &lt;/li&gt;
		&lt;li&gt;g++&lt;/li&gt;
		&lt;li&gt;gnu make&lt;/li&gt;
		&lt;li&gt;This source base will still be used in Visual Studio but not this makefile&lt;/li&gt;
		&lt;li&gt;CppUTest used for unit testing tool&lt;/li&gt;
		&lt;li&gt;Provide default location for CppUTest, which can be overridden by environment variable&lt;/li&gt;
		&lt;li&gt;Boost library installed in /usr/local/include and /usr/local/lib (reasonable assumption or should I go ahead and allow this to be configured easily in the makefile &amp;#8211; what&amp;#8217;s your opinion?)&lt;/li&gt;
		&lt;li&gt;Project is small enough that all headers and source files are in the same directory (should I build the .o&amp;#8217;s and put them in another directory to hide them?)&lt;/li&gt;
	&lt;/ul&gt;


&lt;b&gt;Current Makefile&lt;/b&gt;
&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;ifdef CPP_U_TEST
    CppUTest_base = $(CPP_U_TEST)
else
    CppUTest_base = $(wildcard ~/src/cpputest)
endif

LIB_DIRS = -L$(CppUTest_base)/lib
INC_DIRS = -I$(CppUTest_base)/include
LIBS = -lCppUTest -lboost_date_time -lboost_regex -lboost_thread
CFLAGS = -g $(INC_DIRS) 
LDFLAGS = $(LIB_DIRS) $(LIBS)
CC = g++
SRCS := $(wildcard *.cpp)
OBJS = $(SRCS:.cpp=.o)
OUT = run_all_tests
DEP_DIR = dependencies

all: $(OBJS)
    $(CC) $(CFLAGS) $(LDFLAGS) -o $(OUT) $(OBJS)

clean:
    @rm -rf $(DEP_DIR) $(OBJS) $(OUT)

-include $(SRCS:.cpp=$(dep_dir)/.d)

.cpp.o:
    @if [ ! -d $(DEP_DIR) ] ; then mkdir $(DEP_DIR) ; fi
    $(CC) -c $(CFLAGS) -o $@ $&amp;lt; 
    @$(CC) -MM $(CFLAGS) $*.cpp &amp;gt; $(DEP_DIR)/$*.d&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;</description>
      <pubDate>Wed, 27 Jan 2010 09:02:00 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:2e89212d-2630-4f8c-ac26-b1c8091cd19c</guid>
      <author>Brett Schuchert</author>
      <link>http://blog.objectmentor.com/articles/2010/01/27/makefiles-what-are-you-doing-with-them</link>
      <category>Schuchert's Scattered Synapses </category>
      <category>c</category>
      <category>makefile</category>
      <category>gnu</category>
      <category>build</category>
    </item>
  </channel>
</rss>
