In this question " Checking the gcc version in a Makefile? " it was answered how to extract the version of gcc compiler. However, that does not seem to work with the intel compilers as icc and ifort?
Does anybody know to make it give same output using icc --version
or ifort --version
Asked
Active
Viewed 2,230 times
1

ATK
- 1,296
- 10
- 26
-
Does `icc --version` or `ifort --version` not work for you? – francescalus Feb 14 '19 at 13:59
-
They work, but the output are not appropriate to what I need them for. I would need the digits so I can in my makefile can set a specific flag accordingly. Something like `if version > 15; then FLAG=+ DINTEL_NEW – ATK Feb 14 '19 at 14:05
-
Ah, so you are asking something like "given a string like `ifort (IFORT) 19.0.1.144 20181018`, how can I extract the numerical part?"? (As an aside, checking for a version of a compiler at least x, is generally better written as a test for whether the compiler you are using has support for what you require. This way you don't have to worry about having a custom script for every compiler/version (consider ifort 24 may use a different scheme for reporting).) – francescalus Feb 14 '19 at 14:11
-
Yes this is what I am looking for. I know e.g that compilers before 15.0.1 does not support a feature but those after they do. So in my code I would have some preprocessors to check if an X chunk of code should be compiled or not. – ATK Feb 14 '19 at 14:25
-
Do you have awk or perl? – Beta Feb 14 '19 at 14:44
-
No, is there not a way to achieve this using linux commands, like, sed ? – ATK Feb 14 '19 at 14:47
-
Can you add the strings which you want to dissect? I don't have any of the your compilers and no time to install them, but [this GNUmake library](https://github.com/markpiffer/gmtt) can handle such case pretty simple. – Vroomfondel Feb 14 '19 at 14:56
-
When you write `ifort -v` you get `ifort version 15.0.1` or `ifort version 19.0.1.144`. When writing `ifort --version` you get `ifort (IFORT) 19.0.1.144 20181018
Copyright (c) (C) 1985-2014 Intel Corporation. All rights reserved. ` The only thing I need is the version digits, i.e. 19.0.1.144 or even the first as 19 will do the job – ATK Feb 14 '19 at 15:07
1 Answers
1
If you want to solve it from within make, using gmtt, a helper library for GNUmake, is not unwise. It features a wildcard matcher for strings - wildcards, not regular expressions.
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))
Output:
$ make
15 . 0 . 1
19 . 0 . 1 . 144
19 . 0 . 1 . 144
makefile:36: *** end.

Vroomfondel
- 2,704
- 1
- 15
- 29