AX_VALGRIND_CHECK: Refactor a little to ensure log files are cleaned

Add the log files to MOSTLYCLEANFILES and take the opportunity to
refactor the code a little to reduce duplication for different Valgrind
tools.

Note that the valgrind_*_flags variables are necessary because the
sgcheck tool has an odd --tool=exp-sgcheck argument, rather than
--tool=sgcheck. This is because it is experimental. I want the
autoconf macro to consistently refer to it as sgcheck so that nothing
changes when it becomes non-experimental.