build: enable valgrind

Enable valgrind tests.

Change-Id: Ib5ec22a19c043ef45f5274e4716e2abbae9c19da
Signed-off-by: Patrick Venture <venture@google.com>
diff --git a/configure.ac b/configure.ac
index d6fbe00..1e906a8 100644
--- a/configure.ac
+++ b/configure.ac
@@ -118,6 +118,16 @@
     AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS])
 ])
 
+# 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)])
+
 # Code coverage
 AX_CODE_COVERAGE
 AM_EXTRA_RECURSIVE_TARGETS([check-code-coverage])
diff --git a/test/Makefile.am b/test/Makefile.am
index a1dfba5..86cfad1 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -1,3 +1,4 @@
+@VALGRIND_CHECK_RULES@
 @CODE_COVERAGE_RULES@
 
 AM_CPPFLAGS = \