Re: How to programmatically detect awk flavor (e.g. gawk vs mawk vs nawk vs awk)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

On 10/18/15, Itamar Gal <itamarggal@xxxxxxxxx> wrote:
> I recently posted a question to unix.stackexchange.com asking for the best
> way to programmatically determine which flavor of awk is present on a given
> host.
>
> Someone suggested using the AC_PROG_AWK macro, but didn't elaborate on how
> this would work.

All the AC_PROG_AWK macro does is set the AWK variable to the first
program found in the following list:

  gawk, mawk, nawk, awk.

So you could start with that, then probe $AWK in your own tests to
figure out its characteristics.

The "Autoconf Way" is to try and probe for features, not versions or
flavours (although you can do this too).  So you you need some specific
feature of, say, GNU awk, you can write a test which probes it.  For
example (untested):

  AC_PROG_AWK
  AC_CACHE_CHECK([if $AWK supports feature X], [my_cv_awk_feature_x],
    [AS_IF([$AWK test_case], [my_cv_awk_feature_x=yes],
                             [my_cv_awk_feature_x=no])])
  AS_IF([test x"$my_cv_awk_feature_x" = x"yes"],
    [do_something], [do_something_else])

Perform as many tests as you need.  Then you can adapt your behaviour
(or error out) based on whether the awk implementation supports the
extra features or not.

Cheers,
  Nick

_______________________________________________
Autoconf mailing list
Autoconf@xxxxxxx
https://lists.gnu.org/mailman/listinfo/autoconf



[Index of Archives]     [GCC Help]     [Kernel Discussion]     [RPM Discussion]     [Red Hat Development]     [Yosemite News]     [Linux USB]     [Samba]

  Powered by Linux