<?xml version="1.0" encoding="UTF-8"?>
<!-- **************************************************************************
.... For copyright and licensing terms, see the file named COPYING.
.... **************************************************************************
.-->
<?xml-stylesheet href="docbook-xml.css" type="text/css"?>

<refentry id="redo">

<refmeta xmlns:xi="http://www.w3.org/2001/XInclude">
<refentrytitle>redo</refentrytitle>
<manvolnum>1</manvolnum>
<refmiscinfo class="manual">user commands</refmiscinfo>
<refmiscinfo class="source">redo</refmiscinfo>
<xi:include href="version.xml" />
</refmeta>

<refnamediv>
<refname>redo</refname>
<refpurpose>rebuild utility</refpurpose>
</refnamediv>

<refsynopsisdiv>
<cmdsynopsis>
<command>redo</command>
<arg choice='opt'>--silent</arg>
<arg choice='opt'>--debug</arg>
<arg choice='opt'>--keep-going</arg>
<arg choice='opt'>--verbose</arg>
<arg choice='opt'>--jobs <replaceable>number</replaceable></arg>
<arg choice='opt'>--directory <replaceable>dirname</replaceable></arg>
<arg choice='plain' repeat='rep'><replaceable>filename(s)</replaceable></arg>
</cmdsynopsis>
</refsynopsisdiv>

<refsection><title>Description</title>

<para>
<command>redo</command> unconditionally attempts to rebuild the list of targets given as <replaceable>filenames</replaceable>.
It does this by executing a <filename>.do</filename> program, that is expected both to build each target, and at the same time record what dependencies should cause the target to be rebuilt if given as a target to <citerefentry><refentrytitle>redo-ifchange</refentrytitle><manvolnum>1</manvolnum></citerefentry>.
</para>

<para>
<filename>.do</filename> programs can invoke <citerefentry><refentrytitle>redo-ifchange</refentrytitle><manvolnum>1</manvolnum></citerefentry>, which may recursively cause dependencies to have their <filename>.do</filename> programs invoked.
</para>

</refsection>

<refsection><title>Parallel processing</title>

<para>
<command>redo</command> uses the same jobserver mechanism as used by the GNU and BSD <citerefentry><refentrytitle>make</refentrytitle><manvolnum>1</manvolnum></citerefentry> programs, whereby multiple parts of a build can run in parallel.
If the <arg choice='plain'>--jobs</arg> command-line option is used, and if there is not already a jobserver set up by a parent process, it sets up a jobserver pipe with <replaceable>number</replaceable> job slots.
</para>

<para>
It then attempts to execute as many <filename>.do</filename> programs in parallel as it can procure job slots for.
The distribution of jobs, down the build tree, is thus determined by whether <filename>.do</filename> programs recursively invoke <citerefentry><refentrytitle>redo-ifchange</refentrytitle><manvolnum>1</manvolnum></citerefentry> with one dependency or many.
</para>

<para>
If there is a jobserver already set up, <command>redo</command> assumes that a job slot has already been procured for it, given that it is running.
Similarly, if there is no jobserver and it is not told to set up a jobserver, it acts as if there is a single, implicit, slot; behaving largely as if there were a 1-slot jobserver.
</para>

<para>
It re-uses this implicit slot for the first <filename>.do</filename> program that it spawns, only procuring slots for additional parallel child processes.
Thus if no additional slots are actually available, it devolves from the parallel down to the serial case.
Importantly, it does not release its own implicit job slot back to the jobserver, and never devolves beyond the serial case to not being able to run jobs at all.
</para>

</refsection>

<refsection><title>Options</title>

<para>
The <arg choice='plain'>--directory</arg> command-line option causes <command>redo</command> to change directory to <replaceable>dirname</replaceable> before doing anything.
The <arg choice='plain'>--keep-going</arg> command-line option causes it to attempt to build all targets, even if building one of them fails.
</para>

<para>
The <arg choice='plain'>--verbose</arg> command-line option causes it to print more information about its processing.
The <arg choice='plain'>--debug</arg> command-line option causes it to print debugging information about its internal operation.
And the <arg choice='plain'>--silent</arg> command-line option causes it to print less information about its processing.
</para>

</refsection>

<refsection><title><filename>.do</filename> programs</title>

<refsection><title>Finding <filename>.do</filename> programs</title>

<para>
<command>redo</command> has a two factor search for <filename>.do</filename> programs.
</para>

<para>
Firstly, it searches for <filename>.do</filename> programs in a succession of directories, starting with the directory of the target and (if it does not have an absolute pathname) then checking each successively shorter path prefix until it ends with the current working directory.
So if the target is <filename>a/b/c/d/e</filename>, it will check <filename>a/b/c/d/</filename>, then <filename>a/b/c/</filename>, then <filename>a/b/</filename>, then <filename>a/</filename>, and then finally <filename>.</filename> the current directory.
For a target <filename>/a/b/c/d/e</filename>, on the other hand, it will only check <filename>/a/b/c/d/</filename>.
</para>

<para>
Secondly, within each directory it searches for the <filename>.do</filename> program by looking for successively shorter extension suffixes taken from the target.
To these it prepends the word <filename>default</filename> and the suffix <filename>.do</filename>.
It also, before doing that, checks for the full target filename with <filename>.do</filename> appended.
</para>

<informalexample>
<para>
So if the target is <filename>dir/base.a.b</filename>, it will look for <filename>dir/base.a.b.do</filename>, <filename>dir/default.a.b.do</filename>, <filename>dir/default.b.do</filename>, <filename>dir/default.do</filename>, <filename>base.a.b.do</filename>, <filename>default.a.b.do</filename>, <filename>default.b.do</filename>, and <filename>default.do</filename>.
</para>
</informalexample>

</refsection>

<refsection><title>Running <filename>.do</filename> programs</title>

<para>
A <filename>.do</filename> program can be any kind of executable, although conventionally it is a script.
(<command>redo</command> does not force a choice of shell, and the script must therefore begin with a <code>#!</code> line that names the shell that the script is written for.)
</para>

<para>
<command>redo</command> invokes the program with a <envar>REDOFLAGS</envar> environment variable, which it uses to pass option and target information to recursively executed instances of <command>redo</command> (possibly invoked indirectly via <citerefentry><refentrytitle>redo-ifchange</refentrytitle><manvolnum>1</manvolnum></citerefentry>).
<filename>.do</filename> programs should not alter, or inspect, the value of this variable.
</para>

<para>
<command>redo</command> also invokes it with open file descriptors, indicating the jobserver pipe and where to record dependencies for the current target.
<filename>.do</filename> programs should not close these file descriptors, and should not perform I/O on them other than with <citerefentry><refentrytitle>redo-ifchange</refentrytitle><manvolnum>1</manvolnum></citerefentry> and <citerefentry><refentrytitle>redo-ifcreate</refentrytitle><manvolnum>1</manvolnum></citerefentry>.
</para>

<para>
It sets the <envar>MAKELEVEL</envar> environment variable, which is used in messages to indicate the recursion depth.
</para>

<para>
It invokes the program with three arguments:
</para>
<orderedlist>
<listitem><para>
the directory prefix and base name of the target (e.g. <filename>dir/base.a</filename>)
</para></listitem>
<listitem><para>
the extension part of the target that matched the <filename>default</filename> file (e.g. <filename>.b</filename>)
</para></listitem>
<listitem><para>
the name of a temporary file where the target is to be built
</para></listitem>
</orderedlist>

<para>
<command>redo</command> performs atomic builds of individual targets.
A target is built to a temporary filename (in the same directory), and if and only if the <filename>.do</filename> program exits with a success status is that temporary filename atomically renamed to the actual target.
</para>

</refsection>

</refsection>

<refsection><title>History</title>

<para>
<command>redo</command> version 1.0 came out in 2012.
It switched from UTC time to to TAI64N in 2026.
</para>

</refsection>

<refsection><title>Author</title>
<para><author><personname><firstname>Jonathan</firstname> <surname>de Boyne Pollard</surname></personname></author></para>
</refsection>

</refentry>
