On Mon, Oct 24, 2022 at 08:19:50PM +0200, Bruno Haible wrote:
> does not help here, because nawk and mawk don't implement it. But what
> works, is a test whether $prog supports the function syntax: On this
> platform,
>
> gawk 'function foo () {}' 2>/dev/null
> nawk 'function foo () {}' 2>/dev/null
>
> both have exit code 0, whereas
>
> awk 'function foo () {}' 2>/dev/null
>
> has exit code 2.
>
> To implement this, use a variant of AC_CHECK_PROGS that accepts a test
> argument. (AM_PATH_PROG_WITH_TEST from gnulib/m4/progtest.m4 is not the
> right there here, because it searches only for a single program name,
> not multiple ones.)
>
> Bruno
AC_PATH_PROGS_FEATURE_CHECK does the job although it is slightly complicated
to use:
AC_CACHE_CHECK([for awk], [ac_cv_path_TI_AWK],
[AC_PATH_PROGS_FEATURE_CHECK([TI_AWK], [awk gawk mawk nawk],
[[$ac_path_TI_AWK 'function foo () {}' 2>/dev/null \
&& ac_cv_path_TI_AWK=$ac_path_TI_AWK ac_path_TI_AWK_found=:]],
[AC_MSG_ERROR([awk not found])])])
AC_SUBST([TI_AWK], [$ac_cv_path_TI_AWK])
If this is not going to work we can go back to using AC_CHECK_PROGS with
awk at the front of the list as we shouldn't make the program worse for
the sake of Solaris and/or MS-Windows.