【问题标题】:Using wildcards in automake在 automake 中使用通配符
【发布时间】:2016-04-14 15:05:08
【问题描述】:

我有以下makefile.am:

AUTOMAKE_OPTIONS = foreign
bin_PROGRAMS = prog
DEFS =
CFLAGS =
prog_SOURCES := $(wildcard src/GUI_dialogs.cpp) src/GUI_main_win.cpp
$(info **$(prog_SOURCES)**)

如果我生成 makefile (autoreconf && ./configure) 然后运行 ​​make

我得到以下输出:

**src/GUI_dialogs.cpp src/GUI_main_win.cpp**
g++  -I.     -g -O2 -MT GUI_main_win.o -MD -MP -MF .deps/GUI_main_win.Tpo -c -o GUI_main_win.o `test -f 'src/GUI_main_win.cpp' || echo './'`src/GUI_main_win.cpp
src/GUI_main_win.cpp:1:24: fatal error: ...Header not found as expected...

第一行显示 prog_SOURCES 变量设置正确,但它错过了首先编译 GUI_dialogs 对象。

如果我将 prog_SOURCES 更改为:

 prog_SOURCES := src/GUI_dialogs.cpp src/GUI_main_win.cpp

然后 GUI_dialogs 对象按预期首先编译。

我知道订单可能没有定义。但如果我只有通配符:

prog_SOURCES := $(wildcard src/GUI_dialogs.cpp)

然后我得到:

**src/GUI_dialogs.cpp**
gcc     -o prog   
gcc: fatal error: no input files
compilation terminated.

为什么它只是跳过通配符文件?即使它显然在变量中?

【问题讨论】:

  • 这样做你违反了 autotools 的源代码政策,并且显然会破坏源代码构建。这是故意的吗?
  • 我并不关心如何,但我真的不想管理源文件列表。是的,因为那个网页说我是一个懒惰的开发人员。如果我不懒惰,我会手动编写makefile,而不是使用自动工具。我正在使用的当前系统有一个 shell 脚本,它生成 Makefile.am,然后使用 autotools 生成 makefile。我想删除那个 shell 脚本。
  • 是否可以直接编写 makefile 而不必手动管理依赖项(或直接在 makefile 中使用难看、几乎无法辨认的代码)?
  • @user3159253,我不明白为什么 automake 工具需要知道正在编译的文件?

标签: c++ automake


【解决方案1】:

遇到了类似的问题,从文档看来这不是一个好主意。

https://www.gnu.org/software/automake/manual/html_node/Wildcards.html

“即使你不关心可移植性,并且因为你只针对 GNU Make 而想使用 '$(wildcard ...)',你应该知道 Automake 需要在很多地方确切知道哪个文件应该被处理。由于 Automake 不知道如何扩展 '$(wildcard ...)',所以你不能在这些地方使用它。'$(wildcard ...)' 是一个与 AC_SUBSTed 变量相当的黑盒远在 Automake 方面。

您可以使用 -Wportability 标志收到有关“$(wildcard ...”) 构造的警告。”

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-22
    • 2011-08-01
    • 2016-05-10
    • 2011-05-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多