refactoring Makefile using template
compact logic