Find the answer to your Linux question:
Results 1 to 2 of 2
hello all, Code: 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 ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Aug 2012
    Posts
    28

    .PHONY in makefile


    hello all,
    Code:
    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?

  2. #2
    Just Joined!
    Join Date
    Aug 2012
    Posts
    28
    I found the solution by myself.

    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)

    for more info visit Phony Targets - GNU `make'

    and if you have any double feel free to ask me.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •