A GNU Make Tutorial


Make uses instructions found in a file named makefile or Makefile to determine what actions to take in order to satisfy some requirement. A simple makefile consists of "rules" or "recipes" that describe how to create a particular target. Each rule has the following shape:
	target... : dependencies ...
A target may be either a file to be generated by make or an identifier for an action to be carried out. Make determines that it needs to build a target if one or more dependencies have changed since the target was last built.

A command is an action that make carries out. A rule may have more than one command, each on its own line. Please note: Each command line must begin with a tab character.

Usually a command is in a rule with dependencies and serves to create a target file if any of the dependencies change. However, the rule that specifies commands for the target need not have dependencies.

Rules may form a chain of dependencies. That is, the target to be created may depend on files which themselves need to be created. If another rule specifies how to create it, make will automatically invoke that rule to create the needed file. In this way long chains of dependencies may be created. The following is a somewhat fanciful makefile for baking a cake that shows how dependencies are created.

cake:	cake_mix eggs water icing
	mix cake_mix eggs water
	bake cake
	cool cake
	apply_icing cake icing
cake_mix:	money
	buy cake_mix

money:	job
	go to work
job:	...

[Previous] [Next] [Tutorial Index] [GNU Make]

Copyright 1996 by Byron Weber Becker