3

I'm looking through the CyanogenMod code to try to get a device running the latest version. In the build/core/binary.mk Makefile, there is a rule that looks like this:

$(gen_c_objects): $(intermediates)/%.o: $(intermediates)/%.c $(yacc_cpps) $(proto_generated_headers) \
$(LOCAL_ADDITIONAL_DEPENDENCIES) \
| $(my_compiler_dependencies)
    $(transform-$(PRIVATE_HOST)c-to-o)

Although I'm pretty new to Makefiles, I've never seen a rule of the form A: B: C. I thought it initially meant that C is the prerequisites list (both normal and order-only prereqs) for targets B, and the targets of B are the prerequisites for A, but I realized this couldn't be the case since (I don't think) Make does not have some implicit rules for generating .o files from other .o files.

What does this syntax mean?

Alex W
  • 410
  • 5
  • 11

1 Answers1

3

As stated in my comment on this question's opener, I found my answer shortly after asking the question. This syntax is documented on GNUMake's documentation as a static pattern rule.

Basically, the syntax is of the form

target: target-pattern: prerequisites-patterns

For each target, the target-pattern (the B section) gets applied to the target. The target-pattern should include 1 '%' character to match a substring in the target's name. The other characters in the target-pattern are used to match themselves in the target. The matched substring for '%' (known as the stem) will be used to replace occurrences of non-escaped '%' characters in the prerequisites' patterns. To build on an example from the GNUMake documentation...

s.foo.o: s.%.o: %.c s.%.c

In this case, the target s.foo.o will have the pattern s.%.c applied to it. This means the stem will be set to "foo". Subsequently, the stem is substituted into the prerequisites list to generate the prerequisites: foo.c and s.foo.c. The above syntax becomes equivalent to:

s.foo.o: foo.c s.foo.c
Alex W
  • 410
  • 5
  • 11