Wednesday, 12 August 2015

Make: Phony Targets

Cited from Phony Targets

"A phony target should not be a prerequisite of a real target file; if it is, its recipe will be run every time make goes to update that file. As long as a phony target is never a prerequisite of a real target, the phony target recipe will be executed only when the phony target is a specified goal."

For example, the phony target of "clean" is a not specified goal, and therefore not executed.

din:=/home/cornell/

.PHONY : listfile clean

listfile: $(din)
    ls -lt $^

clean :
    -rm ./test/test.txt

Phony targets can have prerequisites. For example, when the prerequisites are individual programs, the call to an overall phony target will cause the execution of individual programs.

For example, both rules of action1 and action2 will be executed.

d1:=/home/cornell/
d2:=/home/cornell/test

all: action1 action2
.PHONY : all

action1: $(d1)
    ls -lt $^

action2: $(d2)
    rm -rf $^

No comments:

Post a Comment