Quick post on Make tool
Make Tool
Introduction
If you've ever installed software for a Unix-based system by compiling from source, you would have run commands such as 'make compile'. Make is a build automation tool that automatically builds executable programs and libraries from source code by reading files called Makefiles.
Let's look at how it works.
Simple Example
Here are the key points:
- We start by creating a 'Makefile' in the directory.
- A Makefile has recipes that use the prerequisites to make the target.
target: prerequisites<TAB> recipe
We can run the 'makefile' by running the 'make' command at the command line. The make command runs the default target which is also called the 'default goal'.
The prerequisites can be files or just a name for recipes, in which case they are called "phony targets".
A few more points to keep in mind:
- As we can see from the example in fig. 1, the recipe, 'echo "Hello, World!"' is included in the output, we can use the '@' operator to prevent that.
- Normally, if we have multiple targets, only the first target is executed as the default. We can change it by including the '.DEFAULT_GOAL := <target>' on the first line of code.
- The other way to override this behavior and run all targets is to include 'all: <name of all targets>' on the first line.
- We can set variables by using the ':=' operator (e.g. CC = gcc) and to use it use the ${} operators (e.g. ${CC} -c make). ':=' is also called as the simply expanded variable.
Full example
---
Sources:
[1] https://opensource.com/article/18/8/what-how-makefile
[2] https://www.gnu.org/software/make/
Comments
Post a Comment