What does the `%` character do in GNU Make?
I am using GNU make. In a Makefile that I got, i see the symbol '%'. e.g. in context of %.c, %.开发者_如何学Casm , %.o etc.. (Is it a wildcard that will return all the files of that extension)
What does % mean?
What will the below rule do:
%.o: %.c
gcc $< -o:$@
thank you,
-AD
The rule:
%.o: %.c
gcc $< -o:$@
Will for each c file build an object file using the command below it. So yes, % is like a wildcard, but I tend to think of it as "for each" because that's what happens as a result of the rule. $<
means dependent files and $@
means the object to be built. If you did this:
fred.o: fred.c
gcc $< -o:$@
Here $@=fred.o
and $<=fred.c
Likewise
fred.o: fred.c george.c
gcc $< -o:$@
gives $@=fred.o
and $<=fred.c george.c
.
Edit: from the commands I shall expand on this.
%
will match everything matching that around it. So %.c
means all the .c files in the current directory. asm/%.asm
means all the files in the subdir asm with the .asm
extension. It acts like a token, so whatever is found will be used whenever you next use %
i.e. in the label.
So, the rule:
objs/asm/%.o: arch/%.S
nasm -felf64 $< -o $@
Given arch/hello.S
, arch/bye.S
, arch/somethingelse.S
will create obj/asm/hello.o
, obj/asm/bye.S
, obj/asm/somethingelse.o
.
精彩评论