#!/bin/bash

rm -r bin
       
if [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
    cmake -B bin -S ./
    cd bin
    make -j$(grep -c ^processor /proc/cpuinfo)
    mkdir disassembly
    if [ $? -eq 0 ]; then
        cd ..
        typeset -i build_number=$(cat build.nr)
        ((build_number++))
        truncate -s 0 build.nr
        echo $build_number >> build.nr
    else
        cd ..
    fi
elif [ "$(expr substr $(uname -s) 1 10)" == "MINGW64_NT" ]; then
    cmake -B bin -S ./ -G "MinGW Makefiles"
    cd bin
    mingw32-make.exe -j16
    mkdir disassembly
    if [ $? -eq 0 ]; then
        cd ..
        typeset -i build_number=$(cat build.nr)
        ((build_number++))
        truncate -s 0 build.nr
        echo $build_number >> build.nr
    else
        cd ..
    fi
fi
