gpt4 book ai didi

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

转载 作者:IT王子 更新时间:2023-10-29 00:18:21 25 4
gpt4 key购买 nike

我有一个项目使用 automake 来创建 configure 和所有相关文件(我正在使用 autoreconf 命令来制作所有这些东西)。因此,当项目为 macOS (OS X)、Windows 或 Linux 编译时,我试图设置一些条件文件进行编译。但它失败了:

 $ 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.

关于linux - 如何使用automake检查操作系统,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38898591/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com