summaryrefslogtreecommitdiff
path: root/t/verbatim.sh
blob: b41c0881168d1c6e9da19199c84d4121507da4df (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#! /bin/sh
# Copyright (C) 2012-2015 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/>.

# A line starting with '!' used in our internal .am fragments is
# passed verbatim to the output Makefile, and in the right place
# too.  Yes, this test is hacky ... as is the behaviour it tests
# after all ;-)

. test-init.sh

echo AC_OUTPUT >> configure.ac

long1=long
long2="$long1 $long1"
long4="$long2 $long2"
long8="$long4 $long4"
long16="$long8 $long8"
long32="$long16 $long16"
long64="$long32 $long32"
long128="$long64 $long64"
long256="$long128 $long128"
long512="$long256 $long265"

# Sanity check.
case $long512 in
  *' long long '*) ;;
  *) fatal_ 'defining $long512' ;;
esac

mkdir am
cp "$am_amdir"/*.am ./am
cp "$am_amdir"/*.mk ./am

echo pkgdata_DATA = configure.ac > Makefile.am

# The '.am' file are read-only when this test is run under
# "make distcheck", so we need to unlink any of them we want
# to overwrite.
rm -f am/data.am
cat > am/data.am << 'END'
include 0.am
include 1.am
include 2.am
include 3.am
END

echo "!x = $long256" > am/0.am

cat >> am/1.am << 'END'
!## unmodified
!xyz = \
rule:
	@echo Go Custom Rule
!!unmodified!
.PHONY: test-xyz
test-xyz:
	test '$(xyz)' = '!unmodified!'
END

cat > am/2.am << 'END'
!badrule1: ; @echo "'$@' unexpectedly won over 'all'!"; exit 1
!badrule2:
!	@echo "'$@' unexpectedly won over 'all'!"; exit 1
all-local: verbatim-rule
	test -f $<.ok
!verbatim-rule:
!ifeq (ok,ok)
!	@echo $@ run correctly
!	: > $@.ok
!else
!	echo $@ failure; exit 1
!endif
# We want this deliberately after verbatim-rule.
x = ok
END

cat > am/3.am << 'END'
x1 := 1
x2 := 2

foo = .

!ifndef FOO
!foo += $(x1)
!else
!foo += $(x2)
!endif

!ifeq ($(BAR),1)
!bar = aaa
!else
!ifeq "$(BAR)" "2"
!bar = lol
!else
!bar = default
!endif # this comment should be comment ignored
!endif

check-var:
	test '$($(var))' = '$(val)'
END

# Avoid interferences from the environment.
FOO= BAR=; unset FOO BAR

$ACLOCAL
$AUTOMAKE --libdir=.

grep '^!' Makefile.in | grep -v '^!unmodified!$' && exit 1

# Use perl, to avoid possible issues with regex length in vendor greps.
$PERL -e "
  while (<>) { exit (0) if (/^x = $long256$/); }
  exit (1);
" Makefile.in

grep '^!unmodified!$' Makefile.in
test $(grep -c '^!unmodified!$' Makefile.in) -eq 1
grep '^## unmodified$' Makefile.in
grep '^xyz = \\$' Makefile.in

$EGREP 'foo|bar' Makefile.in # For debugging.
test $(grep -c '^foo +=' Makefile.in) -eq 2
test $(grep -c '^bar ='  Makefile.in) -eq 3

$AUTOCONF
./configure

# The created makefile is not broken.
$MAKE -n

$MAKE rule
test ! -f verbatim-rule.ok
$MAKE
test -f verbatim-rule.ok
$MAKE | grep 'Custom Rule' && exit 1
$MAKE test-xyz

$MAKE check-var var=foo val='. 1'
$MAKE check-var var=foo val='. 1' FOO=''
$MAKE check-var var=foo val='. 2' FOO=yes
$MAKE check-var var=foo val='. 2' FOO=' who cares!'

$MAKE check-var var=bar val=default
$MAKE check-var var=bar val=aaa     BAR=1
$MAKE check-var var=bar val=lol     BAR=2
$MAKE check-var var=bar val=default BAR=3

: