How to ensure a target is run before all the other build rules in a makefile?

If you’re sure that’s really what you want, here’s one way to do it: have a rule for a dummy file which the makefile will include.

.PHONY: dummy
dummy:
    # generate the file here

-include dummy

No matter what target you specify, Make will first run the dummy rule, then restart itself.

Leave a Comment