[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Automake-NG] [FYI 3/6] general: assume GNU make semantic in line contin
From: |
Stefano Lattarini |
Subject: |
[Automake-NG] [FYI 3/6] general: assume GNU make semantic in line continuation |
Date: |
Fri, 25 May 2012 02:16:23 +0200 |
The line continuation with a backslash is yet another source of
portability problems for Makefiles.
For example, according to the Autoconf manual, some versions of
make (e.g., HP-UX) read multiple newlines following a backslash,
continuing to the next non-empty line.
Also, according to Posix, make comments start with # and continue
until an unescaped newline is reached; but some BSD make versions
do not follow this requirement.
Finally, some make implementations (like Solaris 10 CCS make)
handle a '\#' sequence at the end of a line like it was a line
continuation:
$ cat Makefile
x = \#
all:; : $(x)
$ /usr/local/bin/gmake
: #
$ /usr/ccs/bin/make -f foo.mk
mksh: Error in reader: Loop detected when expanding macro value `\#
all:; : $(x)'
Current working directory /tmp
Luckily, GNU make is more rational and consistent in its handling
of line continuation, which allows us to drop some Automake time
checks. Not a great simplification, but better than nothing.
* automake.in (read_am_file, file_contents_internal): Don't error
on blank line following trailing backslash, on comment following
trailing backslash, nor on trailing backslash on the last line.
* t/spy-trailing-backslash.sh: New, check that the expected GNU
make semantics actually hold.
* t/backslash-tricks.sh: New test, check that automake truly
supports the uses of backslash it doesn't warn about anymore.
* t/backsl3.sh: Remove as obsolete.
* t/comment5.sh: Likewise.
* t/commen10.sh: Likewise.
* t/commen11.sh: Likewise.
* t/syntax.sh: Likewise.
Signed-off-by: Stefano Lattarini <address@hidden>
---
automake.in | 36 +++++--------------
t/backsl3.sh | 29 ---------------
t/backslash-tricks.sh | 72 +++++++++++++++++++++++++++++++++++++
t/commen10.sh | 32 -----------------
t/commen11.sh | 41 ---------------------
t/comment5.sh | 85 --------------------------------------------
t/spy-trailing-backlash.sh | 72 +++++++++++++++++++++++++++++++++++++
t/syntax.sh | 31 ----------------
8 files changed, 152 insertions(+), 246 deletions(-)
delete mode 100755 t/backsl3.sh
create mode 100755 t/backslash-tricks.sh
delete mode 100755 t/commen10.sh
delete mode 100755 t/commen11.sh
delete mode 100755 t/comment5.sh
create mode 100755 t/spy-trailing-backlash.sh
delete mode 100755 t/syntax.sh
diff --git a/automake.in b/automake.in
index 94253b4..a9d6ef8 100644
--- a/automake.in
+++ b/automake.in
@@ -6116,8 +6116,6 @@ sub read_am_file ($$)
}
elsif (/$WHITE_PATTERN/o)
{
- error $where, "blank line following trailing backslash"
- if $saw_bk;
# Stick a single white line before the incoming macro or rule.
$spacing = "\n";
$blank = 1;
@@ -6182,18 +6180,6 @@ sub read_am_file ($$)
{
# Stick a single white line before the incoming macro or rule.
$spacing = "\n";
- error $where, "blank line following trailing backslash"
- if $saw_bk;
- }
- elsif (/$COMMENT_PATTERN/o)
- {
- error $where, "comment following trailing backslash"
- if $saw_bk && $prev_state != IN_COMMENT;
-
- # Stick comments before the incoming macro or rule.
- $comment .= $spacing . $_;
- $spacing = '';
- $prev_state = IN_COMMENT;
}
elsif ($saw_bk)
{
@@ -6225,6 +6211,13 @@ sub read_am_file ($$)
}
}
+ elsif (/$COMMENT_PATTERN/o)
+ {
+ # Stick comments before the incoming macro or rule.
+ $comment .= $spacing . $_;
+ $spacing = '';
+ $prev_state = IN_COMMENT;
+ }
elsif (/$IF_PATTERN/o)
{
$cond = cond_stack_if ($1, $2, $where);
@@ -6349,9 +6342,6 @@ sub read_am_file ($$)
$output_trailer .= $comment;
- error ($where, "trailing backslash on last line")
- if $saw_bk;
-
error ($where, (@cond_stack ? "unterminated conditionals: @cond_stack"
: "too many conditionals closed in include file"))
if "@saved_cond_stack" ne "@cond_stack";
@@ -6648,17 +6638,7 @@ sub file_contents_internal ($$$%)
# FIXME: no line number available.
$where->set ($file);
- # Sanity checks.
- if (/\\$/)
- {
- error $where, "blank line following trailing backslash:\n$_"
- }
- elsif (/\\#/)
- {
- error $where, "comment following trailing backslash:\n$_"
- }
-
- elsif (/^$/)
+ if (/^$/)
{
$is_rule = 0;
# Stick empty line before the incoming macro or rule.
diff --git a/t/backsl3.sh b/t/backsl3.sh
deleted file mode 100755
index 36fab7f..0000000
--- a/t/backsl3.sh
+++ /dev/null
@@ -1,29 +0,0 @@
-#! /bin/sh
-# Copyright (C) 2003-2012 Free Software Foundation, Inc.
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2, or (at your option)
-# any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-# Make sure we diagnose trailing backslash at the end of a file.
-# Report from Akim Demaile <address@hidden>.
-
-. ./defs || Exit 1
-
-cat > Makefile.am << 'END'
-foo = \
-END
-
-$ACLOCAL
-AUTOMAKE_fails
-cat stderr
-grep 'trailing backslash' stderr
diff --git a/t/backslash-tricks.sh b/t/backslash-tricks.sh
new file mode 100755
index 0000000..d5ef076
--- /dev/null
+++ b/t/backslash-tricks.sh
@@ -0,0 +1,72 @@
+#! /bin/sh
+# Copyright (C) 2012 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+#
+# - Automake should handle trailing backslashes in comments the way GNU
+# make does, i.e., considering the next line as a continuation of the
+# comment.
+#
+# - Automake should allow backslash-escaped '#' characters at the end
+# of a line (in variable definitions as well as well as in recipes),
+# because GNU make allows that.
+#
+# - GNU make handles comments following trailing backslashes gracefully,
+# so Automake should do the same.
+#
+# - Automake should not complain if the Makefile ands with a backslash
+# and newline sequence, because GNU make handles that gracefully.
+#
+
+. ./defs || Exit 1
+
+echo AC_OUTPUT >> configure.ac
+
+# Avoid possible interferences from the environment.
+var1= var2=; unset var1 var2
+
+cat > Makefile.am << 'END'
+# a comment with backslash \
+var1 = foo
+var2 = bar
+
+var3 = \#
+var4 = $(var3)
+
+var5 = ok \
+# ko
+
+.PHONY: test
+test:
+ test -z '$(var1)'
+ test '$(var2)' = bar
+ test '$(var3)' = '#'
+ test '$(var4)' = \#
+ : Use '[', not 'test', here, so that spurious comments
+ : are ensured to cause syntax errors.
+ [ $(var5) = ok ]
+
+# Yes, this file ends with a backslash-newline. So what?
+\
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+$MAKE test
+
+:
diff --git a/t/commen10.sh b/t/commen10.sh
deleted file mode 100755
index d0c246a..0000000
--- a/t/commen10.sh
+++ /dev/null
@@ -1,32 +0,0 @@
-#! /bin/sh
-# Copyright (C) 2005-2012 Free Software Foundation, Inc.
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2, or (at your option)
-# any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-# Make sure comments following trailing backslashes are diagnosed.
-# Report from Harald Dunkel.
-
-. ./defs || Exit 1
-
-cat > Makefile.am << 'END'
-SUBDIRS = foo \
-# bar
-
-END
-
-mkdir foo
-
-$ACLOCAL
-AUTOMAKE_fails
-grep backslash stderr
diff --git a/t/commen11.sh b/t/commen11.sh
deleted file mode 100755
index d4b264a..0000000
--- a/t/commen11.sh
+++ /dev/null
@@ -1,41 +0,0 @@
-#! /bin/sh
-# Copyright (C) 2005-2012 Free Software Foundation, Inc.
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2, or (at your option)
-# any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-# Make sure backslash-newline-hash combinations are diagnosed as
-# comments following a trailing backslash, even when the combination
-# follows a variable assignment that is preceded by a comment.
-
-. ./defs || Exit 1
-
-cat > Makefile.am << 'END'
-# initial comment
-variable = value-before-comment \
-#
-
-# comment
-SUBDIRS = foo \
-# bar
-
-END
-
-mkdir foo
-
-$ACLOCAL
-AUTOMAKE_fails
-grep '^Makefile\.am:3:.*backslash' stderr
-grep '^Makefile\.am:7:.*backslash' stderr
-
-:
diff --git a/t/comment5.sh b/t/comment5.sh
deleted file mode 100755
index 0c2a4d6..0000000
--- a/t/comment5.sh
+++ /dev/null
@@ -1,85 +0,0 @@
-#! /bin/sh
-# Copyright (C) 2002-2012 Free Software Foundation, Inc.
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2, or (at your option)
-# any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-# Test for PR/280.
-# (Automake should complain about trailing backslashes in comments.)
-
-. ./defs || Exit 1
-
-cat >> configure.ac <<'EOF'
-AC_OUTPUT
-EOF
-
-cat > Makefile.am << 'EOF'
-all-local:
- @echo ${var}
-
-# a comment with backslash \
-
-
-var = foo
-EOF
-
-$ACLOCAL
-AUTOMAKE_fails
-grep '^Makefile.am:5: error: blank line following trailing backslash' stderr
-
-
-## Here is a second test because head comments are
-## handled differently in Automake 1.5.
-
-cat > Makefile.am << 'EOF'
-# a comment with backslash \
-
-
-all-local:
- @echo ${var}
-
-var = foo
-EOF
-
-AUTOMAKE_fails
-grep '^Makefile.am:2: error: blank line following trailing backslash' stderr
-
-
-## Make sure we print an 'included' stack on errors.
-
-echo 'include Makefile.inc'> Makefile.am
-cat > Makefile.inc << 'EOF'
-# a comment with backslash \
-
-EOF
-
-AUTOMAKE_fails
-grep '^Makefile.inc:2: error: blank line following trailing backslash' stderr
-grep '^Makefile.am:1: .*included from here' stderr
-grep -v '^Makefile.am:1: .*error:' stderr
-
-
-## Make sure backslashes are still allowed within a comment.
-## This usually happens when commenting out a Makefile rule.
-
-cat > Makefile.am << 'EOF'
-all-local:
- @echo ${var}
-
-# a comment with backslash \
-# but terminated by a line without backslash
-
-var = foo
-EOF
-
-$AUTOMAKE
diff --git a/t/spy-trailing-backlash.sh b/t/spy-trailing-backlash.sh
new file mode 100755
index 0000000..cc5d720
--- /dev/null
+++ b/t/spy-trailing-backlash.sh
@@ -0,0 +1,72 @@
+#! /bin/sh
+# Copyright (C) 2012 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# Check that GNU make line-continuation with backslash-newline has the
+# semantic we expect.
+
+am_create_testdir=empty
+. ./defs || Exit 1
+
+cat > Makefile << 'END'
+default:
+
+hash = \#
+ok: ; true :--$(hash)--:
+
+var1 = \
+rule1:
+
+rule2: \
+; echo ok > sentinel
+
+# The backslash doesn't cause we to continue to read after
+# the fist blank line.
+rule3: \
+
+var2 = ok
+
+# Ditto.
+var3 = a \
+
+b:
+
+# The backslash will cause the next line to be a comment as well \
+$(error comment not continued)
+
+var4 = foo \
+# not seen
+
+.PHONY: test
+test:
+ test $(var1) = rule1:
+ test $(var2) = ok
+ test $(var3) = a
+ test $(var4) = foo
+ test -z '$(var5)'
+
+var5 = \
+END
+
+$MAKE
+$MAKE ok
+$MAKE ok | grep ':--#--:'
+$MAKE rule1 && Exit 1
+$MAKE rule2
+test -f sentinel
+$MAKE rule3
+$MAKE test
+
+:
diff --git a/t/syntax.sh b/t/syntax.sh
deleted file mode 100755
index 5b51a7a..0000000
--- a/t/syntax.sh
+++ /dev/null
@@ -1,31 +0,0 @@
-#! /bin/sh
-# Copyright (C) 1998-2012 Free Software Foundation, Inc.
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2, or (at your option)
-# any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-# Test for error for bad syntax.
-
-. ./defs || Exit 1
-
-cat > Makefile.am << 'END'
-foo = q \
-
-bin_SCRIPTS = foo.sh
-END
-
-$ACLOCAL
-AUTOMAKE_fails -Wnone
-grep '^Makefile\.am:2:.*blank line following trailing backslash' stderr
-
-:
--
1.7.9.5
- [Automake-NG] [FYI 0/6] Some simple fixlets and cleanup patches, Stefano Lattarini, 2012/05/24
- [Automake-NG] [FYI 2/6] fixup: support verbatim lines only in private '.am' fragments, Stefano Lattarini, 2012/05/24
- [Automake-NG] [FYI 1/6] fixup: interaction between verbatim lines and line continuation, Stefano Lattarini, 2012/05/24
- [Automake-NG] [FYI 3/6] general: assume GNU make semantic in line continuation,
Stefano Lattarini <=
- [Automake-NG] [FYI 5/6] tests: don't disable portability warnings when there's no need, Stefano Lattarini, 2012/05/24
- [Automake-NG] [FYI 4/6] general: assume '#' comment in make recipes are ok, Stefano Lattarini, 2012/05/24
- [Automake-NG] [FYI 6/6] am: make function to canonicalize names, Stefano Lattarini, 2012/05/24