toolchain: make magic to compile and link only required sources

This change allows make to figure out which sources need to be compiled
and linked in order to satisfy all undefined symbols.  The results are
shorter compile times and no leakage of weak interrupt handler symbols
into programs that do not use the weakly linked subsystem.