In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
0. Statement
This series of articles (makefile), starting from zero foundation, gradually analyze the grammatical features of makefile through experiments, and finally create a reusable and portable professional compilation environment.
Reference:
1.DT teacher Tang Disciplinary Program
2.GNU make manual: http://www.gnu.org/software/make/manual/make.html
1.Make and makefileMake are an application that continues the dependencies between source programs, maintains compilation automatically according to dependencies, and executes various commands in the host operating system. Makefile is a description file: defines a series of rules to specify the order of source files after compilation, has specific syntax rules, supports function definitions and function calls, can directly integrate various commands of the operating system, and is essentially a script.
The relationship between the two: the description in Makefile is used to instruct the make program how to do its job; make executes the command according to the rules in Makefile, and finally completes the compilation output
Simple example: hello: / / Target echo "hello makefile" / / the command to be executed to achieve the goal, notice that the line begins with a table (\ t)
Make-f mf.txt hello / /-f specifies that the mf.txt file is the rule definition file (Makefile) and executes the hello target in the file
Make / / executes the default target (first target) in the default rule definition file (Makefile/makefile)
The meaning of 2.Makefile structure 2.1.Makefile:
Makefile is used to define source files and dependencies, explaining how to compile individual source files and generate executable files
Definition of dependency:
The meaning of the element in targets:prerequests; command1 Command22.2.Makefile:
Targets / / is usually the name of the target file to be generated and the name of the command to be executed by make
Prerequisite / / other targets or files on which the current goal depends
Command / / commands required to achieve the goal
2.3. Note: there can be multiple targets and dependencies. Using spaces to separate each command line must start with the [tab] character for high-speed make programs (parsers). On this line, a command line continuation character:\ can be written separately to the next line to improve readability. In Makefile, you can add the @ character before the command to make the command unechoed (Makefile prints every command executed by default).
Tips:
Developers can target both the executable file name and the all for the first rule in makefile, so that when the make command is executed and the target already exists, execution will not continue (unless the dependent file is updated) 2.4. Dependency rules:
When the file corresponding to the target does not exist, execute the corresponding command
When the dependency is newer than the target in time, execute the corresponding command
When a dependency occurs, compare each goal on the dependency chain
Hello.out all: func.o main.o gcc-o hello.out func.o main.ofunc.o: func.c gcc-ofunc.o-c func.cmain.o: main.c gcc-o main.o-c main.c
3. What is the goal of the introduction of pseudo-target into 3.1.Makefile?
By default, make believes that the target corresponds to a file, make compares the new and old relationships between the file and the dependency, and decides whether to execute the command or not, and make takes file processing as the first priority.
So when a file with the same name as the target appears, the target will not be executed on the premise that the file is not updated
Pseudo-targets in 3.2.Makefile
Declare a pseudo-target through the PHONY keyword, which does not correspond to any actual file, and the command is always executed regardless of whether the dependency of the pseudo-target is updated or not.
Pseudo-target syntax: declare first, then use
Essence: pseudo-targets are special goals in make: .PHONY dependencies
.PHONY: cleanclean: rm * .o hello.out-rf 3.3. The ingenious use of false targets:
Rule call to simulate the concept of C language functions.
Principle: when the dependency of a target contains a pseudo-target, the commands defined by the pseudo-target will always be executed.
.PHONY: rebuild clean allrebuild: clean allall: hello.outclean: rm * .o hello.out-rf 3.4. Bypass the .PHONY keyword to define a pseudo target
Principle: if a rule has no commands or dependencies, and its target is not an existing file name, the target will always be considered up-to-date when enforcing the rule.
Clean: FORCE rm * .o hello.out-rf FORCE:
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.