require conf/multilib.conf
require conf/machine/include/arm/arch-armv8r.inc
require conf/machine/include/baremetal-tc.conf

# Since we're combining armv7r and armv8r into a single set of multilibs,
# copy the following machine setting to make sure it's available
# From conf/machine/include/arm/arch-armv7r.inc

TUNEVALID[armv7r] = "Enable instructions for ARMv7-r"
TUNE_CCARGS_MARCH = "${@bb.utils.contains('TUNE_FEATURES', 'armv7r', ' -march=armv7-r', '', d)}"
MACHINEOVERRIDES =. "${@bb.utils.contains('TUNE_FEATURES', 'armv7r', 'armv7r:', '', d)}"
TUNECONFLICTS[armv7r] = "armv4 armv5 armv6 armv7a"


# Define all of the multilibs supproted by this configuration
MULTILIB_GLOBAL_VARIANTS = "${@extend_variants(d,'MULTILIBS','multilib')}"

MULTILIBS  = "multilib:libarmv5tesoftfp multilib:libarmv5tehard"
MULTILIBS += "multilib:libnofp"
MULTILIBS += "multilib:libv7nofp multilib:libv7fpsoftfp multilib:libv7fphard"
MULTILIBS += "multilib:libv6mnofp"
MULTILIBS += "multilib:libv7mnofp"
MULTILIBS += "multilib:libv7emnofp multilib:libv7emfpsoftfp"
MULTILIBS += "multilib:libv7emfphard multilib:libv7emdpsoftfp"
MULTILIBS += "multilib:libv7emdphard"
MULTILIBS += "multilib:libv8mbasenofp"
MULTILIBS += "multilib:libv8mmainnofp multilib:libv8mmainfpsoftfp multilib:libv8mmainfphard multilib:libv8mmaindpsoftfp multilib:libv8mmaindphard"

TUNE_CCARGS = "${TUNE_CCARGS:tune-${DEFAULTTUNE}}"
TUNE_PKGARCH = "${TUNE_PKGARCH:tune-${DEFAULTTUNE}}"

# Base configuration
# CFLAGS:
DEFAULTTUNE = "armv7r"

AVAILTUNES += "armv7r"
PACKAGE_EXTRA_ARCHS:tune-armv7r = "${TUNE_PKGARCH:tune-armv7r}"
BASE_LIB:tune-armv7r = "lib"
TUNE_FEATURES:tune-armv7r = "arm armv7r"
TUNE_CCARGS:tune-armv7r = ""
TUNE_PKGARCH:tune-armv7r = "armv7r"


# arm/v5te/softfp
# CFLAGS:  -marm -march=armv5te+fp -mfloat-abi=softfp
DEFAULTTUNE:virtclass-multilib-libarmv5tesoftfp = "armv5tesoftfp"

AVAILTUNES += "armv5tesoftfp"
PACKAGE_EXTRA_ARCHS:tune-armv5tesoftfp = "${TUNE_PKGARCH:tune-armv5tesoftfp}"
BASE_LIB:tune-armv5tesoftfp = "lib/arm/v5te/softfp"
TUNE_FEATURES:tune-armv5tesoftfp = "arm armv7r"
TUNE_CCARGS:tune-armv5tesoftfp = "-marm -march=armv5te+fp -mfloat-abi=softfp"
TUNE_PKGARCH:tune-armv5tesoftfp = "armv5tefp"


# arm/v5te/hard
# CFLAGS: -marm -march=armv5te+fp -mfloat-abi=hard
DEFAULTTUNE:virtclass-multilib-libarmv5tehard = "armv5tehard"

AVAILTUNES += "armv5tehard"
PACKAGE_EXTRA_ARCHS:tune-armv5tehard = "${TUNE_PKGARCH:tune-armv5tehard}"
BASE_LIB:tune-armv5tehard = "lib/arm/v5te/hard"
TUNE_FEATURES:tune-armv5tehard = "arm armv7r"
TUNE_CCARGS:tune-armv5tehard = "-marm -march=armv5te+fp -mfloat-abi=hard"
TUNE_PKGARCH:tune-armv5tehard = "armv5tefphf"


# thumb/nofp
# CFLAGS: -mthumb -mfloat-abi=soft
DEFAULTTUNE:virtclass-multilib-libnofp = "armnofp"

AVAILTUNES += "armnofp"
PACKAGE_EXTRA_ARCHS:tune-armnofp = "${TUNE_PKGARCH:tune-armnofp}"
BASE_LIB:tune-armnofp = "lib/thumb/nofp"
TUNE_FEATURES:tune-armnofp = "arm armv7r"
TUNE_CCARGS:tune-armnofp = "-mthumb -mfloat-abi=soft"
TUNE_PKGARCH:tune-armnofp = "armt"


# thumb/v7/nofp
# CFLAGS: -mthumb -march=armv7 -mfloat-abi=soft
DEFAULTTUNE:virtclass-multilib-libv7nofp = "armv7nofp"

AVAILTUNES += "armv7nofp"
PACKAGE_EXTRA_ARCHS:tune-armv7nofp = "${TUNE_PKGARCH:tune-armv7nofp}"
BASE_LIB:tune-armv7nofp = "lib/thumb/v7/nofp"
TUNE_FEATURES:tune-armv7nofp ="arm armv7r"
TUNE_CCARGS:tune-armv7nofp = "-mthumb -march=armv7 -mfloat-abi=soft"
TUNE_PKGARCH:tune-armv7nofp = "armv7t"


# thumb/v7+fp/softfp
# CFLAGS: -mthumb -march=armv7+fp -mfloat-abi=softfp
DEFAULTTUNE:virtclass-multilib-libv7fpsoftfp = "armv7fpsoftfp"

AVAILTUNES += "armv7fpsoftfp"
PACKAGE_EXTRA_ARCHS:tune-armv7fpsoftfp = "${TUNE_PKGARCH:tune-armv7fpsoftfp}"
BASE_LIB:tune-armv7fpsoftfp = "lib/thumb/v7+fp/softfp"
TUNE_FEATURES:tune-armv7fpsoftfp ="arm armv7r"
TUNE_CCARGS:tune-armv7fpsoftfp = "-mthumb -march=armv7+fp -mfloat-abi=softfp"
TUNE_PKGARCH:tune-armv7fpsoftfp = "armv7fpt"


# thumb/v7+fp/hard
# CFLAGS: -mthumb -march=armv7+fp -mfloat-abi=hard
DEFAULTTUNE:virtclass-multilib-libv7fphard = "armv7fphard"

AVAILTUNES += "armv7fphard"
PACKAGE_EXTRA_ARCHS:tune-armv7fphard = "${TUNE_PKGARCH:tune-armv7fphard}"
BASE_LIB:tune-armv7fphard = "lib/thumb/v7+fp/hard"
TUNE_FEATURES:tune-armv7fphard ="arm armv7r"
TUNE_CCARGS:tune-armv7fphard = "-mthumb -march=armv7+fp -mfloat-abi=hard"
TUNE_PKGARCH:tune-armv7fphard = "armv7fpthf"


# thumb/v6-m/nofp
# CFLAGS: -mthumb -march=armv6s-m -mfloat-abi=soft
DEFAULTTUNE:virtclass-multilib-libv6mnofp = "armv6mnofp"

# Workaround for this multilib in newlib
# newlib/libc/sys/arm/trap.S:88: Error: lo register required -- `sub ip,sp,ip
EXTRA_OECONF:append:pn-libv6mnofp-newlib     = " --disable-newlib-supplied-syscalls"

AVAILTUNES += "armv6mnofp"
PACKAGE_EXTRA_ARCHS:tune-armv6mnofp = "${TUNE_PKGARCH:tune-armv6mnofp}"
BASE_LIB:tune-armv6mnofp = "lib/thumb/v6-m/nofp"
TUNE_FEATURES:tune-armv6mnofp ="arm armv7r"
TUNE_CCARGS:tune-armv6mnofp = "-mthumb -march=armv6s-m -mfloat-abi=soft"
TUNE_PKGARCH:tune-armv6mnofp = "armv6smt"


# thumb/v7-m/nofp
# CFLAGS: -mthumb -march=armv7-m -mfloat-abi=soft
DEFAULTTUNE:virtclass-multilib-libv7mnofp = "armv7mnofp"

AVAILTUNES += "armv7mnofp"
PACKAGE_EXTRA_ARCHS:tune-armv7mnofp = "${TUNE_PKGARCH:tune-armv7mnofp}"
BASE_LIB:tune-armv7mnofp = "lib/thumb/v7-m/nofp"
TUNE_FEATURES:tune-armv7mnofp ="arm armv7r"
TUNE_CCARGS:tune-armv7mnofp = "-mthumb -march=armv7-m -mfloat-abi=soft"
TUNE_PKGARCH:tune-armv7mnofp = "armv7mt"


# thumb/v7e-m/nofp
# CFLAGS: -mthumb -march=armv7e-m -mfloat-abi=soft
DEFAULTTUNE:virtclass-multilib-libv7emnofp = "armv7emnofp"

AVAILTUNES += "armv7emnofp"
PACKAGE_EXTRA_ARCHS:tune-armv7emnofp = "${TUNE_PKGARCH:tune-armv7emnofp}"
BASE_LIB:tune-armv7emnofp = "lib/thumb/v7e-m/nofp"
TUNE_FEATURES:tune-armv7emnofp ="arm armv7r"
TUNE_CCARGS:tune-armv7emnofp = "-mthumb -march=armv7e-m -mfloat-abi=soft"
TUNE_PKGARCH:tune-armv7emnofp = "armv7emt"


# thumb/v7e-m+fp/softfp
# CFLAGS: -mthumb -march=armv7e-m+fp -mfloat-abi=softfp
DEFAULTTUNE:virtclass-multilib-libv7emfpsoftfp = "armv7emfpsoftfp"

AVAILTUNES += "armv7emfpsoftfp"
PACKAGE_EXTRA_ARCHS:tune-armv7emfpsoftfp = "${TUNE_PKGARCH:tune-armv7emfpsoftfp}"
BASE_LIB:tune-armv7emfpsoftfp = "lib/thumb/v7e-m+fp/softfp"
TUNE_FEATURES:tune-armv7emfpsoftfp ="arm armv7r"
TUNE_CCARGS:tune-armv7emfpsoftfp = "-mthumb -march=armv7e-m+fp -mfloat-abi=softfp"
TUNE_PKGARCH:tune-armv7emfpsoftfp = "armv7emfpt"


# thumb/v7e-m+fp/hard
# CFLAGS: -mthumb -march=armv7e-m+fp -mfloat-abi=hard
DEFAULTTUNE:virtclass-multilib-libv7emfphard = "armv7emfphard"

AVAILTUNES += "armv7emfphard"
PACKAGE_EXTRA_ARCHS:tune-armv7emfphard = "${TUNE_PKGARCH:tune-armv7emfphard}"
BASE_LIB:tune-armv7emfphard = "lib/thumb/v7e-m+fp/hard"
TUNE_FEATURES:tune-armv7emfphard ="arm armv7r"
TUNE_CCARGS:tune-armv7emfphard = "-mthumb -march=armv7e-m+fp -mfloat-abi=hard"
TUNE_PKGARCH:tune-armv7emfphard = "armv7emfpthf"


# thumb/v7e-m+dp/softfp
# CFLAGS: -mthumb -march=armv7e-m+fp.dp -mfloat-abi=softfp
DEFAULTTUNE:virtclass-multilib-libv7emdpsoftfp = "armv7emdpsoftfp"

AVAILTUNES += "armv7emdpsoftfp"
PACKAGE_EXTRA_ARCHS:tune-armv7emdpsoftfp = "${TUNE_PKGARCH:tune-armv7emdpsoftfp}"
BASE_LIB:tune-armv7emdpsoftfp = "lib/thumb/v7e-m+dp/softfp"
TUNE_FEATURES:tune-armv7emdpsoftfp ="arm armv7r"
TUNE_CCARGS:tune-armv7emdpsoftfp = "-mthumb -march=armv7e-m+fp.dp -mfloat-abi=softfp"
TUNE_PKGARCH:tune-armv7emdpsoftfp = "armv7emdp"

# thumb/v7e-m+dp/hard
# CFLAGS: -mthumb -march=armv7e-m+fp.dp -mfloat-abi=hard
DEFAULTTUNE:virtclass-multilib-libv7emdphard = "armv7emdphard"

AVAILTUNES += "armv7emdphard"
PACKAGE_EXTRA_ARCHS:tune-armv7emdphard = "${TUNE_PKGARCH:tune-armv7emdphard}"
BASE_LIB:tune-armv7emdphard = "lib/thumb/v7e-m+dp/hard"
TUNE_FEATURES:tune-armv7emdphard ="arm armv7r"
TUNE_CCARGS:tune-armv7emdphard = "-mthumb -march=armv7e-m+fp.dp -mfloat-abi=hard"
TUNE_PKGARCH:tune-armv7emdphard = "armv7emdpthf"


# thumb/v8-m.base/nofp
# CFLAGS: -mthumb -march=armv8-m.base -mfloat-abi=soft
DEFAULTTUNE:virtclass-multilib-libv8mbasenofp = "armv8mbasenofp"

# Workaround for this multilib in newlib
# newlib/libc/sys/arm/trap.S:88: Error: lo register required -- `sub ip,sp,ip'
EXTRA_OECONF:append:pn-libv8mbasenofp-newlib = " --disable-newlib-supplied-syscalls"

AVAILTUNES += "armv8mbasenofp"
PACKAGE_EXTRA_ARCHS:tune-armv8mbasenofp = "${TUNE_PKGARCH:tune-armv8mbasenofp}"
BASE_LIB:tune-armv8mbasenofp = "lib/thumb/v8-m.base/nofp"
TUNE_FEATURES:tune-armv8mbasenofp ="arm armv8r"
TUNE_CCARGS:tune-armv8mbasenofp = "-mthumb -march=armv8-m.base -mfloat-abi=soft"
TUNE_PKGARCH:tune-armv8mbasenofp = "armv8mbaset"

# thumb/v8-m.main/nofp
# CFLAGS: -mthumb -march=armv8-m.main -mfloat-abi=soft
DEFAULTTUNE:virtclass-multilib-libv8mmainnofp = "armv8mmainnofp"

AVAILTUNES += "armv8mmainnofp"
PACKAGE_EXTRA_ARCHS:tune-armv8mmainnofp = "${TUNE_PKGARCH:tune-armv8mmainnofp}"
BASE_LIB:tune-armv8mmainnofp = "lib/thumb/v8-m.main/nofp"
TUNE_FEATURES:tune-armv8mmainnofp ="arm armv8r"
TUNE_CCARGS:tune-armv8mmainnofp = "-mthumb -march=armv8-m.main -mfloat-abi=soft"
TUNE_PKGARCH:tune-armv8mmainnofp = "armv8mmaint"


# thumb/v8-m.main+fp/softfp
# CFLAGS: -mthumb -march=armv8-m.main+fp -mfloat-abi=softfp
DEFAULTTUNE:virtclass-multilib-libv8mmainfpsoftfp = "armv8mmainfpsoftfp"

AVAILTUNES += "armv8mmainfpsoftfp"
PACKAGE_EXTRA_ARCHS:tune-armv8mmainfpsoftfp = "${TUNE_PKGARCH:tune-armv8mmainfpsoftfp}"
BASE_LIB:tune-armv8mmainfpsoftfp = "lib/thumb/v8-m.main+fp/softfp"
TUNE_FEATURES:tune-armv8mmainfpsoftfp ="arm armv8r"
TUNE_CCARGS:tune-armv8mmainfpsoftfp = "-mthumb -march=armv8-m.main+fp -mfloat-abi=softfp"
TUNE_PKGARCH:tune-armv8mmainfpsoftfp = "armv8mmainfpt"

# thumb/v8-m.main+fp/hard
# CFLAGS: -mthumb -march=armv8-m.main+fp -mfloat-abi=hard
DEFAULTTUNE:virtclass-multilib-libv8mmainfphard = "armv8mmainfphard"

AVAILTUNES += "armv8mmainfphard"
PACKAGE_EXTRA_ARCHS:tune-armv8mmainfphard = "${TUNE_PKGARCH:tune-armv8mmainfphard}"
BASE_LIB:tune-armv8mmainfphard = "lib/thumb/v8-m.main+fp/hard"
TUNE_FEATURES:tune-armv8mmainfphard ="arm armv8r"
TUNE_CCARGS:tune-armv8mmainfphard = "-mthumb -march=armv8-m.main+fp -mfloat-abi=hard"
TUNE_PKGARCH:tune-armv8mmainfphard = "armv8mmainfpthf"


# thumb/v8-m.main+dp/softfp
# CFLAGS: -mthumb -march=armv8-m.main+fp.dp -mfloat-abi=softfp
DEFAULTTUNE:virtclass-multilib-libv8mmaindpsoftfp = "armv8mmaindpsoftfp"

AVAILTUNES += "armv8mmaindpsoftfp"
PACKAGE_EXTRA_ARCHS:tune-armv8mmaindpsoftfp = "${TUNE_PKGARCH:tune-armv8mmaindpsoftfp}"
BASE_LIB:tune-armv8mmaindpsoftfp = "lib/thumb/v8-m.main+dp/softfp"
TUNE_FEATURES:tune-armv8mmaindpsoftfp ="arm armv8r"
TUNE_CCARGS:tune-armv8mmaindpsoftfp = "-mthumb -march=armv8-m.main+fp.dp -mfloat-abi=softfp"
TUNE_PKGARCH:tune-armv8mmaindpsoftfp = "armv8mmainfpdpt"


# thumb/v8-m.main+dp/hard
# CFLAGS: -mthumb -march=armv8-m.main+fp.dp -mfloat-abi=hard
DEFAULTTUNE:virtclass-multilib-libv8mmaindphard = "armv8mmaindphard"

AVAILTUNES += "armv8mmaindphard"
PACKAGE_EXTRA_ARCHS:tune-armv8mmaindphard = "${TUNE_PKGARCH:tune-armv8mmaindphard}"
BASE_LIB:tune-armv8mmaindphard = "lib/thumb/v8-m.main+dp/hard"
TUNE_FEATURES:tune-armv8mmaindphard ="arm armv8r"
TUNE_CCARGS:tune-armv8mmaindphard = "-mthumb -march=armv8-m.main+fp.dp -mfloat-abi=hard"
TUNE_PKGARCH:tune-armv8mmaindphard = "armv8mmainfpdpthf"
