makeGcc 9.53 KB
Newer Older
Henry's avatar
Henry committed
1 2 3 4 5
#!/bin/sh
#------------------------------------------------------------------------------
# =========                 |
# \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
#  \\    /   O peration     |
6
#   \\  /    A nd           | Copyright (C) 2011-2016 OpenFOAM Foundation
7
#    \\/     M anipulation  | Copyright (C) 2016-2017 OpenCFD Ltd.
Henry's avatar
Henry committed
8 9
#------------------------------------------------------------------------------
# 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/>.
Henry's avatar
Henry committed
12 13 14 15 16
#
# Script
#     makeGcc
#
# Description
17 18
#     Build script gcc and gmp, mpfr, mpc.
#
19 20 21
#     To force building against the system gmp/mpfr/mpc libraries,
#     use a corresponding '*-system' version. For example,
#
22
#         makeGcc gmp-system
Henry's avatar
Henry committed
23
#
24 25 26 27 28 29 30
#     or use the '-system' options to use system libraries everywhere.
#
#     The WM_COMPILER value can also be used specify a known gcc version.
#     For example (also compiling against system gmp/mpfr/mpc),
#
#         WM_COMPILER=Gcc51 ./makeGcc -system
#
31 32
# ----------------------------------------------
# NO USER-CONFIGURABLE SETTINGS WITHIN THIS FILE
Henry's avatar
Henry committed
33
#------------------------------------------------------------------------------
34
# Run from third-party directory only
35
cd ${0%/*} && wmakeCheckPwd "$WM_THIRD_PARTY_DIR" 2>/dev/null || {
36 37 38 39 40 41
    echo "Error (${0##*/}) : not located in \$WM_THIRD_PARTY_DIR"
    echo "    Check your OpenFOAM environment and installation"
    exit 1
}
. etc/tools/ThirdPartyFunctions
#------------------------------------------------------------------------------
42
unset GMP_ARCH_PATH MPFR_ARCH_PATH                                  # Purge old
43

44 45 46 47
[ "${WM_COMPILER#Gcc}" = "$WM_COMPILER" ] && WM_COMPILER=Gcc        # Force gcc
WM_COMPILER_TYPE=ThirdParty                # Ensure we get the correct settings

# Default GCC, mpfr, gmp and mpc versions from OpenFOAM etc/config.sh file:
48
_foamConfig compiler
49

50 51 52
gmpPACKAGE=${gmp_version:-gmp-system}
mpfrPACKAGE=${mpfr_version:-mpfr-system}
mpcPACKAGE=${mpc_version:-mpc-system}
53
gccPACKAGE=$gcc_version
54

Henry's avatar
Henry committed
55 56 57 58 59 60
#------------------------------------------------------------------------------
usage() {
    exec 1>&2
    while [ "$#" -ge 1 ]; do echo "$1"; shift; done
    cat<<USAGE

61
usage: ${0##*/} [OPTION] [gcc-VERSION] [gmp-VERSION] [mpfr-VERSION] [mpc-VERSION]
62
options:
63 64
  -multilib         for 64-bit systems with 32-bit support required
  -no-multilib      for 64-bit systems without 32-bit support (DEFAULT)
65
  -no-threadsafe    disable mpfr thread-safe (default is auto-detect)
66
  -system           use system versions for gmp/mpfr/mpc
67
  -help
Henry's avatar
Henry committed
68 69 70 71 72

* build combinations of gmp, mpfr, mpc and gcc
      $gmpPACKAGE
      $mpfrPACKAGE
      $mpcPACKAGE
73
      ${gccPACKAGE:-'unspecified GCC version'}
Henry's avatar
Henry committed
74 75 76 77

USAGE
    exit 1
}
78
#------------------------------------------------------------------------------
79
# Build 32-bit libraries on 64-bit systems (normally not needed)
80
optMultilib=disable
81
unset optThreadSafe # unset=auto
Henry's avatar
Henry committed
82

Henry's avatar
Henry committed
83
# Parse options
Henry's avatar
Henry committed
84 85 86
while [ "$#" -gt 0 ]
do
    case "$1" in
87 88 89
    '') ;;      # Ignore empty
    -h | -help) usage   ;;

90 91 92
    -multi*)
        optMultilib=enable
        ;;
93
    -no-multi*)
94
        optMultilib=disable
95
        ;;
96 97 98
    -no-thread*)
        optThreadSafe=disable
        ;;
99 100 101 102
    -sys*)
        gmpPACKAGE="gmp-system"
        mpfrPACKAGE="mpfr-system"
        mpcPACKAGE="mpc-system"
103
        unset GMP_ARCH_PATH MPFR_ARCH_PATH
104 105
        ;;
    gmp-[4-9]* | gmp-system)
Henry's avatar
Henry committed
106
        gmpPACKAGE="${1%%/}"
107
        unset GMP_ARCH_PATH
Henry's avatar
Henry committed
108
        ;;
109
    mpfr-[2-9]* | mpfr-system)
Henry's avatar
Henry committed
110
        mpfrPACKAGE="${1%%/}"
111
        unset MPFR_ARCH_PATH
Henry's avatar
Henry committed
112
        ;;
113
    mpc-[0-9]* | mpc-system)
Henry's avatar
Henry committed
114 115
        mpcPACKAGE="${1%%/}"
        ;;
116
    gcc-[4-9]* | gcc-system)
Henry's avatar
Henry committed
117 118 119
        gccPACKAGE="${1%%/}"
        ;;
    *)
120
        die "unknown option/argument: '$1'"
Henry's avatar
Henry committed
121 122
        ;;
    esac
123
    shift
Henry's avatar
Henry committed
124 125
done

126
[ -n "$gccPACKAGE" ] || die "The gcc-VERSION was not specified"
Henry's avatar
Henry committed
127

128 129 130 131 132 133 134 135 136
cat<<SUMMARY
GCC configuration
------------------
    GCC     = $gccPACKAGE
    GMP     = $gmpPACKAGE
    MPFR    = $mpfrPACKAGE
    MPC     = $mpcPACKAGE
------------------
SUMMARY
Henry's avatar
Henry committed
137

Henry's avatar
Henry committed
138
# Set 32 or 64 bit ABI
Henry's avatar
Henry committed
139 140 141 142 143
case "$WM_ARCH_OPTION" in
32 | 64)
    ABI=$WM_ARCH_OPTION
    ;;
*)
144
    die "The WM_ARCH_OPTION ($WM_ARCH_OPTION) must be 32 or 64"
Henry's avatar
Henry committed
145 146 147 148 149
    ;;
esac


#------------------------------------------------------------------------------
Henry's avatar
Henry committed
150
# Build/install without compiler name
Henry's avatar
Henry committed
151 152 153 154 155 156 157 158
buildBASE=$WM_THIRD_PARTY_DIR/build/$WM_ARCH$WM_COMPILER_ARCH
installBASE=$WM_THIRD_PARTY_DIR/platforms/$WM_ARCH$WM_COMPILER_ARCH

GCC_ARCH_PATH=$installBASE/$gccPACKAGE
GMP_ARCH_PATH=$installBASE/$gmpPACKAGE
MPFR_ARCH_PATH=$installBASE/$mpfrPACKAGE
MPC_ARCH_PATH=$installBASE/$mpcPACKAGE

159 160 161 162 163 164 165 166 167 168 169 170
# Prefix <dir> to LD_LIBRARY_PATH, if it exists. 0 on success, 1 on failure
addLib()
{
    if [ -d "$1" ]
    then
        export LD_LIBRARY_PATH=$1:$LD_LIBRARY_PATH
        return 0
    else
        return 1
    fi
}

171

172
# ================
Henry's avatar
Henry committed
173
# Build GMP
174
# ================
Henry's avatar
Henry committed
175
echo "---------------"
176
if [ -d "$GMP_ARCH_PATH" ]
Henry's avatar
Henry committed
177 178
then
    echo "Already built: $gmpPACKAGE"
179 180 181
elif _foamIsSystem $GMP_ARCH_PATH
then
    echo "Using gmp-system"
Henry's avatar
Henry committed
182 183 184 185
else
    echo "Starting build: $gmpPACKAGE"
    echo
(
186
    sourceDIR=$sourceBASE/$gmpPACKAGE
Henry's avatar
Henry committed
187 188 189
    buildDIR=$buildBASE/$gmpPACKAGE

    cd $sourceDIR || exit 1
190
    export GIT_DIR=$PWD/.git # Mask seeing our own git-repo
Henry's avatar
Henry committed
191 192 193 194 195 196 197 198 199
    make distclean 2>/dev/null

    rm -rf $buildDIR
    mkdir -p $buildDIR
    cd $buildDIR

    set -x
    $sourceDIR/configure ABI=$ABI \
        --prefix=$GMP_ARCH_PATH \
200
        --libdir=$GMP_ARCH_PATH/lib$WM_COMPILER_LIB_ARCH \
Henry's avatar
Henry committed
201
        --enable-cxx \
202
    && set +x \
Henry's avatar
Henry committed
203 204 205 206 207 208 209 210 211
    && make -j $WM_NCOMPPROCS \
    && make install \
    && echo "Built: $gmpPACKAGE"
) || {
    echo "Error building: $gmpPACKAGE"
    exit 1
}
fi

212
if addLib "$GMP_ARCH_PATH/lib$WM_COMPILER_LIB_ARCH"
213
then
214 215 216 217 218 219 220
    configGMP=$(cat <<CONFIG_OPTIONS
    --with-gmp-include=$GMP_ARCH_PATH/include
    --with-gmp-lib=$GMP_ARCH_PATH/lib$WM_COMPILER_LIB_ARCH
CONFIG_OPTIONS
)
else
    unset configGMP
221 222
fi

Henry's avatar
Henry committed
223

224
# ================
Henry's avatar
Henry committed
225
# Build MPFR
226
# ================
Henry's avatar
Henry committed
227 228 229 230
echo "---------------"
if [ -d $MPFR_ARCH_PATH ]
then
    echo "Already built: $mpfrPACKAGE"
231 232 233
elif _foamIsSystem $MPFR_ARCH_PATH
then
    echo "Using mpfr-system"
Henry's avatar
Henry committed
234 235 236 237
else
    echo "Starting build: $mpfrPACKAGE"
    echo
(
238
    sourceDIR=$sourceBASE/$mpfrPACKAGE
Henry's avatar
Henry committed
239 240 241
    buildDIR=$buildBASE/$mpfrPACKAGE

    cd $sourceDIR || exit 1
242
    export GIT_DIR=$PWD/.git # Mask seeing our own git-repo
Henry's avatar
Henry committed
243 244 245 246 247 248
    make distclean 2>/dev/null

    rm -rf $buildDIR
    mkdir -p $buildDIR
    cd $buildDIR

249 250 251 252
    unset configOpt
    # explicitly enable/disable thread-safe
    [ -n "$optThreadSafe" ] && configOpt="--${optThreadSafe}-thread-safe"

Henry's avatar
Henry committed
253 254
    set -x
    $sourceDIR/configure ABI=$ABI \
255 256 257
        --prefix=$MPFR_ARCH_PATH \
        --libdir=$MPFR_ARCH_PATH/lib$WM_COMPILER_LIB_ARCH \
        $configGMP $configOpt \
258
    && set +x \
Henry's avatar
Henry committed
259 260 261 262 263 264 265 266 267
    && make -j $WM_NCOMPPROCS \
    && make install \
    && echo "Built: $mpfrPACKAGE"
) || {
    echo "Error building: $mpfrPACKAGE"
    exit 1
}
fi

268
if addLib "$MPFR_ARCH_PATH/lib$WM_COMPILER_LIB_ARCH"
269
then
270 271 272 273 274 275 276
    configMPFR=$(cat <<CONFIG_OPTIONS
    --with-mpfr-include=$MPFR_ARCH_PATH/include \
    --with-mpfr-lib=$MPFR_ARCH_PATH/lib$WM_COMPILER_LIB_ARCH
CONFIG_OPTIONS
)
else
    unset configMPFR
277
fi
Henry's avatar
Henry committed
278

279 280 281 282

# ================
# Build MPC
# ================
Henry's avatar
Henry committed
283 284 285 286
echo "---------------"
if [ -d $MPC_ARCH_PATH ]
then
    echo "Already built: $mpcPACKAGE"
287 288 289
elif _foamIsSystem $MPC_ARCH_PATH
then
    echo "Using mpc-system"
Henry's avatar
Henry committed
290 291 292 293
else
    echo "Starting build: $mpcPACKAGE"
    echo
(
294
    sourceDIR=$sourceBASE/$mpcPACKAGE
Henry's avatar
Henry committed
295 296 297
    buildDIR=$buildBASE/$mpcPACKAGE

    cd $sourceDIR || exit 1
298
    export GIT_DIR=$PWD/.git # Mask seeing our own git-repo
Henry's avatar
Henry committed
299 300 301 302 303 304 305 306 307
    make distclean 2>/dev/null

    rm -rf $buildDIR
    mkdir -p $buildDIR
    cd $buildDIR

    set -x
    $sourceDIR/configure ABI=$ABI \
        --prefix=$MPC_ARCH_PATH \
308
        --libdir=$MPC_ARCH_PATH/lib$WM_COMPILER_LIB_ARCH \
309
        $configGMP $configMPFR \
310
    && set +x \
Henry's avatar
Henry committed
311 312 313 314 315 316 317 318 319
    && make -j $WM_NCOMPPROCS \
    && make install \
    && echo "Built: $mpcPACKAGE"
) || {
    echo "Error building: $mpcPACKAGE"
    exit 1
}
fi

320
if addLib "$MPC_ARCH_PATH/lib$WM_COMPILER_LIB_ARCH"
Henry's avatar
Henry committed
321
then
322 323 324 325 326 327 328
    configMPC=$(cat <<CONFIG_OPTIONS
    --with-mpc-include=$MPC_ARCH_PATH/include \
    --with-mpc-lib=$MPC_ARCH_PATH/lib$WM_COMPILER_LIB_ARCH
CONFIG_OPTIONS
)
else
    unset configMPC
Henry's avatar
Henry committed
329 330 331
fi


332
# ================
Henry's avatar
Henry committed
333
# Build GCC
334 335
# ================
# may need 32-bit glibc-devel headers to compile
Henry's avatar
Henry committed
336
# E.g. on ubuntu install g++-multilib
337
# or specify -no-multilib on the command-line
Henry's avatar
Henry committed
338 339 340 341 342
#
echo "---------------"
if [ -d $GCC_ARCH_PATH ]
then
    echo "Already built: $gccPACKAGE"
343 344 345
elif _foamIsSystem $GCC_ARCH_PATH
then
    echo "Using gcc-system"
Henry's avatar
Henry committed
346 347 348 349
else
    echo "Starting build: $gccPACKAGE"
    echo
(
350
    sourceDIR=$sourceBASE/$gccPACKAGE
Henry's avatar
Henry committed
351 352 353
    buildDIR=$buildBASE/$gccPACKAGE

    cd $sourceDIR || exit 1
354
    export GIT_DIR=$PWD/.git # Mask seeing our own git-repo
Henry's avatar
Henry committed
355 356 357 358 359 360
    make distclean 2>/dev/null

    rm -rf $buildDIR
    mkdir -p $buildDIR
    cd $buildDIR

361 362 363 364
    unset configOpt
    # with/without multi-lib (32-bit support on 64-bit systems)
    [ -n "$optMultilib" ] && configOpt="--${optMultilib}-multilib"

Henry's avatar
Henry committed
365 366 367 368 369 370 371 372
    set -x
    $sourceDIR/configure \
        --prefix=$GCC_ARCH_PATH \
        --with-pkgversion=OpenFOAM \
        --enable-languages=c,c++ \
        --enable-__cxa_atexit \
        --enable-libstdcxx-allocator=new \
        --with-system-zlib \
373
        $configGMP $configMPFR $configMPC $configOpt \
374
        MAKEINFO=missing \
375
    && set +x \
Henry's avatar
Henry committed
376 377 378 379 380 381 382 383 384 385
    && make -j $WM_NCOMPPROCS \
    && make install \
    && echo "Built: $gccPACKAGE"
) || {
    echo "Error building: $gccPACKAGE"
    exit 1
}
fi


386
#------------------------------------------------------------------------------