The gnu make pattern rule matches the wrong rule

In the following example, when creating the entire target main-gs-universalk9-mo, it seems to match rule 1 instead of rule 2. In make version 3.81, I thought that order matters. Even if I moved rule 2, which should be defined before rule 1. It still ends with rule 1

What is the correct way to encode this and make it work properly?

$(info .FEATURES := $(.FEATURES))


%.o:
    @echo "Rule 1 $?"
    rm -f $@
    cp $*.c $@

main-gs-%-m.o: file1.o file2.o file3.o
    @echo "Rule 2"
    cat $? > $@

binos_%_version.o:
    @echo "Rule 3"
    echo "Hello World" > $@

x86-%-m: main-gs-%-m.o binos_%_version.o
    @echo "Rule 4"
    cat $? > $@

all: x86-universalk9-m

clean:
    @echo "Rule Cleaning"
    rm -f *.o
    rm -f x86-universalk9-m
+4
source share
1 answer

If you look at how the implicit rule search algorithm works , you can see that it is carried out in two stages.

make , , , " ". , make .

main-gs-%-m.o: file1.o file2.o file3.o , , , (.. ), %.o: x86-universalk9-m.

, , , , , %.o: file1.o file2.o file3.o: .

+2

All Articles