在这个问题“ Checking the gcc version in a Makefile?”中,回答了如何提取gcc编译器的版本。但是,这似乎不适用于icc和ifort的intel编译器?
有人知道使用icc --version
或ifort --version
答案 0 :(得分:0)
如果要从make内部解决问题,使用gmtt(一种GNUmake的帮助程序库)并不是不明智的。它具有字符串通配符匹配器-通配符,而不是正则表达式。
include gmtt-master/gmtt-master/gmtt.mk
# Pattern for 3 version numbers: a string, a string, then 3 strings separated by '.'
# (hopefully the version numbers)
PATTERN3 := * * *.*.*
# the same for 4 version numbers (consistency, eh?)
PATTERN4 := * * *.*.*.*
# We take only words 1-3 from the version string and try to pattern match it,
# taking only the numbers from the result. The possibility of either 3 or 4 numbers
# complicates matters, we have to test if PATTERN4 matches, if not then we try PATTERN3
VERSION_NR = $(if $(call glob-match,$(wordlist 1,3,$(CC_VERSION)),$(PATTERN4)),\
$(wordlist 5,11,$(call glob-match,$(wordlist 1,3,$(CC_VERSION)),$(PATTERN4))),\
$(wordlist 5,9,$(call glob-match,$(wordlist 1,3,$(CC_VERSION)),$(PATTERN3))))
# just assume the contents of CC_VERSION is the result of $(shell $(CC) --version) etc.
CC_VERSION := ifort version 15.0.1
$(info $(VERSION_NR))
CC_VERSION := ifort version 19.0.1.144
$(info $(VERSION_NR))
define CC_VERSION
ifort (IFORT) 19.0.1.144 20181018
Copyright (c) (C) 1985-2014 Intel Corporation. All rights reserved.
endef
$(info $(VERSION_NR))
输出:
$ make
15 . 0 . 1
19 . 0 . 1 . 144
19 . 0 . 1 . 144
makefile:36: *** end.