Repository navigation
Expand file tree
/
Copy pathcheck_gcc_version.sh
More file actions
42 lines (38 loc) · 1.63 KB
/
Copy pathcheck_gcc_version.sh
File metadata and controls
42 lines (38 loc) · 1.63 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
#!/bin/bash
# -----------------------------------------------------------------------------------------------------------
# Copyright (c) 2026 Huawei Technologies Co., Ltd.
# Licensed under the CANN Open Software License Agreement Version 2.0.
# -----------------------------------------------------------------------------------------------------------
# Shared host GCC version policy:
# - require GCC >= 7.3.0 (fatal on lower)
# - warn if GCC > 11.3.0 (non-fatal)
# Source this file from build scripts (do NOT execute), e.g.:
# source "$(dirname "$0")/check_gcc_version.sh"
# check_gcc_version
# Or call: check_gcc_version <gcc-binary> to check a specific compiler.
check_gcc_version() {
local gcc_bin="${1:-gcc}"
if ! command -v "${gcc_bin}" >/dev/null 2>&1; then
echo "ERROR: ${gcc_bin} not found. hyper_multicore requires GCC >= 7.3.0." >&2
return 1
fi
local ver
ver="$("${gcc_bin}" -dumpfullversion -dumpversion 2>/dev/null | head -1)"
if [ -z "${ver}" ]; then
echo "ERROR: cannot determine version of ${gcc_bin}." >&2
return 1
fi
local major minor patch
IFS='.' read -r major minor patch <<< "${ver}"
major="${major:-0}"; minor="${minor:-0}"; patch="${patch:-0}"
local num=$((major * 10000 + minor * 100 + patch))
if [ "${num}" -lt 70300 ]; then
echo "ERROR: GCC version ${ver} < 7.3.0. Install GCC >= 7.3.0 ." >&2
return 1
fi
if [ "${num}" -gt 110300 ]; then
echo "WARNING: GCC version ${ver} > 11.3.0. May cause unknown problems." >&2
fi
echo "INFO: GCC ${ver} accepted (recommended range [7.3.0, 11.3.0])."
return 0
}