androidbuddy
androidbuddy

Reputation: 304

.PHONY in linux makefile

SUBDIRS = foo bar baz

.PHONY: dirs $(SUBDIRS)

dirs: $(SUBDIRS)

$(SUBDIRS):

@echo $@

@ls $@

Anybody can just help me out to understand this make-file? If possible explain me each statement (why do we need it?, what is the purpose? etc.)

And how exactly this make-file works?

Upvotes: 0

Views: 340

Answers (1)

keltar
keltar

Reputation: 18399

It have wrong formatting, so i can only guess what it was before... Well, so it is:

first line assignes list "foo bar baz" to variable named SUBDIRS

second line is special command that makes all specified targets 'phonetical' - you can invoke "make dirs" or "make foo", and it will find target with that name and execute it, but it's no actual file with this name (like usual non-phony targets)

third one - creates target named 'dirs' which depends on value of SUBDIRS variable. space-separated list. this target have no real actions

fourth line creates rules for SUBRIDS variable contents, with no dependencies. The rest of text is actions that have to be performed to 'make' this target (so, in your case - if you just call "make", it will call "make dirs" (because it's the first target), which depends on foo, bar and baz - so these targets will be invoked. to perform each of these targets, make will call echo and ls - so eventually you'll get these three directory names and list of their files)

Upvotes: 1

Related Questions