forked from docker-archive/runc
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathlib.sh
More file actions
90 lines (83 loc) · 1.86 KB
/
Copy pathlib.sh
File metadata and controls
90 lines (83 loc) · 1.86 KB
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
#!/bin/bash
# get_platform computes the platform section of target triples on this OS.
function get_platform() {
# Fedora doesn't have ID_LIKE and only has ID=fedora, so we need to
# construct a fake ID_LIKE to treat AlmaLinux and Fedora the same way.
local ID_LIKE
# shellcheck source=/etc/os-release disable=SC1091 # outside our sources
ID_LIKE="$(
source /etc/os-release
echo "${ID:-} ${ID_LIKE:-}"
)"
local PLATFORM
case "$ID_LIKE" in
*suse*)
PLATFORM=suse-linux
;;
*rhel* | *fedora* | *centos*)
PLATFORM=redhat-linux
;;
*)
PLATFORM=linux-gnu
;;
esac
echo "$PLATFORM"
}
# set_cross_vars sets a few environment variables used for cross-compiling,
# based on the architecture specified in $1.
function set_cross_vars() {
GOARCH="$1" # default, may be overridden below
local cc_flags=""
unset GOARM
PLATFORM="$(get_platform)"
[[ "$PLATFORM" == *suse* ]] && is_suse=1
case "$1" in
386)
# Always use the 64-bit compiler to build the 386 binary, which works
# for the more common cross-build method for x86 (namely, the
# equivalent of dpkg --add-architecture).
local cpu_type
if [ -v is_suse ]; then
cpu_type=i586
else
cpu_type=i686
fi
HOST=x86_64-${PLATFORM}
# Pass these via CC rather than CFLAGS, so that autoconf
# still uses its default CFLAGS (-g -O2) when CFLAGS is unset.
cc_flags=" -m32 -march=$cpu_type"
;;
amd64)
HOST=x86_64-${PLATFORM}
;;
arm64)
HOST=aarch64-${PLATFORM}
;;
armel)
HOST=arm-${PLATFORM}eabi
GOARCH=arm
GOARM=5
;;
armhf)
HOST=arm-${PLATFORM}eabihf
GOARCH=arm
GOARM=7
;;
ppc64le)
HOST=powerpc64le-${PLATFORM}
;;
riscv64)
HOST=riscv64-${PLATFORM}
;;
s390x)
HOST=s390x-${PLATFORM}
;;
*)
echo "set_cross_vars: unsupported architecture: $1" >&2
exit 1
;;
esac
CC="${HOST:+$HOST-}gcc${cc_flags}"
STRIP="${HOST:+$HOST-}strip"
export HOST GOARM GOARCH CC STRIP
}