makeFFTW 4.97 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           | www.openfoam.com
mark's avatar
mark committed
7 8
#    \\/     M anipulation  |
#------------------------------------------------------------------------------
Mark Olesen's avatar
Mark Olesen committed
9
#     Copyright (C) 2016-2020 OpenCFD Ltd.
10
#------------------------------------------------------------------------------
mark's avatar
mark committed
11
# License
Mark Olesen's avatar
Mark Olesen committed
12
#     This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
mark's avatar
mark committed
13 14 15 16 17 18 19
#
# Script
#     makeFFTW
#
# Description
#     Build script for FFTW
#
20 21
# ----------------------------------------------
# NO USER-CONFIGURABLE SETTINGS WITHIN THIS FILE
mark's avatar
mark committed
22
#------------------------------------------------------------------------------
23 24
# Dynamic library ending (default is .so)
[ "$(uname -s)" = Darwin ] && EXT_SO=.dylib || EXT_SO=.so
25

mark's avatar
mark committed
26 27 28 29
# Short-circuit test for an installation
if [ "$1" = "-test" ]
then
    [ "$#" -eq 2 ] || { echo "${0##*/} -test : needs 1 argument"; exit 1; }
30 31 32
    dir="${2%/}" # <- *_ARCH_PATH
    if [ -d "$dir/include" ] \
    && [ -r "$dir/lib$WM_COMPILER_LIB_ARCH/libfftw3$EXT_SO" ]
mark's avatar
mark committed
33
    then
34 35
        echo "    fftw include: $dir/include"
        echo "    fftw library: $dir/lib$WM_COMPILER_LIB_ARCH"
mark's avatar
mark committed
36 37 38 39 40 41
        exit 0
    else
        exit 2
    fi
fi
#------------------------------------------------------------------------------
42
# Run from third-party directory only
43 44
cd "${0%/*}" || exit
wmakeCheckPwd "$WM_THIRD_PARTY_DIR" 2>/dev/null || {
45 46 47 48 49 50
    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
51

52
# FFTW version from OpenFOAM etc/config.sh file:
53
_foamConfig FFTW
mark's avatar
mark committed
54 55

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

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

63
usage: ${0##*/} [OPTION] [fftw-VERSION] [-- configure-options]
mark's avatar
mark committed
64
options:
65
  -force        Force compilation, even if include/library already exists
66
  -gcc          Force use of gcc/g++
mark's avatar
mark committed
67 68 69
  -help

* build FFTW with
70
      ${fftwPACKAGE:-'unspecified FFTW version'}
mark's avatar
mark committed
71 72

USAGE
73
    showDownloadHint FFTW
mark's avatar
mark committed
74 75 76
    exit 1
}
#------------------------------------------------------------------------------
77
exportCompiler          # Compiler info for CMake/configure
78

79 80
unset optForce

mark's avatar
mark committed
81 82 83 84
# Parse options
while [ "$#" -gt 0 ]
do
    case "$1" in
85
    '') ;;      # Ignore empty
86
    --) break;; # Extra configure options (leave on $@ for later detection)
87 88
    -h | -help) usage   ;;
    -gcc)       useGcc  ;;
89
    -force)     optForce=true ;;
90

mark's avatar
mark committed
91 92 93 94 95 96 97 98 99 100 101 102
    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"

103
# Nothing to build
mark's avatar
mark committed
104 105 106 107
if _foamIsNone "$fftwPACKAGE"
then
    echo "Using fftw-none (skip ThirdParty build of FFTW)"
    exit 0
108
elif _foamIsSystem "$fftwPACKAGE"
mark's avatar
mark committed
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
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
124
#   FFTW_ARCH_PATH  : installation directory
mark's avatar
mark committed
125

126
FFTW_SOURCE_DIR=$sourceBASE/$fftwPACKAGE
mark's avatar
mark committed
127 128
FFTW_ARCH_PATH=$installBASE/$fftwPACKAGE

129 130
if [ -z "$optForce" ] \
&& [ -r "$FFTW_ARCH_PATH/lib$WM_COMPILER_LIB_ARCH/libfftw3$EXT_SO" ]
mark's avatar
mark committed
131 132 133 134 135 136 137
then
    echo "Already has FFTW shared library"
else
    echo "Starting build: FFTW ($fftwPACKAGE)"
    echo

    (
138 139 140 141 142 143 144 145 146 147 148 149
        # Configuration options:
        unset configOpt

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

        # End of configuration options
        # ----------------------------
mark's avatar
mark committed
150 151
        buildDIR=$buildBASE/$fftwPACKAGE

152 153
        cd "$FFTW_SOURCE_DIR" || exit
        export GIT_DIR="$PWD/.git" # Mask seeing our own git-repo
mark's avatar
mark committed
154 155 156 157 158 159 160 161 162 163 164 165

        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 \
166
            $configOpt \
167 168 169 170 171
        && set +x \
        && make -j $WM_NCOMPPROCS \
        && make install \
        && echo "Built $fftwPACKAGE" \
        && pkgconfigAdjust $FFTW_ARCH_PATH
mark's avatar
mark committed
172 173 174 175 176 177 178
    ) || {
        echo "Error building: FFTW"
        exit 1
    }
fi

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