makeFFTW 4.75 KB
Newer Older
mark's avatar
mark committed
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.
mark's avatar
mark committed
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/>.
mark's avatar
mark committed
12 13 14 15 16 17 18
#
# Script
#     makeFFTW
#
# Description
#     Build script for FFTW
#
19 20
# ----------------------------------------------
# NO USER-CONFIGURABLE SETTINGS WITHIN THIS FILE
mark's avatar
mark committed
21
#------------------------------------------------------------------------------
22 23 24
# Dynamic library endings (default is .so)
[ "$(uname -s)" = Darwin ] && SO=dylib || SO=so

mark's avatar
mark committed
25 26 27 28 29
# Short-circuit test for an installation
if [ "$1" = "-test" ]
then
    [ "$#" -eq 2 ] || { echo "${0##*/} -test : needs 1 argument"; exit 1; }
    dir="$2" # <- FFTW_ARCH_PATH
30
    if [ -d "$dir/include" -a -r "$dir/lib$WM_COMPILER_LIB_ARCH/libfftw3.$SO" ]
mark's avatar
mark committed
31
    then
32 33
        echo "    fftw include: $dir/include"
        echo "    fftw library: $dir/lib$WM_COMPILER_LIB_ARCH"
mark's avatar
mark committed
34 35 36 37 38 39
        exit 0
    else
        exit 2
    fi
fi
#------------------------------------------------------------------------------
40
# Run from third-party directory only
41
cd ${0%/*} && wmakeCheckPwd "$WM_THIRD_PARTY_DIR" 2>/dev/null || {
42 43 44 45 46 47
    echo "Error (${0##*/}) : not located in \$WM_THIRD_PARTY_DIR"
    echo "    Check your OpenFOAM environment and installation"
    exit 1
}
. etc/tools/ThirdPartyFunctions
#------------------------------------------------------------------------------
mark's avatar
mark committed
48

49
# FFTW version from OpenFOAM etc/config.sh file:
50
_foamConfig FFTW
mark's avatar
mark committed
51 52

fftwPACKAGE=${fftw_version:-fftw-system}
53

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

60
usage: ${0##*/} [OPTION] [fftw-VERSION] [-- configure-options]
mark's avatar
mark committed
61 62 63 64 65
options:
  -gcc              Force gcc/g++ instead of the values from \$WM_CC, \$WM_CXX
  -help

* build FFTW with
66
      ${fftwPACKAGE:-'unspecified FFTW version'}
mark's avatar
mark committed
67 68 69 70 71

USAGE
    exit 1
}
#------------------------------------------------------------------------------
72
exportCompiler          # Compiler info for CMake/configure
73

mark's avatar
mark committed
74 75 76 77
# Parse options
while [ "$#" -gt 0 ]
do
    case "$1" in
78
    '') ;;      # Ignore empty
79
    --) break;; # Extra configure options (leave on $@ for later detection)
80 81 82
    -h | -help) usage   ;;
    -gcc)       useGcc  ;;

mark's avatar
mark committed
83 84 85 86 87 88 89 90 91 92 93 94
    fftw-[0-9]* | fftw_[0-9]* | fftw-system )
        fftwPACKAGE="${1%%/}"
        ;;
    *)
        die "unknown option/argument: '$1'"
        ;;
    esac
    shift
done

[ -n "$fftwPACKAGE" ] || die "The fftw-VERSION was not specified"

95
# Nothing to build
mark's avatar
mark committed
96 97 98 99
if _foamIsNone "$fftwPACKAGE"
then
    echo "Using fftw-none (skip ThirdParty build of FFTW)"
    exit 0
100
elif _foamIsSystem "$fftwPACKAGE"
mark's avatar
mark committed
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
then
    echo "Using fftw-system (skip ThirdParty build of FFTW)"
    exit 0
fi

#------------------------------------------------------------------------------
#
# Build FFTW
# For 64-bit
# - FFTW itself will normally build into 'lib64',
#   but provide --libdir on configure to be 100% certain
# - Third-Party builds into 'lib64'
# - system is normally built into 'lib64'
#
#   FFTW_SOURCE_DIR : location of the original sources
116
#   FFTW_ARCH_PATH  : installation directory
mark's avatar
mark committed
117

118
FFTW_SOURCE_DIR=$sourceBASE/$fftwPACKAGE
mark's avatar
mark committed
119 120
FFTW_ARCH_PATH=$installBASE/$fftwPACKAGE

121
if [ -r "$FFTW_ARCH_PATH/lib$WM_COMPILER_LIB_ARCH/libfftw3.$SO" ]
mark's avatar
mark committed
122 123 124 125 126 127 128
then
    echo "Already has FFTW shared library"
else
    echo "Starting build: FFTW ($fftwPACKAGE)"
    echo

    (
129 130 131 132 133 134 135 136 137 138 139 140
        # Configuration options:
        unset configOpt

        # Additional configure options
        if [ "$1" = "--" ]
        then
            shift
            configOpt="$configOpt $@"
        fi

        # End of configuration options
        # ----------------------------
mark's avatar
mark committed
141 142 143
        buildDIR=$buildBASE/$fftwPACKAGE

        cd $FFTW_SOURCE_DIR || exit 1
144
        export GIT_DIR=$PWD/.git # Mask seeing our own git-repo
mark's avatar
mark committed
145 146 147 148 149 150 151 152 153 154 155 156

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

        set -x
        $FFTW_SOURCE_DIR/configure \
            --prefix=$FFTW_ARCH_PATH \
            --libdir=$FFTW_ARCH_PATH/lib$WM_COMPILER_LIB_ARCH \
            --enable-shared --disable-static \
            --disable-fortran \
157
            $configOpt \
158 159 160 161 162
        && set +x \
        && make -j $WM_NCOMPPROCS \
        && make install \
        && echo "Built $fftwPACKAGE" \
        && pkgconfigAdjust $FFTW_ARCH_PATH
mark's avatar
mark committed
163 164 165 166 167 168 169
    ) || {
        echo "Error building: FFTW"
        exit 1
    }
fi

#------------------------------------------------------------------------------