Re: AS_ECHO and printf

Paul Eggert <[email protected]>
Newsgroups gmane.comp.sysutils.autoconf.general
Organization UCLA Computer Science Department
Message-ID <[email protected]>
On 2023-05-22 02:35, Po Lu wrote:
> printf is not portable; it is missing, both as a built-in to
> ksh and a command, on Ultrix 4.5, as well as (AFAIK) Solaris 2.6, the
> first of which is important for historical purposes, and the second of
> which is still found in the wild in some fields.

In Autoconf and Gnulib the general rule is to draw the line at systems 
that are no longer supported by their suppliers. This applies to both 
Solaris 2.6 (end of life 2006, back when Sun was still independent) and 
Ultrix 4.5 (so poorly supported that I can't easily find out when end of 
life was, but I think around 2000). If it's easy to support these 
obsolete systems without significantly hurting current systems or 
complicating maintenance that's OK (though a volunteer needs to step 
up); otherwise, it's not worth the trouble.

That being said, Autoconf-generated 'configure' scripts should still 
work on these obsolete systems, as Autoconf automatically re-execs 
'configure' with one of the more POSIX-compatible shells that are 
shipped with these systems. With Solaris, the shells used are bash, ksh, 
or /usr/xpg4/bin/sh; with Ultrix, sh5 is used. If your installation has 
omitted these shells I suggest that you simply install them. Otherwise, 
if your POSIX-compatible shell has some other name you should be able to 
configure with a command like this:

CONFIG_SHELL=/my/sh ./configure CONFIG_SHELL=/my/sh

as documented in the Autoconf manual. When this issue came up in the 
past (and this was a while ago), these workarounds were sufficient to 
get builds working.


On 2023-05-22 07:57, Zack Weinberg wrote:

> I would be willing to consider a patch that adds to _AS_DETECT_BETTER_SHELL
> a check for support for `printf '%s' "$message"` and `printf '%s\n'
> "$message"` (those two constructs specifically), and/or a patch that
> partially restores _AS_ECHO_PREPARE such that it attempts to fall back
> to `echo [-n]` on systems where the above two constructs don't work.

I looked into the former idea and doubt whether it'd be worth the 
trouble. Although we could add something like this to m4sh.m4 ...

   # Printing a long string crashes Solaris 7 /usr/bin/printf.
   m4_define([_AS_SHELL_PRINTF_WORKS],
 
[[bs='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'
   bs=$bs$bs
   bs=$bs$bs$bs
   bs=$bs$bs$bs$bs$bs
   test "X`(printf '%s\n' $bs) 2>/dev/null`" = "X$bs"]])
   ...
   _AS_DETECT_REQUIRED([_AS_SHELL_PRINTF_WORKS])

... this would slow down every execution of 'configure' (a fork would be 
required) merely to work around bugs in obsolete shells. And these 
obsolete shells are already caught and eliminated by the other 
_AS_DETECT_REQUIRED calls. So I imagine that doing this wouldn't help in 
practice, and so would slow down 'configure' unnecessarily.

The latter idea (i.e., partially restoring _AS_ECHO_PREPARE) has the 
same problem, plus it'd require even more hacking and testing.

If there's a better way to do things that would not hurt 'configure' 
scripts on typical hosts while still porting to obsolete ones, then we 
could accept such a patch. Someone would have to write and test it on 
these older platforms though.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.