autotools: Makefile.am: link 如果文件存在

autotools: Makefile.am: link if file exists

my Makefile.am 创建可执行文件 main: "symplerTest" 我想 link 文件 "geometry/source/*.o"。目前我 link 是这样的:

symplerTest_LDFLAGS = \
    ...
    geometry/source/*.o 

行得通。但是现在在下一步中,我只想 link 只有文件 *.o 存在。我试过这个:

if ("$(wildcard $(geometry/source/*.o))","")
symplerTest_LDFLAGS += geometry/source/*.o
endif

但得到以下错误信息:

srcUnittest/Makefile.am:81: error: endif without if
srcUnittest/Makefile.am:79: warning: wildcard $(geometry/source/*.o: non-POSIX variable name
srcUnittest/Makefile.am:79: (probably a GNU make extension)

问题似乎出在 ("$(wildcard $(geometry/source/*.o))","")

谢谢!

您混淆了 Automake 指令 if 和 Make 指令 ifeq,

Automake 手册位于 20 Conditionals 重点:

Automake supports a simple type of conditionals.

These conditionals are not the same as conditionals in GNU Make. Automake conditionals are checked at configure time by the configure script, and affect the translation from Makefile.in to Makefile. They are based on options passed to configure and on results that configure has discovered about the host system. GNU Make conditionals are checked at make time, and are based on variables passed to the make program or defined in the Makefile.

if 根本不是 Make 指令。 ifeq 是一个有效的 Make 指令 参数可以是 (arg1, arg2) 的形式。

ifeq (arg1, arg2)

表示,如果 arg1 等于 arg2.

(arg1, arg2) 形式的参数对于 Automake 指令 if 无效。 Automake if 指令的有效参数是 Automake 条件名称, 例如

if DEBUG

意味着,对于 Automake,如果由 DEBUG 命名的条件为真 - 其中 DEBUG 是您之前通过方式创建的条件名称 的 AM_CONDITIONAL 宏.

请参阅链接文档。