Subject: bug#10231: libtool.m4 makes the wrong shell (dash) run libtool

From: Hallvard B Furuseth <[email-masked]>
Date: Tue, 06 Dec 2011 12:59:52 +0100

This is an old bug by now, but the reports I've seen do not seem to
get at all of it.

libtool.m4:LT_INIT says LIBTOOL='$(SHELL) $(top_builddir)/libtool'.
Gnu Make exports SHELL=/bin/sh.  Maybe other Makes too, I do not know.

Thus even when a package is configured and built with the same $SHELL,
the libtool script can get run by another shell than it was built for.
This breaks when libtool is built as a bash script using '+=', but
$(SHELL) does not support '+='.  In my case: Ubuntu's /bin/sh = dash.

Either the LIBTOOL= line should lose $(SHELL) so the #!<shell> line in
the libtool script takes effect, or it should use e.g. $(LT_SHELL)
which would be set to the shell which libtool was built for, or
libtool should exec itself with its desired shell.  Users should not
have to set CONFIG_SHELL=/bin/sh.

This applies to at least libtoolize 2.4.2 and Ubuntu's patched 2.4.
I'm using aclocal 1.11.1, autoconf 2.68.

Here is a minimized example:

mkdir foo foo/m4
cd    foo
echo 'int main() {return 0;}'	> foo.c

cat <<'EOF'			> Makefile.in
top_builddir = @top_builddir@
foo.o:; @LIBTOOL@ --mode=compile @CC@ -c foo.c
EOF

cat <<'EOF'			> configure.ac
AC_INIT([foo])
AC_CONFIG_AUX_DIR([m4])
AC_CONFIG_MACRO_DIR([m4])
AC_PROG_CC
LT_INIT([disable-shared])
AC_CONFIG_FILES([Makefile])
AC_OUTPUT
EOF

libtoolize --copy --install --quiet; aclocal -I m4; autoconf
./configure --quiet
cat Makefile; echo "libtool head == `head -1 libtool`"
make

Output:

top_builddir = .
foo.o:; $(SHELL) $(top_builddir)/libtool --mode=compile gcc -c foo.c
libtool head == #! /bin/bash
/bin/sh ./libtool --mode=compile gcc -c foo.c
eval: 1: base_compile+= gcc: not found
eval: 1: base_compile+= -c: not found
libtool: compile: you must specify a compilation command
libtool: compile: Try `libtool --help --mode=compile' for more information.
make: *** [foo.o] Error 1

Any advise as to what to do (other than staying with libtool 1.5)?
For now I use the simplest fix, removing $(SHELL).  Or should
Makefile.in be using something else than @LIBTOOL@?