Not sure if this belongs here - but its bugging me. I have a makefile :


TEXDEP=$(D1)/*tex $(D2)/*tex $(D3)/*tex $(D4)/*tex

all: $(DOCNAME).pdf
$(DOCNAME).pdf: $(DOCNAME).tex $(TEXDEP) $(DOCNAME).nls $(DOCNAME).bbl
    pdflatex $(DOCNAME) && pdflatex $(DOCNAME)
$(DOCNAME).nls: $(DOCNAME).nlo
    makeindex $^ -s nomencl.ist -o $@
$(DOCNAME).nlo: $(DOCNAME).tex $(TEXDEP)
    pdflatex $(DOCNAME)
$(DOCNAME).bbl: $(DOCNAME).tex $(TEXDEP) $(DBIB)/*bib
    pdflatex $(DOCNAME) && bibtex $(DOCNAME)

.PHONY: clean
    rm -f *.pdf *.bbl *.nlo *.nls

As can be seen, the current directory contains SI16-SC13B038.tex, which is the main tex file - there are other tex files in directories (stored in variables D1,D2,D3,D4) which are included in the main one. I am using the nomencl package for nomenclatures and natbib for the bibliography (the references are in the directory name stored in DBIB).

The issue I am having is that the make file does not seem to evaluate dependencies - how many ever times I invoke make all the operations are done. Something's wrong with the makefile - help me out!

  • 1
    I am not sure this is on topic but I think your dependency TEXDEP=$(DOCNAME).nlo should be TEXDEP=$(DOCNAME).nls as the nlo file is written out each time so newer than your source Jul 8, 2016 at 16:02
  • @DavidCarlisle: well, the nlo and bbl files dont belong in TEXDEP - that's redundant - it still doesn seem to work Jul 8, 2016 at 16:25
  • Possible duplicate of How to properly 'make' a latex project?, though with slightly other specifics that discourage merging. My answer has been tuned to this question, but I have left a link at the other one now.
    – ccorn
    Jul 9, 2016 at 2:54

1 Answer 1


As @DavidCarlisle has indicated, if a .nlo gets recreated with each run, this causes an update of the .nls target, then of the .pdf target. But then .nlo has been updated again, so the cycle repeats every time you invoke make. To overcome that, you'd use a checksum file instead of the .nlo dependency, and touch the checksum file only if the .nlo file contents have changed. Here is an untested Makefile fragment:

$(DOCNAME).nls: $(DOCNAME).nlo-stamp
        makeindex -s nomencl.ist -o $@ $(DOCNAME).nlo

$(DOCNAME).nlo-stamp: $(DOCNAME).nlo
        sha1sum $^ >$@2
        if cmp -s $@2 $@; then rm $@2; else mv -f $@2 $@; fi

Replace your rule for $(DOCNAME).nls with that.

Do not forget to append *.*-stamp *.*-stamp2 to the list of files to clean.

Note: If you copy-paste Makefile fragments, pipe them through unexpand to regenerate the TAB characters.

Instead of the above, I'd suggest using latexmk. It does such things properly and figures out all necessary program runs automatically.

With latexmk, a complete GNU Makefile generally looks like the following (just tune DOCNAME):

# Tools
LATEXMK = latexmk
RM = rm -f

# Project-specific settings
DOCNAME = basename-of-your-main-document

# Targets
all: doc
doc: pdf
pdf: $(DOCNAME).pdf

# Rules
%.pdf: %.tex
        $(LATEXMK) -pdf -M -MP -MF $*.d $*

        $(LATEXMK) -silent -c
        $(RM) *.bbl

clean: mostlyclean
        $(LATEXMK) -silent -C
        $(RM) *.run.xml *.synctex.gz
        $(RM) *.d

.PHONY: all clean doc mostlyclean pdf

# Include auto-generated dependencies
-include *.d

This keeps track of dependencies automatically. Even if only an installed and used package file has changed, make triggers recompilation.

This is almost perfect. Almost because if you shadow a texmf-dist package with a local one, the changed dependency path is not detected automatically. It will however be recorded with the next TeX run.

To get the custom index files processed, add a latexmkrc file:

add_cus_dep('nlo', 'nls', 0, 'makenlo2nls');
sub makenlo2nls {
    system( "makeindex -o \"$_[0].nls\" -s nomencl.ist \"$_[0].nlo\"" );

BibTeX processing should work without extra configuration.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.