我需要在我的 makefile 中设置几个标志,这些标志仅需要特定于 Windows,即我不希望它们在其他操作系统上“看到”。我正在使用 MinGW 来构建我的项目。这些是我只想为 Windows 设置的标志:
AM_LDFLAGS += -lws2_32
AM_LDFLAGS += -Xlinker --allow-multiple-definition
这就是我在 makefile.am 中所做的:
SYS := $(shell gcc -dumpmachine)
ifneq (, $(findstring mingw, $(SYS)))
AM_LDFLAGS += -lws2_32
AM_LDFLAGS += -Xlinker --allow-multiple-definition
endif
当我执行 autoreconf -isf
时,它失败并显示以下消息:
Makefile.am:34: endif without if
Makefile.am:30: `:='-style assignments are not portable
Makefile.am:30: shell gcc -dumpmachine: non-POSIX variable name
Makefile.am:30: (probably a GNU make extension)
Makefile.am:31: findstring mingw, $(SYS: non-POSIX variable name
Makefile.am:31: (probably a GNU make extension)
aminclude.mk:162: .PHONY was already defined in condition TRUE, which includes condition DX_COND_doc ...
Makefile.am:80: `aminclude.mk' included from here
core/Makefile.mk:169: ... `.PHONY' previously defined here
Makefile.am:56: `core/Makefile.mk' included from here
Makefile.am:271: <D: non-POSIX variable name
Makefile.am:230: user variable `distdir' defined here...
/mingw/share/automake-1.11/am/distdir.am: ... overrides Automake variable `distdir' defined here
autoreconf-2.68: automake failed with exit status: 1
关于如何处理这个问题有什么建议吗?
最佳答案
您应该将检查添加到您的configure.ac中,如下所示:
AC_CANONICAL_HOST
case $host_os in
*mingw*) mingw=true ;;
*) mingw=false ;;
esac
AM_CONDITIONAL([MINGW], [test x$mingw = xtrue])
然后在Makefile.am中,你可以这样做
if MINGW
AM_LDFLAGS += -lws2_32
AM_LDFLAGS += -Xlinker --allow-multiple-definition
endif
确保没有缩进 Makefile.am 中 if 条件的正文!
关于linux - 在 makefile 中添加特定于平台的标志,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27610970/