autotools: Fix for autoconf-archive 2019.01.19

The code coverage macros from the archive changed in a backward
incompatible way. This adds a workaround to autodetect either version
and do the right thing.

Tested:
    Builds with the old version of autotools using the CI. Manually
    edited the CI to include the new 2019.01.19 version and ran the same
    test to ensure the coverage results are the same.

Change-Id: Iebc9a3c32de4fd1c2da26e6eb3bc44cf296a4ca6
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/.gitignore b/.gitignore
index 15f8350..b82c23f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -22,6 +22,7 @@
 .dirstamp
 .libs
 /aclocal.m4
+/aminclude_static.am
 /autom4te.cache
 /build-aux
 /confdefs.h
diff --git a/Makefile.am b/Makefile.am
index bccf5dd..0917a7b 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -29,6 +29,14 @@
 CODE_COVERAGE_GENHTML_OPTIONS += --prefix $(abs_srcdir) --prefix $(abs_builddir)
 export CODE_COVERAGE_GENHTML_OPTIONS
 
+if AUTOCONF_CODE_COVERAGE_2019_01_06
+include $(top_srcdir)/aminclude_static.am
+clean-local: code-coverage-clean
+distclean-local: code-coverage-dist-clean
+else
+@CODE_COVERAGE_RULES@
+endif
+
 export AM_CPPFLAGS = -I$(abs_builddir)/src -I$(abs_srcdir)/src \
                      $(CODE_COVERAGE_CPPFLAGS)
 export AM_CFLAGS = $(CODE_COVERAGE_CFLAGS)
diff --git a/configure.ac b/configure.ac
index d3439d6..0fa7dfe 100644
--- a/configure.ac
+++ b/configure.ac
@@ -5,7 +5,7 @@
 AC_CONFIG_HEADERS([config.h])
 AC_CONFIG_MACRO_DIRS([m4])
 AC_CONFIG_AUX_DIR([build-aux])
-AM_INIT_AUTOMAKE([nostdinc foreign subdir-objects -Wall -Werror dist-xz tar-ustar])
+AM_INIT_AUTOMAKE([nostdinc foreign subdir-objects -Wall -Wno-portability -Werror dist-xz tar-ustar])
 AM_SILENT_RULES([yes])
 
 # Make sure the default CFLAGS of `-O2 -g` don't override CODE_COVERAGE_CFLAGS
@@ -130,10 +130,13 @@
 
 # Code coverage
 AX_CODE_COVERAGE
-AM_EXTRA_RECURSIVE_TARGETS([check-code-coverage])
 AS_IF([test "x$CODE_COVERAGE_ENABLED" = "xyes"], [
     AX_APPEND_COMPILE_FLAGS([-DHAVE_GCOV], [CODE_COVERAGE_CPPFLAGS])
 ])
+m4_ifdef([_AX_CODE_COVERAGE_RULES],
+    [AM_CONDITIONAL(AUTOCONF_CODE_COVERAGE_2019_01_06, [true])],
+    [AM_CONDITIONAL(AUTOCONF_CODE_COVERAGE_2019_01_06, [false])])
+AX_ADD_AM_MACRO_STATIC([])
 
 # Append -Werror after doing autoconf compiler checks
 # Otherwise some perfectly valid checks can fail and cause our
diff --git a/test/Makefile.am b/test/Makefile.am
index 103010d..ebbe4c9 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -1,5 +1,4 @@
 @VALGRIND_CHECK_RULES@
-@CODE_COVERAGE_RULES@
 
 gtest_cppflags = $(AM_CPPFLAGS) $(GTEST_CFLAGS) $(GMOCK_CFLAGS)
 gtest_ldadd = $(GPIOPLUS_LIBS) $(GTEST_LIBS) $(GMOCK_LIBS) -lgmock_main