Makefile: condense dependency scanning into one loop