refactor makefile, do some detect to eliminate hard-code