Restructure Makefiles, split structures into lib