由于我对 bash shell 脚本还很陌生,所以我无法理解我用来编译某些程序的 Makefile。
你能解释一下下面源代码中'$@'和'$<'的含义吗?提前谢谢你。
CC=g++
CFLAGS=-c -Wall -I /usr/local/include/boost-1_37/ -g
LDFLAGS=-L /usr/local/lib
SOURCES=cluster.cpp test.cpp
OBJECTS=$(SOURCES:.cpp=.o)
EXECUTABLE=k-means
all: $(SOURCES) $(EXECUTABLE)
$(EXECUTABLE): $(OBJECTS)
$(CC) $(LDFLAGS) $(OBJECTS) -o **$@**
.cpp.o:
$(CC) $(CFLAGS) **$<** -o **$@**
clean:
rm -fr *.o *~ $(EXECUTABLE)
最佳答案
参见 Automatic Variables在 GNU make 手册中:
$@
The file name of the target of the rule. If the target is an archive member, then
$@
is the name of the archive file. In a pattern rule that has multiple targets (see Introduction to Pattern Rules),$@
is the name of whichever target caused the rule's recipe to be run.
$<
The name of the first prerequisite. If the target got its recipe from an implicit rule, this will be the first prerequisite added by the implicit rule (see Implicit Rules).
关于linux - 关于 Makefile 的 bash shell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14442417/