Automake:为什么我的 Makefile 从源目录而不是构建目录中选择文件?

Automake: Why is my Makefile picking files from the source directory instead of the build directory?

我正在使用 Automake

我在 dist_man1_MANS 中列出了一些源文件,如下所示:

dist_man1_MANS = some-file.1 some-other-file.1

现在,Automake + configure 最终在 Makefile 中生成了这个:

dist_man1_MANS = some-file.1 some-other-file.1

# ...

install-man1: $(dist_man1_MANS)
    # generated recipe here

因为我没有在 .1 文件前加上 $(srcdir),我假设,因为我从构建目录(它的当前工作目录)运行 make ), 它应该在构建目录中找到它们。

所以,我正在做树外构建,例如,在 /tmp/build:

/path/to/src/configure --prefix=$(pwd)/install
make
make install

并且构建成功,即make找到手册页并安装它们。但是,它们不在构建目录中。我将其添加到生成的 Makefile 中:

install-man1: $(dist_man1_MANS)
    @echo ">>> $(^)"
    @echo "::: $(dist_man1_MANS)"
    # generated recipe here

现在,我假设两个 echo 打印相同的内容,因为 $^ 表示 the names of all the prerequisites, with spaces between them。令我惊讶的是,输出是:

>>> /path/to/src/some-file.1 /path/to/src/some-other-file.1
::: some-file.1 some-other-file.1

所以:

  1. make 是如何准确找到 /path/to/src/ 前缀的?在这种背景下,它从何而来?
  2. 为什么 $^$(dist_man1_MANS) 不同?

我找到了答案。

Automake 将其生成的 Makefile 中的 VPATH 变量(make 的特殊变量)设置为:

VPATH = /path/to/src

来自之前的链接:

4.5.1 VPATH: Search Path for All Prerequisites

The value of the make variable VPATH specifies a list of directories that make should search. Most often, the directories are expected to contain prerequisite files that are not in the current directory; however, make uses VPATH as a search list for both prerequisites and targets of rules.

因此make首先在当前工作目录中搜索some-file.1some-other-file.1先决条件,如果找不到则再搜索/path/to/src/some-file.1/path/to/src/some-other-file.1第一个。在这种情况下,我理解为什么 $^$(dist_man1_MANS) 不同:$^ 有效 (已解决)先决条件的列表。