[Top][All Lists]

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

a debugging trick: how to peek into m4's processing

From: Bruno Haible
Subject: a debugging trick: how to peek into m4's processing
Date: Sat, 23 May 2009 14:35:45 +0200
User-agent: KMail/1.9.9

Hi Eric, Ralf,

For about 15 years, writing and debugging autoconf macros has been very hard
for me. I've come to partially understand how m4 internally works, thanks to
Eric's new documentation in the m4 manual, and due to the ability of "seeing"
what m4 does when I call it directly, on the command line.

But inside autoconf, it's more complicated, because when I call 'aclocal'
or 'autoconf', additional processing is done outside m4, which obstructs
the view on what happens inside m4.

  - Before AC_INIT, I don't get any output at all.

  - Trying to inspect the definition of a macro, through e.g.
    leads to tons of errors error: possibly undefined macro: AC_PREREQ error: possibly undefined macro: AC_INIT error: possibly undefined macro: AM_INIT_AUTOMAKE error: possibly undefined macro: AC_PROG_CC error: possibly undefined macro: AC_PROG_INSTALL error: possibly undefined macro: AC_SUBST error: possibly undefined macro: AM_CONDITIONAL
      configure:2533: error: possibly undefined macro: _m4_defun_pro
    and produces no configure file that I could look at.

I figure that what I need is a most basic and robust 'println' device.

  - autoconf has a --trace option but no example how to use it.
    Actually what I want is to see some particular expansions, not
    the arguments and results of macro calls.

  - The output of m4_syscmd does not appear on standard output.

  - m4 has no primitives for creating external files.

Here comes the trick: If, say, I want to see the definition of AM_INIT_AUTOMAKE
at a particular point, I do:

m4_syscmd([cat 1>&2 <<\EOT

Here comes the definition of AM_INIT_AUTOMAKE:]

  - Offers an unobstructed view to the m4 state.
  - Any m4 expression, any number of m4 expressions can be printed.
  - The results appear on the screen immediately. No need to open a file
    to view them.

Could something like this be documented in the autoconf manual?

Or, alternatively, document how to use --trace for the same purpose?


PS: The concrete problem for which I needed this, is to find out where to
use [...], m4_quote, m4_dquote in an expression with m4_bpatsubst and
m4_defn. It is fine if Eric the wizard can explain to me which of the 10
possibilities is the right one. But it's even better if the autoconf manual
would give me the tools to find out about it myself.

m4_syscmd([cat 1>&2 <<\EOT

[Here comes the definition of _AC_INIT_PACKAGE 1:]

m4_bpatsubst(m4_defn([_AC_INIT_PACKAGE]), [AC_PACKAGE_NAME], [gl_INIT_DUMMY])

[Here comes the definition of _AC_INIT_PACKAGE 2:]

m4_bpatsubst(m4_quote(m4_defn([_AC_INIT_PACKAGE])), [AC_PACKAGE_NAME], 

[Here comes the definition of _AC_INIT_PACKAGE 3:]

m4_bpatsubst(m4_quote([m4_defn([_AC_INIT_PACKAGE])]), [AC_PACKAGE_NAME], 

[Here comes the definition of _AC_INIT_PACKAGE 4:]

m4_bpatsubst(m4_dquote(m4_defn([_AC_INIT_PACKAGE])), [AC_PACKAGE_NAME], 

[Here comes the definition of _AC_INIT_PACKAGE 5:]

m4_bpatsubst(m4_dquote([m4_defn([_AC_INIT_PACKAGE])]), [AC_PACKAGE_NAME], 

[Here comes the definition of _AC_INIT_PACKAGE 6:]

m4_bpatsubst([m4_defn([_AC_INIT_PACKAGE])], [AC_PACKAGE_NAME], [gl_INIT_DUMMY])

[Here comes the definition of _AC_INIT_PACKAGE 7:]

m4_bpatsubst([m4_quote(m4_defn([_AC_INIT_PACKAGE]))], [AC_PACKAGE_NAME], 

[Here comes the definition of _AC_INIT_PACKAGE 8:]

m4_bpatsubst([m4_quote([m4_defn([_AC_INIT_PACKAGE])])], [AC_PACKAGE_NAME], 

[Here comes the definition of _AC_INIT_PACKAGE 9:]

m4_bpatsubst([m4_dquote(m4_defn([_AC_INIT_PACKAGE]))], [AC_PACKAGE_NAME], 

[Here comes the definition of _AC_INIT_PACKAGE 10:]

m4_bpatsubst([m4_dquote([m4_defn([_AC_INIT_PACKAGE])])], [AC_PACKAGE_NAME], 


reply via email to

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