makefile $@, $^, $<, $? 表示的意义

ref:https://www.cnblogs.com/gamesun/p/3323155.html


$@  表示目标文件
$^  表示所有的依赖文件
$<  表示第一个依赖文件
$?  表示比目标还要新的依赖文件列表

如一个目录下有如下文件:

$ ls
hello.c  hi.c  main.c  Makefile

按照 Makefile 规则规规矩矩的写:
复制代码

main: main.o hello.o hi.o
        gcc -o main main.o hello.o hi.o

main.o: main.c
        cc -c main.c

hello.o: hello.c
        cc -c hello.c

hi.o: hi.c
        cc -c hi.c

clean:
        rm *.o
        rm main

复制代码

改为用上述符号进行替代:
复制代码

main: main.o hello.o hi.o
        gcc -o $@ $^
main.o: main.c
        cc -c $<
hello.o: hello.c
        cc -c $<
hi.o: hi.c
        cc -c $<
clean:
        rm *.o
        rm main

复制代码

原文地址:https://www.cnblogs.com/schips/p/10733792.html