【问题标题】:adding platform specific flags in makefile在 makefile 中添加特定于平台的标志
【发布时间】:2014-12-22 21:53:09
【问题描述】:

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

对如何处理有什么建议吗?

【问题讨论】:

    标签: linux windows makefile mingw autotools


    【解决方案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 条件的主体!

    【讨论】:

    • 最好使用预定义的$host_os 来处理交叉编译场景
    • @vitalyster 我在 configure.ac 中试过这个:AC_CANONICAL_HOST case $host_os in windows* ) AM_LDFLAGS += -lws2_32 AM_LDFLAGS += -Xlinker --allow-multiple-definition ;; *) AM_LDFLAGS += AM_LDFLAGS += ;; esac 但没有奏效。我会尝试@ptomato 的建议,看看它是否有效。
    • @ptomato 我尝试了你的建议,清理; make 失败并出现与 strtok 相关的错误。所以我将makefile.am 编辑为if !MINGW.....。这没有意义。我在这里错过了什么吗?
    • @ptomato 这是我得到的确切错误:collect2.exe: error: ld returned 1 exit status make[1]: *** [tape/tape.la] Error 1 make[1]: Leaving directory...所以,我想在 Linux 机器上测试它,所以通过上述操作,Linux 机器不应该看到这些标志,但是它看到了那些标志并出错了。上面的解决方案有什么错误吗?
    • @SrinGupta:这不是你得到的错误;那只是让抱怨错误。真正的错误将高于输出中的错误。您可以通过执行AC_MSG_CHECKING([for mingw]) AC_MSG_RESULT([$mingw]) 之类的操作来查看检查的结果
    猜你喜欢
    • 1970-01-01
    • 2014-06-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-15
    • 1970-01-01
    相关资源
    最近更新 更多