An Introduction to Makefiles

What does a makefile tell make?
A makefile tells make how to compile and link a program.

What does a simple makefile consist of?
A simple makefile consists of rules.

What is a rule in a makefile?
In a makefile, a rule is a description of how and when to remake certain files which are the targets of a particular rule.

What does a rule look like?
A rule looks like this:

target(s) ... : prerequisite(s) ...
	recipe(s)
	...
	...

What is a target?
A target is the name of a file to be generated or the name of an action to carry out.

What is a prerequisite?
A prerequisite is a file that's used as input to create a target.

What is a recipe?
The recipe is an action that make carries out.

What do you need to put at the beginning of every recipe line?
You need to put a tab at the beginning of every recipe line?

What can you do if you want to use a different prefix other than tab for recipes?
If you want to use a different prefix other than tab for recipes, set the .RECIPEPREFIX variable to an alternate character.

make carries out the ... on the prerequisites to create or update the ...
make carries out the recipes on the prerequisites to create or update the target.

How do you split lines in a makefile?
To split lines in a makefile, put a backslash at the end.

What does make not know anything about when it comes to recipes?
When it comes to recipes, make does not know anything about how the recipes work.

What is your responsibility in writing recipes for make?
Your responsibility in writing recipes for make is to write the recipes that will update the target file properly.

What are targets which don't refer to actual files called?
Targets which don't refer to actual files are called phony targets.

Which target does make start with by default?
By default, make starts with the first target written even if it's in a series of targets.

What is the target that make starts with also called?
The target that make starts with is also called the default goal.

make doesn't start with targets beginning with ... unless they also contain one or more ...
make doesn't start with targets beginning with . unless they also contain one or more /.

What are goals?
Goals are targets that make strives to ultimately update.

What are the two ways you can override the default goal in make?
The two ways you can override the default goal in make are:

  1. Writing the name of the target as an argument.
  2. Setting the value of the .DEFAULT_GOAL variable.

What must make do before it can fully process a rule?
Before make can fully process a rule, it must process the rules for the prerequisites.

When does make run the recipe to regenerate a target?
make will regenerate or recompile a target if the file doesn't exist or if its prerequisite files are newer than it.

...