Hacker News .hnnew | past | comments | ask | show | jobs | submitlogin

Consolidation of .PHONY targets is an anti-feature, the .PHONY decl is supposed to be adjacent to its target...


Possible opinion detected. Explain why.


Look at https://github.com/EbodShojaei/bake#basic-formatting. It starts with a horribly contrived example¹ including this²:

  .PHONY: clean
  all: $(TARGET)
      $(CC) $(CFLAGS) -o $@ $^

  .PHONY: install
  clean:
      rm -f *.o
And changes it to this with a consolidated .PHONY, but still no install target. Surely it should complain “there is no install target, what are you marking it as phoney³ for?”

  .PHONY: all clean install

  all: $(TARGET)
      $(CC) $(CFLAGS) -o $@ $^

  clean:
      rm -f *.o
I will not say that this way of writing it is unreasonable; users unfamiliar with the available targets can benefit from such a thing up the top (though in practice there’s normally a block of other stuff first, and other ways of achieving it). But this is also a reasonable way of writing it, with strong advantages of its own:

  .PHONY: all
  all: $(TARGET)
      $(CC) $(CFLAGS) -o $@ $^

  .PHONY: clean
  clean:
      rm -f *.o

  .PHONY: install
  # Um… where’s the `install:` line?
Treating .PHONY as more an inline attribute like this rather than a target of its own makes it much more obvious that the install target is missing, and makes desynchronisation of .PHONY and the actual targets much less likely.

—⁂—

¹ The first atrocity is that it’s not even a legal makefile: barring a .RECIPEPREFIX override, recipes must be indented by one tab. Running make with this file produces “Makefile:10: ** missing separator. Stop.” Taking invalid code and making it valid is not the domain of a linter or formatter. The Markdown is also abysmal because it doesn’t use tabs, but rather a single space in the output. Given that tabs are structural in makefiles, this is an astonishing lapse.

The second atrocity is the mismatching of .PHONY targets, despite joining the lines (by not having a blank line after the .PHONY line), which is completely unrealistic. Or at least I find it so.

² I have normalised whitespace so we can focus on the .PHONY changes. Assume tabs are where they need to be. Unfortunately HN hates interesting whitespace.

³ Ah, the number of times I’ve written .PHONEY… stupid americentric software.


Thanks for taking the time ! I had to write some demos out to test, but you are thoroughly correct.




Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: