<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8"/>
<title>Redo implementation in Bourne Shell</title>
</head>
<body>
<p>I have implemented <a href="http://cr.yp.to/redo.html">the build system <i>redo</i> as designed by <abbr title="Daniel Julius Bernstein">DJB</abbr></a> in <i>Bourne Shell</i>. To understand how <i>redo</i> can be simpler, more flexible, more powerful and more reliable than <a href="https://en.wikipedia.org/wiki/Make_(software)"><i>make</i></a>, read <a href="http://homepage.ntlworld.com/jonathan.deboynepollard/FGA/introduction-to-redo.html"><cite>Introduction to redo</cite></a> and/or <a href="https://github.com/apenwarr/redo#readme"><cite>redo: a top-down software build system</cite></a>.</p>
<p></p>
<p>The implementation itself depends only on <a href="https://en.wikipedia.org/wiki/GNU_Core_Utilities"><i><abbr title="GNU is Not Unix">GNU</abbr> Core Utilities</i></a> or <a href="https://en.wikipedia.org/wiki/BusyBox"><i>BusyBox</i></a>. It takes around twice the time of <a href="https://github.com/apenwarr/redo"><i>apenwarr</i>'s <i>Python</i> <i>redo</i> implementation</a> to return from a dependency check while using fewer resources.</p>
<dl>
<dt><a href="redo"><cite>redo</cite></a></dt>
<dd>the main program</dd>
<dt><a href="redo-always"><cite>redo-always</cite></a></dt>
<dd>marks the current target as always needing to be rebuilt</dd>
<dt><a href="redo-dot"><cite>redo-dot</cite></a></dt>
<dd>prints redo dependency graph in <a href="https://en.wikipedia.org/wiki/DOT_language"><i>DOT</i> format</a> (<a href="redo-dot-example">example output</a>, <a href="redo-dot-example.png">example rendering</a>)</dd>
<dt><a href="redo-ifchange"><cite>redo-ifchange</cite></a></dt>
<dd>adds dependencies for the current target (if a dependency changes, the target will be rebuilt)</dd>
<dt><a href="redo-ifcreate"><cite>redo-ifcreate</cite></a></dt>
<dd>adds non-existence dependencies for the current target (if a non-existence dependency is created, the target will be rebuilt)</dd>
<dt><a href="redo-ood"><cite>redo-ood</cite></a></dt>
<dd>prints a list of all target files that are out of date</dd>
<dt><a href="redo-targets"><cite>redo-targets</cite></a></dt>
<dd>prints a list of all target files that exist (a target is a file <i>redo</i> can build)</dd>
<dt><a href="redo-sources"><cite>redo-sources</cite></a></dt>
<dd>prints a list of all source files that exist (a source is a dependency that is not a target)</dd>
<dt><a href="redo-stamp"><cite>redo-stamp</cite></a></dt>
<dd>detects if the current target has changed (see <a href="https://github.com/apenwarr/redo/blob/master/Documentation/redo-stamp.md"><i>apenwarr</i>'s documentation</a>)</dd>
<!--
<dt><a href=""><cite></cite></a></dt>
<dd></dd>
-->
</dl>
<section id="faq">
<h1>Frequently Asked Questions</h1>
<section>
<h1>How do I build a file with <i>redo</i>?</h1>
<p>To build a file <samp>target</samp>, you have to create a dofile <samp>target.do</samp> with shell commands that write the intended result of the build <em>either</em> to standard output <em>or</em> to its parameter <i>$3</i>. Then run <code>redo target</code>.</p>
<p>The default target is <samp>all</samp>: <code>redo</code> without arguments executes commands from <samp>all.do</samp>.</p>
</section>
<section>
<h1>What do the <i>redo</i> parameters <i>$1</i>, <i>$2</i>, <i>$3</i> mean?</h1>
<p>When <i>redo</i> runs a dofile, it gives it three parameters:</p>
<table>
<tr><td>$1</td><td>filename of target</td></tr>
<tr><td>$2</td><td>basename of target, without extension if default dofile is used</td></tr>
<tr><td>$3</td><td>filename of temporary output file that is renamed on build success</td></tr>
</table>
</section>
<section>
<h1>How does the extension removal in parameter <i>$2</i> work?</h1>
<p>Redo removes the extension that it gets from the default dofile filename:</p>
<table>
<tr><th>Target</th><th>Dofile</th><th>Parameter <i>$2</i></th></tr>
<tr><td><samp>a.b.c</samp></td><td><samp>a.b.c.do</samp></td><td>a.b.c</td></tr>
<tr><td><samp>a.b.c</samp></td><td><samp>default.do</samp></td><td>a.b.c</td></tr>
<tr><td><samp>a.b.c</samp></td><td><samp>default.<mark>c</mark>.do</samp></td><td>a.b</td></tr>
<tr><td><samp>a.b.c</samp></td><td><samp>default.<mark>b.c</mark>.do</samp></td><td>a</td></tr>
</table>
</section>
<section>
<h1>How do I declare dependencies with <i>redo</i>?</h1>
<p>Use the <i>redo-ifchange</i> command in a dofile: <code>redo-ifchange dependency</code> inside <samp>target.do</samp> means: If the <samp>target</samp> is built, the <samp>dependency</samp> is built if it does not exist and recorded as a dependency. On subsequent builds, if <samp>dependency</samp> does not exist or has changed since the last build, both <samp>dependency</samp> and <samp>target</samp> are rebuilt.</p>
</section>
<section>
<h1>How does this <i>redo</i> implementation check dependencies?</h1>
<p>For dependency checking, this implementation of <i>redo</i> checks the dependencies' <a href="https://en.wikipedia.org/wiki/Stat_(Unix)">ctime</a> against the stored ctime. If the ctime differs, it checks the dependencies' <a href="https://en.wikipedia.org/wiki/Md5sum">md5sum</a> against the stored md5sum. This is arguably more useful than just using ctime.</p>
</section>
<section>
<h1>How do I declare non-existence dependencies with <i>redo</i>?</h1>
<p>Use the <i>redo-ifcreate</i> command in a dofile: <code>redo-ifcreate ne_dependency</code> inside <samp>target.do</samp> means: If <samp>target</samp> is built, the non-existing file <samp>ne_dependency</samp> is recorded as a non-existence dependency. If <samp>ne_dependency</samp> exists on subsequent builds, <samp>target</samp> is rebuilt.</p>
</section>
<section>
<h1>What are command line options for this <i>redo</i> implementation?</h1>
<table>
<tr><th>Short option</th><th>Long option</th><th>Effect</th></tr>
<tr><td>-d</td><td>--debug</td><td>print dependency checks as they happen</td></tr>
<tr><td>-h</td><td>--help</td><td>print usage instructions and exit</td></tr>
<tr><td>-s</td><td>--shuffle</td><td>randomize build order to find dependency bugs</td></tr>
<tr><td>-x</td><td>--xtrace</td><td>print commands as they are executed (variables expanded)</td></tr>
</table>
</section>
<section>
<h1>How can I use this <i>redo</i> implementation to build in parallel?</h1>
<p>You can use the shell builtins <code>&amp;</code> and <code>wait</code> to execute commands asynchronously. The following line in a dofile builds targets <i>a</i> and <i>b</i> in parallel: <code>redo-ifchange a &amp; redo-ifchange b &amp; ; wait</code></p>
</section>
</section>
<h1></h1>
</body>
</html>