LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   .PHONY in makefile (https://www.linuxquestions.org/questions/linux-newbie-8/phony-in-makefile-4175433982/)

rambolinuxbuddy 10-25-2012 03:14 AM

.PHONY in makefile
 
hello all,

SUBDIRS = foo bar baz

.PHONY: dirs $(SUBDIRS)

dirs: $(SUBDIRS)

$(SUBDIRS):
@echo $@
@ls $@

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

and how exactly this make-file works?

pan64 10-25-2012 04:56 AM

http://www.gnu.org/software/make/man...y-Targets.html

rambolinuxbuddy 10-25-2012 05:23 AM

I had that link already.
anyways I tried it with myself and I found out the solution how exactly it works.

---------- Post added 10-25-12 at 05:24 AM ----------

explanation of code is as below:-

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)


All times are GMT -5. The time now is 05:29 AM.