>_ IzzyLab

Hands-on task

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

Default target and dependencies

medium~7 min

In /root/proj, write a Makefile with an all target that depends on two other targets — foo and bar. The foo target must create a file foo.out containing the word foo, and the bar target a file bar.out containing the word bar. The all target does nothing itself — it just pulls in both. Running bare make (with no arguments) must build both files. The Makefile is handy to write in the Editor tab above the terminal: in a Makefile it puts a real TAB at the start of a recipe line.

What you'll practise:
  • make
  • default target
  • dependencies
  • makefile
  • build order

Topic breakdown

The first target in a Makefile is the default target: it's exactly what bare make builds with no arguments. Dependencies are listed after the colon (target: dep1 dep2) — before tackling the target itself, make recursively builds everything it depends on. This way an "aggregating" target with no recipe of its own can simply pull in other targets, each with its own recipe (with the mandatory TAB).

What's checked

  1. make builds foo.out and bar.out

What it looks like