From: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org,
"Carlo Marcelo Arenas Belón" <carenas@gmail.com>,
"Jeff King" <peff@peff.net>
Subject: Re: [PATCH v2 0/3] detect-compiler: clang updates
Date: Sat, 07 Aug 2021 04:02:45 +0200 [thread overview]
Message-ID: <87bl6aypke.fsf@evledraar.gmail.com> (raw)
In-Reply-To: <20210806205235.988761-1-gitster@pobox.com>
On Fri, Aug 06 2021, Junio C Hamano wrote:
> So here is a mini-series that summarizes what has been suggested so
> far on the topic.
>
> Carlo Marcelo Arenas Belón (1):
> build: update detect-compiler for newer Xcode version
>
> Jeff King (1):
> build: clang version may not be followed by extra words
>
> Junio C Hamano (1):
> build: catch clang that identifies itself as "$VENDOR clang"
>
> detect-compiler | 9 +++------
> 1 file changed, 3 insertions(+), 6 deletions(-)
Perhaps I've missed some obvious reason not to do this, but why are we
parsing the --version output of two modern compilers, as opposed to just
asking them what type/version they are via their usual macro facilities?
I.e. something like the below:
diff --git a/detect-compiler b/detect-compiler
index 70b754481c8..37908ac9ea8 100755
--- a/detect-compiler
+++ b/detect-compiler
@@ -5,19 +5,47 @@
CC="$*"
-# we get something like (this is at least true for gcc and clang)
+#!/bin/sh
#
-# FreeBSD clang version 3.4.1 (tags/RELEASE...)
-get_version_line() {
- $CC -v 2>&1 | grep ' version '
-}
+# Probe the compiler for vintage, version, etc. This is used for setting
+# optional make knobs under the DEVELOPER knob.
+
+CC="$*"
+
+v=$($CC -E - <<-EOF 2>&1 | grep -e '=')
+GNUC=__GNUC__
+GNUC_MINOR=__GNUC_MINOR__
+GNUC_PATCHLEVEL=__GNUC_PATCHLEVEL__
+clang=__clang__
+clang_major=__clang_major__
+clang_minor=__clang_minor__
+clang_patchlevel=__clang_patchlevel__
+EOF
+eval "$v"
get_family() {
- get_version_line | sed 's/^\(.*\) version [0-9][^ ]* .*/\1/'
+ # Clang also sets the GNUC macros, but GCC does not set
+ # clang's.
+ if test "$clang" != "__clang__"
+ then
+ echo clang
+ elif test "$GNUC" != "__GNUC__"
+ then
+ echo gcc
+ else
+ echo unknown
+ fi
}
get_version() {
- get_version_line | sed 's/^.* version \([0-9][^ ]*\) .*/\1/'
+ case "$(get_family)" in
+ clang)
+ echo "$clang_major.$clang_minor.$clang_patchlevel"
+ ;;
+ gcc)
+ echo "$GNUC.$GNUC_MINOR.$GNUC_PATCHLEVEL"
+ ;;
+ esac
}
print_flags() {
@@ -41,12 +69,6 @@ gcc)
clang)
print_flags clang
;;
-"FreeBSD clang")
- print_flags clang
- ;;
-"Apple LLVM")
- print_flags clang
- ;;
*)
: unknown compiler family
;;
next prev parent reply other threads:[~2021-08-07 2:08 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-06 8:06 [PATCH] makefile: update detect-compiler for newer Xcode version Carlo Marcelo Arenas Belón
2021-08-06 12:00 ` Bagas Sanjaya
2021-08-06 13:32 ` Carlo Arenas
2021-08-06 16:37 ` Eric Sunshine
2021-08-06 13:42 ` Atharva Raykar
2021-08-06 18:11 ` Junio C Hamano
2021-08-06 19:20 ` Jeff King
2021-08-06 20:52 ` [PATCH v2 0/3] detect-compiler: clang updates Junio C Hamano
2021-08-06 20:52 ` [PATCH v2 1/3] build: update detect-compiler for newer Xcode version Junio C Hamano
2021-08-06 20:52 ` [PATCH v2 2/3] build: clang version may not be followed by extra words Junio C Hamano
2021-08-06 20:52 ` [PATCH v2 3/3] build: catch clang that identifies itself as "$VENDOR clang" Junio C Hamano
2021-08-07 2:09 ` Jeff King
2021-08-07 2:02 ` Ævar Arnfjörð Bjarmason [this message]
2021-08-07 2:15 ` [PATCH v2 0/3] detect-compiler: clang updates Jeff King
2021-08-07 2:56 ` Ævar Arnfjörð Bjarmason
2021-08-07 14:13 ` Jeff King
2021-08-07 14:26 ` Ævar Arnfjörð Bjarmason
2021-08-07 14:40 ` Jeff King
2021-08-07 15:36 ` Ævar Arnfjörð Bjarmason
2021-08-09 18:10 ` Jeff King
2021-08-08 0:30 ` Carlo Arenas
2021-08-09 18:08 ` Jeff King
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87bl6aypke.fsf@evledraar.gmail.com \
--to=avarab@gmail.com \
--cc=carenas@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=peff@peff.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.