# [texhax] Makefile dependencies for complex documents

Piotr Zielinski Piotr.Zielinski at cl.cam.ac.uk
Mon Mar 22 22:32:29 CET 2004

Hi,

The problem of using make to compile latex documents has been
discussed here before, but the only solutions I know of (latexmake,
latexmk, texi2dvi) are basically designed to run
latex/bibtex/makeindex sufficiently many times to resolve all
_internal_ dependencies of a latex document.  I am after automatic
generation of a Makefile with _external_ dependencies, such as files
included by \includegraphics, \input, etc.

A little internet search revealed that there is a program called
makelatex, which generates these dependencies. However, it does this
by scanning the input file and all files that are explicitly included
with the \input command.  This approach works with simple cases but
fails, for example, when the input command is hidden inside a macro.

I think, the better way would be to redefine \input so that it would
write the name of the file-to-be-included to a special auxiliary file,
say \jobname.dep.  This file would then be processed by another
program, which would resolve all file names and produce a proper
Makefile entry.

So far, I haven't found anything like this, so I've written a couple
of tex macros and a very crude filename resolution program.  Because
this program currently looks for files only in the current directory,
I haven't redefined \input yet.  Instead, macro \dep used in front of
\input causes the latter command to log the filename into
\jobname.dep:

\expandafter\ifx\csname dep\endcsname\relax
\newwrite\dependfile
\openout\dependfile=\jobname.dep\relax
\def\depends#1{\write\dependfile{#1}}%
\def\dep#1#2{\depends{#2}#1{#2}}%
\fi