<?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=ifchange">

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

<refnamediv>
<refname>redo-ifchange</refname>
<refpurpose>record and rebuild dependencies</refpurpose>
</refnamediv>

<refsynopsisdiv>
<cmdsynopsis>
<command>redo-ifchange</command>
<arg choice='plain' repeat='rep'><replaceable>filename(s)</replaceable></arg>
</cmdsynopsis>
<cmdsynopsis>
<envar>REDOFLAGS</envar>=
<arg choice='opt'>--silent</arg>
<arg choice='opt'>--debug</arg>
<arg choice='opt'>--keep-going</arg>
<arg choice='opt'>--verbose</arg>
</cmdsynopsis>
</refsynopsisdiv>

<refsection><title>Description</title>

<para>
<command>redo-ifchange</command> is a dependency redcording and rebuilding utility that is run by a "do" script that is in turn invoked by <citerefentry><refentrytitle>redo</refentrytitle><manvolnum>1</manvolnum></citerefentry>.
</para>

<para>
<command>redo-ifchange</command> records that the current target (whose "do" script is being run) depends from the dependencies named <replaceable>filenames</replaceable>.
The dependency recorded is that the current target should be built if <replaceable>filenames</replaceable> have changed.
</para>

<para>
It also determines, using previously saved dependency information if available, which of the dependencies is itself out of date, and recursively attempts to re-build them, as if by invoking <citerefentry><refentrytitle>redo</refentrytitle><manvolnum>1</manvolnum></citerefentry>.
It delays processing of every dependency that is locked by a concurrent invocation of <citerefentry><refentrytitle>redo</refentrytitle><manvolnum>1</manvolnum></citerefentry> or <citerefentry><refentrytitle>redo-ifchange</refentrytitle><manvolnum>1</manvolnum></citerefentry>.
</para>

</refsection>

<refsection><title>Options</title>

<para>
<command>redo-ifchange</command> of necessity recognizes a few of the command-line options supported by <citerefentry><refentrytitle>redo</refentrytitle><manvolnum>1</manvolnum></citerefentry>, that apply to all redo processes in the tree.
However, they are not part of its command-line usage and they are not intended to be used on its command line.
</para>

<para>
Instead, they are passed to it via the <envar>REDOFLAGS</envar> environment variable which is set up by the ultimate <citerefentry><refentrytitle>redo</refentrytitle><manvolnum>1</manvolnum></citerefentry> parent process.
This is also how <command>redo-ifchange</command> is informed about where to record dependency information and where the open file descriptors for the jobserver pipe are.
Do not, therefore, clear the environment or close arbitrary file descriptors when invoking <command>redo-ifchange</command>.
</para>

<para>
For compatibility, <command>redo-ifchange</command> also understands the <envar>MAKEFLAGS</envar>, <envar>MFLAGS</envar>, <envar>MAKELEVEL</envar>, and <envar>__MKLVL__</envar> environment variables.
The latter two are used to track recursion depth, by redo and by the GNU and BSD <citerefentry><refentrytitle>make</refentrytitle><manvolnum>1</manvolnum></citerefentry> programs.
The former two contain command-line options passed down from an ultimake <citerefentry><refentrytitle>make</refentrytitle><manvolnum>1</manvolnum></citerefentry> process, similar to <envar>REDOFLAGS</envar>.
</para>

<para>
Only a few of the options passed via <envar>MAKEFLAGS</envar> and <envar>MFLAGS</envar> are acted upon, namely <arg choice='plain'>-s</arg>, <arg choice='plain'>-k</arg>, <arg choice='plain'>-d</arg>, <arg choice='plain'>-p</arg>, and the undocumented options used to pass along jobserver pipe file descriptor information.
All other options used in these environment variables are ignored.
</para>

</refsection>

<refsection><title>Changes</title>

<para>
If a <replaceable>filename</replaceable> denotes a (character or block) device file, a socket, a FIFO, or a directory, it is considered "changed" based solely upon its last modification timestamp.
<command>redo-ifchange</command> does not attempt to open or to read the contents of such files.
</para>

<para>
If <replaceable>filename</replaceable> denotes a symbolic link, it is considered "changed" based upon a combination of its last modification timestamp and the CubeHash hash of its target.
To prevent re-calculating the hash value of a symbolic link target repeatedly, <command>redo-ifchange</command> assumes that if a link's symbolic last modification timestamp has not changed, it has not been written to, and therefore the hash of its target cannot have changed.
</para>

<para>
If <replaceable>filename</replaceable> denotes an ordinary file, it is considered "changed" based upon a combination of its last modification timestamp and the CubeHash hash of its contents.
To prevent re-calculating the hash value of a file repeatedly, <command>redo-ifchange</command> assumes that if a file's last modification timestamp has not changed, it has not been written to, and therefore the hash of its contents cannot have changed.
</para>

<para>
In both cases, <command>redo-ifchange</command> records the timestamp and hash information in the <filename>.redo</filename> database.
</para>

<para>
<command>redo-ifchange</command> tries not to hash the same file multiple times.
If the same <replaceable>filename</replaceable> is encountered multiple times by a single <command>redo-ifchange</command> process, or if by comparing device and i-node numbers it transpires that <command>redo-ifchange</command> has already hashed the file, it re&#x2010;uses the prior hash value without re&#x2010;reading the file.
Since <citerefentry><refentrytitle>redo</refentrytitle><manvolnum>1</manvolnum></citerefentry> (and hence <command>redo-ifchange</command>) performs atomic builds, an already hashed file will not satisfy the device and i-node check if it is re&#x2010;built, and will be hashed afresh.
</para>

</refsection>

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

</refentry>
