From 626f3b20ef11fe4aa3ac4576a869cf7dd4e34558 Mon Sep 17 00:00:00 2001 From: apaz Date: Tue, 15 Nov 2022 11:47:47 -0600 Subject: [PATCH] build: improve parsing of gfortran version (#47352) Co-authored-by: Jameson Nash --- Make.inc | 7 +++++-- contrib/normalize_triplet.py | 13 ++++++++++--- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/Make.inc b/Make.inc index 5676f8c0a2878..a6c17ccd80138 100644 --- a/Make.inc +++ b/Make.inc @@ -1140,8 +1140,11 @@ USE_BINARYBUILDER ?= 0 endif # Auto-detect triplet once, create different versions that we use as defaults below for each BB install target -FC_VERSION := $(shell $(FC) --version 2>/dev/null | head -1) -FC_OR_CC_VERSION := $(or $(FC_VERSION),$(shell $(CC) --version 2>/dev/null | head -1)) +FC_VERSION := $(shell $(FC) -dM -E - < /dev/null | grep __GNUC__ | cut -d' ' -f3) +ifeq ($(USEGCC)$(FC_VERSION),1) +FC_OR_CC_VERSION := $(shell $(CC) -dumpfullversion -dumpversion 2>/dev/null | cut -d'.' -f1) +# n.b. clang's __GNUC__ macro pretends to be gcc 4.2.1, so leave it as the empty string here if the compiler is not certain to be GCC +endif BB_TRIPLET_LIBGFORTRAN_CXXABI := $(shell $(call invoke_python,$(JULIAHOME)/contrib/normalize_triplet.py) $(or $(XC_HOST),$(XC_HOST),$(BUILD_MACHINE)) "$(FC_OR_CC_VERSION)" "$(or $(shell echo '\#include ' | $(CXX) $(CXXFLAGS) -x c++ -dM -E - | grep _GLIBCXX_USE_CXX11_ABI | awk '{ print $$3 }' ),1)") BB_TRIPLET_LIBGFORTRAN := $(subst $(SPACE),-,$(filter-out cxx%,$(subst -,$(SPACE),$(BB_TRIPLET_LIBGFORTRAN_CXXABI)))) BB_TRIPLET_CXXABI := $(subst $(SPACE),-,$(filter-out libgfortran%,$(subst -,$(SPACE),$(BB_TRIPLET_LIBGFORTRAN_CXXABI)))) diff --git a/contrib/normalize_triplet.py b/contrib/normalize_triplet.py index b493d0d3afff8..77c047b360b76 100755 --- a/contrib/normalize_triplet.py +++ b/contrib/normalize_triplet.py @@ -113,9 +113,16 @@ def p(x): if not sys.argv[2]: libgfortran_version = "libgfortran5" else: - # Take the last thing that looks like a version number, and extract its major component - version_numbers = list(filter(lambda x: re.match("\d+\.\d+(\.\d+)?", x), sys.argv[2].split())) - major_ver = int(version_numbers[-1].split('.')[0]) + # Grab the first number in the last word with a number + # This will be the major version number. + major_ver = -1 + words = sys.argv[2].split() + for word in words[::-1]: + major_ver = re.search("[0-9]+", word) + if major_ver: + major_ver = int(major_ver.group()) + break + if major_ver <= 6: libgfortran_version = "libgfortran3" elif major_ver <= 7: