Using a make rule to call another

make

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?

Best Answer

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).

Related Question