Makefile improvements: rule consolidation, dependency generation

This PR addresses #599 using the `-MMD` option of gcc/clang (and the `-M` option of nvcc) to automatically generate header file dependencies, finally making the build truly incremental.

In addition, some consolidation of build rules is included (more might be possible), and the explicit enumeration of build directories is made a bit more automatic (further improvements in this direction are also possible).

This is pretty fresh so you might want to let it age a couple days in case I messed something up; I'll be working off this branch.
Make merges multiple rules into one with a union over prerequisites, see https://www.gnu.org/software/make/manual/html_node/Multiple-Rules.html. The additional rules are provided in the `.d` files included in the last line of the `Makefile`. (Note that on first build, the `.d` files don't exist, but this doesn't matter, because everything has to be built anyway.)