blob: 50087f567062c4ff858bd6cae83fb3c59a0e4038 [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() {
Jeff King33f13ad2021-08-06 15:20:22 -040020 get_version_line | sed 's/^.* version \([0-9][^ ]*\).*/\1/'
Nguyễn Thái Ngọc Duy1da15802018-04-14 19:19:44 +000021}
22
23print_flags() {
24 family=$1
25 version=$(get_version | cut -f 1 -d .)
26
27 # Print a feature flag not only for the current version, but also
28 # for any prior versions we encompass. This avoids needing to do
29 # numeric comparisons in make, which are awkward.
30 while test "$version" -gt 0
31 do
32 echo $family$version
33 version=$((version - 1))
34 done
35}
36
37case "$(get_family)" in
38gcc)
39 print_flags gcc
40 ;;
Junio C Hamanof32c5d32021-08-06 13:35:37 -070041clang | *" clang")
Nguyễn Thái Ngọc Duy1da15802018-04-14 19:19:44 +000042 print_flags clang
43 ;;
Junio C Hamanof32c5d32021-08-06 13:35:37 -070044"Apple LLVM")
Nguyễn Thái Ngọc Duy1da15802018-04-14 19:19:44 +000045 print_flags clang
46 ;;
47*)
48 : unknown compiler family
49 ;;
50esac