build: unified makefile.am files
added lock, discount isn't thread safe