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>
  • Loading branch information
apaz-cli and vtjnash authored Nov 15, 2022
1 parent 58b559f commit 626f3b2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
7 changes: 5 additions & 2 deletions Make.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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 <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))))
Expand Down
13 changes: 10 additions & 3 deletions contrib/normalize_triplet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 626f3b2

Please sign in to comment.