linux - 在 makefile 中添加特定于平台的标志

标签 linux windows makefile mingw autotools

我需要在我的 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/

相关文章:

linux - 在构建 docker image level=error msg ="Can' t close tar writer : io: read/write on closed pipe"

linux - 如何从终端运行已安装的 python 包

c++ - 等待 ShellExecuteEx(在 Windows 进程上设置访问权限)

makefile - 使用 Cmake 创建 tar 存档

linux - 无法为 Ubuntu 安装 LightTable

mysql - 运行 mysql 出现 :"systemctl start mysqld.service "错误

windows - 如何将 EXE 中的文件偏移量映射到其 PE 部分

c++ - 将 std::vector<char> 截断为长度 N 以释放内存的有效方法

linux - gcc 出现错误 libcpp/charset.c(1747) : error: identifier "saved_error_handler" is undefined

c - GTK+ 使 Cygwin 错误