>_ IzzyLab

Hands-on task

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

A variable in a Makefile

easy~5 min

In /root/proj there is src.txt. Write a Makefile where the name of the result is set by a variable OUT with the value result, and the build target copies src.txt into a file whose name is taken from this variable — $(OUT). After make build a result file should appear — a copy of src.txt.

What you'll practise:
  • make
  • make variables
  • variable substitution
  • targets and recipes

Topic breakdown

Variables in a Makefile are declared as NAME = value and expanded via $(NAME) — the parentheses are mandatory. The point is to pull a repeated value (an artifact name, compiler flags, paths) into a single place, so you change it in one spot rather than throughout the file. In a target's recipe the substitution $(...) is expanded before the command is executed.

What's checked

  1. make build creates result from src.txt
  2. result name is set by the OUT variable

What it looks like