Re: Empty else part in AS_IF
On 10/09/13 21:31, Eric Blake wrote: On 10/09/2013 01:18 PM, Julien LIE wrote: The following piece of code: AS_IF([test x$var != xfalse], [$test=1], [m4_ifdef([AM_CONDITIONAL], [AM_CONDITIONAL([TEST], [false])])]) gives the following configure code with autoconf 2.69: if test x$var != xfalse; then : $test=1 That's unusual shell syntax (it does NOT do a variable assignment; did you mean 'test=1' instead of trying to execute the program whose name is the expansion of $test concatenated with '=1'?) else fi which is not a valid syntax. Indeed. The problem is that autoconf cannot tell if a non-empty literal will expand to empty text (m4_ifdef results in no output). You'll have to workaround it yourself: AS_IF([test x$var != xfalse], [$test=1], [: m4_ifdef(...)]) Is it the expected behaviour of AS_IF when the else part is empty? Yes, it's expected that autoconf can't predict which macros expand to nothing. It's a dark corner case, where it costs far more m4 time to try and work around it (and probably get things wrong in the process) than it does to just say don't do that. The better(TM) approach is to let m4 figure out that the else part is empty by not quoting the m4_ifdef, thereby deferring its evaluation. AS_IF([test x$var != xfalse], [$test=1], m4_ifdef([AM_CONDITIONAL], [AM_CONDITIONAL([TEST], [false])])) Should give the expected result. I haven't investigated if an additional level of quoting around [AM_CONDITIONAL([TEST], [false])], i.e. using [[AM_CONDITIONAL([TEST], [false])]] instead would improve matters in case of more complicated content. Regards, Thomas -- Thomas Jahns DKRZ GmbH, Department: Application software Deutsches Klimarechenzentrum Bundesstrae 45a D-20146 Hamburg Phone: +49-40-460094-151 Fax: +49-40-460094-270 Email: Thomas Jahns ja...@dkrz.de smime.p7s Description: S/MIME Cryptographic Signature ___ Autoconf mailing list Autoconf@gnu.org https://lists.gnu.org/mailman/listinfo/autoconf
Re: Empty else part in AS_IF
On 10/10/2013 06:32 AM, Thomas Jahns wrote: Yes, it's expected that autoconf can't predict which macros expand to nothing. It's a dark corner case, where it costs far more m4 time to try and work around it (and probably get things wrong in the process) than it does to just say don't do that. The better(TM) approach is to let m4 figure out that the else part is empty by not quoting the m4_ifdef, thereby deferring its evaluation. AS_IF([test x$var != xfalse], [$test=1], m4_ifdef([AM_CONDITIONAL], [AM_CONDITIONAL([TEST], [false])])) Should give the expected result. Almost. If AM_CONDITIONAL is defined, this expands to: AS_IF([test x$var != xfalse], [$test=1], AM_CONDITIONAL([TEST], [false])) which means the body of AM_CONDITIONAL is expanded before calling AS_IF, and that might not always work. I haven't investigated if an additional level of quoting around [AM_CONDITIONAL([TEST], [false])], i.e. using [[AM_CONDITIONAL([TEST], [false])]] instead would improve matters in case of more complicated content. Yes, you would be safer with: AS_IF([test x$var != xfalse], [$test=1], m4_ifdef([AM_CONDITIONAL], [[AM_CONDITIONAL([TEST], [false])]])) which results in either: AS_IF([test x$var != xfalse], [$test=1], [AM_CONDITIONAL([TEST], [false])]) or AS_IF([test x$var != xfalse], [$test=1], ) (ie. you DO want to double quote the 2nd argument of m4_ifdef so that the net result is still a quoted 3rd argument to AS_IF). Another solution is to ensure that AM_CONDITIONAL is always defined (where its definition is a no-op if using an old automake that did not already define it): m4_define_default([AM_CONDITIONAL]) AS_IF([test x$var != xfalse], [$test=1], [AM_CONDITIONAL([TEST], [false])]) Finally, a question: what version of automake are you targetting? These days, RHEL 5 is about as old as I will personally go for a development target; but RHEL 5 includes automake 1.9.x, which defines AM_CONDITIONAL. Furthermore, unless you have taken efforts to patch your old automake, any stock upstream automake older than 1.12.2 will inject code into YOUR package that causes 'make distcheck' to have a CVE (ie. automake's CVE-2012-3386 and CVE-2009-4029 are viral - if your automake still suffers from one or both of those flaws, then every package built with that automake also suffers from the flaw). If you are worried about developing your code on a machine that has an automake older than 1.9, or even with automake 1.9 but where the vendor has not patched the CVEs yet, you are catering to museumware, and it may be simpler to just update your code to remove the cruft of trying to support something that ancient. -- Eric Blake eblake redhat com+1-919-301-3266 Libvirt virtualization library http://libvirt.org signature.asc Description: OpenPGP digital signature ___ Autoconf mailing list Autoconf@gnu.org https://lists.gnu.org/mailman/listinfo/autoconf
Re: Empty else part in AS_IF
Hi Eric Finally, a question: what version of automake are you targetting? In fact, I am not targetting any version of automake. INN embeds a few m4 files provided by the rra-c-util package: http://www.eyrie.org/~eagle/software/rra-c-util/ INN's building system only uses Autoconf; it does not use Automake. INN already has its legacy Makefiles (maintained by hand). rra-c-util contains Automake macros, so importing for instance krb5.m4 from rra-c-util into INN would break the build because of an undefined AM_CONDITIONAL macro. That is why rra-c-util adds m4_ifdef([AM_CONDITIONAL], ...) in upstream so that other programs, that do not use Automake, can directly embed m4 rra-c-util files without requiring Automake. -- Julien ÉLIE « Et cette même nuit, c'est-à-dire trois semaines plus tard… » (Astérix) ___ Autoconf mailing list Autoconf@gnu.org https://lists.gnu.org/mailman/listinfo/autoconf
Re: Empty else part in AS_IF
Eric Blake ebl...@redhat.com writes: Another solution is to ensure that AM_CONDITIONAL is always defined (where its definition is a no-op if using an old automake that did not already define it): m4_define_default([AM_CONDITIONAL]) AS_IF([test x$var != xfalse], [$test=1], [AM_CONDITIONAL([TEST], [false])]) This would reintroduce the same problem, though, wouldn't it? AM_CONDITIONAL would expand to nothing, and then the else branch of AS_IF would be empty. Or does this give AS_IF enough information to figure that out because it avoids using the lower-level m4_* function? -- Russ Allbery (r...@stanford.edu) http://www.eyrie.org/~eagle/ ___ Autoconf mailing list Autoconf@gnu.org https://lists.gnu.org/mailman/listinfo/autoconf
Re: Empty else part in AS_IF
Eric Blake ebl...@redhat.com writes: Indeed. The problem is that autoconf cannot tell if a non-empty literal will expand to empty text (m4_ifdef results in no output). You'll have to workaround it yourself: AS_IF([test x$var != xfalse], [$test=1], [: m4_ifdef(...)]) But if the contents of m4_ifdef expand into shell code, doesn't this prepend : to the first line of that shell code, effectively commenting it out? It seems cleaner to use [:] in the else branch of m4_ifdef for that reason. -- Russ Allbery (r...@stanford.edu) http://www.eyrie.org/~eagle/ ___ Autoconf mailing list Autoconf@gnu.org https://lists.gnu.org/mailman/listinfo/autoconf
Re: Empty else part in AS_IF
On 10/10/2013 04:41 PM, Russ Allbery wrote: Eric Blake ebl...@redhat.com writes: Another solution is to ensure that AM_CONDITIONAL is always defined (where its definition is a no-op if using an old automake that did not already define it): m4_define_default([AM_CONDITIONAL]) AS_IF([test x$var != xfalse], [$test=1], [AM_CONDITIONAL([TEST], [false])]) This would reintroduce the same problem, though, wouldn't it? AM_CONDITIONAL would expand to nothing, and then the else branch of AS_IF would be empty. Or does this give AS_IF enough information to figure that out because it avoids using the lower-level m4_* function? If that's the case, then write AM_CONDITIONAL so that it always produces a shell statement: m4_define_default([AM_CONDITIONAL], [:]) -- Eric Blake eblake redhat com+1-919-301-3266 Libvirt virtualization library http://libvirt.org signature.asc Description: OpenPGP digital signature ___ Autoconf mailing list Autoconf@gnu.org https://lists.gnu.org/mailman/listinfo/autoconf
Re: Empty else part in AS_IF
Eric Blake ebl...@redhat.com writes: If that's the case, then write AM_CONDITIONAL so that it always produces a shell statement: m4_define_default([AM_CONDITIONAL], [:]) Oh, good idea. Yes, that's even cleaner. -- Russ Allbery (r...@stanford.edu) http://www.eyrie.org/~eagle/ ___ Autoconf mailing list Autoconf@gnu.org https://lists.gnu.org/mailman/listinfo/autoconf