#!/bin/bash
set -e

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

BUILD_FOLDER="$1"
mkdir -p $BUILD_FOLDER
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