+dnl ----------------
+dnl CUSTOMIZE CFLAGS
+dnl ----------------
+dnl The user didn't specify CFLAGS, so customize them.
+
+if test "$GCC" != yes; then
+ dnl Use -v and some other options with SunStudio cc. lex produces
+ dnl code that causes unreachable-statement warnings. It might be
+ dnl better to use an autoconf test, except -v will probably succeed
+ dnl with many other compilers but have different meaning.
+ AS_CASE([`${CC} -V 2>&1`],
+ [cc:*\ Sun\ C*], [CFLAGS=\
+"${CFLAGS:+$CFLAGS }-v -errtags=yes -erroff=E_STATEMENT_NOT_REACHED"])
+fi
+
+AC_CACHE_CHECK([whether compiler supports -Wall], [nmh_cv_has_wall],
+ [nmh_saved_cflags="$CFLAGS"
+ CFLAGS="$AM_CFLAGS $CFLAGS -Wall -Werror"
+ AC_TRY_COMPILE([],[],nmh_cv_has_wall=yes,nmh_cv_has_wall=no)
+ CFLAGS="$nmh_saved_cflags"])
+test "$nmh_cv_has_wall" = "yes" && CFLAGS="${CFLAGS:+$CFLAGS }-Wall"
+
+AC_CACHE_CHECK([whether compiler supports -Wextra], [nmh_cv_has_wextra],
+ [nmh_saved_cflags="$CFLAGS"
+ CFLAGS="$AM_CFLAGS $CFLAGS -Wextra -Werror"
+ AC_TRY_COMPILE([],[],nmh_cv_has_wextra=yes,
+ nmh_cv_has_wextra=no)
+ CFLAGS="$nmh_saved_cflags"])
+test "$nmh_cv_has_wextra" = "yes" && CFLAGS="${CFLAGS:+$CFLAGS }-Wextra"
+
+AC_SUBST([AM_CFLAGS])
+
+dnl Check for any platform-specific additional AM_CPPFLAGS. This depends on
+dnl MULTIBYTE_ENABLED having already been set.
+NMH_ADDL_CPPFLAGS
+
+if test "$GCC" = yes; then
+ dnl Do this regardless of auto_cflags value.
+ dnl Enable _FORTIFY_SOURCE checking, which is supported by
+ dnl gcc 4.1 and later, but only when optimization is enabled.
+ dnl It shouldn't hurt with earlier versions because it's a cpp macro.
+ dnl If the user configures with a CFLAGS that contains a -O flag
+ dnl but then removes it a make time, they'll also have to remove
+ dnl -D_FORTIFY_SOURCE from AM_CPPFLAGS because it requires optimization.
+ dnl Use "\ " instead of ' ' or " " for compatiblity with posh.
+ AS_CASE([$CFLAGS],
+ [-O|*\ -O|-O[[!0]]*|*\ -O[[!0]]*],
+ [AM_CPPFLAGS="${AM_CPPFLAGS:+$AM_CPPFLAGS }-D_FORTIFY_SOURCE=2"])
+fi
+
+dnl FreeBSD needs a bit of magic to bring getline() into scope.
+dnl We do this here rather than in (say) h/mh.h because this macro must
+dnl be defined before <stdio.h> is pulled in.
+dnl
+dnl And while we're here, add the packages tree to the cpp and ld search
+dnl paths. Note that FreeBSD's pkg(8) seems to be hardwired to use /usr/local.
+dnl If /usr/ports is installed, we use its idea of where things are installed,
+dnl otherwise we assume /usr/local.
+
+AS_IF([test `uname` = FreeBSD],
+ [CPPFLAGS="${CPPFLAGS:+$CPPFLAGS }-D_WITH_GETLINE"
+ nmh_cv_freebsd_localbase=`echo '.include <bsd.port.mk>' \
+ | make -k -f /dev/stdin -V LOCALBASE 2>/dev/null | sed 1q`
+ test -z "$nmh_cv_freebsd_localbase" && nmh_cv_freebsd_localbase=/usr/local
+ CPPFLAGS="${CPPFLAGS:+$CPPFLAGS }-I$nmh_cv_freebsd_localbase/include"
+ LDFLAGS="${LDFLAGS:+$LDFLAGS }-L$nmh_cv_freebsd_localbase/lib"
+])
+
+dnl --------------
+dnl CUSTOMIZE LINK
+dnl --------------
+AS_IF([test `uname` = OpenBSD],
+ dnl Munge "often/almost always misused" warnings from OpenBSD linker
+ dnl so that they don't color the waterfall.
+ [POSTLINK="2>&1 | sed -e \
+'s/: w\(arning: s.*() is .* misused, please use\)/: W\1/'"])
+AC_SUBST([POSTLINK])