Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Makefile - Pattern Rules

Tags:

makefile

I am new to writing makefiles. Recently I have seen pattern rules in makefiles. For example:

%.o: %.cc
        # command to compile comes here

After rigourous searching in the net, I found out what the above statement does, But I came across another statement below.

%: %.o
        # Command to link lies here

I do not understand this rule. Can anyone explain the second pattern rule?

like image 911
Seelamsetty Avatar asked Dec 04 '25 10:12

Seelamsetty


1 Answers

The second rule is also a pattern rule, it says how to make a file with no extension from a file with the same name, but .o at the end. So it's a rule to link foo from foo.o, bar from bar.o and so on.

like image 103
Jack Kelly Avatar answered Dec 06 '25 10:12

Jack Kelly



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!