tests: Let 'ltorder.sh' run successfully with Guix dynamic loader
[automake.git] / t / remake-gnulib-add-acsubst.sh
blobe98afb95c9a0c43bc27618a64638e73ebdba193b
1 #! /bin/sh
2 # Copyright (C) 2011-2018 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 # Test remake rules when a new AC_SUBST'd variable is added, and C header
18 # files are involved.
19 # This test overlaps with others, and is not strictly necessary per se,
20 # but it exercises a real use case (from gnulib, see:
21 # <https://lists.gnu.org/archive/html/bug-gnulib/2011-04/msg00005.html>
22 # for more info).
24 required=cc
25 . test-init.sh
27 cat >> configure.ac <<'END'
28 AC_PROG_CC
29 MY_MACROS
30 AC_OUTPUT
31 END
33 cat > Makefile.am <<'END'
34 ACLOCAL_AMFLAGS = -I m4
35 noinst_PROGRAMS = foo
36 foo_SOURCES = foo.c
37 BUILT_SOURCES = foo.h
38 edit_h = sed -e 's|[@]foovar@|@foovar@|g'
39 foo.h: foo.in.h
40 $(edit_h) < $(srcdir)/foo.in.h > $@-t
41 cat $@-t;: For debugging.
42 mv -f $@-t $@
43 EXTRA_DIST = foo.in.h
44 MOSTLYCLEANFILES = foo.h foo.h-t
45 END
47 mkdir m4
49 cat > m4/foo.m4 <<'END'
50 AC_DEFUN([MY_MACROS], [
51 FOO_MACRO
52 dnl: ZAP_MACRO
54 END
56 cat > m4/bar.m4 <<'END'
57 AC_DEFUN([FOO_MACRO], [
58 foovar=42; AC_SUBST([foovar])
59 dnl: barvar=47; AC_SUBST([barvar])
61 END
63 cat > foo.in.h <<'END'
64 #define foo @foovar@
65 END
67 cat > foo.c <<'END'
68 #include "foo.h"
69 int main (void) { return 0; }
70 typedef int checkfoo[1 - 2 * (foo != 42)];
71 END
73 $ACLOCAL -I m4
74 $AUTOCONF
75 $AUTOMAKE
77 ./configure
78 $MAKE
80 : AC_SUBST @barvar@ and add it to foo.h.
82 $sleep
84 sed -e 's/^dnl:/ /' m4/bar.m4 > t
85 mv -f t m4/bar.m4
86 cat m4/bar.m4
88 cat >> foo.in.h <<'END'
89 #define bar @barvar@
90 END
92 cat >> foo.c <<'END'
93 typedef int checkbar[1 - 2 * (bar != 47)];
94 END
96 cat >> Makefile.am <<'END'
97 edit_h += -e 's|[@]barvar@|@barvar@|g'
98 END
100 using_gmake || $MAKE Makefile
101 $MAKE
103 : AC_SUBST @zapvar@ and add it to foo.h.
104 # Do it in a slightly different way from how it was done for @barvar@.
106 $sleep
108 cat >> Makefile.am <<'END'
109 edit_h += -e 's|[@]zapvar@|$(zapvar)|g'
112 cat >> foo.c <<'END'
113 typedef int checkzap[1 - 2 * (zap != 163)];
116 sed -e 's/^dnl://' m4/foo.m4 > t
117 mv -f t m4/foo.m4
118 cat m4/foo.m4
120 cat >> foo.in.h <<'END'
121 #define zap @zapvar@
124 cat >> m4/bar.m4 <<'END'
125 AC_DEFUN([ZAP_MACRO], [zapvar=163; AC_SUBST([zapvar])])
128 using_gmake || $MAKE Makefile
129 $MAKE
131 $MAKE distcheck