Update the UNIX build Makefile to work with .cpp files

This allows the Makefile to compile the code again, though it cannot be
compiled correctly yet.
Make sure all functions are properly declared

Now that we changed the filenames to .cpp, the UNIX_BUILD actually
compiles them as C++ instead of C. This means we have to make sure that
all functions are properly declared before being used (in C, using a
function without a declaration would make the compiler just declare it
on the spot, but this is not possible in C++ due to name mangling).

Since the regular Arduino build already happened under C++, all the
functions needed there were already declared.

Additionally, this adds a "mode" parameter to the mkdir call, since that
was left out (which didn't cause any compilation errors previously, but
probably caused a random undefined value to be passed to mkdir).
Explicitely set -DUNIX_BUILD in the Makefile

Previously, UNIX_BUILD was automatically set, but this only worked on
x86 and x86_64. Since the only point of the Makefile is to do UNIX
builds, it might as well set the define explicitely, which could make
the code work on other architectures out of the box as well.
Only enable fprintf and save when SERIAL_OVERRIDE is enabled

Their implementations need to override the output function and cannot work
without that.
Add a bit more structure to the Makefile

This moves more stuff into variables, which makes it easier to
selectively change things in the build.