"No target" error using Make

Problem:

You problem is that make doesn't know about your targets.

You can run your above Makefile with make stackoverflow.markdown for example and it will work.

make only, however, will fail, since you only specified how to create your targets, but not which.

As leiaz point's out the above pattern rule is called an implicit rule.

Makefile:

SRC = $(wildcard *.html)
TAR = $(SRC:.html=.markdown)

.PHONY: all clean

all: $(TAR)

%.markdown: %.html
    pandoc -o $< $@

clean:
    rm -f $(TAR)

Explanation:

SRC get's all source files (those ending in .html) via Makefile's wildcard.

TAR substitutes each source file listed in SRC with a target ending with .markdown instead of .html.

.PHONY lists non-physical targets that are always out-of-date and are therefore always executed - these are often all and clean.

The target all has as dependency (files listed on the right side of the :) all *.markdown files. This means all these targets are executed.

%.markdown: %.html
    pandoc -o $< $@

This snippet says: Each target ending with .markdown is depended on a file with the same name, except that the dependency is ending with .html. The wildcard % is to be seen as a * like in shell. The % on the right side, however, is compared to the match on the left side. Source.

Note that the whitespace sequence infront of pandoc is a TAB, since make defines that as a standard.

Finally, the phony clean target depicts how to clean your system from the files you've created with this Makefile. In this case, it's deleting all targets (those files that were named *.markdown.


Pattern rules are implicit rules.

You have no targets defined in your Makefile. You can specify the target on the command line : make something.markdown will use the recipe to create something.markdown from something.html.

Or you can add to your Makefile a rule specifying default targets.

all: file1.markdown file2.markdown

Or with a wildcard :

all: *.markdown

When you run just make, the first target of the first rule is the default goal. It doesn't need to be called all.

So above, the target all have all the files you want to make as prerequisites, so when you make all, it will make all the listed files.

Tags:

Make