R: rewrite Makefile, use subdirs for code (#594).