In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
What exactly is the goal in the makefile we learned before? By default: a > make thinks that the target corresponds to a file; b > make compares the old and new relationships between the target file and the dependent file to decide whether to execute the command; c > make takes file processing as the first priority. So what's the point of the following code? Let's take the code as an example to illustrate that func.c and main.c are still used in the previous blog.
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.cclean: rm * .o hello.out
Let's look at the effect before and after make.
We see that the goal of clean has been successfully implemented, so let's create a clean file in the folder and take a look.
When we see the make clean command executed again, it says that clean is up-to-date and does not execute the command. The reason is that there is a file with the same name in the folder, and when it is executed, it finds that the file exists and is updated in time, so it will not execute the command. So is there any way to solve this problem? In makefile, there is the concept of a pseudo-target: a > declare a pseudo-target through the .PHONY keyword; b > the pseudo-target does not correspond to any actual file; c > the command is always executed regardless of whether the dependency of the pseudo-target is updated or not. The syntax of a pseudo-target is to declare first and then execute. Its essence is the dependence of the special goal in make. PHONY.
Let's take the code as an example to see how pseudo targets are used.
Let's take a look at the compilation effect.
We see that makefile can always implement the goal of clean with or without a clean file. Let's take a look at the magic use of pseudo-targets: rule calls (similar to function calls in C). Its principle is that when the dependency of a target contains a pseudo-target, the commands defined by the pseudo-target will always be executed.
Let's take the code as an example.
Hello.out: 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.PHONY: rebuild clean allrebuild: clean allall: hello.outclean: rm * .o hello.out
Let's analyze that the pseudo-target rebuild depends on clean and all. While clean deletes the generated .o and hello.out files, all depends on hello.out. In other words, the role of rebuild is equivalent to recompilation, and then compile again after cleaning up. Come down. Let's see the effect.
So .PHONY is a keyword in standard makefile, while standard makefile is supported in GNU, and some compilers do not support standard makefile. How do we define pseudo-targets when the .PHONY keyword fails? The principle is that if a rule does not have a command or dependency, and its target is not an existing file name; when the rule is enforced, the target is always considered up-to-date.
Next, let's take the code as an example to analyze and illustrate.
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.cclean: FORCE rm * .o hello.outFORCE:
Let's see if make clean will still work.
We see that although there is no definition of pseudo-goal .PHONY, our clean goal is executed because we use this trick. Through the study of pseudo-target, summarized as follows: 1, by default, make believes that the goal corresponds to a file; 2, .PHONY is used to declare a pseudo-target, which does not correspond to the actual file; 3, the nature of pseudo-target is a special goal in make .PHONY dependence; 4, use pseudo-target to simulate "function calls".
Welcome to learn makefile language, you can add me QQ:243343083.
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.