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
- Targets are file names, separated by spaces. Typically, only one per rule.
- Commands are a series of steps used to make the targets. They MUST start with the tab character, not spaces.
- Prerequisites are also space separated file names. These are files that need to exist before this target is run. Otherwise known as dependencies
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