<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Keep It With Mine &#187; Tips</title>
	<atom:link href="http://bruno.defraine.net/techtips/category/tip/feed/" rel="self" type="application/rss+xml" />
	<link>http://bruno.defraine.net/techtips</link>
	<description>Collection of assorted technology tips</description>
	<lastBuildDate>Wed, 03 May 2017 09:10:09 +0000</lastBuildDate>
	<language>en-US</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.9.19</generator>
	<item>
		<title>Continue SVN history in a git repository</title>
		<link>http://bruno.defraine.net/techtips/continue-svn-in-git/</link>
		<comments>http://bruno.defraine.net/techtips/continue-svn-in-git/#comments</comments>
		<pubDate>Mon, 02 Sep 2013 19:00:26 +0000</pubDate>
		<dc:creator><![CDATA[bruno]]></dc:creator>
				<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://bruno.defraine.net/techtips/?p=122</guid>
		<description><![CDATA[The following is a basic command to continue (part of) a Subversion repository as a git repository. git svn clone -A authors --no-metadata --localtime $URL The file authors can be initially empty. The process will be interrupted when an unknown author is encountered. The format is: username = Firstname Lastname &#60;email&#62; Alternatively, if you want [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>The following is a basic command to continue (part of) a Subversion repository as a git repository.<br />
<span id="more-122"></span></p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git</span> <span style="color: #c20cb9; font-weight: bold;">svn</span> clone <span style="color: #660033;">-A</span> authors <span style="color: #660033;">--no-metadata</span> <span style="color: #660033;">--localtime</span> <span style="color: #007800;">$URL</span></pre></td></tr></table></div>

<p>The file <tt>authors</tt> can be initially empty. The process will be interrupted when an unknown author is encountered. The format is:</p>
<pre>
username = Firstname Lastname &lt;email&gt;
</pre>
<p>Alternatively, if you want to recover the author information from Unix user accounts:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git filter-branch</span> <span style="color: #660033;">--env-filter</span> <span style="color: #ff0000;">&quot;. ~/filter.sh&quot;</span> HEAD</pre></td></tr></table></div>

<p>Where <tt>filter.sh</tt> is something like:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">mail</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$(cat /etc/mailname)</span>&quot;</span>
&nbsp;
<span style="color: #007800;">user</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$GIT_AUTHOR_NAME</span>&quot;</span>
<span style="color: #007800;">full</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$(getent passwd &quot;$user&quot; | cut -d ':' -f 5 | cut -d ',' -f 1)</span>&quot;</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$full</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #007800;">GIT_AUTHOR_NAME</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$full</span>&quot;</span>
        <span style="color: #007800;">GIT_AUTHOR_EMAIL</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$user</span>@<span style="color: #007800;">$mail</span>&quot;</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #007800;">user</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$GIT_COMMITTER_NAME</span>&quot;</span>
<span style="color: #007800;">full</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$(getent passwd &quot;$user&quot; | cut -d ':' -f 5 | cut -d ',' -f 1)</span>&quot;</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$full</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #007800;">GIT_COMMITTER_NAME</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$full</span>&quot;</span>
        <span style="color: #007800;">GIT_COMMITTER_EMAIL</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$user</span>@<span style="color: #007800;">$mail</span>&quot;</span>
<span style="color: #000000; font-weight: bold;">fi</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://bruno.defraine.net/techtips/continue-svn-in-git/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Handling merge conflicts with git</title>
		<link>http://bruno.defraine.net/techtips/handling-merge-conflicts-with-git/</link>
		<comments>http://bruno.defraine.net/techtips/handling-merge-conflicts-with-git/#comments</comments>
		<pubDate>Wed, 23 Jan 2013 15:31:09 +0000</pubDate>
		<dc:creator><![CDATA[bruno]]></dc:creator>
				<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://bruno.defraine.net/techtips/?p=87</guid>
		<description><![CDATA[Like a similar post for Mercurial, this tip tries to document a list of systematic steps to handle merge conflicts with git. List the conflict status (first column = ours, second column = theirs): git status -s Or more detailed (stage 1 = ancestor, stage 2 = ours, stage 3 = theirs): git ls-files -u [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Like a <a href="http://bruno.defraine.net/techtips/handling-merge-conflicts-with-mercurial/" title="Handling merge conflicts with Mercurial">similar post for Mercurial</a>, this tip tries to document a list of systematic steps to handle merge conflicts with git.<br />
<span id="more-87"></span></p>
<ol>
<li>
<div>List the conflict status (first column = ours, second column = theirs):</div>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git status</span> <span style="color: #660033;">-s</span></pre></td></tr></table></div>

<div>Or more detailed (stage 1 = ancestor, stage 2 = ours, stage 3 = theirs):</div>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git ls-files</span> <span style="color: #660033;">-u</span></pre></td></tr></table></div>

</li>
<li>
<div>In case of a <code>git-merge</code>, you can check the history of both heads:</div>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git log</span> <span style="color: #660033;">--graph</span> <span style="color: #660033;">--left-right</span> <span style="color: #660033;">--boundary</span> HEAD...MERGE_HEAD</pre></td></tr></table></div>

<div>Or, to list only the commits that contribute to conflicts:</div>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git log</span> <span style="color: #660033;">--left-right</span> <span style="color: #660033;">--merge</span></pre></td></tr></table></div>

<div>In case of <code>git-rebase</code>, you can investigate the history and the commit that is being applied:</div>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git log</span>
<span style="color: #c20cb9; font-weight: bold;">git show</span> $<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">cat</span> .git<span style="color: #000000; font-weight: bold;">/</span>rebase-apply<span style="color: #000000; font-weight: bold;">/</span>original-commit<span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></td></tr></table></div>

</li>
<li>Resolve the conflict:
<ol>
<li>Manual resolution and mark as resolved:

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">vim</span> <span style="color: #000000; font-weight: bold;">&lt;</span><span style="color: #c20cb9; font-weight: bold;">file</span><span style="color: #000000; font-weight: bold;">&gt;</span>
<span style="color: #c20cb9; font-weight: bold;">git diff</span> <span style="color: #660033;">-c</span> <span style="color: #000000; font-weight: bold;">&lt;</span><span style="color: #c20cb9; font-weight: bold;">file</span><span style="color: #000000; font-weight: bold;">&gt;</span>
<span style="color: #c20cb9; font-weight: bold;">git add</span> <span style="color: #000000; font-weight: bold;">&lt;</span><span style="color: #c20cb9; font-weight: bold;">file</span><span style="color: #000000; font-weight: bold;">&gt;</span></pre></td></tr></table></div>

</li>
<li>Resolution using a tool:

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git mergetool</span> <span style="color: #000000; font-weight: bold;">&lt;</span><span style="color: #c20cb9; font-weight: bold;">file</span><span style="color: #000000; font-weight: bold;">&gt;</span></pre></td></tr></table></div>

</li>
<li>Resolve by selecting local/other version:

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git checkout</span> <span style="color: #660033;">--ours</span> <span style="color: #000000; font-weight: bold;">&lt;</span><span style="color: #c20cb9; font-weight: bold;">file</span><span style="color: #000000; font-weight: bold;">&gt;</span>
<span style="color: #c20cb9; font-weight: bold;">git checkout</span> <span style="color: #660033;">--theirs</span> <span style="color: #000000; font-weight: bold;">&lt;</span><span style="color: #c20cb9; font-weight: bold;">file</span><span style="color: #000000; font-weight: bold;">&gt;</span>
<span style="color: #c20cb9; font-weight: bold;">git diff</span> <span style="color: #660033;">-c</span> <span style="color: #000000; font-weight: bold;">&lt;</span><span style="color: #c20cb9; font-weight: bold;">file</span><span style="color: #000000; font-weight: bold;">&gt;</span>
<span style="color: #c20cb9; font-weight: bold;">git add</span> <span style="color: #000000; font-weight: bold;">&lt;</span><span style="color: #c20cb9; font-weight: bold;">file</span><span style="color: #000000; font-weight: bold;">&gt;</span></pre></td></tr></table></div>

</li>
<p>Note that <code>git-diff</code> can be used to inspect changes against both parents at the same time. The default is <code>--cc</code> (combined/condensed) which omits those hunks from <code>-c</code> (combined) that are identical to the hunk from either parent (see <a href="http://www.kernel.org/pub/software/scm/git/docs/git-diff-tree.html">git-diff-tree(1)</a>).
</ol>
</li>
<li>
(If the resolution went wrong) You can still redo the merge if it is not yet staged:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git merge-index</span> <span style="color: #c20cb9; font-weight: bold;">git-merge-one-file</span> <span style="color: #000000; font-weight: bold;">&lt;</span><span style="color: #c20cb9; font-weight: bold;">file</span><span style="color: #000000; font-weight: bold;">&gt;</span></pre></td></tr></table></div>

</li>
<li>
(If you decide the merge was a bad idea, or want to start over) Abort the merge:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git merge</span> <span style="color: #660033;">--abort</span></pre></td></tr></table></div>

<div>Or the rebase:</div>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git rebase</span> <span style="color: #660033;">--abort</span></pre></td></tr></table></div>

</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://bruno.defraine.net/techtips/handling-merge-conflicts-with-git/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Bash Arrays</title>
		<link>http://bruno.defraine.net/techtips/bash-arrays/</link>
		<comments>http://bruno.defraine.net/techtips/bash-arrays/#comments</comments>
		<pubDate>Thu, 10 Jan 2013 09:23:21 +0000</pubDate>
		<dc:creator><![CDATA[bruno]]></dc:creator>
				<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://bruno.defraine.net/techtips/?p=81</guid>
		<description><![CDATA[Arrays are the main advanced data structure in Bash, but the syntax can be hard to remember. The following list summarizes the main operations. Assigning an entire array: nodes=&#40;a b c d&#41; nodes=&#40;foo*&#41; Copying an entire array: nodes=&#40;&#34;$@&#34;&#41; nodes=&#40;&#34;${values[@]}&#34;&#41; Getting individual elements (zero-based indexing) or the element count: echo ${nodes[i]} echo ${#nodes[@]} Iterating an array: [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Arrays are the main advanced data structure in Bash, but the syntax can be hard to remember. The following list summarizes the main operations.<br />
<span id="more-81"></span></p>
<p>Assigning an entire array:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">nodes</span>=<span style="color: #7a0874; font-weight: bold;">&#40;</span>a b c d<span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #007800;">nodes</span>=<span style="color: #7a0874; font-weight: bold;">&#40;</span>foo<span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></td></tr></table></div>

<p>Copying an entire array:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">nodes</span>=<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #ff0000;">&quot;$@&quot;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #007800;">nodes</span>=<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #ff0000;">&quot;<span style="color: #007800;">${values[@]}</span>&quot;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></td></tr></table></div>

<p>Getting individual elements (zero-based indexing) or the element count:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #800000;">${nodes[i]}</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #800000;">${#nodes[@]}</span></pre></td></tr></table></div>

<p>Iterating an array:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">for</span> node <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${nodes[@]}</span>&quot;</span>; <span style="color: #000000; font-weight: bold;">do</span> ... <span style="color: #000000; font-weight: bold;">done</span>
<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">i</span>=<span style="color: #000000;">0</span>; i<span style="color: #000000; font-weight: bold;">&lt;</span><span style="color: #800000;">${#nodes[@]}</span>; i++<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>; <span style="color: #000000; font-weight: bold;">do</span> <span style="color: #007800;">node</span>=<span style="color: #800000;">${nodes[i]}</span>; ... <span style="color: #000000; font-weight: bold;">done</span></pre></td></tr></table></div>

<p>Appending to an array:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;">nodes<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #800000;">${#nodes[@]}</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>=foo</pre></td></tr></table></div>

<p>If you need the last form regularly, it can be simplified with the following shorthand:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> push_back <span style="color: #7a0874; font-weight: bold;">&#123;</span> <span style="color: #7a0874; font-weight: bold;">eval</span> <span style="color: #ff0000;">&quot;$1[<span style="color: #000099; font-weight: bold;">\$</span>{#$1[@]}]=<span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #000099; font-weight: bold;">\$</span>2<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span>; <span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
push_back nodes foo</pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://bruno.defraine.net/techtips/bash-arrays/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Makefile auto dependencies with GCC</title>
		<link>http://bruno.defraine.net/techtips/makefile-auto-dependencies-with-gcc/</link>
		<comments>http://bruno.defraine.net/techtips/makefile-auto-dependencies-with-gcc/#comments</comments>
		<pubDate>Fri, 12 Oct 2012 11:53:06 +0000</pubDate>
		<dc:creator><![CDATA[bruno]]></dc:creator>
				<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://bruno.defraine.net/techtips/?p=74</guid>
		<description><![CDATA[There are many ways of having automatic dependencies in a Makefile. The following, however, is the most clean and complete solution that I know of for modern compilers. GNU Make has a number of builtin rules and variables for building programs, for example, for C: COMPILE.c = $&#40;CC&#41; $&#40;CFLAGS&#41; $&#40;CPPFLAGS&#41; $&#40;TARGET_ARCH&#41; -c LINK.o = $&#40;CC&#41; [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>There are <a href="http://mad-scientist.net/make/autodep.html" title="Autodependencies with GNU make">many ways</a> of having automatic dependencies in a <code>Makefile</code>. The following, however, is the most clean and complete solution that I know of for modern compilers.<br />
<span id="more-74"></span></p>
<p>GNU Make has a number of builtin rules and variables for building programs, for example, for C:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="make" style="font-family:monospace;">COMPILE<span style="color: #004400;">.</span>c <span style="color: #004400;">=</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">CC</span><span style="color: #004400;">&#41;</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">CFLAGS</span><span style="color: #004400;">&#41;</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">CPPFLAGS</span><span style="color: #004400;">&#41;</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">TARGET_ARCH</span><span style="color: #004400;">&#41;</span> <span style="color: #004400;">-</span>c
LINK<span style="color: #004400;">.</span>o <span style="color: #004400;">=</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">CC</span><span style="color: #004400;">&#41;</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">LDFLAGS</span><span style="color: #004400;">&#41;</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">TARGET_ARCH</span><span style="color: #004400;">&#41;</span>
OUTPUT_OPTION <span style="color: #004400;">=</span> <span style="color: #004400;">-</span>o <span style="color: #000088; font-weight: bold;">$@</span>
&nbsp;
<span style="color: #004400;">%.</span>o<span style="color: #004400;">:</span> <span style="color: #004400;">%.</span>c
	<span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span>COMPILE<span style="color: #004400;">.</span>c<span style="color: #004400;">&#41;</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">OUTPUT_OPTION</span><span style="color: #004400;">&#41;</span> <span style="color: #000088; font-weight: bold;">$&lt;</span>
&nbsp;
<span style="color: #004400;">%:</span> <span style="color: #004400;">%.</span>o
	<span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span>LINK<span style="color: #004400;">.</span>o<span style="color: #004400;">&#41;</span> <span style="color: #000088; font-weight: bold;">$^</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">LOADLIBES</span><span style="color: #004400;">&#41;</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">LDLIBS</span><span style="color: #004400;">&#41;</span> <span style="color: #004400;">-</span>o <span style="color: #000088; font-weight: bold;">$@</span></pre></td></tr></table></div>

<p>Because of these builtins, a basic <code>Makefile</code> for a C project with <code>gcc</code> can be quite simple:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="make" style="font-family:monospace;">CC<span style="color: #004400;">=</span>gcc
LDLIBS<span style="color: #004400;">=-</span>lm
&nbsp;
SRC<span style="color: #004400;">=$</span><span style="color: #004400;">&#40;</span><span style="color: #0000CC; font-weight: bold;">wildcard</span> <span style="color: #004400;">*.</span>c<span style="color: #004400;">&#41;</span>
OBJ<span style="color: #004400;">=$</span><span style="color: #004400;">&#40;</span>SRC<span style="color: #004400;">:.</span>c<span style="color: #004400;">=.</span>o<span style="color: #004400;">&#41;</span>
&nbsp;
<span style="color: #990000;">.PHONY</span><span style="color: #004400;">:</span> clean
&nbsp;
foo<span style="color: #004400;">:</span> foo<span style="color: #004400;">.</span>o bar<span style="color: #004400;">.</span>o
&nbsp;
clean<span style="color: #004400;">:</span>
        rm <span style="color: #004400;">-</span>f <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">OBJ</span><span style="color: #004400;">&#41;</span> foo</pre></td></tr></table></div>

<p>This will not track dependencies on headers and other include files, so this will not properly rebuild when these files are updated. With not too much modification, we can ask <code>gcc</code> to output a dependency file next to each object file that is produced. We ask <code>make</code> to include these dependency files where available:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="make" style="font-family:monospace;">CC<span style="color: #004400;">=</span>gcc
OUTPUT_OPTION<span style="color: #004400;">=-</span>MMD <span style="color: #004400;">-</span>MP <span style="color: #004400;">-</span>o <span style="color: #000088; font-weight: bold;">$@</span>
LDLIBS<span style="color: #004400;">=-</span>lm
&nbsp;
SRC<span style="color: #004400;">=$</span><span style="color: #004400;">&#40;</span><span style="color: #0000CC; font-weight: bold;">wildcard</span> <span style="color: #004400;">*.</span>c<span style="color: #004400;">&#41;</span>
OBJ<span style="color: #004400;">=$</span><span style="color: #004400;">&#40;</span>SRC<span style="color: #004400;">:.</span>c<span style="color: #004400;">=.</span>o<span style="color: #004400;">&#41;</span>
DEP<span style="color: #004400;">=$</span><span style="color: #004400;">&#40;</span>SRC<span style="color: #004400;">:.</span>c<span style="color: #004400;">=.</span>d<span style="color: #004400;">&#41;</span>
&nbsp;
<span style="color: #990000;">.PHONY</span><span style="color: #004400;">:</span> clean
&nbsp;
foo<span style="color: #004400;">:</span> foo<span style="color: #004400;">.</span>o bar<span style="color: #004400;">.</span>o
&nbsp;
<span style="color: #004400;">-</span><span style="color: #666622; font-weight: bold;">include</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">DEP</span><span style="color: #004400;">&#41;</span>
&nbsp;
clean<span style="color: #004400;">:</span>
        rm <span style="color: #004400;">-</span>f <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">OBJ</span><span style="color: #004400;">&#41;</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">DEP</span><span style="color: #004400;">&#41;</span> foo</pre></td></tr></table></div>

<p>The options will generate dependency files alongside compilation (<code>-MMD</code> instead of <code>-MM</code>), and with phony targets (<code>-MP</code>) for dependencies. The rationale for doing this is described in <a href="http://scottmcpeak.com/autodepend/autodepend.html" title="Autodependencies with GNU make">Autodependencies with GNU make</a>, although this article dates from a time when apparently only <code>-MM</code> was available. The options <code>-MMD -MP</code> are a modern way of implementing what is proposed in the article.</p>
<p>Besides GCC, also Clang 3.0 and ICC 12.1 seem to support these options.</p>
]]></content:encoded>
			<wfw:commentRss>http://bruno.defraine.net/techtips/makefile-auto-dependencies-with-gcc/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>H.264/AAC encoding using FFmpeg</title>
		<link>http://bruno.defraine.net/techtips/h264-aac-encoding-using-ffmpeg/</link>
		<comments>http://bruno.defraine.net/techtips/h264-aac-encoding-using-ffmpeg/#comments</comments>
		<pubDate>Tue, 11 Sep 2012 09:49:12 +0000</pubDate>
		<dc:creator><![CDATA[bruno]]></dc:creator>
				<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://bruno.defraine.net/techtips/?p=63</guid>
		<description><![CDATA[The x264 encoding guide gives a nice explanation of the different options for H.264 encoding. Normally: ffmpeg -i in.avi -strict experimental -crf 23 -preset medium out.m4v Where you can deviate from the above defaults: -crf [18-28] perceived output quality (lower crf is better quality) -preset [ultrafast,superfast,veryfast,faster,fast,medium,slow,slower,veryslow] compression effort (slower preset is better compression)]]></description>
				<content:encoded><![CDATA[<p>The <a href="http://ffmpeg.org/trac/ffmpeg/wiki/x264EncodingGuide">x264 encoding guide</a> gives a nice explanation of the different options for H.264 encoding. Normally:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">ffmpeg</span> <span style="color: #660033;">-i</span> in.avi <span style="color: #660033;">-strict</span> experimental <span style="color: #660033;">-crf</span> <span style="color: #000000;">23</span> <span style="color: #660033;">-preset</span> medium out.m4v</pre></td></tr></table></div>

<p>Where you can deviate from the above defaults:</p>
<dl>
<dt>-crf [18-28]</dt>
<dd>perceived output quality (lower crf is better quality)</dd>
<dt>-preset [ultrafast,superfast,veryfast,faster,fast,medium,slow,slower,veryslow]</dt>
<dd>compression effort (slower preset is better compression)</dd>
</dl>
]]></content:encoded>
			<wfw:commentRss>http://bruno.defraine.net/techtips/h264-aac-encoding-using-ffmpeg/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Joining H.264/AAC video files</title>
		<link>http://bruno.defraine.net/techtips/joining-h264-aac-video-files/</link>
		<comments>http://bruno.defraine.net/techtips/joining-h264-aac-video-files/#comments</comments>
		<pubDate>Tue, 11 Sep 2012 09:19:37 +0000</pubDate>
		<dc:creator><![CDATA[bruno]]></dc:creator>
				<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://bruno.defraine.net/techtips/?p=60</guid>
		<description><![CDATA[It is possible to join H.264/AAC video files without re-enconding, if you convert them to an MPEG transport stream (TS). This format supports concatenation. Of course, the video files need to have the same height and width, aspect ratio,&#8230; Using ffmpeg: ffmpeg -i 01.m4v -c copy -bsf:v h264_mp4toannexb 01.ts ffmpeg -i 02.m4v -c copy -bsf:v [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>It is possible to join H.264/AAC video files without re-enconding, if you convert them to an MPEG transport stream (TS). This format supports concatenation. Of course, the video files need to have the same height and width, aspect ratio,&#8230;<br />
<span id="more-60"></span></p>
<p>Using <code>ffmpeg</code>:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">ffmpeg</span> <span style="color: #660033;">-i</span> 01.m4v <span style="color: #660033;">-c</span> copy -bsf:v h264_mp4toannexb 01.ts
<span style="color: #c20cb9; font-weight: bold;">ffmpeg</span> <span style="color: #660033;">-i</span> 02.m4v <span style="color: #660033;">-c</span> copy -bsf:v h264_mp4toannexb 02.ts
<span style="color: #c20cb9; font-weight: bold;">ffmpeg</span> <span style="color: #660033;">-i</span> concat:<span style="color: #ff0000;">&quot;01.ts|02.ts&quot;</span> <span style="color: #660033;">-c</span> copy -bsf:a aac_adtstoasc join.m4v
<span style="color: #c20cb9; font-weight: bold;">rm</span> 01.ts 02.ts</pre></td></tr></table></div>

<p>The bitstream filters take care of container requirements.</p>
]]></content:encoded>
			<wfw:commentRss>http://bruno.defraine.net/techtips/joining-h264-aac-video-files/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Using wget to mirror entire website folder</title>
		<link>http://bruno.defraine.net/techtips/using-wget-to-mirror-entire-website-folder/</link>
		<comments>http://bruno.defraine.net/techtips/using-wget-to-mirror-entire-website-folder/#comments</comments>
		<pubDate>Fri, 31 Aug 2012 07:08:34 +0000</pubDate>
		<dc:creator><![CDATA[bruno]]></dc:creator>
				<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://bruno.defraine.net/techtips/?p=45</guid>
		<description><![CDATA[GNU wget can create a very usable local or offline mirror of an entire folder of a website using the following combination of options. From the output directory, use this invocation: URL=http://www.emsl.pnl.gov/docs/global/index.shtml wget -r -l inf -k -N -np -p -E $URL You can play around with the options: -r recursive -l inf follow link [&#8230;]]]></description>
				<content:encoded><![CDATA[<p><a href="http://www.gnu.org/software/wget/" title="Wget">GNU wget</a> can create a very usable local or offline mirror of an entire folder of a website using the following combination of options.<br />
<span id="more-45"></span></p>
<p>From the output directory, use this invocation:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">URL</span>=http:<span style="color: #000000; font-weight: bold;">//</span>www.emsl.pnl.gov<span style="color: #000000; font-weight: bold;">/</span>docs<span style="color: #000000; font-weight: bold;">/</span>global<span style="color: #000000; font-weight: bold;">/</span>index.shtml
<span style="color: #c20cb9; font-weight: bold;">wget</span> <span style="color: #660033;">-r</span> <span style="color: #660033;">-l</span> inf <span style="color: #660033;">-k</span> <span style="color: #660033;">-N</span> <span style="color: #660033;">-np</span> <span style="color: #660033;">-p</span> <span style="color: #660033;">-E</span> <span style="color: #007800;">$URL</span></pre></td></tr></table></div>

<p>You can play around with the options:</p>
<dl>
<dt>-r</dt>
<dd>recursive</dd>
<dt>-l inf</dt>
<dd>follow link infinitely</dd>
<dt>-k</dt>
<dd>convert links after downloading</dd>
<dt>-N</dt>
<dd>time-stamping</dd>
<dt>-np</dt>
<dd>no parent</dd>
<dt>-p</dt>
<dd>retrieve prerequisites of pages</dd>
<dt>-E</dt>
<dd>page extensions according to MIME type</dd>
</dl>
<p>The files will be stored under <code>hostname/path/to/file</code>. If you know up front that the origin of the files is restricted to a particular host or even subpath, you can additionally use:</p>
<dl>
<dt>-nH</dt>
<dd>no subdir for host</dd>
<dt>&#8211;cut-dirs=<em>N</em></dt>
<dd>strip <em>N</em> path components</dd>
</dl>
]]></content:encoded>
			<wfw:commentRss>http://bruno.defraine.net/techtips/using-wget-to-mirror-entire-website-folder/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>clang C++11 on Mac OS X</title>
		<link>http://bruno.defraine.net/techtips/clang-cpp11-on-mac-os-x/</link>
		<comments>http://bruno.defraine.net/techtips/clang-cpp11-on-mac-os-x/#comments</comments>
		<pubDate>Tue, 28 Aug 2012 09:24:00 +0000</pubDate>
		<dc:creator><![CDATA[bruno]]></dc:creator>
				<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://bruno.defraine.net/techtips/?p=41</guid>
		<description><![CDATA[From Marshall Clow, how to get C++11 support with the bundled clang on Mac OS X: clang++ -std=c++0x -stdlib=libc++ This will use the new libc++.]]></description>
				<content:encoded><![CDATA[<p>From <a href="http://marshall.calepin.co/llvmclang-and-standard-libraries-on-mac-os-x.html" title="LLVM/clang and standard libraries on Mac OS X">Marshall Clow</a>, how to get C++11 support with the bundled <a href="http://clang.llvm.org/">clang</a> on Mac OS X:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;">clang++ <span style="color: #660033;">-std</span>=c++0x <span style="color: #660033;">-stdlib</span>=libc++</pre></td></tr></table></div>

<p>This will use the new <a href="http://libcxx.llvm.org/">libc++</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://bruno.defraine.net/techtips/clang-cpp11-on-mac-os-x/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Generate certificate signing requests using OpenSSL</title>
		<link>http://bruno.defraine.net/techtips/generate-certificate-signing-request-using-openssl/</link>
		<comments>http://bruno.defraine.net/techtips/generate-certificate-signing-request-using-openssl/#comments</comments>
		<pubDate>Mon, 27 Aug 2012 10:15:02 +0000</pubDate>
		<dc:creator><![CDATA[bruno]]></dc:creator>
				<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://bruno.defraine.net/techtips/?p=28</guid>
		<description><![CDATA[If you are going to request a CA to sign a certificate for you on a regular basis (i.e. certificates that expire after 1 or 2 years), then it is very useful to automate the process of creating a CSR and a private key with a configuration file. Start by defining the root for the [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>If you are going to request a <a href="http://en.wikipedia.org/wiki/Certificate_authority" title="Certificate authority">CA</a> to sign a certificate for you on a regular basis (i.e. certificates that expire after 1 or 2 years), then it is very useful to automate the process of creating a <a href="http://en.wikipedia.org/wiki/Certificate_signing_request" title="Certificate signing request">CSR</a> and a private key with a configuration file.<br />
<span id="more-28"></span></p>
<p>Start by defining the root for the filenames:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">FN</span>=com.host.my
<span style="color: #c20cb9; font-weight: bold;">vim</span> <span style="color: #007800;">$FN</span>.cnf</pre></td></tr></table></div>

<p>Now save the following information in the configuration file:</p>
<pre>
[ req ]
default_bits = 2048
default_md = sha1
encrypt_key = no
prompt = no
distinguished_name = dn

[ dn ]
C = GB
ST = My State or Province
L = My Locality
O = My Organization
OU = My Organization Unit
CN = my.host.com
emailAddress = admin@my.host.com
</pre>
<p>Next, to generate a new key and certificate signing request:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;">openssl req <span style="color: #660033;">-new</span> <span style="color: #660033;">-config</span> <span style="color: #007800;">$FN</span>.cnf <span style="color: #660033;">-keyout</span> <span style="color: #007800;">$FN</span>.key <span style="color: #660033;">-out</span> <span style="color: #007800;">$FN</span>.csr</pre></td></tr></table></div>

<p>Or, to create a certificate signing request for an existing key:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;">openssl req <span style="color: #660033;">-new</span> <span style="color: #660033;">-config</span> <span style="color: #007800;">$FN</span>.cnf <span style="color: #660033;">-key</span> <span style="color: #007800;">$FN</span>.key <span style="color: #660033;">-out</span> <span style="color: #007800;">$FN</span>.csr</pre></td></tr></table></div>

<p><em>(Optional)</em> To consult the information in the certificate signing request, or to verify the key fingerprint:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;">openssl req <span style="color: #660033;">-in</span> <span style="color: #007800;">$FN</span>.csr <span style="color: #660033;">-noout</span> <span style="color: #660033;">-text</span>
openssl req <span style="color: #660033;">-verify</span> <span style="color: #660033;">-in</span> <span style="color: #007800;">$FN</span>.csr <span style="color: #660033;">-key</span> <span style="color: #007800;">$FN</span>.key <span style="color: #660033;">-noout</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://bruno.defraine.net/techtips/generate-certificate-signing-request-using-openssl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Handling merge conflicts with Mercurial</title>
		<link>http://bruno.defraine.net/techtips/handling-merge-conflicts-with-mercurial/</link>
		<comments>http://bruno.defraine.net/techtips/handling-merge-conflicts-with-mercurial/#comments</comments>
		<pubDate>Fri, 17 Aug 2012 12:17:38 +0000</pubDate>
		<dc:creator><![CDATA[bruno]]></dc:creator>
				<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://bruno.defraine.net/techtips/?p=18</guid>
		<description><![CDATA[When you encounter a merge conflict with Mercurial, things can get a little disorienting. The following is a practical list of steps to handle a merge conflict without getting lost. List the conflict status (U = Unresolved, R = Resolved): hg resolve -la Check the parents (first parent = local, second parent = other): hg [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>When you encounter a merge conflict with Mercurial, things can get a little disorienting. The following is a practical list of steps to handle a merge conflict without getting lost.<br />
<span id="more-18"></span></p>
<ol>
<li>List the conflict status (U = Unresolved, R = Resolved):

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;">hg resolve <span style="color: #660033;">-la</span></pre></td></tr></table></div>

</li>
<li>Check the parents (first parent = local, second parent = other):

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;">hg parents</pre></td></tr></table></div>

</li>
<li>Resolve the conflict:
<ol>
<li>Manual resolution and mark as resolved:

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">vim</span> <span style="color: #000000; font-weight: bold;">&lt;</span><span style="color: #c20cb9; font-weight: bold;">file</span><span style="color: #000000; font-weight: bold;">&gt;</span>
hg resolve <span style="color: #660033;">-m</span> <span style="color: #000000; font-weight: bold;">&lt;</span><span style="color: #c20cb9; font-weight: bold;">file</span><span style="color: #000000; font-weight: bold;">&gt;</span></pre></td></tr></table></div>

</li>
<li>Resolution using a tool (such as <a href="http://www.defraine.net/~brunod/fmdiff/" title="fmdiff">fmmerge</a>):

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;">hg resolve <span style="color: #660033;">-t</span> fmmerge <span style="color: #000000; font-weight: bold;">&lt;</span><span style="color: #c20cb9; font-weight: bold;">file</span><span style="color: #000000; font-weight: bold;">&gt;</span></pre></td></tr></table></div>

</li>
<li>Resolve by selecting local/other version:

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;">hg resolve <span style="color: #660033;">-t</span> internal:local <span style="color: #000000; font-weight: bold;">&lt;</span><span style="color: #c20cb9; font-weight: bold;">file</span><span style="color: #000000; font-weight: bold;">&gt;</span>
hg resolve <span style="color: #660033;">-t</span> internal:other <span style="color: #000000; font-weight: bold;">&lt;</span><span style="color: #c20cb9; font-weight: bold;">file</span><span style="color: #000000; font-weight: bold;">&gt;</span></pre></td></tr></table></div>

</li>
</ol>
</li>
<li>(If the resolution went wrong) Marking a file as unresolved, to redo the merge:

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;">hg resolve <span style="color: #660033;">-u</span> <span style="color: #000000; font-weight: bold;">&lt;</span><span style="color: #c20cb9; font-weight: bold;">file</span><span style="color: #000000; font-weight: bold;">&gt;</span></pre></td></tr></table></div>

</li>
<li>(If you decide the merge was a bad idea) To abort the merge altogether:

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;">hg update <span style="color: #660033;">-C</span> <span style="color: #000000; font-weight: bold;">&lt;</span><span style="color: #c20cb9; font-weight: bold;">rev</span><span style="color: #000000; font-weight: bold;">&gt;</span></pre></td></tr></table></div>

</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://bruno.defraine.net/techtips/handling-merge-conflicts-with-mercurial/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
