autoconf
[Top][All Lists]
Advanced

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

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


From: Nick Bowler
Subject: Re: How to programmatically detect awk flavor (e.g. gawk vs mawk vs nawk vs awk)
Date: Mon, 19 Oct 2015 10:36:50 -0400

Hi,

On 10/18/15, Itamar Gal <address@hidden> 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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]