Discussion:
backslashes in variable definition
Volker Boerchers
2004-06-21 14:38:23 UTC
Permalink
Hi,

the _SOURCES values of our Makefile.am's are split into multiple lines
to improve readability like this

libfoo_la_SOURCES = \
foo.c \
bar.c

However if one forgets a backslash the source files after that are
silently ignored by automake.

libfoo_la_SOURCES = \
foo.c # missing '\'
bar.c

These errors are hard to detect, at least for libraries since missing
dependencies are detected later.

The output of the attached example is (using automake 1.5 or 1.7.6):

$ ./autogen.sh
automake: configure.in: installing `./install-sh'
automake: configure.in: installing `./mkinstalldirs'
automake: configure.in: installing `./missing'
automake: Makefile.am: installing `./COPYING'
automake: configure.in: installing `./depcomp'

$ ./configure
[omitted]

$ make
make all-am
make[1]: Entering directory `/home/vboerchers/hello'
source='hello.c' object='hello.o' libtool=no \
depfile='.deps/hello.Po' tmpdepfile='.deps/hello.TPo' \
depmode=gcc /bin/sh ./depcomp \
gcc -DHAVE_CONFIG_H -I. -I. -I. -g -O2 -c `test -f hello.c || echo './'`hello.c
gcc -g -O2 -o hello hello.o
hello.o: In function `main':
/home/vboerchers/hello/hello.c:2: undefined reference to `f'
collect2: ld returned 1 exit status
make[1]: *** [hello] Error 1
make[1]: Leaving directory `/home/vboerchers/hello'
make: *** [all] Error 2

$ make clean
test -z "hello" || rm -f hello
rm -f ChangeLog AUTHORS INSTALL Makefile.in Makefile NEWS README
rm -f aclocal.m4 config.h* depcomp install-sh missing mkinstalldirs
rm -f stamp* COPYING configure config.*
bar.c
make: execvp: bar.c: Permission denied
make: *** [clean-local] Error 127

Please note that the 'bar.c' is attached to the 'clean-local'-target
that is placed *before* the erroneous variable definition.

Would it be possible for automake to detect such errors, and to give a
warning like in case of trailing backslashes at the end of a variable
definition?

Volker
--
Volker Börchers
TECON Systems AG
Andrew Suffield
2004-06-21 19:48:36 UTC
Permalink
Post by Volker Boerchers
the _SOURCES values of our Makefile.am's are split into multiple lines
to improve readability like this
libfoo_la_SOURCES = \
foo.c \
bar.c
However if one forgets a backslash the source files after that are
silently ignored by automake.
libfoo_la_SOURCES = \
foo.c # missing '\'
bar.c
These errors are hard to detect, at least for libraries since missing
dependencies are detected later.
You should see the error you get if you do this:

libfoo_la_SOURCES = \
# foo.c \
bar.c
--
.''`. ** Debian GNU/Linux ** | Andrew Suffield
: :' : http://www.debian.org/ |
`. `' |
`- -><- |
Volker Boerchers
2004-06-22 10:35:06 UTC
Permalink
Hi Andrew,
Post by Volker Boerchers
the _SOURCES values of our Makefile.am's are split into multiple lines
to improve readability like this
=20
libfoo_la_SOURCES =3D \
=09foo.c \
=09bar.c
=20
However if one forgets a backslash the source files after that are
silently ignored by automake.
=20
libfoo_la_SOURCES =3D \
foo.c # missing '\'=20
bar.c
=20
These errors are hard to detect, at least for libraries since missing
dependencies are detected later.
=20
=20
libfoo_la_SOURCES =3D \
# foo.c \
bar.c
hmm, perhaps my mail was capable of being misunderstood. The example
that was attached to my previous mail was

hello_SOURCES =3D \
=09 hello.c
=09 bar.c

The error appears not until link time, when the bar.o object is
missing (automake 1.5 and 1.7.6). Your example=20

hello_SOURCES =3D \
#=09 hello.c \
=09 bar.c

is detected as erroneous by automake 1.5

$ automake || echo error with automake
Makefile.am:9: comment following trailing backslash
error with automake
$ automake --version | grep automake
automake (GNU automake) 1.5

but not by automake 1.7.6:

$ automake || echo error in automake
$ automake --version | grep automake
automake (GNU automake) 1.7.6

BTW there is another interesting case that I have mentioned in my
previous mail

hello_SOURCES =3D \
=09 hello.c \
=09 bar.c \

automake 1.5 detects that as long as there is a full line after the
last backslash:

$ automake || echo error with automake
Makefile.am:11: blank line following trailing backslash
error with automake

automake 1.7.6 even detects it on the last line:

$ automake || echo error in automake
Makefile.am: trailing backslash on last line
error in automake

It would be nice if automake would generate an error in all these
cases.

Volker
--=20
Volker B=F6rchers
TECON Systems AG

Loading...