mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-04-27 19:35:32 +00:00
Right now we'd need to import lib.sh just in order to get cross-build information for rust, and it seems a little bit premature to do so at this stage and only for rust. Let's skip it and keep this transition simple. Signed-off-by: Fabiano Fidêncio <fabiano.fidencio@intel.com>
121 lines
2.2 KiB
Bash
Executable File
121 lines
2.2 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
#
|
|
# Copyright (c) 2018-2023 Intel Corporation
|
|
#
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
#
|
|
|
|
set -e
|
|
|
|
typeset -r script_name=${0##*/}
|
|
|
|
typeset -r cidir=$(dirname "$0")
|
|
|
|
function usage() {
|
|
cat <<EOF
|
|
Description: Display host architecture name in various formats.
|
|
|
|
Usage: $script_name [options]
|
|
|
|
Options:
|
|
|
|
-d, --default : Show arch(1) architecture (this is the default).
|
|
-g, --golang : Show architecture name using golang naming.
|
|
-r, --rust : Show architecture name using rust naming
|
|
-h, --help : Show this help.
|
|
-k, --kernel : Show architecture name compatible with Linux* build system.
|
|
|
|
EOF
|
|
}
|
|
|
|
# Convert architecture to the name used by golang
|
|
function arch_to_golang() {
|
|
local -r arch="$1"
|
|
|
|
case "$arch" in
|
|
aarch64) echo "arm64";;
|
|
ppc64le) echo "$arch";;
|
|
x86_64) echo "amd64";;
|
|
s390x) echo "s390x";;
|
|
*) die "unsupported architecture: $arch";;
|
|
esac
|
|
}
|
|
|
|
# Convert architecture to the name used by rust
|
|
function arch_to_rust() {
|
|
local arch="$1"
|
|
|
|
if [ "${arch}" == "ppc64le" ]; then
|
|
arch="powerpc64le"
|
|
fi
|
|
|
|
echo "${arch}"
|
|
}
|
|
|
|
# Convert architecture to the name used by the Linux kernel build system
|
|
function arch_to_kernel() {
|
|
local -r arch="$1"
|
|
|
|
case "$arch" in
|
|
aarch64) echo "arm64";;
|
|
ppc64le) echo "powerpc";;
|
|
x86_64) echo "$arch";;
|
|
s390x) echo "s390x";;
|
|
*) die "unsupported architecture: $arch";;
|
|
esac
|
|
}
|
|
|
|
function main() {
|
|
local type="default"
|
|
|
|
local getopt_cmd="getopt"
|
|
|
|
# macOS default getopt does not recognize GNU options
|
|
[ "$(uname -s)" == "Darwin" ] && getopt_cmd="/usr/local/opt/gnu-getopt/bin/${getopt_cmd}"
|
|
|
|
local args=$("$getopt_cmd" \
|
|
-n "$script_name" \
|
|
-a \
|
|
--options="dgrhk" \
|
|
--longoptions="default golang rust help kernel" \
|
|
-- "$@")
|
|
|
|
eval set -- "$args"
|
|
[ $? -ne 0 ] && { usage >&2; exit 1; }
|
|
|
|
while [ $# -gt 1 ]
|
|
do
|
|
case "$1" in
|
|
-d|--default) ;;
|
|
|
|
-g|--golang) type="golang";;
|
|
|
|
-r|--rust) type="rust";;
|
|
|
|
-h|--help)
|
|
usage
|
|
exit 0
|
|
;;
|
|
|
|
-k|--kernel) type="kernel";;
|
|
|
|
--)
|
|
shift
|
|
break
|
|
;;
|
|
esac
|
|
shift
|
|
done
|
|
|
|
local -r arch=$(uname -m)
|
|
|
|
case "$type" in
|
|
default) echo "$arch";;
|
|
golang) arch_to_golang "$arch";;
|
|
rust) arch_to_rust "${arch}";;
|
|
kernel) arch_to_kernel "$arch";;
|
|
esac
|
|
}
|
|
|
|
main "$@"
|