All of this is covered by pattern rules in Makefile.rules near line 576