tests: expose automake bug#14560
[platform/upstream/automake.git] / t / subst-no-trailing-empty-line.sh
1 #! /bin/sh
2 # Copyright (C) 2003-2013 Free Software Foundation, Inc.
3 #
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2, or (at your option)
7 # any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
17 # If the last line of a automake-rewritten definition is made only of
18 # @substitutions@, automake should take care of appending an empty
19 # variable to make sure that line cannot end up substituted as a blank
20 # line (that would confuse HP-UX Make).
21 # These checks have been introduced in commit 'Release-1-9-254-g9d0eaef'
22 # into the former test 'subst2.test'.
23
24 . test-init.sh
25
26 # These are deliberately quite long, so that the xxx_PROGRAMS definition
27 # in Makefile.am below will be split on multiple lines, with the last
28 # line containing only @substituted@ stuff that expands to empty (this is
29 # required to expose the bug we are testing).
30 v1=ABCDEFGHIJKLMNOPQRSTUVWX
31 v2=ABCDEFGHIJKLMNOPQRSTUVWXY
32 v3=ABCDEFGHIJKLMNOPQRSTUVWXYZ
33
34 # Literal backslash for use by grep.
35 bs='\\'
36
37 cat >> configure.ac <<END
38 AC_SUBST([A], [''])
39 AC_SUBST([$v1], [''])
40 AC_SUBST([$v2], [''])
41 AC_SUBST([$v3], [''])
42 AC_OUTPUT
43 END
44
45 cat >Makefile.am <<END
46 AUTOMAKE_OPTIONS = no-dependencies
47 CC = false
48 EXEEXT =
49
50 ## The "x" and "zardoz" strings and the use of '+=' are there to ensure
51 ## that these variables get rewritten by Automake.
52 noinst_PROGRAMS = x @$v1@ @$v2@ @$v3@
53 bin_PROGRAMS = @A@
54 bin_PROGRAMS += @$v1@ @$v2@ @$v3@
55 check_PROGRAMS = zardoz \$(noinst_PROGRAMS)
56
57 ## Required whenever there are @substituted@ values in the
58 ## PROGRAMS primary, otherwise automake will complain.
59 EXTRA_PROGRAMS =
60
61 print-programs:
62         @echo BEG1: \$(noinst_PROGRAMS) :END1
63         @echo BEG2: \$(bin_PROGRAMS) :END2
64         @echo BEG3: \$(check_PROGRAMS) :END3
65 END
66
67 $ACLOCAL
68 $AUTOCONF
69 $AUTOMAKE
70 # For debugging.
71 $EGREP -n 'ABCD|am__empty' Makefile.in
72 # Sanity check.
73 test $($EGREP -c "^[ $tab]*@$v2@ @$v3@[ $tab]*$bs?$" Makefile.in) -eq 3
74
75 ./configure
76 {
77   sed -n '/^noinst_PROGRAMS *=/,/[^\\]$/p' Makefile
78   sed -n '/^bin_PROGRAMS *=/,/[^\\]$/p' Makefile
79   sed -n '/^check_PROGRAMS *=/,/[^\\]$/p' Makefile
80   sed -n '/^am__EXEEXT.*=/,/[^\\]$/p' Makefile
81 } >t-programs
82 cat t-programs
83 grep '^ *$' t-programs && exit 1
84
85 run_make -O print-programs
86 grep '^BEG1: x :END1$' stdout
87 grep '^BEG2: :END2$' stdout
88 grep '^BEG3: zardoz x :END3$' stdout
89
90 run_make -O am__empty=X print-programs
91 grep '^BEG1: x X :END1$' stdout
92 grep '^BEG2: X :END2$' stdout
93 grep '^BEG3: zardoz x X :END3$' stdout
94
95 :