aboutsummaryrefslogtreecommitdiff
path: root/utils/getg++.sh
blob: 922b1a99214ee3f640d257ce40b4570a7747bbc7 (plain) (blame)
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
#!/bin/sh

# Shave and a Haircut
# (c) 2019 Epic Games
# US Patent 6720962

returnVersion=n
returnDTS=n
maya=

while [ "$1" != "" ]; do
    if [ "$1" = "-v" ]; then
        returnVersion=y
    elif [ "$1" == "-dts" ]; then
        returnDTS=y
    else
        maya=$1
    fi

    shift
done

if [ "${maya}" = "" ]; then
    echo "Usage: $0 mayaVersion" >&2
    echo ""
    exit
fi

gpp=
utilsDir=`dirname $0`
os=`${utilsDir}/getos.sh`

case ${os} in
    ce*|deb*|fc*|rh*)
        gppVerNeeded=`${utilsDir}/getMayaVersions.sh |
                grep "^${maya}[[:space:]]" | head -n 1 | cut -f 3`

        if [ "${gppVerNeeded}" != "" ]; then
            if [ "${returnVersion}" = "y" ]; then
                echo ${gppVerNeeded}
                exit
            fi

            # 4.8.2 builds on CentOS 6 require DTS.
            if [ "${os/.*/}" = "ce6" -a "${gppVerNeeded}" = "4.8.2" ]; then
                if [ "${returnDTS}" = "y" ]; then
                    echo y
                    exit
                fi

                source /opt/rh/devtoolset-2/enable
            elif [ "${returnDTS}" = "y" ]; then
                echo n
                exit
            fi

            # Check to see if there is a directory in /opt containing the
            # compiler we want.
            compressedVer=`echo ${gppVerNeeded} | sed 's/\.//g'`
            shortVer=`echo ${gppVerNeeded} | cut -d. -f-2`

            if [ -x /opt/gcc${compressedVer}/bin/g++ ]; then
		    gpp="/opt/gcc${compressedVer}/bin/g++"
            elif [ -x /opt/gcc${compressedVer}/bin/g++${compressedVer} ]; then
		    gpp="/opt/gcc${compressedVer}/bin/g++${compressedVer}"
            elif [ -x /usr/bin/g++-${shortVer} ]; then
		    gpp="/usr/bin/g++-${shortVer}"
            else
                # Nothing in /opt, so see if the native g++ is the correct
                # version.
                nativeVer=`g++ -v 2>&1 | grep "gcc version" | sed 's/^[^0-9]*\([0-9.]*\).*$/\1/'`

                if [ "${nativeVer}" = "${gppVerNeeded}" ]; then
                    gpp=g++
                fi
            fi
        fi
        ;;

    osx*)
        if [ "${returnDTS}" = "y" ]; then
            echo n
            exit
        fi

        # getosxvars.sh sets environment variables which control where we find
        # the compiler, so we can just use 'g++' in all cases.
        gpp=g++
        ;;
esac

echo ${gpp}