Bug: https://reviewboard.asterisk.org/r/1330/
Author: Tzafrir Cohen <tzafrir.cohen@xorcom.com>
Description: fix detection of weakref attribute in menuselect

Asterisk relies on weakref symbols for optional dependencies. Their
detection broke with gcc 4.6. This fixes their detection. Requires
re-running autoconf in menuselect.

diff --git a/acinclude.m4 b/acinclude.m4
index 9410608..3517918 100644
--- a/menuselect/acinclude.m4
+++ b/menuselect/acinclude.m4
@@ -1,35 +1,20 @@
 # Helper function to check for gcc attributes.
-# AST_GCC_ATTRIBUTE([attribute name], [attribute syntax], [attribute scope], [makeopts flag])
+# AST_GCC_TYPE_ATTRIBUTE([attribute name], [attribute extra], [attribute scope])
 
-AC_DEFUN([AST_GCC_ATTRIBUTE],
+AC_DEFUN([AST_GCC_TYPE_ATTRIBUTE],
 [
 AC_MSG_CHECKING(checking for compiler 'attribute $1' support)
 saved_CFLAGS="$CFLAGS"
 CFLAGS="$CFLAGS -Wall -Wno-unused -Werror"
-m4_ifval([$4],$4=0)
 
-if test "x$2" = "x"
-then
 AC_COMPILE_IFELSE(
-	AC_LANG_PROGRAM([$3 void __attribute__(($1)) *test(void *muffin, ...) {return (void *) 0;}],
+	AC_LANG_PROGRAM([$3 __attribute__(($1 $2)) int muffin;],
 			[]),
 	AC_MSG_RESULT(yes)
-	m4_ifval([$4],$4=1)
 	AC_DEFINE_UNQUOTED([HAVE_ATTRIBUTE_$1], 1, [Define to 1 if your GCC C compiler supports the '$1' attribute.]),
 	AC_MSG_RESULT(no)
 )
-else
-AC_COMPILE_IFELSE(
-	AC_LANG_PROGRAM([$3 void __attribute__(($2)) *test(void *muffin, ...) {return (void *) 0;}],
-			[]),
-	AC_MSG_RESULT(yes)
-	m4_ifval([$4],$4=1)
-	AC_DEFINE_UNQUOTED([HAVE_ATTRIBUTE_$1], 1, [Define to 1 if your GCC C compiler supports the '$1' attribute.]),
-	AC_MSG_RESULT(no)
-)
-fi
 
-m4_ifval([$4],[AC_SUBST($4)])
 CFLAGS="$saved_CFLAGS"
 ])
 
diff --git a/configure.ac b/configure.ac
index d04aeb7..d4472a5 100644
--- a/menuselect/configure.ac
+++ b/menuselect/configure.ac
@@ -51,9 +51,8 @@ AC_ARG_ENABLE([debug],
     esac])
 AC_SUBST(MENUSELECT_DEBUG)
 
-AST_GCC_ATTRIBUTE(weak_import)
-AST_GCC_ATTRIBUTE(weakref)
-AST_GCC_ATTRIBUTE(weak)
+AST_GCC_TYPE_ATTRIBUTE(weak_import)
+AST_GCC_TYPE_ATTRIBUTE(weakref, ("foo"), static)
 
 AC_FUNC_ALLOCA
 AC_CHECK_FUNCS([asprintf getloadavg setenv strcasestr strndup strnlen strsep unsetenv vasprintf])
