I am trying to modify the AOSP build system to run a script after 'make dist'
I have code that does what I want it to.... but I don't really understand it and would love an explanation and what is happening. The file I am looking at is:
https://android.googlesource.com/platform/build.git/+/master/core/distdir.mk
.PHONY: dist
dist: ;
dist_goal := $(strip $(filter dist,$(MAKECMDGOALS)))
MAKECMDGOALS := $(strip $(filter-out dist,$(MAKECMDGOALS)))
ifeq (,$(strip $(filter-out $(INTERNAL_MODIFIER_TARGETS),$(MAKECMDGOALS))))
# The commandline was something like "make dist" or "make dist showcommands".
# Add a dependency on a real target.
dist: $(DEFAULT_GOAL)
endif
The part that is confusing me is how there are two definitions for dist: but no warnings. If I had a recipe on to the second dist: target it will generate a warning about dist being redefined. What is the point of this second target?
dist: ;
just says, "to update dist
target, do nothing". Without this, if the second part were not present, Make would not know what how to make dist
. (In fact the "empty recipe" here ;
is not really needed - it is only needed for specific situations, and this is not one of them - without it, you would still be doing "nothing" here)
If the second part is present:
dist: $(DEFAULT_GOAL)
that means, "to update dist
target, update $(DEFAULT_GOAL)
If both parts are present, we update $(DEFAULT_GOAL)
and then do nothing more.
In general, you can have one explicit rule for a target with a recipe present (here, the recipe is just ;
), and then you can have other rules without recipes, they just establish additional dependencies as they are noted. There is no ambiguity which recipe to execute and Make is happy.