Search code examples
makefileiccintel-fortran

Checking ifort/icc version in makefile


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


Solution

  • 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.