Move more logic into Makefile.lib.