Porcupine
Porcupine

Reputation: 6475

Unable to do make clean despite .PHONY

I have created a Makefile, to convert markdown to other formats. I have used .PHONY: clean but I am still unable to do make clean. It searches for clean.md file. I know its because of $(MAKECMDGOALS) but I need it to convert just one file.

SOURCE= $(wildcard *.md)
## Pattern Substitution
HTML=$(SOURCE:.md=.gen.html) 
PDF=$(SOURCE:.md=.gen.pdf) 

## Targets and dependencies
.PHONY: all
all : $(HTML) $(PDF)

html:   clean $(HTML)
pdf:    clean $(PDF)

.PHONY: clean
clean:
    - $(RM) -f *.gen.*

.PHONY: $(MAKECMDGOALS)
$(MAKECMDGOALS): $(MAKECMDGOALS:%=%.html) $(MAKECMDGOALS:%=%.gen.pdf)

%.gen.html : %.md
    $(PANDOC) $(PANDOC_OPTIONS) $(PANDOC_HTML_OPTIONS) -o $@ $<

%.gen.pdf : %.md
    $(PANDOC) $(PANDOC_OPTIONS) $(PANDOC_PDF_OPTIONS) -o $@ $<

Please suggest changes.

Upvotes: 0

Views: 144

Answers (1)

Alex Cohn
Alex Cohn

Reputation: 57163

GOALS := $(filter-out clean, $(MAKECMDGOALS))

.PHONY: $(GOALS)
$(GOALS): $(GOALS:%=%.html) $(GOALS:%=%.gen.pdf)

Upvotes: 2

Related Questions