makeMesa 5.6 KB
Newer Older
1 2 3 4 5
#!/bin/sh
#------------------------------------------------------------------------------
# =========                 |
# \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
#  \\    /   O peration     |
6
#   \\  /    A nd           | Copyright (C) 2016-2018 OpenCFD Ltd.
7 8 9
#    \\/     M anipulation  |
#------------------------------------------------------------------------------
# License
Mark Olesen's avatar
Mark Olesen committed
10 11
#     This file is part of OpenFOAM, licensed under GNU General Public License
#     <http://www.gnu.org/licenses/>.
12 13 14 15 16 17 18 19
#
# Script
#     makeMesa
#
# Description
#     Build script for Mesa
#
# Note
mark's avatar
mark committed
20 21 22
#     Building with mesa-12.x.x fails to create an include/GL directory and
#     an "osmesa.h" file. Both make it fairly useless for off-screen VTK.
#
23
#     Building with mesa-11.x, mesa-13.x and mesa-17.x seems to be okay.
24
#
25 26
# ----------------------------------------------
# NO USER-CONFIGURABLE SETTINGS WITHIN THIS FILE
27
#------------------------------------------------------------------------------
28
# Run from third-party directory only
29
cd ${0%/*} && wmakeCheckPwd "$WM_THIRD_PARTY_DIR" 2>/dev/null || {
30 31
    echo "Error (${0##*/}) : not located in \$WM_THIRD_PARTY_DIR"
    echo "    Check your OpenFOAM environment and installation"
32 33 34 35
    exit 1
}
. etc/tools/ThirdPartyFunctions
#------------------------------------------------------------------------------
36

37 38 39
unset vtk_version mesa_version                           # Purge current values

# mesa version from OpenFOAM etc/config.sh file:
40
_foamConfig vtk
41

42
mesaPACKAGE=$mesa_version
43

44
#------------------------------------------------------------------------------
45 46 47 48 49
usage() {
    exec 1>&2
    while [ "$#" -ge 1 ]; do echo "$1"; shift; done
    cat<<USAGE

Mark Olesen's avatar
Mark Olesen committed
50
usage: ${0##*/} [OPTION] mesa-VERSION [-- configure-options]
51
options:
52
  -gcc              Force gcc/g++ instead of the values from \$WM_CC, \$WM_CXX
53 54 55 56 57 58 59 60 61
  -help

* build Mesa with
      ${mesaPACKAGE:-'unspecified MESA version'}

USAGE
    exit 1
}
#------------------------------------------------------------------------------
62
exportCompiler          # Compiler info for CMake/configure
63 64

# Non-standard location for clang?
65 66
case "$WM_COMPILER_TYPE-$WM_COMPILER" in
ThirdParty-Clang*)
67
    thirdPartyClang=true
68 69 70 71 72
    ;;
*)
    unset thirdPartyClang
    ;;
esac
73

74
# Parse options
75 76 77
while [ "$#" -gt 0 ]
do
    case "$1" in
78
    '') ;;      # Ignore empty
Mark Olesen's avatar
Mark Olesen committed
79
    --) break;; # Extra configure options (leave on $@ for later detection)
80
    -h | -help) usage   ;;
81
    -gcc)
82
        useGcc
83 84 85 86 87
        unset thirdPartyClang
        ;;
    mesa-*)
        mesaPACKAGE="${1%%/}"
        ;;
Mark Olesen's avatar
Mark Olesen committed
88

89 90 91 92 93 94 95 96 97
    *)
        die "unknown option/argument: '$1'"
        ;;
    esac
    shift
done

[ -n "$mesaPACKAGE" ] || die "The mesa-VERSION was not specified"

98
# Nothing to build
99 100 101 102
if _foamIsNone "$mesaPACKAGE"
then
    echo "Using mesa-none (skip ThirdParty build of MESA)"
    exit 0
103
elif _foamIsSystem "$mesaPACKAGE"
104 105 106 107 108 109
then
    echo "Using mesa-system (skip ThirdParty build of MESA)"
    exit 0
fi

#------------------------------------------------------------------------------
110
# Locate third-party clang as required
111 112 113 114 115 116 117
if [ "$thirdPartyClang" = true ]
then
    thirdPartyClang=$(command -v clang) || {
        echo "Error: could not properly locate clang"
        exit 2
    }

Mark Olesen's avatar
Mark Olesen committed
118
    # Root installation directory
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
    thirdPartyClang=${thirdPartyClang%/bin/clang}

    [ -d "$thirdPartyClang" ] || {
        echo "Error: could not properly locate clang"
        exit 2
    }
fi

#------------------------------------------------------------------------------
#
# Build MESA
# For 64-bit
# - MESA itself will normally build into 'lib64'.
#
#   MESA_SOURCE_DIR : location of the original sources
134
#   MESA_ARCH_DIR   : installation directory
135

136
MESA_SOURCE_DIR=$sourceBASE/$mesaPACKAGE
137 138
MESA_ARCH_PATH=$installBASE/$mesaPACKAGE

139 140 141 142 143
#
# Manual adjustments to mesa
# - avoid GLES (GLES1) since <GLES/gl.h> may mask the <GL/gl.h> header
adjustMESA()
{
144 145
    pkgconfigAdjust $MESA_ARCH_PATH

146 147 148 149
    \rm -rf $MESA_ARCH_PATH/include/GLES $MESA_ARCH_PATH/include/GLES1
    echo "removed all gles1 includes"
}

150
(
Mark Olesen's avatar
Mark Olesen committed
151
    # Configuration options:
152 153 154 155 156 157 158
    unset configOpt

    if [ -d "$thirdPartyClang" ]
    then
        configOpt="$configOpt --with-llvm-prefix=$thirdPartyClang"
    fi

Mark Olesen's avatar
Mark Olesen committed
159 160 161 162 163 164 165 166
    # Additional configure options
    if [ "$1" = "--" ]
    then
        shift
        configOpt="$configOpt $@"
    fi

    # End of configuration options
167 168 169 170
    # ----------------------------
    buildDIR=$buildBASE/$mesaPACKAGE

    cd $MESA_SOURCE_DIR || exit 1
171
    export GIT_DIR=$PWD/.git # Mask seeing our own git-repo
172

Mark Olesen's avatar
Mark Olesen committed
173
    # Remove any existing build
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
    rm -rf $MESA_ARCH_PATH
    rm -rf $buildDIR
    mkdir -p $buildDIR
    cd $buildDIR

    echo "----"
    echo "Building $mesaPACKAGE"
    echo "    Source         : $MESA_SOURCE_DIR"
    echo "    Target         : $MESA_ARCH_PATH"
    if [ -d "$thirdPartyClang" ]
    then
        echo "    Clang          : $thirdPartyClang"
    fi
    echo "----"

Mark Olesen's avatar
Mark Olesen committed
189
    # Possibly for older mesa versions (see paraview wiki)
190 191 192 193 194 195 196 197 198 199
    # CXXFLAGS="-O2 -DDEFAULT_SOFTWARE_DEPTH_BITS=31" \
    # CFLAGS="-O2 -DDEFAULT_SOFTWARE_DEPTH_BITS=31" \

    ## autoreconf -fi
    set -x
    $MESA_SOURCE_DIR/configure \
        --prefix=$MESA_ARCH_PATH \
        --disable-xvmc \
        --disable-glx \
        --disable-dri \
200
        --disable-gbm \
201
        --disable-egl \
202
        --disable-gles1 \
203 204 205
        --enable-texture-float \
        --enable-gallium-osmesa --with-gallium-drivers=swrast \
        $configOpt \
206 207 208 209 210
    && set +x \
    && make -j $WM_NCOMPPROCS \
    && make install \
    && echo "Built $mesaPACKAGE" \
    && adjustMESA
211 212 213 214 215
) || {
    echo "Error building: MESA"
    exit 1
}

216
# -----------------------------------------------------------------------------