blob: a87650b71bb095d403993486a7f2af6967be4d55 [file] [log] [blame]
Nguyễn Thái Ngọc Duy1da15802018-04-14 19:19:44 +00001#!/bin/sh
2#
3# Probe the compiler for vintage, version, etc. This is used for setting
4# optional make knobs under the DEVELOPER knob.
5
6CC="$*"
7
8# we get something like (this is at least true for gcc and clang)
9#
10# FreeBSD clang version 3.4.1 (tags/RELEASE...)
11get_version_line() {
Michael J Gruber1fbfd962022-05-09 13:22:02 +020012 LANG=C LC_ALL=C $CC -v 2>&1 | grep ' version '
Nguyễn Thái Ngọc Duy1da15802018-04-14 19:19:44 +000013}
14
15get_family() {
Jeff King33f13ad2021-08-06 15:20:22 -040016 get_version_line | sed 's/^\(.*\) version [0-9].*/\1/'
Nguyễn Thái Ngọc Duy1da15802018-04-14 19:19:44 +000017}
18
19get_version() {
Mike Hommey382a9462023-04-26 09:48:43 +090020 # A string that begins with a digit up to the next SP
21 ver=$(get_version_line | sed 's/^.* version \([0-9][^ ]*\).*/\1/')
22
23 # There are known -variant suffixes that do not affect the
24 # meaning of the main version number. Strip them.
25 ver=${ver%-win32}
26 ver=${ver%-posix}
27
28 echo "$ver"
Nguyễn Thái Ngọc Duy1da15802018-04-14 19:19:44 +000029}
30
31print_flags() {
32 family=$1
33 version=$(get_version | cut -f 1 -d .)
34
35 # Print a feature flag not only for the current version, but also
36 # for any prior versions we encompass. This avoids needing to do
37 # numeric comparisons in make, which are awkward.
38 while test "$version" -gt 0
39 do
40 echo $family$version
41 version=$((version - 1))
42 done
43}
44
45case "$(get_family)" in
46gcc)
47 print_flags gcc
48 ;;
Junio C Hamanof32c5d32021-08-06 13:35:37 -070049clang | *" clang")
Nguyễn Thái Ngọc Duy1da15802018-04-14 19:19:44 +000050 print_flags clang
51 ;;
Junio C Hamanof32c5d32021-08-06 13:35:37 -070052"Apple LLVM")
Nguyễn Thái Ngọc Duy1da15802018-04-14 19:19:44 +000053 print_flags clang
54 ;;
55*)
56 : unknown compiler family
57 ;;
58esac