Tzu ng
Tzu ng

Reputation: 9244

all target in Makefile

I'm learning using beautiful Linux tool : make. And there is something I want to understand:

Let's take a look at this simple example:

JADE = $(shell find pages/*.jade)
HTML = $(JADE:.jade=.html)

all: $(HTML)

%.html: %.jade
    jade < $< --path $< > $@

clean:
    rm -f $(HTML)

.PHONY: clean

When I run watch make , I really don't understand much the output string: make: Nothing to do with `all'.

Questions:

  1. What does the all action do ?
  2. Does the all action do anything with watch tool ?

Upvotes: 2

Views: 4291

Answers (1)

Daniel Roethlisberger
Daniel Roethlisberger

Reputation: 7058

The all target is really just the default target in the makefile you presented. The first target in the file is the default target, which is built when running make without specifying a target.

When make tells you that it has no work to do when building the all target, then it means that all the dependencies have been previously built and are up to date (i.e. none of their dependencies have been changed since last building them). In your case it means that the HTML output files are newer than the corresponding Jade input files. Thus there is nothing for make to do.

The watch utility just repeatedly runs a command for you to watch how its output changes over time. Watch will just run make every so many seconds and show the output. When it is run the first time, it will build everything, and all subsequent invocations of make by watch will say everything is up to date. So it really does not seem to be all that useful to run make within watch, unless you have something modifying the files at arbitrary points in time and you want to react by rebuilding them, but that seems to be a somewhat contrived example.

Upvotes: 4

Related Questions