1#! /bin/sh
2# Copyright (C) 2013-2021 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 <https://www.gnu.org/licenses/>.
16
17# Basic tests for '%...%' preprocessing in included Makefile fragments:
18#   %reldir%        a.k.a.  %D%
19#   %canon_reldir%  a.k.a.  %C%
20
21. test-init.sh
22
23cat >> configure.ac << 'END'
24AC_CONFIG_FILES([zot/Makefile])
25AC_OUTPUT
26END
27
28mkdir foo foo/bar foo/foobar zot
29
30cat > Makefile.am << 'END'
31include $(top_srcdir)/foo/local.mk
32include $(srcdir)/foo/foobar/local.mk
33include local.mk
34END
35
36cat > zot/Makefile.am << 'END'
37include $(top_srcdir)/zot/local.mk
38
39## Check that '%canon_reldir%' doesn't remain overridden
40## by the previous include.
41%canon_reldir%_zot_whoami:
42	echo "I am %reldir%/Makefile.am" >$@
43
44include $(top_srcdir)/top.mk
45include ../reltop.mk
46END
47
48cat > local.mk << 'END'
49%canon_reldir%_whoami:
50	echo "I am %reldir%/local.mk" >$@
51END
52
53cat > top.mk << 'END'
54%canon_reldir%_top_whoami:
55	echo "I am %reldir%/top.mk" >$@
56END
57
58cat > reltop.mk << 'END'
59%C%_reltop_whoami:
60	echo "I am %D%/reltop.mk" >$@
61END
62
63cp local.mk foo
64cp local.mk foo/bar
65cp local.mk foo/foobar
66cp local.mk zot
67
68cat >> foo/local.mk << 'END'
69include %reldir%/bar/local.mk
70## Check that '%canon_reldir%' doesn't remain overridden by the
71## previous include.  The duplicated checks are done to ensure that
72## Automake substitutes all pre-processing occurrences on a line,
73## not just the first one.
74test-%reldir%:
75	test '%reldir%'       = foo  &&  test '%reldir%' = foo
76	test '%D%'            = foo  &&  test '%D%'      = foo
77	test '%canon_reldir%' = foo  &&  test '%C%'      = foo
78END
79
80$ACLOCAL
81$AUTOCONF
82$AUTOMAKE
83./configure
84
85check ()
86{
87  test $# -eq 2 || fatal_ "made_into(): bad usage"
88  target=$1 contents=$2
89  rm -f "$target" \
90   && $MAKE "$target" \
91   && test x"$(cat "$target")" = x"$contents"
92}
93
94check whoami "I am local.mk"
95check foo_whoami "I am foo/local.mk"
96check foo_bar_whoami "I am foo/bar/local.mk"
97check foo_foobar_whoami "I am foo/foobar/local.mk"
98$MAKE test-foo
99
100cd zot
101check whoami "I am local.mk"
102check ___top_whoami "I am ../top.mk"
103check ___reltop_whoami "I am ../reltop.mk"
104check zot_whoami "I am Makefile.am"
105
106:
107