# SPDX-License-Identifier: GPL-2.0-only OR License-Ref-kk-custom
#
# Copyright (C) 2023 Kernkonzept GmbH.
# Author(s): Georg Kotheimer <georg.kotheimer@kernkonzept.com>

GENERIC_BUILTINS_SRC += $(GENERIC_SOURCES_TF)

BUILTINS_SRC += aarch64/fp_mode.c

# Clang < 18
ifeq ($(call libclang_rt_if_min_version,18),)
  BUILTINS_SRC += cpu_model.c
# Clang >= 18
else
  BUILTINS_SRC += cpu_model/aarch64.c
endif

ifeq ($(BID_VARIANT_FLAG_NOFPU),)
  # Clang == 18
  ifneq ($(call libclang_rt_if_version,18),)
    BUILTINS_SRC += aarch64/sme-abi.S aarch64/sme-abi-init.c aarch64/sme-libc-routines.c
  endif

  # Clang == 19
  ifneq ($(call libclang_rt_if_version,19),)
    BUILTINS_SRC += aarch64/sme-abi.S aarch64/sme-libc-mem-routines.S \
                    aarch64/sme-abi-init.c aarch64/sme-abi-vg.c aarch64/sme-libc-routines.c
  endif

  # Clang >= 20
  ifneq ($(call libclang_rt_if_min_version,20),)
    BUILTINS_SRC += aarch64/sme-abi.S aarch64/sme-libc-mem-routines.S \
                    aarch64/sme-abi-assert.c aarch64/sme-libc-routines.c
  endif
endif

# TODO: Variants of aarch64/lse.S (guarded by defines)
# Required for outline atomics (-moutline-atomics), currently not
# supported on L4 as __getauxval(AT_HWCAP) always returns 0 indicating that the
# required atomic operations are not available, so no point in adding the
# outline atomics support code here in libclang_rt.
