Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8282679
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T10:27:22+00:00 2026-06-08T10:27:22+00:00

I still don’t understand why phony rules in Makefiles have .PHONY as their target

  • 0

I still don’t understand why “phony” rules in Makefiles have “.PHONY” as their target. It would be much more logical as a prerequisite.

Do I have to elaborate on this? If A depends on B and B is phony, then A is phony too. So the dependency graph .PHONY←B→A is waay surprising compared to .PHONY→B→A. (Another argument is that an implementation of make must handle the .PHONY target very special.)

While this critique may seem rather theoretical (to pointless) – “since make is so ancient, its syntax is here to stay”. But I am not proposing any syntax change, there is an alternative:

With GNU Make (at least), the following Makefile declares a phony target_A:

target_A: _PHONY
        touch target_A

_PHONY:
        #noop

Question 1: This is so simple and clean, surely I am not its first inventor. In fact, given this alternative, why did make ever need the special syntax?

It seems to me that this would also quite nicely solve questions about wildcards in phony targets, and could even shed some light on .PHONY’s meaning when beginners doubt.

Question 2: Can you think of any circumstance where this approach is inferior? (Is invoking make .PHONY of any use?)

(I should mention that while I have invoked other makes, GNU Make is the only implementation that I have some experience with – reading and writing Makefiles.)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T10:27:24+00:00Added an answer on June 8, 2026 at 10:27 am

    One big problem with using target_A: .PHONY is that it makes it much harder to use many of make’s built-in variables. Take this common recipe as an example:

    %.a: $(OBJ_FILES)
        $(LD) $(LFLAGS) -o $@ $^
    

    The $^ variable pulls in everything that’s listed as a prerequisite. If .PHONY was also listed there then it would be passed to the linker on the command-line, which would probably not result in anything good happening. Using meta-targets like .PHONY as prerequisites makes these built-in variables significantly less useful, as they require a lot of extra processing like $(filter-out .PHONY,$^) every time they are used. Inverting the relationship and instead making .PHONY the target is a bit awkward for the sake of thinking about dependency trees, but it cleans up the rest of the makefile.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have read the documentation for the CI Caching but still don't understand much
I have a doubt here where after so much explainations I still don't really
I have been using Clojure alot recently but I still don't understand what functionality
I always have problems with the function live() and I still don't understand how
I have read the documentation, but I still don't understand which classloader I should
As much I would like to I still don't know how to implement metaprogramming.
I have looked at this question but still don't understand the difference between Iterable
That's an issue I still don't understand. Sometimes I have to write: NSString* myVariable;
Something I still don't understand when performing an http-get request to the server is
Been looking through other answers and I still don't understand the modulo for negative

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.