# When do makefiles recompile and when don't they? (How to force makefiles working.) [closed]

I have noticed that makefiles sometimes do their job (they compile the document) and sometimes they don't (then, they claim nothing has changed). In the latter case, depending on how the makefile looks, there is no output at all or a message is prompted stating that there was nothing to do. In one of my examples, it tells "„example.pdf“ ist bereits aktuell." (translates to: "„example.pdf“ is already up-to-date.")

The latter is, I suppose, a feature (not a bug) to save time in case make is called when the source code did not change (because then, of course, there is in fact nothing to do). However, sometimes this behavior is wrong, because the LaTeX source code did change.

I was wondering (and investigating for some time) the precise reasons and circumstances when and why the make script does not recompile although the code has changed. The main reason for wondering about this is, of course, that I want to be able to force the script to recompile. In the course of writing this question I finally figured that out(!), but there are still open questions.

First, my observations and answers, then the open questions.

Consider the following MWE:

\documentclass{beamer}

\begin{document}

\begin{frame}
frame 1
\end{frame}

\end{document}


Now, consider two variants of makefiles, both are named "makefile". Careful: the lines following the label must be preceded by a tabulator, not by whitespaces.

Variant 1:

example.pdf:
pdflatex example.tex
pdflatex example.tex


Variant 2:

example:
pdflatex example.tex
pdflatex example.tex


To verify my observations, you will need to run both makefile variants. For convenience (i.e., to prevent renaming the files all the time) you can just call the first variant makefile1, the second makefile2, and then run either make -f makefile1 or make -f makefile2.

Apparently, the label used in the makefile (i.e. "example.pdf:" vs. "example:") determines whether they might not work. That is, variant 2 of the makefile (not using the ".pdf" ending in the label) will always recompile, no matter what (this can easily be verified via just calling the script multiple times without touching any tex files in between). Only variant 1 does sometimes (or always(?), see below) claim that nothing is to do.

This already answers my question of how to force recompiling (namely by just using a makecript label without the ending .pdf). Still, I still have the following questions:

(A) Why is this the case? What is the semantics of the label ending ".pdf"? More importantly, how were I supposed to find out about that? I really gave my best finding a manual for LaTeX makefiles or related stackoverlow questions but really couldn't find anything! Nobody even seemed to have my problem that the script did not run although the LaTeX source code did indeed change.

(B) I did my best finding a MWE example which proves that the makescript variant 1 sometimes does recompile, but not in all cases in which it should. Still, I failed. When creating this post, I was not able to reproduce this behavior. Instead, makefile variant 1 did always claim that nothing was to do as long as the PDF existed -- not matter how (extremely) severe the changes in the code were (even if I deleted all content present in the compiled PDF and created completely new content it still did not recompile). Thus my question: Did I just remember/recognize it incorrectly before that also variant 1 does sometimes recompile (even when a PDF exists) or does it really never recompile as long as the result PDF exists? If it does sometimes recompile (which is what I believed prior to writing this) I'd be happy for a MWE, just out of curiosity.

Thank you!

## closed as off-topic by David Purton, Kurt, Stefan Pinnow, TeXnician, BobyandbobNov 3 '18 at 9:42

This question appears to be off-topic. The users who voted to close gave this specific reason:

• "This question does not fall within the scope of TeX, LaTeX or related typesetting systems as defined in the help center." – David Purton, Kurt, Stefan Pinnow, TeXnician, Bobyandbob
If this question can be reworded to fit the rules in the help center, please edit the question.

• This is not really a TeX related question. But the problem is that you have not told Make which files your pdf depends on. So it will only rebuild when example.pdf isn't present. Change your rule to example.pdf: example.tex. – David Purton Nov 3 '18 at 3:47
• variant 2 always builds because no file called example is ever produced. So it always tries to run it. – David Purton Nov 3 '18 at 3:49
• You should just google for makefile tutorial or something similar to learn how they work in general. You might also be interested in latexmk which is often better suited to building latex files. – David Purton Nov 3 '18 at 3:54

First off make isn't a tool specific to LaTeX, it's a general tool for building stuff. This is useful in allowing it to be used with many different tools, but it unfortunately also means that you have to figure out the dependencies manually (or use some other tool in conjunction with make, but that is beyond the scope of this post).

Secondly target names aren't mere labels. They are normally* the names of files to build.

make's job is to first figure out whether the target exists and if it does exist figure out if it is "up to date". If it does not exist or is "out of date" then it gets built, if it is up to date it gets skipped.

To figure out if it is up to date it looks at the dependencies between targets and on files that are not targets. If a target's dependencies are targets in themselves then they will be looked at first. If a target is older than it's dependencies then it will be considered "out of date" and will be rebuilt.

Your problem is that your target has no dependencies. So if the target file exists it is always considered "up to date". You need to add dependencies on your source files.

Regarding documentation there are multiple implementations of make with different features, but probablly the most common these days is gnu make. You can find it's documentation at https://www.gnu.org/software/make/manual/make.html

* There also exist "phony" targets that don't correspond to a file and are always run but again that is beyond the scope of this post.