doc: typos in test file.
[automake.git] / t / preproc-basics.sh
blob83dccf81906c98c0ff8501caf97e566dacdd420c
1 #! /bin/sh
2 # Copyright (C) 2013-2024 Free Software Foundation, Inc.
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.
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.
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/>.
17 # Basic tests for '%...%' preprocessing in included Makefile fragments:
18 # %reldir% a.k.a. %D%
19 # %canon_reldir% a.k.a. %C%
21 . test-init.sh
23 cat >> configure.ac << 'END'
24 AC_CONFIG_FILES([zot/Makefile])
25 AC_OUTPUT
26 END
28 mkdir foo foo/bar foo/foobar zot
30 cat > Makefile.am << 'END'
31 include $(top_srcdir)/foo/local.mk
32 include $(srcdir)/foo/foobar/local.mk
33 include local.mk
34 END
36 cat > zot/Makefile.am << 'END'
37 include $(top_srcdir)/zot/local.mk
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" >$@
44 include $(top_srcdir)/top.mk
45 include ../reltop.mk
46 END
48 cat > local.mk << 'END'
49 %canon_reldir%_whoami:
50 echo "I am %reldir%/local.mk" >$@
51 END
53 cat > top.mk << 'END'
54 %canon_reldir%_top_whoami:
55 echo "I am %reldir%/top.mk" >$@
56 END
58 cat > reltop.mk << 'END'
59 %C%_reltop_whoami:
60 echo "I am %D%/reltop.mk" >$@
61 END
63 cp local.mk foo
64 cp local.mk foo/bar
65 cp local.mk foo/foobar
66 cp local.mk zot
68 cat >> foo/local.mk << 'END'
69 include %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.
74 test-%reldir%:
75 test '%reldir%' = foo && test '%reldir%' = foo
76 test '%D%' = foo && test '%D%' = foo
77 test '%canon_reldir%' = foo && test '%C%' = foo
78 END
80 $ACLOCAL
81 $AUTOCONF
82 $AUTOMAKE
83 ./configure
85 check ()
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"
94 check whoami "I am local.mk"
95 check foo_whoami "I am foo/local.mk"
96 check foo_bar_whoami "I am foo/bar/local.mk"
97 check foo_foobar_whoami "I am foo/foobar/local.mk"
98 $MAKE test-foo
100 cd zot
101 check whoami "I am local.mk"
102 check ___top_whoami "I am ../top.mk"
103 check ___reltop_whoami "I am ../reltop.mk"
104 check zot_whoami "I am Makefile.am"