linux - 关于 Makefile 的 bash shell

标签 linux bash makefile

由于我对 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/

相关文章:

php - linux 服务器上的 cakephp 帮助程序文件名大写问题

java - 无法在centos R中安装rJava

bash - 使用 CAM::PDF 将加密级别提高到 128 位,以实现密码 pdf 保护

linux - 是什么导致在 find 中执行 -type f 的时间增加

macos - 安装 Valgrind 时 make 失败

c - 为什么即使我刚刚编译了源代码,我的 makefile 也会重新编译?

linux - 在发送到 rsyslog 的 Linux 审核日志中配置服务器名称

linux - 当用户按任意键时telnet发送哪些数据

linux - 为什么在旧版本的 ubuntu 上使用新版本的 glibc 时会发生堆栈粉碎?

unix - 在Makefile中使用sed