Rule coverage is often used in makefiles. Similarly, a target may have multiple prerequisites. This dependency can be put together or specified separately.
Example 1:
test1:
@echo "test111"
test2:
@echo "test222"
test3:
@echo "test333"
hehe: test1 test2 test3
@echo "get hehe"
test: hehe
In the above example, for the target hehe , there are multiple prerequisites: test1 test2 and test3 , and the dependent targets will be parsed in turn during make.
The result after running is:
Here are the rules:
hehe: test1 test2 test3
It can also be formulated separately.
Example 2:
test1:
@echo "test111"
test2:
@echo "test222"
test3:
@echo "test333"
hehe: test1
hehe: test2
hehe: test3
@echo "get hehe"
test: hehe
The result of such an operation:
It can be seen that the results in Example 1 and Example 2 are the same.
From the above two examples, we can see that for the target hehe , the command is only used once. What will happen if it is replaced with two commands?
Example 3:
test1:
@echo "test111"
test2:
@echo "test222"
test3:
@echo "test333"
hehe: test1
@echo "11111"
hehe: test2
@echo "22222"
hehe: test3
test: hehe
Take a look at the results of the operation:
From the results we conclude that:
- Different dependencies of the same target in makefile rules can be specified separately;
- Dependencies in makefile rules can be superimposed, but commands can only be covered;
- The first dependency target of makefile is determined according to the final command, and other dependencies are in order;
Through example 3 , it is determined that the final command is echo 22222 , and the dependent target is test2 at this moment, so test2 will be the first dependent target of hehe, and the others follow the order of definition.
Example 4:
test1:
@echo "test111"
test2:
@echo "test222"
test3:
@echo "test333"
hehe: test1
hehe: test2
hehe: test3
@echo "3333"
test: hehe
Take a look at the results of the operation:
From the example, although test3 is the last dependency, because of the command, test3 will be the first dependency, and other dependencies are in the order of definition.