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

时间:2014-12-22 21:53:09

标签: 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

有关如何处理此事的任何建议吗?

1 个答案:

答案 0 :(得分:2)

您应该将检查添加到您的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条件的主体!