replace bash script with Makefile; assorted code cleanups