Seelamsetty
Seelamsetty

Reputation: 35

Makefile - Pattern Rules

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?

Upvotes: 3

Views: 480

Answers (1)

Jack Kelly
Jack Kelly

Reputation: 18667

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.

Upvotes: 5

Related Questions