1

In my current setting, I have some .mk that are automatically generated, over which I have no control. One of the rules defined in these files is clean.

The part of the code I am working on uses include to access variables from those .mk files. However, I'd like to have another rule clean to remove the files generated in the folder I am working on.

If I create a rule named clean, I get the warning

warning: overriding commands for target

Is there a way to "extend" clean, i.e., o make it run both the clean defined in those .mk files and my own clean?

Of course, I could create another rule other_clean and call the old clean. Or also I could do something like:

other_clean:
    make clean
    rm *.o

But I'd like to know if there is any functionality in make that allows me to "inherit" the recipe defined elsewhere into my own clean. I saw there are these things called double-colon rules, but I can't use them because the files I am including are automatically generated.

Community
  • 1
  • 1
vaulttech
  • 493
  • 1
  • 5
  • 15
  • You've already discovered double colon rules but if you can't change the file then that's moot, just define a different name (remember to make it `.PHONY`), and have it depend on `clean`, i.e `other_clean: clean`. – user657267 Feb 11 '16 at 18:04
  • Actually... the question was more out of curiosity, to know if there was anything that I was missing that did the job exactly in the way I wanted (i.e., using the name "clean"). After all, it feels more elegant to remember "clean" than to remember any other name that I may, in the far future, forget. – vaulttech Feb 15 '16 at 13:37
  • 1
    There is one other way but it still involves changing the original recipe: say the `clean` recipe is defined as `clean: ; rm whatever.foo`, if you change this to `clean: ; rm $(stuff_to_clean)` you can then provide target-specific variable overrides later on such as `clean: stuff_to_clean += some_other_file.foo`, as long as only a single definition of the `clean` rule contains recipes this is fine. – user657267 Feb 16 '16 at 03:48
  • I think you should investigate the double-colon rule: http://owen.sj.ca.us/~rk/howto/slides/make/slides/makecolon.html – Frizlab Sep 26 '16 at 23:43

0 Answers0