Nat's Garden

Make

Makefiles help decide which parts of a large program need to be compiled. In general, it is a system used to run instructions depending on what files have changed in a project.

File Structure

targets: prerequisites
	command
	command
	command

As a quick example:

#main.cpp
#include <iostream>
int main(){
	std::cout << "Hello world!";
}
main: main.cpp
	g++ main.cpp -o main

Here, this target will only run when the file main does not exist OR if main.cpp is newer than main, since main.cpp is a dependency of main.

Make uses the filesystem timestamps to determine if a file has been changed. This is often correct, but sometimes... not so correct.

When just running the command make, it will always run the first target in the file. You can specify targets by passing its name: make <target name>.

Variables

Variables can only be strings

Targets

Wildcards

Examples

#programming