I was working on cleaning up our on-device test runs last week, and as
a result I needed to update a lot of test Makefiles in the Swift
tree. I found it especailly annoying to update the build system of
tests that are building mutliple images (typically a shared
The main reason is that you can't see what's (if anything) special
about the build from the main makefile. You always need to open
mutliple Makefiles. Another reason is the way you have to add a
special line to your clean rule to do the right thing, and you never
really know which arguments to pass.
Most of the secondary Makefiles we have are just a couple variable
definitions and then an include of Makefile.rules. This patch removes
most of the secondary Makefiles and replaces them with a direct
invocation of Makefile.rules in the main Makefile. The specificities
of each sub-build are listed right there on the recursive $(MAKE)
call. All the variables that matter are being passed automagically by
make as they have been passed on the command line. The only things you
need to specify are the variables customizating the Makefile.rules
logic for each image.
This patch also deals with the clean rules using this trick to avoid
having to duplicate the recursive invocation in a separate clean rule:
$(MAKE) -f $(MAKEFILE_RULES) ... $(MAKECMDGOALS)
The MAKECMDGOALS variable at the end contains the list of build goals
that have been passed on the command line. When it's empty, this
invocation just calls the default Makefile.rules rule which is what
you want. When "clean" is passed as a goal, the rule will be invoked
too and it is passed through MAKECMDGOALS invoking the appropriate
cleaning logic from Makefile.rules.
I really like the conciseness of this approach and the fact that
everything is visible in one place. What do others think?