在automake中使用通配符

Using wildcards in automake

本文关键字:通配符 automake      更新时间:2023-10-16

我有以下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)**)

如果我生成生成生成文件(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.

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

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

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

"即使你不关心可移植性,并且因为你只针对GNU Make而很想使用'$(通配符…)',你也应该知道Automake在很多地方需要确切地知道应该处理哪些文件。由于Automake不知道如何扩展'$(wildcard…],你不能在这些地方使用它。'$(wildcard…)就Automake而言,"是一个与AC_SUBSTed变量相当的黑框。

您可以使用-Wportability标志获得有关"$(通配符…")构造的警告。"