Skip to content

Add :: to rules in Makefile.common #178

@mandli

Description

@mandli

I ran into a case where I wanted to augment the clean and clobber targets in a local Makefile but did not want to either add to the SOURCE list or copy the entire rule into the local Makefile. I have found two solutions to this problem:

  1. An alternative that is used often for clean-like rules that allows for multiple definitions of a target, all of which are executed, using GNU Make :: syntax. This makes sense to me for the clean and clobber rules, but mixing : and :: does not work. I have not figure out how to override the :: rules if we do change this, i.e. what would you do if you wanted to really replace clean. I would suggest this would be unwise anyway, and renaming the target to myclean or something else hideous would still work. Example based on this stack exchange question:
    .
clean::
  -rm -f netcdf_test
clean::
  -rm -f xgeoclaw

is equivalent to

clean:
  -rm -f xgeoclaw
  -rm -f netcdf_test
  1. Another alternative is to recursively define the clean as is done in this stack exchange post. This will illicit warnings about overriding commands, but this happens for other cases anyway. Example:
clean:
  $(MAKE) -f Makefile.common $@
  -rm -f netcdf_test

with Makefile.common remaining the same.

I would propose that more generally adding :: to the Makefile.common would be a better, cleaner solution more generally. This would obviously require a minor change to Makefile.common and changes to any downstream Makefile that overrides the clean or clobber. In the meantime I am going to implement the second option, which does not require any changes but does throw warnings.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions