在 BitBake 配方中可靠地确定机器架构

Determine machine architecture reliably in a BitBake recipe

我正在为需要了解底层机器微体系结构的程序包编写配方。换句话说,对于 64 位 Arm 系统,我想要一个字符串,例如 aarch64arm64,对于 64 位 Intel 系统,我想要一个字符串 x86_64

到目前为止,我已经确定:

我原以为以明确定义的格式了解机器架构很重要,但似乎并没有那么简单。有什么建议吗?

我习惯用 uname -m 来做这个(Windows 粉丝可以使用 SET processor 的输出),所以对我来说,在 Yocto 中它最终是一个折腾:

  1. 根据 TARGET_ARCH 的超级手册条目:
TARGET_ARCH

The target machine's architecture. The OpenEmbedded build system supports many
architectures. Here is an example list of architectures supported. This list is by
no means complete as the architecture is configurable:

     arm
     i586
     x86_64
     powerpc
     powerpc64
     mips
     mipsel

uname -m 更好一些,因为您还可以获得子架构信息。从我此刻可以访问的机器:

Intel-based Nuc build system:  x86_64
ARM embedded system:           armv7l
Raspberry Pi 4B:               aarch64
  1. 我发现 GNU automake(本机)和 libtool(可用于目标)包计算一个名为 UNAME_MACHINE_ARCH 的有用变量。如果您已经在使用 libtool 或愿意接受它只是为了为您完成此操作:-@),您可以通过这种方式解决。在构建的树中查找名为 config.guess.

    的文件
  2. 通过使用 Yocto BUILD_ARCH:

    ,您可能比 libtool 更通用
BUILD_ARCH

Specifies the architecture of the build host (e.g. i686). The OpenEmbedded build
system sets the value of BUILD_ARCH from the machine name reported by the uname
command.

因此,请使用这些并根据您的项目情况做出自己的选择。