configure: libtool < 2.4.6 doesn't work with fstack-protector-strong

* configure.ac: GCC -fstack-protector-strong gives undefined symbol error
  when linking on __stack_chk_fail_local with libtool < 2.4.6.  The gcc arg
  is not passed on when linking.  OpenIndiana hipster has 2.4.2 at the
  moment. Test the libtool version and drop the arg and warn the user.
diff --git a/configure.ac b/configure.ac
index 7d9aa3f..402c891 100755
--- a/configure.ac
+++ b/configure.ac
@@ -79,6 +79,18 @@
 PKG_PROG_PKG_CONFIG
 AC_PROG_CC_C99
 
+dnl libtool prereq.
+AC_USE_SYSTEM_EXTENSIONS
+
+dnl -------
+dnl libtool
+dnl -------
+LT_INIT
+
+dnl create libtool now, so we can test version below for
+dnl fstack-protector-strong
+LT_OUTPUT
+
 dnl autoconf 2.59 appears not to support AC_PROG_SED
 dnl AC_PROG_SED
 AC_CHECK_PROG([SED],[sed],[sed],[/bin/false])
@@ -122,7 +134,6 @@
 dnl so lets set some sane CFLAGS for it.
 dnl ---------------------------------------------
 
-AC_USE_SYSTEM_EXTENSIONS()
 AC_DEFUN([AC_C_FLAG], [{
 	AC_LANG_PUSH(C)
 	ac_c_flag_save="$CFLAGS"
@@ -159,7 +170,25 @@
         AC_C_FLAG([-Os], [
           AC_C_FLAG([-O2])
         ])
-        AC_C_FLAG([-fstack-protector-strong])
+        dnl fstack-protector-strong gives __stack_chk_fail_local
+        dnl being an 'Undefined symbol' on OpenIndiana hipster, with gcc 6.
+        dnl gcc -shared is being used to do the link, however the error is
+        dnl from ld. Disable. An issue with libtool < 2.4.6 dropping the
+        dnl -fstack-protector-strong argument from the shared link.
+        AC_MSG_CHECKING([whether libtool can support fstack-protector])
+        if test x"$(./libtool --version \
+         	    | awk -F '[[ \t.]]' \
+        		'NR == 1 { \
+   				if ($(NF-2) <= 2 && $(NF-1) <= 4 && $NF < 6) \
+        				print 0; \
+        			else print 1 \
+        		}')" = "x1" ; then
+        	AC_MSG_RESULT([yes])
+        	AC_C_FLAG([-fstack-protector-strong])
+        else
+        	AC_MSG_RESULT([no])
+        	AC_MSG_WARN([upgrade to libtool >= 2.4.6!])
+        fi
         AC_C_FLAG([-fpie])
         AC_C_FLAG([-fno-omit-frame-pointer])
         AC_C_FLAG([-Wall])
@@ -226,10 +255,6 @@
 dnl -----------------
 AC_GNU_SOURCE
 
-dnl -------
-dnl libtool
-dnl -------
-LT_INIT
 
 dnl ----------------------
 dnl Packages configuration