As a follow up to this question, there is one more case I haven\'t been able to figure out in a few hours of tinkering.
Here is what the makefile currently looks like: