Makefiles are collaborations between Make and Bash
Every command line must start with a single tab
missing separator errorThe general structure of a makefile revolves and rules:
target: dependencies
system_commandThe target is the literal file you want the computer to target
If a file with the target filename is found in the filesystem, Make looks at the dependencies
The first target in the file is the default
You can specify a target by running make target_name
target_name: dependencies
\t commandsFor some reason I can't get my tabs working inside of the source-block, so I used i͡nstead.
If you just want Make to run terminal commands and not create any files, you create a phony target
.PHONY nameWe use single dollar signs to represent Makefile variables (as opposed to bash variables) or call built-in Make functions
$(MAKE) runs the command make
When evaluating a target, make will jump down to its dependencies, if they exist
$@ Is shorthand for the name of the
current target
% is a wildcard
$*@ tells Make to not echo the command
text you wrote
echo "hello world",
Make will printecho "hello world"
hello world
:= declares a variable by evaluating
the right side immediately
= declares a variable, but it doesn't
evaluate the right side until the variable is actually used in a
command
Bash shell variables are denoted with two dollar signs:
$$variable
$$var
$$name> overwrite redirect >> append redirect
Bash uses semicolons but Make doesn't. This can lead to some oddness in makefiles — you have to be clear on where semicolons are necessary and where they aren't.
Bash uses semicolons as a newline symbol
You can't put comments inside of multiline commands being sent to bash
Make tries to execute every single line as a separate shell command, executed in a separate isolated subshell
To keep multiple lines inside of the same shell (like when doing a for loop) we use
\ to tell us that the end of the
current line isn't the end of what to send to this shell
NOTE: when we use \ Make appends the
next line to the end of the current one
Directories are a bit special when it comes to Make
Changing the content of a file contained in a directory doesn't change its name or pointer, and so doesn't alter the directory's text file or its time stamp