summaryrefslogtreecommitdiff
path: root/t/remake-gnulib-add-acsubst.sh
blob: 3aea5b9985af025960629d41d308cdf6e1c02f50 (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
#! /bin/sh
# Copyright (C) 2011-2012 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/>.

# Test remake rules when a new AC_SUBST'd variable is added, and C header
# files are involved.
# This test overlaps with others, and is not strictly necessary per se,
# but it exercises a real use case (from gnulib, see:
#  <http://lists.gnu.org/archive/html/bug-gnulib/2011-04/msg00005.html>
# for more info).

required=cc
. test-init.sh

cat >> configure.ac <<'END'
AC_PROG_CC
MY_MACROS
AC_OUTPUT
END

cat > Makefile.am <<'END'
ACLOCAL_AMFLAGS = -I m4
noinst_PROGRAMS = foo
foo_SOURCES = foo.c
BUILT_SOURCES = foo.h
edit_h = sed -e 's|[@]foovar@|@foovar@|g'
foo.h: foo.in.h
	$(edit_h) < $(srcdir)/foo.in.h > $@-t
	cat $@-t;: For debugging.
	mv -f $@-t $@
EXTRA_DIST = foo.in.h
MOSTLYCLEANFILES = foo.h foo.h-t
END

mkdir m4

cat > m4/foo.m4 <<'END'
AC_DEFUN([MY_MACROS], [
     FOO_MACRO
dnl: ZAP_MACRO
])
END

cat > m4/bar.m4 <<'END'
AC_DEFUN([FOO_MACRO], [
     foovar=42; AC_SUBST([foovar])
dnl: barvar=47; AC_SUBST([barvar])
])
END

cat > foo.in.h <<'END'
#define foo @foovar@
END

cat > foo.c <<'END'
#include "foo.h"
int main (void) { return 0; }
typedef int checkfoo[1 - 2 * (foo != 42)];
END

$ACLOCAL -I m4
$AUTOCONF
$AUTOMAKE

./configure
$MAKE

: AC_SUBST @barvar@ and add it to foo.h.

$sleep

sed -e 's/^dnl:/   /' m4/bar.m4 > t
mv -f t m4/bar.m4
cat m4/bar.m4

cat >> foo.in.h <<'END'
#define bar @barvar@
END

cat >> foo.c <<'END'
typedef int checkbar[1 - 2 * (bar != 47)];
END

cat >> Makefile.am <<'END'
edit_h += -e 's|[@]barvar@|@barvar@|g'
END

using_gmake || $MAKE Makefile
$MAKE

: AC_SUBST @zapvar@ and add it to foo.h.
# Do it in a slightly different way from how it was done for @barvar@.

$sleep

cat >> Makefile.am <<'END'
edit_h += -e 's|[@]zapvar@|$(zapvar)|g'
END

cat >> foo.c <<'END'
typedef int checkzap[1 - 2 * (zap != 163)];
END

sed -e 's/^dnl://' m4/foo.m4 > t
mv -f t m4/foo.m4
cat m4/foo.m4

cat >> foo.in.h <<'END'
#define zap @zapvar@
END

cat >> m4/bar.m4 <<'END'
AC_DEFUN([ZAP_MACRO], [zapvar=163; AC_SUBST([zapvar])])
END

using_gmake || $MAKE Makefile
$MAKE

$MAKE distcheck

: