0

Can m4 macro do redirection output to the variable with shell $(...)? Variable $MANPAGE_DOCBOOK_XSL is empty :(.

if test "x${XMLCATALOG}" != "x" -a "x$have_xmlcatalog_file" = "xyes"; then
    DOCBOOK_XSL_URI="http://docbook.sourceforge.net/release/xsl/current"
    DOCBOOK_XSL_PATH="manpages/docbook.xsl"
    MANPAGE_DOCBOOK_XSL=$(${XMLCATALOG} ${XML_CATALOG_FILE} ${DOCBOOK_XSL_URI}/${DOCBOOK_XSL_PATH} | sed -n 's|^file:/\+|/|p;q')
fi

https://github.com/pevik/ima-evm-utils/blob/master/m4/manpage-docbook-xsl.m4#L22

Looking at similar code in Wayland, they just check whether command works (whether catalog can be found), but not for the value.

https://github.com/wayland-project/wayland/blob/master/configure.ac#L167

pevik
  • 4,523
  • 3
  • 33
  • 44
  • Which is the m4 macro? Everything you've presented looks like straight-up shell code. – John Bollinger Aug 12 '20 at 03:31
  • Look at the link: https://github.com/pevik/ima-evm-utils/blob/master/m4/manpage-docbook-xsl.m4#L22. That's the question: is that m4 macro correct? I thought it's possible to use shell in m4 macros. – pevik Aug 12 '20 at 14:58
  • I don't understand what your concern is. `m4` is a macro language. It's not too simplistic to say that it converts input to output by expanding the macros it finds within. `m4` doesn't care about the significance to other software or systems of its output. – John Bollinger Aug 12 '20 at 15:05
  • Are you having some kind of difficulty with the code in question? – John Bollinger Aug 12 '20 at 15:06
  • Look at https://github.com/pevik/ima-evm-utils/blob/travis/docker.debug/m4/manpage-docbook-xsl.m4#L24 (I can put it into the question, if needed). Running `echo "running (stdout only): ${XMLCATALOG} ${XML_CATALOG_FILE} ${DOCBOOK_XSL_URI}/${DOCBOOK_XSL_PATH}"` prints URI. But when I `echo $MANPAGE_DOCBOOK_XSL`, it's empty output. Thus assertion does not work. What am I missing? – pevik Aug 12 '20 at 19:07
  • We really need a [mre]. The context in which `$MANPAGE_DOCBOOK_XSL` is expanded is important. If the above fragment is the only one related to how that variable gets a value, then my first guesses would be that it is never executed or that *when that code is executed*, `$XMLCATALOG` is unset or null or the value of `$have_xmlcatalog_file` is not `yes`. – John Bollinger Aug 12 '20 at 19:20
  • 1
    In any event, with respect to the lead question, m4 macros do not execute command substitutions, but that's irrelevant. m4 can certainly emit shell scripts, and that's how m4 is used by Autoconf. Those can absolutely perform command substitutions. You can examine the generated `configure` script in an editor to confirm that that code fragment came through unmangled, and more generally to troubleshoot some kinds of Autoconf problems. – John Bollinger Aug 12 '20 at 19:25

1 Answers1

0

In the end I found it was wrong sed part (nothing magic in m4 itself). I sent a patch which fixes the software:

https://patchwork.kernel.org/patch/11712861/

-       MANPAGE_DOCBOOK_XSL=$(${XMLCATALOG} ... | sed -n 's|^file:/\+|/|p;q')
+       MANPAGE_DOCBOOK_XSL=$(${XMLCATALOG} ... | sed 's|^file:/\+|/|')

I guess I should delete this question as invalid.

pevik
  • 4,523
  • 3
  • 33
  • 44