131 Week 12 - Build Automation Flashcards
Build automation systems
Automate the process of compiling source code (from multiple source files) into binary executable code
Build script generation tools
Generate files for build automation systems.
Do not build executable code directly.
Users can set up a high-level configuration and generate build scripts for a specific operating system.
Need for build automation systems
Build automation is crucial for collaboration and faster compilation through incremental builds.
Make
Build automation system reads a script, called makefile.
Makefile
The project structure (e.g., files and dependencies between files).
Instructions for the creation of binary files (e.g., object files and executable files).
Makefile target
Is the name for the ACTIONS that follow the target.
Can be a filename, variable or string.
To execute the actions of target targetName, type:
“make targetName”
Makefile dependencies
A list of the requirements for a target such as filenames or other targets.
If target and the dependencies are filenames, their timestamps are compared, and if the target does not exist or if it is older than the dependencies, the actions are executed only .
If a dependency is the name of another target , control will descend to the actions of the other target.
Makefile actions
Shell commands that are executed when “make targetName” is run.
Use tab to indent an action.
backslash can be used to split an action over multiple lines
Makefile rule
Formed of the target, dependencies and actions.
A rule contains the actions to meet a target when the dependencies are fulfilled.
Makefile variables
Variables are defined using variableName = variableContent.
Variables are used by starting with a dollar sign and then including the variable name in brackets. E.g.,
CC = gcc
$(CC) code.c -o code
Automatic variables
$@ - The filename of the target.
$* - The filename of the target without the file extension.
$^ - The filenames of all dependencies.
$< - The filename of the first dependency.
$? - The filenames of all dependencies that are newer than the target.
Pattern matching character
If you have 2 rules with the same action for different filenames you can use the pattern matching character % which matches a dependency filename without the extension.
e.g.,
%.o: %.c mylib.h
gcc -c $< -o $@
Phony targets
Targets that do not represent filenames but are instead names that are always treated as out of date so will always run.
Common examples are “all” and “clean”.
all establishes a default rule which will be run if just make is typed instead of a specified rule.
clean is often used to remove files.