detect_gcc 4.86 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
#! /bin/bash

function detect_gcc_or_clang()
{
    command -v $1 >/dev/null 2>&1
    if [ $? -ne 0 ]; then
      dgc_ret=0
      return
    fi

    # First we try to understand if g++ command line is linked to clang
    
    $1 --version | grep "Apple LLVM"
    if [ $? == 0 ]; then
        echo "Apple LLVM based g++"

        # we try the detect the version
        major=$(g++ --version | grep LLVM | sed 's/.*\([0-9][0-9]*\)\.\([0-9][0-9]*\)\.\([0-9][0-9]*\).*(.*/\1/g')

        # we check if the detection is garbage
        echo "$major" | egrep -q '^[0-9]+$'
        if [ $? == 0 ]; then
           dgc_major=$($1 --version | grep LLVM | sed 's/.*\([0-9][0-9]*\)\.\([0-9][0-9]*\)\.\([0-9][0-9]*\).*(.*/\1/g')
           dgc_middle=$($1 --version | grep LLVM | sed 's/.*\([0-9][0-9]*\)\.\([0-9][0-9]*\)\.\([0-9][0-9]*\).*(.*/\2/g')
           dgc_minor=$($1 --version | grep LLVM | sed 's/.*\([0-9][0-9]*\)\.\([0-9][0-9]*\)\.\([0-9][0-9]*\).*(.*/\3/g')

           if [ $dgc_major -gt 6 ]; then
             echo -e "clang++ $dgc_major.$dgc_middle.$dgc_minor \033[92;1m SUCCESS \033[0m"
             dgc_compiler=clang++
             dgc_ret=1
           elif [ $dgc_major -lt 6 ]; then
             echo -e "clang++ $dgc_major.$dgc_middle.$dgc_minor \033[91;5;1m FAILED \033[0m your Apple clang $major.middle;$minor is too old, 6.1.0 or higher is required"
             dgc_ret=0
           elif [ $dgc_middle -gt 1  ]; then
             echo -e "clang++ $dgc_major.$dgc_middle.$dgc_minor \033[92;1m SUCCESS \033[0m"
             dgc_compiler=clang++
             dgc_ret=1
           elif [ $dgc_minor -lt 1 ]; then
             echo -e "clang++ $dgc_major.$dgc_middle.$dgc_minor \033[91;5;1m FAILED \033[0m your Apple clang $major.middle;$minor is too old, 6.1.0 or higher is required"
             dgc_ret=0
           else
             echo -e "Apple clang++ version $dgc_major.$dgc_middle.$dgc_minor \033[92;1m SUCCESS \033[0m"
             dgc_compiler=clang++
             dgc_ret=1
           fi
           return
        fi
        dgc_ret=2
        return
    fi

    $1 --version | grep $1
    if [ $? == 0 -a x"$1" == x"gcc" ]; then
        dgc_major=$($1 --version | grep $1 | sed 's/.*\([0-9][0-9]*\)\.\([0-9][0-9]*\)\.\([0-9][0-9]*\).*/\1/g')
        dgc_middle=$($1 --version | grep $1 | sed 's/.*\([0-9][0-9]*\)\.\([0-9][0-9]*\)\.\([0-9][0-9]*\).*/\2/g')
        dgc_minor=$($1 --version | grep $1 | sed 's/.*\([0-9][0-9]*\)\.\([0-9][0-9]*\)\.\([0-9][0-9]*\).*/\3/g')

        if [ $dgc_major -gt 4 ]; then
          echo -e "$1 $dgc_major.$dgc_middle.$dgc_minor \033[92;1m SUCCESS \033[0m"
          dgc_compiler=g++
          dgc_ret=1
        elif [ $dgc_major -lt 4 ]; then
          echo -e "$1 $dgc_major.$dgc_middle.$dgc_minor  \033[91;5;1m FAILED \033[0m your g++ version is too old, 4.8.2 at least required"
          dgc_ret=0
        elif [ $dgc_middle -gt 8  ]; then
          echo -e "$1 $dgc_major.$dgc_middle.$dgc_minor \033[92;1m SUCCESS \033[0m"
          dgc_compiler=g++
          dgc_ret=1
        elif [ $dgc_middle -lt 8 ]; then
          echo -e "$1 $dgc_major.$dgc_middle.$dgc_minor \033[91;5;1m FAILED \033[0m your g++ version is too old, 4.8.2 at least required"
          dgc_ret=0
        elif [ $dgc_minor -gt 1  ]; then
          echo -e "$1 $dgc_major.$dgc_middle.$dgc_minor \033[92;1m SUCCESS \033[0m"
          dgc_compiler=g++
          dgc_ret=1
        else
          echo -e "$1 $dgc_major.$dgc_middle.$dgc_minor \033[92;1m FAILED \033[0m your g++ version is too old, 4.8.2 at least required"
          dgc_ret=0
        fi
        return
    fi

    $1 --version | grep $1
    if [ $? == 0 -a x"$1" == x"clang" ]; then
        dgc_major=$($1 --version | grep $1 | sed 's/.*\([0-9][0-9]*\)\.\([0-9][0-9]*\)\.\([0-9][0-9]*\).*/\1/g')
        dgc_middle=$($1 --version | grep $1 | sed 's/.*\([0-9][0-9]*\)\.\([0-9][0-9]*\)\.\([0-9][0-9]*\).*/\2/g')
        dgc_minor=$($1 --version | grep $1 | sed 's/.*\([0-9][0-9]*\)\.\([0-9][0-9]*\)\.\([0-9][0-9]*\).*/\3/g')

        if [ $dgc_major -gt 3 ]; then
          echo -e "$1 $dgc_major.$dgc_middle.$dgc_minor \033[92;1m SUCCESS \033[0m"
          dgc_compiler=clang++
          dgc_ret=1
        elif [ $dgc_major -lt 3 ]; then
          echo -e "$1 $dgc_major.$dgc_middle.$dgc_minor  \033[91;5;1m FAILED \033[0m your clang version is too old 3.6.0 at least required"
          dgc_ret=0
        elif [ $dgc_middle -gt 6  ]; then
          echo -e "$1 $dgc_major.$dgc_middle.$dgc_minor \033[92;1m SUCCESS \033[0m"
          dgc_compiler=clang++
          dgc_ret=1
        elif [ $dgc_middle -lt 6 ]; then
          echo -e "$1 $dgc_major.$dgc_middle.$dgc_minor \033[91;5;1m FAILED \033[0m your clang version is too old 3.6.0 at least required"
          dgc_ret=0
        else
          echo -e "$1 $dgc_major.$dgc_middle.$dgc_minor \033[92;1m SUCCESS \033[0m"
          dgc_compiler=clang++
          dgc_ret=0
        fi
        return
    fi


    dgc_ret=0
}