diff --git a/channels/chan_dahdi.c b/channels/chan_dahdi.c
index 5a36328ad61c7b74e8347f465fe258a980f879b7..b59e157a5bd287039c49f93cd5624ac6f5c69e5c 100644
--- a/channels/chan_dahdi.c
+++ b/channels/chan_dahdi.c
@@ -2144,6 +2144,7 @@ static void dahdi_ami_channel_event(struct dahdi_pvt *p, struct ast_channel *cha
 		ch_name);
 }
 
+#ifdef HAVE_PRI
 /*!
  * \internal
  * \brief Post an AMI DAHDI channel association event.
@@ -2160,6 +2161,7 @@ static void my_ami_channel_event(void *pvt, struct ast_channel *chan)
 
 	dahdi_ami_channel_event(p, chan);
 }
+#endif
 
 /* linear_mode = 0 - turn linear mode off, >0 - turn linear mode on
 * 	returns the last value of the linear setting 
diff --git a/configure b/configure
index 167cd4409c26eb76d6a36b48d71494dc18f122a7..691bbbff8bc44c62636326c3bbb50b3122f59244 100755
--- a/configure
+++ b/configure
@@ -1,5 +1,5 @@
 #! /bin/sh
-# From configure.ac Revision: 306396 .
+# From configure.ac Revision: 309036 .
 # Guess values for system-dependent variables and create Makefiles.
 # Generated by GNU Autoconf 2.65 for asterisk trunk.
 #
@@ -7400,57 +7400,6 @@ __EOL__
 fi
 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_BISON2" >&5
 $as_echo "$ac_cv_path_BISON2" >&6; }
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for flex that ignores fwrite return value" >&5
-$as_echo_n "checking for flex that ignores fwrite return value... " >&6; }
-if test "${ac_cv_FLEX_WORKAROUND+set}" = set; then :
-  $as_echo_n "(cached) " >&6
-else
-
-	if test "x$FLEX" != "x:" ; then
-		# Create a temporary directory $tmp in $TMPDIR (default /tmp).
-		# Use mktemp if possible; otherwise fall back on mkdir,
-		# with $RANDOM to make collisions less likely.
-		: ${TMPDIR=/tmp}
-		{
-		  tmp=`
-		    (umask 077 && mktemp -d "$TMPDIR/fooXXXXXX") 2>/dev/null
-		  ` &&
-		  test -n "$tmp" && test -d "$tmp"
-		} || {
-		  tmp=$TMPDIR/foo$$-$RANDOM
-		  (umask 077 && mkdir "$tmp")
-		} || exit $?
-		cat >$tmp/test.fl <<__EOL__
-%{
-#include <unistd.h>
-#include <stdio.h>
-static void yyunput (int c,char *buf_ptr  ) __attribute__((unused));
-static int input(void) __attribute__((unused));
-%}
-
-%%
-username    printf( "%s", getlogin() );
-__EOL__
-		${FLEX} -o ${tmp}/test.c ${tmp}/test.fl
-		${CC} -o ${tmp}/test.o -c ${tmp}/test.c -Wall -Werror >/dev/null 2>&1
-		if test -e "${tmp}/test.o"; then
-			ac_cv_FLEX_WORKAROUND=no
-		else
-			ac_cv_FLEX_WORKAROUND=yes
-		fi
-		rm -rf ${tmp}
-	fi
-
-fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_FLEX_WORKAROUND" >&5
-$as_echo "$ac_cv_FLEX_WORKAROUND" >&6; }
-
-if test "x${ac_cv_FLEX_WORKAROUND}" = "xyes"; then
-
-$as_echo "#define NEED_FLEX_FWRITE_WORKAROUND 1" >>confdefs.h
-
-fi
-
 if test "x${ac_cv_path_BISON2}" = "x" ; then
 	BISON=:
 	PBX_BISON=0
diff --git a/configure.ac b/configure.ac
index 763cd1a226d6f6b496fb5f2e2e9e821233399bb9..9e8a2df816ba5fcdf4da8f81b0dfddfffbe60bb3 100644
--- a/configure.ac
+++ b/configure.ac
@@ -301,47 +301,6 @@ __EOL__
 		rm -rf ${tmp}
 	fi
 	])
-AC_CACHE_CHECK([for flex that ignores fwrite return value], [ac_cv_FLEX_WORKAROUND], [
-	if test "x$FLEX" != "x:" ; then
-		# Create a temporary directory $tmp in $TMPDIR (default /tmp).
-		# Use mktemp if possible; otherwise fall back on mkdir,
-		# with $RANDOM to make collisions less likely.
-		: ${TMPDIR=/tmp}
-		{
-		  tmp=`
-		    (umask 077 && mktemp -d "$TMPDIR/fooXXXXXX") 2>/dev/null
-		  ` &&
-		  test -n "$tmp" && test -d "$tmp"
-		} || {
-		  tmp=$TMPDIR/foo$$-$RANDOM
-		  (umask 077 && mkdir "$tmp")
-		} || exit $?
-		cat >$tmp/test.fl <<__EOL__
-%{
-#include <unistd.h>
-#include <stdio.h>
-static void yyunput (int c,char *buf_ptr  ) __attribute__((unused));
-static int input(void) __attribute__((unused));
-%}
-
-%%
-username    printf( "%s", getlogin() );
-__EOL__
-		${FLEX} -o ${tmp}/test.c ${tmp}/test.fl
-		${CC} -o ${tmp}/test.o -c ${tmp}/test.c -Wall -Werror >/dev/null 2>&1
-		if test -e "${tmp}/test.o"; then
-			ac_cv_FLEX_WORKAROUND=no
-		else
-			ac_cv_FLEX_WORKAROUND=yes
-		fi
-		rm -rf ${tmp}
-	fi
-	])
-
-if test "x${ac_cv_FLEX_WORKAROUND}" = "xyes"; then
-	AC_DEFINE([NEED_FLEX_FWRITE_WORKAROUND], 1, [Define to 1 if your system has a version of flex that does not check the return value of fwrite.])
-fi
-
 if test "x${ac_cv_path_BISON2}" = "x" ; then
 	BISON=:
 	PBX_BISON=0
diff --git a/include/asterisk/autoconfig.h.in b/include/asterisk/autoconfig.h.in
index 1b64234cabbee116e440e35dbf28b474fad8509d..ac63fdae7670479c63b6ea677ec78bbe76dfcaf7 100644
--- a/include/asterisk/autoconfig.h.in
+++ b/include/asterisk/autoconfig.h.in
@@ -1098,10 +1098,6 @@
 /* Build chan_misdn for mISDN 1.2 or later. */
 #undef MISDN_1_2
 
-/* Define to 1 if your system has a version of flex that does not check the
-   return value of fwrite. */
-#undef NEED_FLEX_FWRITE_WORKAROUND
-
 /* Define to the address where bug reports for this package should be sent. */
 #undef PACKAGE_BUGREPORT
 
diff --git a/main/ast_expr2.fl b/main/ast_expr2.fl
index 75b3e76329f1085020a13525b983d7664bc578b3..624618e9f9c3677dc7f3c44c2eb7748bae862019 100644
--- a/main/ast_expr2.fl
+++ b/main/ast_expr2.fl
@@ -65,11 +65,9 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 #include "asterisk/channel.h"
 #endif
 
-#ifdef NEED_FLEX_FWRITE_WORKAROUND
-/*!\note Some versions of Flex use fwrite without checking its return value, which
- * is a warning on some compilers.  Therefore, we use this workaround, to trick
- * the compiler into suppressing this warning. */
-#define fwrite(a,b,c,d)	do { int __res = fwrite(a,b,c,d); (__res); } while (0)
+/* Conditionally redefine the macro from flex 2.5.35, in case someone uses flex <2.5.35 to regenerate this file. */
+#ifndef ECHO
+#define ECHO do { if (fwrite( yytext, yyleng, 1, yyout )) {} } while (0)
 #endif
 
 enum valtype {
diff --git a/main/ast_expr2f.c b/main/ast_expr2f.c
index bfa5a6ebdd17c16f21ac00fbc7912c1df73f6bd3..cc0f0f1959631702fbec25d483aa0b194d33f2cd 100644
--- a/main/ast_expr2f.c
+++ b/main/ast_expr2f.c
@@ -559,11 +559,9 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 #include "asterisk/channel.h"
 #endif
 
-#ifdef NEED_FLEX_FWRITE_WORKAROUND
-/*!\note Some versions of Flex use fwrite without checking its return value, which
- * is a warning on some compilers.  Therefore, we use this workaround, to trick
- * the compiler into suppressing this warning. */
-#define fwrite(a,b,c,d)	do { int __res = fwrite(a,b,c,d); (__res); } while (0)
+/* Conditionally redefine the macro from flex 2.5.35, in case someone uses flex <2.5.35 to regenerate this file. */
+#ifndef ECHO
+#define ECHO do { if (fwrite( yytext, yyleng, 1, yyout )) {} } while (0)
 #endif
 
 enum valtype {
@@ -611,7 +609,7 @@ int ast_yyget_column(yyscan_t yyscanner);
 static int curlycount = 0;
 static char *expr2_token_subst(const char *mess);
 
-#line 613 "ast_expr2f.c"
+#line 611 "ast_expr2f.c"
 
 #define INITIAL 0
 #define var 1
@@ -859,10 +857,10 @@ YY_DECL
 	register int yy_act;
     struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
 
-#line 132 "ast_expr2.fl"
+#line 130 "ast_expr2.fl"
 
 
-#line 864 "ast_expr2f.c"
+#line 862 "ast_expr2f.c"
 
     yylval = yylval_param;
 
@@ -953,132 +951,132 @@ do_action:	/* This label is used only to access EOF actions. */
 
 case 1:
 YY_RULE_SETUP
-#line 134 "ast_expr2.fl"
+#line 132 "ast_expr2.fl"
 { SET_COLUMNS; SET_STRING; return TOK_OR;}
 	YY_BREAK
 case 2:
 YY_RULE_SETUP
-#line 135 "ast_expr2.fl"
+#line 133 "ast_expr2.fl"
 { SET_COLUMNS; SET_STRING; return TOK_AND;}
 	YY_BREAK
 case 3:
 YY_RULE_SETUP
-#line 136 "ast_expr2.fl"
+#line 134 "ast_expr2.fl"
 { SET_COLUMNS; SET_STRING; return TOK_EQ;}
 	YY_BREAK
 case 4:
 YY_RULE_SETUP
-#line 137 "ast_expr2.fl"
+#line 135 "ast_expr2.fl"
 { SET_COLUMNS; SET_STRING; return TOK_OR;}
 	YY_BREAK
 case 5:
 YY_RULE_SETUP
-#line 138 "ast_expr2.fl"
+#line 136 "ast_expr2.fl"
 { SET_COLUMNS; SET_STRING; return TOK_AND;}
 	YY_BREAK
 case 6:
 YY_RULE_SETUP
-#line 139 "ast_expr2.fl"
+#line 137 "ast_expr2.fl"
 { SET_COLUMNS; SET_STRING; return TOK_EQ;}
 	YY_BREAK
 case 7:
 YY_RULE_SETUP
-#line 140 "ast_expr2.fl"
+#line 138 "ast_expr2.fl"
 { SET_COLUMNS; SET_STRING; return TOK_EQTILDE;}
 	YY_BREAK
 case 8:
 YY_RULE_SETUP
-#line 141 "ast_expr2.fl"
+#line 139 "ast_expr2.fl"
 { SET_COLUMNS; SET_STRING; return TOK_TILDETILDE;}
 	YY_BREAK
 case 9:
 YY_RULE_SETUP
-#line 142 "ast_expr2.fl"
+#line 140 "ast_expr2.fl"
 { SET_COLUMNS; SET_STRING; return TOK_GT;}
 	YY_BREAK
 case 10:
 YY_RULE_SETUP
-#line 143 "ast_expr2.fl"
+#line 141 "ast_expr2.fl"
 { SET_COLUMNS; SET_STRING; return TOK_LT;}
 	YY_BREAK
 case 11:
 YY_RULE_SETUP
-#line 144 "ast_expr2.fl"
+#line 142 "ast_expr2.fl"
 { SET_COLUMNS; SET_STRING; return TOK_GE;}
 	YY_BREAK
 case 12:
 YY_RULE_SETUP
-#line 145 "ast_expr2.fl"
+#line 143 "ast_expr2.fl"
 { SET_COLUMNS; SET_STRING; return TOK_LE;}
 	YY_BREAK
 case 13:
 YY_RULE_SETUP
-#line 146 "ast_expr2.fl"
+#line 144 "ast_expr2.fl"
 { SET_COLUMNS; SET_STRING; return TOK_NE;}
 	YY_BREAK
 case 14:
 YY_RULE_SETUP
-#line 147 "ast_expr2.fl"
+#line 145 "ast_expr2.fl"
 { SET_COLUMNS; SET_STRING; return TOK_PLUS;}
 	YY_BREAK
 case 15:
 YY_RULE_SETUP
-#line 148 "ast_expr2.fl"
+#line 146 "ast_expr2.fl"
 { SET_COLUMNS; SET_STRING; return TOK_COMMA;}
 	YY_BREAK
 case 16:
 YY_RULE_SETUP
-#line 149 "ast_expr2.fl"
+#line 147 "ast_expr2.fl"
 { SET_COLUMNS; SET_STRING; return TOK_MINUS;}
 	YY_BREAK
 case 17:
 YY_RULE_SETUP
-#line 150 "ast_expr2.fl"
+#line 148 "ast_expr2.fl"
 { SET_COLUMNS; SET_STRING; return TOK_MULT;}
 	YY_BREAK
 case 18:
 YY_RULE_SETUP
-#line 151 "ast_expr2.fl"
+#line 149 "ast_expr2.fl"
 { SET_COLUMNS; SET_STRING; return TOK_DIV;}
 	YY_BREAK
 case 19:
 YY_RULE_SETUP
-#line 152 "ast_expr2.fl"
+#line 150 "ast_expr2.fl"
 { SET_COLUMNS; SET_STRING; return TOK_MOD;}
 	YY_BREAK
 case 20:
 YY_RULE_SETUP
-#line 153 "ast_expr2.fl"
+#line 151 "ast_expr2.fl"
 { SET_COLUMNS; SET_STRING; return TOK_COND;}
 	YY_BREAK
 case 21:
 YY_RULE_SETUP
-#line 154 "ast_expr2.fl"
+#line 152 "ast_expr2.fl"
 { SET_COLUMNS; SET_STRING; return TOK_COMPL;}
 	YY_BREAK
 case 22:
 YY_RULE_SETUP
-#line 155 "ast_expr2.fl"
+#line 153 "ast_expr2.fl"
 { SET_COLUMNS; SET_STRING; return TOK_COLON;}
 	YY_BREAK
 case 23:
 YY_RULE_SETUP
-#line 156 "ast_expr2.fl"
+#line 154 "ast_expr2.fl"
 { SET_COLUMNS; SET_STRING; return TOK_COLONCOLON;}
 	YY_BREAK
 case 24:
 YY_RULE_SETUP
-#line 157 "ast_expr2.fl"
+#line 155 "ast_expr2.fl"
 { SET_COLUMNS; SET_STRING; return TOK_LP;}
 	YY_BREAK
 case 25:
 YY_RULE_SETUP
-#line 158 "ast_expr2.fl"
+#line 156 "ast_expr2.fl"
 { SET_COLUMNS; SET_STRING; return TOK_RP;}
 	YY_BREAK
 case 26:
 YY_RULE_SETUP
-#line 159 "ast_expr2.fl"
+#line 157 "ast_expr2.fl"
 {
 		/* gather the contents of ${} expressions, with trailing stuff,
 		 * into a single TOKEN.
@@ -1091,24 +1089,24 @@ YY_RULE_SETUP
 	YY_BREAK
 case 27:
 YY_RULE_SETUP
-#line 169 "ast_expr2.fl"
+#line 167 "ast_expr2.fl"
 {}
 	YY_BREAK
 case 28:
 /* rule 28 can match eol */
 YY_RULE_SETUP
-#line 170 "ast_expr2.fl"
+#line 168 "ast_expr2.fl"
 {SET_COLUMNS; SET_STRING; return TOKEN;}
 	YY_BREAK
 case 29:
 /* rule 29 can match eol */
 YY_RULE_SETUP
-#line 172 "ast_expr2.fl"
+#line 170 "ast_expr2.fl"
 {/* what to do with eol */}
 	YY_BREAK
 case 30:
 YY_RULE_SETUP
-#line 173 "ast_expr2.fl"
+#line 171 "ast_expr2.fl"
 {
 		SET_COLUMNS;
 		/* the original behavior of the expression parser was
@@ -1121,7 +1119,7 @@ YY_RULE_SETUP
 case 31:
 /* rule 31 can match eol */
 YY_RULE_SETUP
-#line 182 "ast_expr2.fl"
+#line 180 "ast_expr2.fl"
 {
 		SET_COLUMNS;
 		SET_STRING;
@@ -1131,7 +1129,7 @@ YY_RULE_SETUP
 case 32:
 /* rule 32 can match eol */
 YY_RULE_SETUP
-#line 188 "ast_expr2.fl"
+#line 186 "ast_expr2.fl"
 {
 		curlycount = 0;
 		BEGIN(var);
@@ -1141,7 +1139,7 @@ YY_RULE_SETUP
 case 33:
 /* rule 33 can match eol */
 YY_RULE_SETUP
-#line 194 "ast_expr2.fl"
+#line 192 "ast_expr2.fl"
 {
 		curlycount--;
 		if (curlycount < 0) {
@@ -1155,7 +1153,7 @@ YY_RULE_SETUP
 case 34:
 /* rule 34 can match eol */
 YY_RULE_SETUP
-#line 204 "ast_expr2.fl"
+#line 202 "ast_expr2.fl"
 {
 		curlycount++;
 		yymore();
@@ -1163,7 +1161,7 @@ YY_RULE_SETUP
 	YY_BREAK
 case 35:
 YY_RULE_SETUP
-#line 210 "ast_expr2.fl"
+#line 208 "ast_expr2.fl"
 {
 		BEGIN(0);
 		SET_COLUMNS;
@@ -1173,7 +1171,7 @@ YY_RULE_SETUP
 	YY_BREAK
 case 36:
 YY_RULE_SETUP
-#line 217 "ast_expr2.fl"
+#line 215 "ast_expr2.fl"
 {
 		curlycount = 0;
 		BEGIN(var);
@@ -1183,7 +1181,7 @@ YY_RULE_SETUP
 case 37:
 /* rule 37 can match eol */
 YY_RULE_SETUP
-#line 223 "ast_expr2.fl"
+#line 221 "ast_expr2.fl"
 {
 		char c = yytext[yyleng-1];
 		BEGIN(0);
@@ -1194,7 +1192,7 @@ YY_RULE_SETUP
 	}
 	YY_BREAK
 case YY_STATE_EOF(trail):
-#line 232 "ast_expr2.fl"
+#line 230 "ast_expr2.fl"
 {
 		BEGIN(0);
 		SET_COLUMNS;
@@ -1205,10 +1203,10 @@ case YY_STATE_EOF(trail):
 	YY_BREAK
 case 38:
 YY_RULE_SETUP
-#line 240 "ast_expr2.fl"
+#line 238 "ast_expr2.fl"
 ECHO;
 	YY_BREAK
-#line 1210 "ast_expr2f.c"
+#line 1208 "ast_expr2f.c"
 case YY_STATE_EOF(INITIAL):
 case YY_STATE_EOF(var):
 	yyterminate();
@@ -2384,7 +2382,7 @@ void *ast_yyrealloc  (void * ptr, yy_size_t  size , yyscan_t yyscanner)
 
 #define YYTABLES_NAME "yytables"
 
-#line 240 "ast_expr2.fl"
+#line 238 "ast_expr2.fl"