add test for global Makefile, refactor: extract function for writing Makefile