From 721ac4a3906af8c047c85268c41c887ab1a118c8 Mon Sep 17 00:00:00 2001 From: henderkes Date: Fri, 22 May 2026 11:49:15 +0700 Subject: [PATCH] enable hardware intrinsics for libaom --- src/SPC/builder/unix/library/libaom.php | 10 +++++++++- src/SPC/util/SPCTarget.php | 15 +++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/SPC/builder/unix/library/libaom.php b/src/SPC/builder/unix/library/libaom.php index f2f50d85..2208b39b 100644 --- a/src/SPC/builder/unix/library/libaom.php +++ b/src/SPC/builder/unix/library/libaom.php @@ -7,6 +7,7 @@ namespace SPC\builder\unix\library; use SPC\toolchain\ToolchainManager; use SPC\toolchain\ZigToolchain; use SPC\util\executor\UnixCMakeExecutor; +use SPC\util\SPCTarget; trait libaom { @@ -17,9 +18,16 @@ trait libaom $new = trim($extra . ' -D_GNU_SOURCE'); f_putenv("SPC_COMPILER_EXTRA={$new}"); } + $targetCpu = SPCTarget::getTargetArch(); + if (str_starts_with($targetCpu, 'aarch')) { + $targetCpu = str_replace($targetCpu, 'aarch', 'arm'); + } UnixCMakeExecutor::create($this) ->setBuildDir("{$this->source_dir}/builddir") - ->addConfigureArgs('-DAOM_TARGET_CPU=generic') + ->addConfigureArgs( + "-DAOM_TARGET_CPU={$targetCpu}", + '-DCONFIG_RUNTIME_CPU_DETECT=1' + ) ->build(); f_putenv("SPC_COMPILER_EXTRA={$extra}"); $this->patchPkgconfPrefix(['aom.pc']); diff --git a/src/SPC/util/SPCTarget.php b/src/SPC/util/SPCTarget.php index 037c6d8c..25f2b0fb 100644 --- a/src/SPC/util/SPCTarget.php +++ b/src/SPC/util/SPCTarget.php @@ -127,4 +127,19 @@ class SPCTarget default => PHP_OS_FAMILY, }; } + + /** + * Returns the target OS arch, e.g. x86_64, aarch64, arm, x86. + */ + public static function getTargetArch(): string + { + $target = (string) getenv('SPC_TARGET'); + return match (true) { + str_starts_with($target, 'aarch64') => 'aarch64', + str_starts_with($target, 'arm-') => 'arm', + str_starts_with($target, 'x86_64-') => 'x86_64', + str_starts_with($target, 'x86-') => 'x86', + default => GNU_ARCH, + }; + } }