move generate into lib, add Makefile