Skip to content

Commit aa6961f

Browse files
apaz-clivtjnash
authored andcommitted
build: improve parsing of gfortran version (#47352)
Co-authored-by: Jameson Nash <vtjnash@gmail.com> (cherry picked from commit 626f3b2)
1 parent 2bfab32 commit aa6961f

File tree

2 files changed

+26
-11
lines changed

2 files changed

+26
-11
lines changed

Make.inc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1188,7 +1188,12 @@ USE_BINARYBUILDER ?= 0
11881188
endif
11891189

11901190
# Auto-detect triplet once, create different versions that we use as defaults below for each BB install target
1191-
BB_TRIPLET_LIBGFORTRAN_CXXABI := $(shell $(call invoke_python,$(JULIAHOME)/contrib/normalize_triplet.py) $(or $(XC_HOST),$(XC_HOST),$(BUILD_MACHINE)) "$(shell $(FC) --version | head -1)" "$(or $(shell echo '\#include <string>' | $(CXX) $(CXXFLAGS) -x c++ -dM -E - | grep _GLIBCXX_USE_CXX11_ABI | awk '{ print $$3 }' ),1)")
1191+
FC_VERSION := $(shell $(FC) -dM -E - < /dev/null | grep __GNUC__ | cut -d' ' -f3)
1192+
ifeq ($(USEGCC)$(FC_VERSION),1)
1193+
FC_OR_CC_VERSION := $(shell $(CC) -dumpfullversion -dumpversion 2>/dev/null | cut -d'.' -f1)
1194+
# 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
1195+
endif
1196+
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 <string>' | $(CXX) $(CXXFLAGS) -x c++ -dM -E - | grep _GLIBCXX_USE_CXX11_ABI | awk '{ print $$3 }' ),1)")
11921197
BB_TRIPLET_LIBGFORTRAN := $(subst $(SPACE),-,$(filter-out cxx%,$(subst -,$(SPACE),$(BB_TRIPLET_LIBGFORTRAN_CXXABI))))
11931198
BB_TRIPLET_CXXABI := $(subst $(SPACE),-,$(filter-out libgfortran%,$(subst -,$(SPACE),$(BB_TRIPLET_LIBGFORTRAN_CXXABI))))
11941199
BB_TRIPLET := $(subst $(SPACE),-,$(filter-out cxx%,$(filter-out libgfortran%,$(subst -,$(SPACE),$(BB_TRIPLET_LIBGFORTRAN_CXXABI)))))

contrib/normalize_triplet.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -109,16 +109,26 @@ def p(x):
109109
# not been specified
110110
if libgfortran_version == "blank_libgfortran":
111111
if len(sys.argv) >= 3:
112-
libgfortran_version = {
113-
"4": "libgfortran3",
114-
"5": "libgfortran3",
115-
"6": "libgfortran3",
116-
"7": "libgfortran4",
117-
"8": "libgfortran5",
118-
"9": "libgfortran5",
119-
"10": "libgfortran5",
120-
"11": "libgfortran5",
121-
}[list(filter(lambda x: re.match("\d+\.\d+(\.\d+)?", x), sys.argv[2].split()))[-1].split('.')[0]]
112+
# If there was no gfortran/gcc version passed in, default to the latest libgfortran version
113+
if not sys.argv[2]:
114+
libgfortran_version = "libgfortran5"
115+
else:
116+
# Grab the first number in the last word with a number
117+
# This will be the major version number.
118+
major_ver = -1
119+
words = sys.argv[2].split()
120+
for word in words[::-1]:
121+
major_ver = re.search("[0-9]+", word)
122+
if major_ver:
123+
major_ver = int(major_ver.group())
124+
break
125+
126+
if major_ver <= 6:
127+
libgfortran_version = "libgfortran3"
128+
elif major_ver <= 7:
129+
libgfortran_version = "libgfortran4"
130+
else:
131+
libgfortran_version = "libgfortran5"
122132

123133
if cxx_abi == "blank_cxx_abi":
124134
if len(sys.argv) == 4:

0 commit comments

Comments
 (0)