12

I am writing a LaTeX project that I am using a makefile for. I have a clean function to clean the excess LaTeX files:

.PHONY: clean
clean:
    \rm *.aux *.blg *.out *.bbl *.log

But in some cases I need to get rid of the generated files as well as the PDF file. I have attempted this using:

.PHONY: clean_all
clean_all:
        $(clean) \rm *.pdf

This does not work as it only removes the PDF file.

My question is how do I invoke the clean rule inside the clean_all rule?

1

1 Answer 1

15

Make the clean_all target depending on clean target:

.PHONY: clean_all clean

clean:
        rm -f *.aux *.blg *.out *.bbl *.log

clean_all: clean
        rm -f *.pdf

I added the -f to rm so that non-existing files do not generate an error in the rules (e.g. when you would run the command twice).

(BTW, I never heard of these rules being talked about as functions, you might want to recheck your terminology and have more success while Googling things about makefiles).

7
  • I called rules functions as I am new to makefiles and I am used to using the word. I have changed the title to accommodate your note. Although this corrects my problem, the PDF file is a dependency of the rule that produces it so it is not removed anyway. Commented Apr 12, 2014 at 11:56
  • @user133987 No problem about the functions/rules, just wanted to make sure you pick up the more common terminology. I updated the answer, because it still had $(clean) in it and the ` (why where those there?). Invoking make clean_all` should both remove the .pdf and the others.
    – Anthon
    Commented Apr 12, 2014 at 12:46
  • Unfortunately, this still does not remove the PDF file. I used the $(clean) as I thought that It might be like scripting, where I you call a function (but I see now that you put it as a dependency). Would it help if I added in the entire source of my makefile? Commented Apr 12, 2014 at 13:13
  • @user133987 The full Makefile can help, but more important is if there are any error messages. If e.g. there are no .blg file you will get a "No such file or directory". You can prevent that with the -f option to rm
    – Anthon
    Commented Apr 12, 2014 at 14:09
  • 1
    @baxx just put multiple targets on the first line separated by spaces( clean: clean1 clean2)
    – Anthon
    Commented Feb 16, 2020 at 12:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .