Wednesday, February 25, 2015

Getting File Basebase without Extension in GNU Makefile

Sometimes we would like to write a generic rule in GNU makefiles.

For instance, we would like to write a rule to process a LaTex file and then process BibTex entries for any LaTeX files. We can write the rule as follows,


%.dvi: %.tex
    latex $<
    bibtex $(basename $<)
    latex $<
    latex $<

In the example, if we issue a command make example.tex, the value of $< is example.tex while $(basename $<) yields the basename without the extension. The basename without the extension is required for bibtex to work in this example.

This solution is provided by the discussion here.

1 comment: