Absolutely not a perfect solution, and maybe you're already using it within your Makefiles, but for anyone who doesn't yet know about it there's Latexmk[1] which is supposed to automate all of this hassle. I think at least on Debian it's included with texlive-full. In addition it has some nice flags like `-outdir` which lets you send all the crazy LaTeX intermediate build/aux files to a separate directory that's easy to gitignore.
> LaTeX needs several passes to compile because it was designed with minicomputers of the 80s in mind, i.e. tiny memory constraints.
That's certainly part of it, but any typesetting program will need multiple passes to properly handle tables of contents—you can't know a section's page number until you've compiled everything before that section (including the table of contents), but adding a new section to the contents could push everything ahead by another page. The only unique thing about LaTeX here is that it directly exposes these multiple passes to the user.
https://mgeier.github.io/latexmk.html#running-latexmk