linux – 如何使用automake检查操作系统

我有一个项目,使用automake创建配置和所有相关文件(我使用autoreconf命令来制作所有这些东西).因此,我正在尝试设置一些条件文件,以便在项目编译macOS(OS X),WindowsLinux时进行编译.但它失败了以下内容:

 $autoreconf -i ..
src/Makefile.am:30: error: LINUX does not appear in AM_CONDITIONAL
autoreconf: automake failed with exit status: 1

包含Makefile.am中的错误的部分如下:

if OSX
    butt_SOURCES += CurrentTrackOSX.h CurrentTrackOSX.m
endif
if LINUX
    butt_SOURCES += currentTrack.h currentTrackLinux.cpp
endif
if WINDOWS
    butt_SOURCES += currentTrack.h currentTrack.cpp
endif

我的问题是,如何检查操作系统是否为Linux?如果有可能,有没有更好的方法来检查automake中的操作系统?

最佳答案
您可以检测它directly in the Makefile,或者在配置源文件(可能是configure.ac)中定义条件,因为您使用的是autoreconf:

# AC_CANONICAL_HOST is needed to access the 'host_os' variable    
AC_CANONICAL_HOST

build_linux=no
build_windows=no
build_mac=no

# Detect the target system
case "${host_os}" in
    linux*)
        build_linux=yes
        ;;
    cygwin*|mingw*)
        build_windows=yes
        ;;
    darwin*)
        build_mac=yes
        ;;
    *)
        AC_MSG_ERROR(["OS $host_os is not supported"])
        ;;
esac

# Pass the conditionals to automake
AM_CONDITIONAL([LINUX],[test "$build_linux" = "yes"])
AM_CONDITIONAL([WINDOWS],[test "$build_windows" = "yes"])
AM_CONDITIONAL([OSX],[test "$build_mac" = "yes"])

Note: host_os refers to the target system,so if you are cross-compiling it sets the OS conditional of the system you are compiling to.

相关文章

文章浏览阅读1.8k次,点赞63次,收藏54次。Linux下的目录权限...
文章浏览阅读1.6k次,点赞44次,收藏38次。关于Qt的安装、Wi...
本文介绍了使用shell脚本编写一个 Hello
文章浏览阅读1.5k次,点赞37次,收藏43次。【Linux】初识Lin...
文章浏览阅读3k次,点赞34次,收藏156次。Linux超详细笔记,...
文章浏览阅读6.8k次,点赞109次,收藏114次。【Linux】 Open...