Link Search Menu Expand Document

Makefile

Makefile stores commands like that in Bash script. The difference is that Makefile has no the executing order we should treat it as a general principle sets where we can find several commands, called target. See GNU manual for more.


What’s Makefile ?

The make utility automatically determines which pieces of a large program need to be recompiled, and issues commands to recompile them. Makefiles contain five kinds of things: explicit rules, implicit rules, variable definitions, directives, and comments. – GNU

What’s inside a Makefile ?

target

A target could be a file generated by the program or an action. The latter is also called Phony Target. We can use .PHONY to differenciate them.

.PHONY: clean fclean all re

rule

rule is the key part of Makefile.

# a rule look like this:
targets : prerequisites
        recipe

implicit rule

Sometimes, we don’t provide a rule for a target, and Makefile will find a implicit rule for it. The most used example is object file like foo.o from foo.c. Normally, foo.o is made automatically from foo.c with a recipe of the form ‘$(CC) $(CPPFLAGS) $(CFLAGS) -c’.

How to use it ?

After a Makefile is prepared, we simply tape make in command line to activate the default command.


Post creation time: 2019-06-20

Copyright © 2018-2021 Zemin XU.