configure: Enable valgrind support

I've caught some issues with valgrind that were missed by the compiler
sanitizers (though were interestingly picked up by the cmake build of
the test suites).

Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
Change-Id: I96ac0a331c2d7466ee66a7ce2e8d8b2b8d497d5d
diff --git a/configure.ac b/configure.ac
index 138fa05..6b36124 100644
--- a/configure.ac
+++ b/configure.ac
@@ -127,6 +127,16 @@
 AM_CONDITIONAL([LIBMCTP_BINDING_serial], [true])
 AM_CONDITIONAL([LIBMCTP_BINDING_astlpc], [true])
 
+# Check for valgrind
+AS_IF([test "x$enable_tests" = "xno"], [enable_valgrind=no])
+m4_foreach([vgtool], [valgrind_tool_list],
+    [AX_VALGRIND_DFLT(vgtool, [off])])
+AX_VALGRIND_DFLT([memcheck], [on])
+AX_VALGRIND_CHECK
+AM_EXTRA_RECURSIVE_TARGETS([check-valgrind])
+m4_foreach([vgtool], [valgrind_tool_list],
+    [AM_EXTRA_RECURSIVE_TARGETS([check-valgrind-]vgtool)])
+
 AX_CODE_COVERAGE
 m4_ifdef([_AX_CODE_COVERAGE_RULES],
     [AM_CONDITIONAL(AUTOCONF_CODE_COVERAGE_2019_01_06, [true])],