1- ARCH_NAME = armv7l
1+ # Allow the following machines to use native execution
2+ #
3+ # - Beaglebone Black (Cortex-A8)
4+ # - Raspberry Pi 3 (Cortex-A53)
5+ # - Raspberry Pi 4 (Cortex-A72)
6+ # - Raspberry Pi 5 (Cortex-A76)
7+ ALLOW_MACHINES = BeagleBone-Black Raspberry-Pi-3 Raspberry-Pi-4 Raspberry-Pi-5
28ARCH_RUNNER = qemu-arm
39ARCH_DEFS = \
410 "/* target: ARM */\n$\
@@ -14,6 +20,39 @@ ARCH_DEFS = \
1420 \#define MAX_ARGS_IN_REG 4\n$\
1521 "
1622
23+ # If the running machine has the "fastfetch" tool installed, the build
24+ # system will verify whether native execution can be performed.
25+ ifneq ($(shell which fastfetch) ,)
26+ # 1. Replace whitespaces with hyphens after retrieving the host
27+ # machine name via the "fastfetch" tool.
28+ #
29+ # 2. If at least one machine name in the allowlist is found in
30+ # the host machine name, it can perform native execution.
31+ #
32+ # Therefore, set USE_QEMU to 0.
33+ HOST_MACHINE = $(shell fastfetch --logo none --structure Host | sed 's/ /-/g')
34+ USE_QEMU = $(if $(strip $(foreach MACHINE, $(ALLOW_MACHINES ) , $(findstring $(MACHINE ) ,$(HOST_MACHINE ) ) ) ) ,0,1)
35+
36+ # Special case: GitHub workflows on Arm64 runners
37+ #
38+ # When an Arm-hosted runner executes "fastfetch --logo none --structure Host",
39+ # it produces the following output:
40+ #
41+ # Host: Virtual Machine (Hyper-V UEFI Release v4.1)
42+ #
43+ # Arm-hosted runners are also capable of performing native execution. However,
44+ # directly adding "Virtual-Machine" to the allowlist would be ambiguous.
45+ # Therefore, the build system instead checks the CPU name using the
46+ # "fastfetch --logo none --structure CPU" command.
47+ #
48+ # If the detected CPU is "Neoverse-N2", the build system treats the running
49+ # machine as an Arm-hosted runner and enable native execution.
50+ ifeq ($(USE_QEMU),1)
51+ HOST_CPU = $(shell fastfetch --logo none --structure CPU | sed 's/ /-/g')
52+ USE_QEMU = $(if $(strip $(findstring Neoverse-N2,$(HOST_CPU ) ) ) ,0,1)
53+ endif
54+ endif
55+
1756# Find the sysroot of the ARM GNU toolchain if using dynamic linking.
1857#
1958# Since developers may install the toolchain manually instead of
@@ -23,7 +62,7 @@ ARCH_DEFS = \
2362# Therefore, the following process first locates find the correct
2463# sysroot of the toolchain, and then generate the ELF interpreter
2564# prefix for later use.
26- ifneq ($(HOST_ARCH ) , $( ARCH_NAME ) )
65+ ifeq ($(USE_QEMU ) ,1 )
2766 ifeq ($(DYNLINK),1)
2867 CROSS_COMPILE = arm-none-linux-gnueabihf-
2968 ARM_CC = $(CROSS_COMPILE ) gcc
0 commit comments