m4 macro expansion problem

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

 



Dear all,

I am trying to define a package version properly by first defining its
components separately (major and minor version number, patchlevel, and
extra).

The major and minor numbers are assumed to be always present. The
patchlevel and the extra bits are optional.

In pseudo-shell code, the version would built like this:

major=x
minor=y
patch=z
extra=rc2
extra_prefix='+' # Could also be a '~'
version="$major.$minor"
if [ -n "$patchlevel"]; then
  version="$version.$patchlevel";
fi
if [ -n "$extra" ]; then
  version="$version${extra_prefix}${extra}"
fi

I would like to express all this in m4, more precisely in aclocal.m4, so
that the configure script has proper version information.

At the moment I don't manage to do so and failed to find an exemple of a
macro whose body can take several lines but with the spaces at the begin
of the lines (except the first one) being ignored. So I resorted to
format but I didn't manage to make that work either and it any way feels
too complex to be correct.

Here is how the code looks like at the moment:

# Package version
define(`PKG_VERSION_MAJOR', `4')dnl
define(`PKG_VERSION_MINOR', `14')dnl
define(`PKG_VERSION_PATCH_LEVEL', `0')dnl
define(`PKG_VERSION_EXTRA', `dev0-2021-06-03')dnl
define(`PKG_VERSION_EXTRA_PREFIX', `+')dnl could also be `~'
define(`PKG_VERSION',
  ``format(dnl
    PKG_VERSION_MAJOR.PKG_VERSION_MINOR`%s%s',dnl
    ifelse(PKG_VERSION_PATCH_LEVEL,`',`',.PKG_VERSION_PATCH_LEVEL),dnl
    ifelse(PKG_VERSION_PATCH_LEVEL,`',`',dnl
      PKG_VERSION_EXTRA_PREFIX`'PKG_VERSION_EXTRA)dnl
  )''dnl
)dnl

All this expands to PKG_VERSION inocnfigure.

I do realise this may seem a bit overkill and I could just duplicate the
information, but if possible, I'd like to avoid that and have a clear
separation between the definition of the different components and the
logic that describes how the version is built from them.

Incidentally, when running autoconf, would it be possible to generate,
besides to configure, a VERSION file that would contain just the version
string? That's what we have at the moment so it would guarantee backward
compatibility. I could also have a VERSION.in file and have vERSION be
generated by configure, but I'd prefer to have VERSION generated exactly
at the same time than configure. I guess it has to do with diverting
output but a concrete example would be more than welcome.

Many thanks in advance for your help!

Sébastien.




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

  Powered by Linux