Skip to content

Commit

Permalink
build: improve parsing of gfortran version (#47352)
Browse files Browse the repository at this point in the history
Co-authored-by: Jameson Nash <vtjnash@gmail.com>
(cherry picked from commit 626f3b2)
  • Loading branch information
apaz-cli authored and KristofferC committed Dec 21, 2022
1 parent 7479889 commit 21a2c43
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
7 changes: 6 additions & 1 deletion Make.inc
Original file line number Diff line number Diff line change
Expand Up @@ -1188,7 +1188,12 @@ USE_BINARYBUILDER ?= 0
endif

# Auto-detect triplet once, create different versions that we use as defaults below for each BB install target
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)")
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 <string>' | $(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))))
BB_TRIPLET := $(subst $(SPACE),-,$(filter-out cxx%,$(filter-out libgfortran%,$(subst -,$(SPACE),$(BB_TRIPLET_LIBGFORTRAN_CXXABI)))))
Expand Down
30 changes: 20 additions & 10 deletions contrib/normalize_triplet.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,26 @@ def p(x):
# not been specified
if libgfortran_version == "blank_libgfortran":
if len(sys.argv) >= 3:
libgfortran_version = {
"4": "libgfortran3",
"5": "libgfortran3",
"6": "libgfortran3",
"7": "libgfortran4",
"8": "libgfortran5",
"9": "libgfortran5",
"10": "libgfortran5",
"11": "libgfortran5",
}[list(filter(lambda x: re.match("\d+\.\d+(\.\d+)?", x), sys.argv[2].split()))[-1].split('.')[0]]
# If there was no gfortran/gcc version passed in, default to the latest libgfortran version
if not sys.argv[2]:
libgfortran_version = "libgfortran5"
else:
# 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:
libgfortran_version = "libgfortran4"
else:
libgfortran_version = "libgfortran5"

if cxx_abi == "blank_cxx_abi":
if len(sys.argv) == 4:
Expand Down

0 comments on commit 21a2c43

Please sign in to comment.