#!/usr/bin/env bash
##
## Copyright (C) HySoP 2011-2022
##
## Licensed under the Apache License, Version 2.0 (the "License");
## you may not use this file except in compliance with the License.
## You may obtain a copy of the License at
##
##         http://www.apache.org/licenses/LICENSE-2.0
##
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.
##
set -feu -o pipefail

if [ $# -ne 4 ]; then
    echo "Usage ./build build_folder CC CXX FC"
    exit 1
fi


BUILD_FOLDER="$1"
if [ ! -d "$BUILD_FOLDER" ]; then
    echo "Folder $1 has not been generated by previous step."
    exit 1
fi

cd $BUILD_FOLDER
if [ ! -f Makefile ]; then
    echo "The makefile has not been generated."
    exit 1
fi

CC="$2" CXX="$3" FC="$4" make VERBOSE=1 -j4

exit 0