doc: update Vala documentation
[automake.git] / t / preproc-demo.sh
blob67981d4d5bb065baf4575a04d89f451cc85f005f
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 # Demo of a package using pre-processing substitutions '%reldir%' and
18 # '%canon_reldir%', and their respective shorthands '%D%' and '%C%'.
20 am_create_testdir=empty
21 required=cc
22 . test-init.sh
24 if cross_compiling; then
25 WE_ARE_CROSS_COMPILING=yes
26 else
27 WE_ARE_CROSS_COMPILING=no
29 export WE_ARE_CROSS_COMPILING
31 SAFE_PRINT_FAIL=; unset SAFE_PRINT_FAIL
33 cat > configure.ac << 'END'
34 AC_INIT([GNU Demo], [0.7], [bug-automake@gnu.org])
35 AC_CONFIG_AUX_DIR([build-aux])
36 AM_INIT_AUTOMAKE([1.12.6 foreign subdir-objects -Wall])
37 AM_CONDITIONAL([NATIVE_BUILD], [test $WE_ARE_CROSS_COMPILING != yes])
38 AC_CONFIG_FILES([Makefile])
39 AC_PROG_CC
40 AM_PROG_CC_C_O
41 AM_PROG_AR
42 AC_PROG_RANLIB
43 AC_OUTPUT
44 END
46 mkdir build-aux lib lib/tests src tests
48 ## Top level.
50 cat > Makefile.am << 'END'
51 bin_PROGRAMS =
52 check_PROGRAMS =
53 noinst_LIBRARIES =
54 AM_CPPFLAGS =
55 AM_TESTS_ENVIRONMENT =
56 CLEANFILES =
57 EXTRA_DIST =
58 LDADD =
59 TESTS =
61 include $(srcdir)/src/progs.am
62 include $(srcdir)/lib/gnulib.am
63 include $(srcdir)/tests/check.am
64 END
66 ## Src subdir.
68 cat > src/progs.am <<'END'
69 bin_PROGRAMS += %reldir%/hello
71 bin_PROGRAMS += %D%/goodbye
72 %canon_reldir%_goodbye_SOURCES = %D%/hello.c
73 %C%_goodbye_CPPFLAGS = $(AM_CPPFLAGS) -DGREETINGS='"Goodbye"'
75 # The testsuite should have access to our built programs.
76 AM_TESTS_ENVIRONMENT += \
77 PROGDIR='$(top_builddir)/%reldir%'; \
78 export PROGDIR; \
79 PATH='$(abs_builddir)/%reldir%'$(PATH_SEPARATOR)$$PATH; \
80 export PATH;
81 END
83 cat > src/hello.c <<'END'
84 #include "safe-print.h"
85 #include <stdlib.h>
86 #include <stdio.h>
88 #ifndef GREETINGS
89 # define GREETINGS "Hello"
90 #endif
92 int
93 main (void)
95 safe_print (stdout, GREETINGS ", World!\n");
96 exit (EXIT_SUCCESS);
98 END
100 ## Lib subdir.
102 cat > lib/gnulib.am << 'END'
103 noinst_LIBRARIES += %D%/libgnu.a
105 AM_CPPFLAGS += -I%D% -I$(top_srcdir)/%D%
106 LDADD += $(noinst_LIBRARIES)
108 %C%_libgnu_a_SOURCES = \
109 %D%/safe-print.c \
110 %D%/safe-print.h
112 if NATIVE_BUILD
113 include %D%/tests/gnulib-check.am
114 endif
117 cat > lib/safe-print.c <<'END'
118 #include "safe-print.h"
119 #include <string.h>
120 #include <stdlib.h>
122 void
123 safe_print (FILE *fp, const char * str)
125 if (fprintf (fp, "%s", str) != strlen (str)
126 || fflush (fp) != 0 || ferror (fp))
128 fprintf (stderr, "I/O error\n");
129 exit (EXIT_FAILURE);
135 cat > lib/safe-print.h <<'END'
136 #include <stdio.h>
137 void safe_print (FILE *, const char *);
140 ## Lib/Tests (sub)subdir.
142 cat > lib/tests/gnulib-check.am <<'END'
143 check_PROGRAMS += %D%/safe-print-test
144 TESTS += $(check_PROGRAMS)
147 cat > lib/tests/safe-print-test.c <<'END'
148 #include "safe-print.h"
150 main (void)
152 safe_print (stdout, "dummy\n");
153 return 0;
157 ## Tests subdir.
159 cat > tests/check.am <<'END'
160 TEST_EXTENSIONS = .sh
161 SH_LOG_COMPILER = $(SHELL)
163 AM_TESTS_ENVIRONMENT += EXEEXT='$(EXEEXT)'; export EXEEXT;
165 handwritten_TESTS = \
166 %D%/hello.sh \
167 %D%/built.sh
168 TESTS += $(handwritten_TESTS)
169 EXTRA_DIST += $(handwritten_TESTS)
171 TESTS += %D%/goodbye.sh
172 CLEANFILES += %D%/goodbye.sh
173 %D%/goodbye.sh: %D%/hello.sh
174 $(MKDIR_P) %D%
175 rm -f $@ $@-t
176 sed -e 's/hello/goodbye/' \
177 -e 's/Hello/Goodbye/' \
178 < $(srcdir)/%D%/hello.sh >$@-t
179 chmod a-w,a+x $@-t && mv -f $@-t $@
182 cat > tests/hello.sh <<'END'
183 #!/bin/sh
184 set -x -e
185 if test "$WE_ARE_CROSS_COMPILING" = yes; then
186 echo Skipping: cannot run in cross-compilation mode
187 exit 77
188 else
189 hello || exit 1
190 test "`hello`" = 'Hello, World!' || exit 1
194 cat > tests/built.sh <<'END'
195 #!/bin/sh
196 set -x
197 test -n "$PROGDIR" || exit 99
198 test -f "$PROGDIR/hello$EXEEXT" || exit 1
199 test -x "$PROGDIR/hello$EXEEXT" || exit 1
200 test -f "$PROGDIR/goodbye$EXEEXT" || exit 1
201 test -x "$PROGDIR/goodbye$EXEEXT" || exit 1
205 ## Go.
207 $ACLOCAL
208 $AUTOCONF
209 $AUTOMAKE --add-missing --copy
210 test ! -e compile
211 test -f build-aux/compile
213 ./configure
215 $MAKE
217 run_make -O check VERBOSE=x
218 cat tests/built.log
219 cat tests/hello.log
220 cat tests/goodbye.log
221 if cross_compiling; then
222 test ! -e lib/tests/safe-print-test.log
223 count_test_results total=3 pass=1 fail=0 xpass=0 xfail=0 skip=2 error=0
224 else
225 count_test_results total=4 pass=4 fail=0 xpass=0 xfail=0 skip=0 error=0
228 $MAKE distcheck