change makefile, move common functions to library