Search code examples
bashautotoolsautoconfm4autoreconf

Autoconf m4_bmatch not working with variable


Here is some code in my configure.ac:

THIS="h5cc"
AC_MSG_WARN([$THIS])
AC_MSG_WARN(m4_bmatch([h5pcc],
         [h5pcc], [parallel],
         [h5cc], [serial],
         [neither]
         ))
AC_MSG_ERROR(m4_bmatch([$THIS],
         [h5pcc], [parallel],
         [h5cc], [serial],
         [neither]
         ))

I autoconf and then configure, which results in this:

configure: WARNING: h5cc
configure: WARNING: parallel
configure: error: neither

As far as I can tell, that's not supposed to happen, right? What am I missing?


Solution

  • You're mixing M4 code within your configure, but m4 only executes before expansion (i.e. when you run autoconf), while THIS=h5cc is a shell construct that gets executed by your shell (when you run ./configure).

    So what m4_bmatch sees is a literal $THIS which indeed is neither.

    Short version, don't use m4_* functions for things that you want to change at configure time.