#!/bin/sh
# Copyright (C) 2020-2021 OpenCFD Ltd.
# SPDX-License-Identifier: (GPL-3.0+)

# Script-based (re)configuration for elements not addressed by
# bin/tools/foamConfigurePaths or debian/patches.
# In some cases the scripted changes can be more robust than patching.

# Run from top-level directory
# ---------------------------------------------------------------------------

# The debian/ directory is the parent directory
debianDir="${0%/*}/.."

# The project directory is one above debian/
projectDir="${0%/*}/../.."

file="$projectDir"/etc/cshrc
if [ -f "$file" ]
then

    # The csh magic needs a hint about the directory name,
    # which is normally "OpenFOAM...", but debian has "openfoam..."

    # orig: set projectName="$WM_PROJECT"
    # new:  set projectName=openfoam  # debian

    sed -i \
        -e 's@^\([ ]*set[ ]*projectName\)=.*@\1=openfoam  # debian@' \
        "$file"

    echo "Define projectName as 'openfoam' for csh magic"
fi

for compiler in Clang Gcc
do
    file="$projectDir"/wmake/rules/General/"$compiler"/c++
    [ -f "$file" ] || continue

    # OpenFOAM has gcc >= 4.8.5 (c++11), but bionic (18.04) and newer
    # can use (c++14) and make newer CGAL versions happy

    sed -i \
        -e 's/-std=c++11/-std=c++14/' \
        "$file"

    echo "Use c++14 instead of c++11 ($compiler)"
done

exit 0 # A clean exit

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