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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
|
#! /bin/sh
# Copyright (C) 2013-2020 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 <https://www.gnu.org/licenses/>.
# Demo of a package using pre-processing substitutions '%reldir%' and
# '%canon_reldir%', and their respective shorthands '%D%' and '%C%'.
am_create_testdir=empty
required=cc
. test-init.sh
if cross_compiling; then
WE_ARE_CROSS_COMPILING=yes
else
WE_ARE_CROSS_COMPILING=no
fi
export WE_ARE_CROSS_COMPILING
SAFE_PRINT_FAIL=; unset SAFE_PRINT_FAIL
cat > configure.ac << 'END'
AC_INIT([GNU Demo], [0.7], [bug-automake@gnu.org])
AC_CONFIG_AUX_DIR([build-aux])
AM_INIT_AUTOMAKE([1.12.6 foreign subdir-objects -Wall])
AM_CONDITIONAL([NATIVE_BUILD], [test $WE_ARE_CROSS_COMPILING != yes])
AC_CONFIG_FILES([Makefile])
AC_PROG_CC
AM_PROG_CC_C_O
AM_PROG_AR
AC_PROG_RANLIB
AC_OUTPUT
END
mkdir build-aux lib lib/tests src tests
## Top level.
cat > Makefile.am << 'END'
bin_PROGRAMS =
check_PROGRAMS =
noinst_LIBRARIES =
AM_CPPFLAGS =
AM_TESTS_ENVIRONMENT =
CLEANFILES =
EXTRA_DIST =
LDADD =
TESTS =
include $(srcdir)/src/progs.am
include $(srcdir)/lib/gnulib.am
include $(srcdir)/tests/check.am
END
## Src subdir.
cat > src/progs.am <<'END'
bin_PROGRAMS += %reldir%/hello
bin_PROGRAMS += %D%/goodbye
%canon_reldir%_goodbye_SOURCES = %D%/hello.c
%C%_goodbye_CPPFLAGS = $(AM_CPPFLAGS) -DGREETINGS='"Goodbye"'
# The testsuite should have access to our built programs.
AM_TESTS_ENVIRONMENT += \
PROGDIR='$(top_builddir)/%reldir%'; \
export PROGDIR; \
PATH='$(abs_builddir)/%reldir%'$(PATH_SEPARATOR)$$PATH; \
export PATH;
END
cat > src/hello.c <<'END'
#include "safe-print.h"
#include <stdlib.h>
#include <stdio.h>
#ifndef GREETINGS
# define GREETINGS "Hello"
#endif
int
main (void)
{
safe_print (stdout, GREETINGS ", World!\n");
exit (EXIT_SUCCESS);
}
END
## Lib subdir.
cat > lib/gnulib.am << 'END'
noinst_LIBRARIES += %D%/libgnu.a
AM_CPPFLAGS += -I%D% -I$(top_srcdir)/%D%
LDADD += $(noinst_LIBRARIES)
%C%_libgnu_a_SOURCES = \
%D%/safe-print.c \
%D%/safe-print.h
if NATIVE_BUILD
include %D%/tests/gnulib-check.am
endif
END
cat > lib/safe-print.c <<'END'
#include "safe-print.h"
#include <string.h>
#include <stdlib.h>
void
safe_print (FILE *fp, const char * str)
{
if (fprintf (fp, "%s", str) != strlen (str)
|| fflush (fp) != 0 || ferror (fp))
{
fprintf (stderr, "I/O error\n");
exit (EXIT_FAILURE);
}
}
END
cat > lib/safe-print.h <<'END'
#include <stdio.h>
void safe_print (FILE *, const char *);
END
## Lib/Tests (sub)subdir.
cat > lib/tests/gnulib-check.am <<'END'
check_PROGRAMS += %D%/safe-print-test
TESTS += $(check_PROGRAMS)
END
cat > lib/tests/safe-print-test.c <<'END'
#include "safe-print.h"
int
main (void)
{
safe_print (stdout, "dummy\n");
return 0;
}
END
## Tests subdir.
cat > tests/check.am <<'END'
TEST_EXTENSIONS = .sh
SH_LOG_COMPILER = $(SHELL)
AM_TESTS_ENVIRONMENT += EXEEXT='$(EXEEXT)'; export EXEEXT;
handwritten_TESTS = \
%D%/hello.sh \
%D%/built.sh
TESTS += $(handwritten_TESTS)
EXTRA_DIST += $(handwritten_TESTS)
TESTS += %D%/goodbye.sh
CLEANFILES += %D%/goodbye.sh
%D%/goodbye.sh: %D%/hello.sh
$(MKDIR_P) %D%
rm -f $@ $@-t
sed -e 's/hello/goodbye/' \
-e 's/Hello/Goodbye/' \
< $(srcdir)/%D%/hello.sh >$@-t
chmod a-w,a+x $@-t && mv -f $@-t $@
END
cat > tests/hello.sh <<'END'
#!/bin/sh
set -x -e
if test "$WE_ARE_CROSS_COMPILING" = yes; then
echo Skipping: cannot run in cross-compilation mode
exit 77
else
hello || exit 1
test "`hello`" = 'Hello, World!' || exit 1
fi
END
cat > tests/built.sh <<'END'
#!/bin/sh
set -x
test -n "$PROGDIR" || exit 99
test -f "$PROGDIR/hello$EXEEXT" || exit 1
test -x "$PROGDIR/hello$EXEEXT" || exit 1
test -f "$PROGDIR/goodbye$EXEEXT" || exit 1
test -x "$PROGDIR/goodbye$EXEEXT" || exit 1
END
## Go.
$ACLOCAL
$AUTOCONF
$AUTOMAKE --add-missing --copy
test ! -e compile
test -f build-aux/compile
./configure
$MAKE
run_make -O check VERBOSE=x
cat tests/built.log
cat tests/hello.log
cat tests/goodbye.log
if cross_compiling; then
test ! -e lib/tests/safe-print-test.log
count_test_results total=3 pass=1 fail=0 xpass=0 xfail=0 skip=2 error=0
else
count_test_results total=4 pass=4 fail=0 xpass=0 xfail=0 skip=0 error=0
fi
$MAKE distcheck
:
|