More Makefile cleanups, fix m4 variables in templates.
Fix various -Wextra warnings.

Unused variables, signed/unsigned comparisons.