How do I execute a shell command, and assign the output to an AC_DEFINE variable in configure.ac

747 views Asked by At

I need to identify the major version of a software, to do this it's principally to execute

command --version | head | awk -F "." '{print $1}'

Now, i need to assign this output to a AC_DEFINE variable.

I've tried;

majorvar=$(command --version | head | awk -F "." '{print $1}')

AC_DEFINE_UNQUOTED([myVar],["$majorvar"],[description])

here 'command' appeared in the resulting config.h file

and

AC_DEFINE([myVar],0,[descr])

AC_SUBST([myVar],[$(command --version | head | awk -F "." '{print $1}')])

where the value set by the define (0) is appearing in the result.

Is it possible to obtain the result that I want, i.e

#define myVar 5

or am I going about this in the wrong way, and if so, how should I go about it?

BR/Patrik

1

There are 1 answers

0
domson On

I needed several month to wrap my head around the concept of macros. As the name already tells, macros are 'bigger' than scripts. I hope this example can help.

AC_DEFUN([VERSION],
[$(test -f $srcdir/VERSION && cat $srcdir/VERSION || AS_ECHO(["$PACKAGE_VERSION"]); )])

am_stable_version_rx='[[1-9]\.[0-9]+(\.[0-9]+)?]'
am_beta_version_rx="[$am_stable_version_rx[bdfhjlnprtvxz]]"

am_release_type=`AS_ECHO(["$VERSION"]) | LC_ALL=C awk ["
  /^$am_stable_version_rx$/ { print \"stable\"; exit(0); }
  /^$am_beta_version_rx$/ { print \"beta version\"; exit(0); }
  { print \"development snapshot\"; }"]`

test "$am_release_type" = stable || cat <<EOF

WARNING: You are about to use a $am_release_type of AC_PACKAGE_NAME VERSION.
WARNING: It might easily suffer from new bugs or regressions.
WARNING: You are strongly advised not to use it in production code.

Please report bugs, problems and feedback to <AC_PACKAGE_BUGREPORT>.
EOF

The code snippet defines:

  1. a macro function DEFUN named VERSION
  2. a script variable with regex for versioning
  3. a script variable assignment containing a macro AS_ECHO which places the VERSION script during the generation of the configure script.