When the card status is not ready yet (after a successful write tx is
completed) a second DMA is scheduled to read the return code (instead of
manually reading it when it's ready). The current code schedules the DMA
and immediately proceeds to complete the read due to a missing early
return. This results in the IRQ handler being called one extra time and
desyncing the TX sequence, which hangs due to "done" > "total"
It is unclear when this happens, allegedly when the DMA IRQ is
triggered before the card becomes Idle (response is pushed after it
becomes Idle).
* Use '/usr/bin/env bash', because not all distros put bash in /bin
(some in /usr/bin), and with NixOS it's even more complicated. This
should make it compatible across all distros.
* The 'set -euo pipefail' makes the script exit immediately on error,
otherwise it tries to continue e.g. running make when the CMake
configuration failed.
* Change to the directory the script sits in, in case it is ever called
from another directory.
* With CMake 4.x, declaring compatibility with version 3.5 straight up
errors. Passing the environment variable fixes this issue. See
https://gitlab.kitware.com/cmake/cmake/-/issues/26613 and
https://gitlab.kitware.com/cmake/cmake/-/issues/26698 for more info.
* CMake doesn't always emit Makefiles by default, so use `cmake --build'
to build using whatever method CMake will choose.
* Compile using all available cores, instead of only using a single CPU
core.