bashconfigureautotoolsautoconfm4

How to trace which `configure.ac` m4 macro expands to a specific bash code block in `configure`?


Following this question, I am working on debugging a legacy build system and need to understand how a specific section of the generated configure script is produced from its configure.ac m4 source. Specifically, I'm trying to trace back the source of the following bash code block in the configure script:

_ACEOF
cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
exec 5>>config.log
{
  echo
  sed 'h;s/./-/g;s/^.../## /;s/...$/ ##/;p;x;p;x' <<_ASBOX
## Running $as_me. ##
_ASBOX
  printf "%s\n" "$ac_log"
} >&5

As described here.

From here, here, and here, I've learned that autoconf and autom4te have a --trace option that could potentially be used to figure out which part of the configure.ac file leads to this generated script section. However, I'm unsure how to effectively use this --trace option for this purpose.

Can someone guide me on using the --trace option (or any other method) to pinpoint which m4 macro(s) in configure.ac expand to generate this specific bash code block in the configure script?

Any help or insight into this would be greatly appreciated, as it would help me understand and potentially modify the build configuration for this project.


Solution

  • I've learned that autoconf and autom4te have a --trace option that could potentially be used to figure out which part of the configure.ac file leads to this generated script section. However, I'm unsure how to effectively use this --trace option for this purpose.

    Ignore autom4te. It is a support tool used by the front-end Autotools, not really intended for you to use directly. You would leverage it by running autoconf with its --trace option.

    But I don't see any way that that would serve your purpose. The --trace option provides information about invocations of specific macros that you designate, telling you where those macros are used. That might be of interest if you already knew which macros were involved in generating the text you're looking at, but that's what you're trying to find out.

    A better initial approach to that problem could be an m4 version of print-statement debugging. Bear in mind that configure is generated from configure.ac by expanding macros appearing in the latter. Anything in configure.ac that is not a macro or an m4 directive is carried through to configure as literal text. Thus, you can put characteristic literal commands in configure.ac that you will recognize in the generated configure. You could consider echo or printf commands with characteristic arguments, such that you could get information from them not only by examining the configure script, but also by running it.

    For example:

    AC_INIT([jmodelica.org], [0.0.0])
    echo Foad1
    AM_INIT_AUTOMAKE()
    echo Foad2
    ...
    

    You may be able to do similar by tracking details already present in configure.ac to configure, but that probably will not give you the granularity you want.

    You do need to be aware that autoconf makes use of m4 facilities that allow it to perform a certain amount of reordering, but I don't think that will interfere too much.