+cc_version() {
+ echo "${cc_version_cached:=`cc_version_nocache`}"
+}
+
+print_cc_version() {
+ cc_version
+ printf 'Compiler identification: '
+ cc_id
+}
+
+# For the current C compiler try to print a short and uniform identification
+# string (such as "gcc-9.3.0") that is convenient to use in a case statement.
+cc_id_nocache() {
+ cc_id_firstline=`cc_version | head -1`
+ : "${cc_id_firstline:?}"
+
+ cc_id_guessed=`echo "$cc_id_firstline" | sed 's/^.*clang version \([0-9\.]*\).*$/clang-\1/'`
+ if [ "$cc_id_firstline" != "$cc_id_guessed" ]; then
+ echo "$cc_id_guessed"
+ return
+ fi
+
+ cc_id_guessed=`echo "$cc_id_firstline" | sed 's/^IBM XL C.*, V\([0-9\.]*\).*$/xlc-\1/'`
+ if [ "$cc_id_firstline" != "$cc_id_guessed" ]; then
+ echo "$cc_id_guessed"
+ return
+ fi
+
+ cc_id_guessed=`echo "$cc_id_firstline" | sed 's/^.* Sun C \([0-9\.]*\) .*$/suncc-\1/'`
+ if [ "$cc_id_firstline" != "$cc_id_guessed" ]; then
+ echo "$cc_id_guessed"
+ return
+ fi
+
+ # OpenBSD default GCC:
+ # "gcc (GCC) 4.2.1 20070719"
+ # RedHat GCC:
+ # "gcc (GCC) 8.3.1 20190223 (Red Hat 8.3.1-2)"
+ # "gcc (GCC) 10.3.1 20210422 (Red Hat 10.3.1-1)"
+ # other GCC packages:
+ # "sparc-sun-solaris2.9-gcc (GCC) 4.2.0 (gccfss)"
+ # "gcc (GCC) 5.5.0"
+ # "gcc (nb4 20200810) 7.5.0"
+ # "gcc (OpenIndiana 7.5.0-il-0) 7.5.0"
+ # "gcc (Debian 8.3.0-6) 8.3.0"
+ # "gcc (Raspbian 8.3.0-6+rpi1) 8.3.0"
+ # "egcc (GCC) 8.4.0"
+ # "gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0"
+ # "gcc (FreeBSD Ports Collection) 10.3.0"
+ cc_id_guessed=`echo "$cc_id_firstline" | sed 's/^.* (.*) \([0-9\.]*\).*$/gcc-\1/'`
+ if [ "$cc_id_firstline" != "$cc_id_guessed" ]; then
+ echo "$cc_id_guessed"
+ return
+ fi
+}
+
+cc_id() {
+ echo "${cc_id_cached:=`cc_id_nocache`}"
+}
+
+# Call this function each time CC has changed.
+discard_cc_cache() {
+ cc_version_cached=
+ cc_id_cached=
+}
+
+# For the current C compiler try to print CFLAGS value that tells to treat
+# warnings as errors.
+cc_werr_cflags() {
+ case `cc_id` in
+ gcc-*|clang-*)
+ echo '-Werror'
+ ;;
+ xlc-*)
+ # XL C 12.1 and 13.1 recognize "-qhalt=w". XL C 16.1 recognizes that
+ # and "-Werror".
+ echo '-qhalt=w'
+ ;;
+ suncc-*)
+ echo '-errwarn=%all'
+ ;;
+ esac
+}
+
+# Tell whether "gcc" is a symlink to Clang (this is the case on macOS).
+gcc_is_clang_in_disguise() {
+ case `cc_id`/`basename "${CC:?}"` in
+ clang-*/gcc)
+ return 0
+ ;;
+ esac
+ return 1
+}
+
+os_id() {
+ # OS does not change between builds or in the middle of a build, so it is
+ # fine to cache uname output.
+ : "${os_id_sysname:=`uname -s`}"
+ printf '%s-' "$os_id_sysname"
+ : "${os_id_release:=`uname -r`}"
+ case "$os_id_sysname" in
+ AIX)
+ : "${os_id_version:=`uname -v`}"
+ echo "${os_id_version}.${os_id_release}"
+ ;;
+ Darwin|NetBSD|OpenBSD|SunOS)
+ echo "$os_id_release"
+ ;;
+ FreeBSD|Linux)
+ # Meaningful version is usually the substring before the first dash.
+ echo "$os_id_release" | sed 's/^\([0-9\.]*\).*$/\1/'
+ ;;
+ Haiku)
+ # Meaningful version is the substring before the plus sign.
+ # "hrev55181" stands for "R1/beta3".
+ # "hrev54154" stands for "R1/beta2".
+ : "${os_id_version:=`uname -v`}"
+ echo "$os_id_version" | sed 's/^\(hrev.*\)+.*$/\1/'
+ ;;
+ *)
+ echo 'UNKNOWN'
+ ;;
+ esac
+}
+