>_ IzzyLab

Hands-on task

This task is step 7 of the course “Make: builds and automation”

Concatenate dependencies via $^

medium~7 min

In /root/proj there are a.txt, b.txt, c.txt. Write a Makefile with a bundle target that depends on all three and concatenates them into a single file bundle in the same order. In the recipe use the automatic variable $^ (the list of all dependencies) instead of listing the names by hand.

What you'll practise:
  • make
  • automatic variables
  • $^
  • target dependencies

Topic breakdown

make's automatic variables substitute parts of the rule itself into the recipe, saving you from duplicating names. $@ is the target name, $< is the first dependency, and $^ is the full list of dependencies, space-separated, in the order they are listed. Relying on $^, the recipe always works with exactly the set of files specified in the prerequisites: change the dependency list and the recipe adapts on its own.

What's checked

  1. bundle is the concatenation of the three files in order
  2. the recipe takes the dependency list from $^

What it looks like