1 Introduction
GNU make is a utility software that automatically constructs software by reading files called makefile. It is a tool used to convert files. The conversion target is called "target". At the same time, it also checks the file dependency. If necessary, it calls some external software to complete the task. Its Dependency check system is very simple, mainly based on the dependent file modification time. In most cases, it is used to compile the source code, generate the result code, and then connect the result code to generate executable files or library files. It uses a file named "makefile" to determine the dependency of a target file, and then sends the command for generating this target to shell for execution.
Ii. Make command
Make: by default, makefile or makefile is used for compilation.
Make-f [makefile_name]: explicitly specifies the name of The makefile.
Three makefile details the MAKEFILE file consists of one or more rules.
3.1 rules
The rule is used to describe how to generate one or more target files.
Makefile example:
hello: main.o func1.o func2.o gcc main.o func1.o func2.o -o hellomain.o: main.c gcc -c main.cfunc1.o: func1.c gcc -c func1.cfunc2.o: func2.c gcc -c func2.c.PHONY: cleanclean: rm -f hello main.o func1.o func2.o
The first two rows are a rule. The basic form is as follows:
Target: Dependent commands
That is:
targest : prerequisites command
Note: The command must start with the tab key.
3.2 Variables
The usage of variables is similar to that of shell scripts:
obj=main.o func1.o func2.o func3.ohello:$(obj) gcc $(obj) -o hello
The benefit of using variables is maintainability.
3.3 default Variables
The default variables are as follows:
$ ^: Indicates all dependent files.
$ @: Indicates the target
$ <: Indicates the first dependent file.
Use default variables:
obj=main.o func1.o func2.o func3.ohello:$(obj) gcc $^ -o $@
3.4 Miscellaneous
1. # post-Annotation
2. The command must start with the tab key.
3. Add @ before the command to cancel the screen echo.
#makefile of helloobj=main.o func1.o func2.o func3.ohello:$(obj) @gcc $^ -o $@