forked from kata-containers/tests
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kata-arch.sh
executable file
·127 lines (97 loc) · 2.2 KB
/
kata-arch.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/usr/bin/env bash
#
# Copyright (c) 2018 Intel Corporation
#
# SPDX-License-Identifier: Apache-2.0
#
set -e
typeset -r script_name=${0##*/}
typeset -r cidir=$(dirname "$0")
source "${cidir}/lib.sh"
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
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
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
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
}
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 "$@"