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)
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
24 if cross_compiling
; then
25 WE_ARE_CROSS_COMPILING
=yes
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
])
46 mkdir build-aux lib lib
/tests src tests
50 cat > Makefile.am
<< 'END'
55 AM_TESTS_ENVIRONMENT
=
61 include $
(srcdir
)/src
/progs.am
62 include $
(srcdir
)/lib
/gnulib.am
63 include $
(srcdir
)/tests
/check.am
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%'; \
79 PATH='$(abs_builddir)/%reldir%'$(PATH_SEPARATOR)$$PATH; \
83 cat > src
/hello.c
<<'END'
84 #include "safe-print.h"
89 # define GREETINGS "Hello"
95 safe_print (stdout, GREETINGS ", World!\n");
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
= \
113 include
%D
%/tests
/gnulib-check.am
117 cat > lib
/safe-print.c
<<'END'
118 #include "safe-print.h"
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");
135 cat > lib
/safe-print.h
<<'END'
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"
152 safe_print (stdout, "dummy\n");
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 = \
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
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'
185 if test "$WE_ARE_CROSS_COMPILING" = yes; then
186 echo Skipping: cannot run in cross-compilation mode
190 test "`hello`" = 'Hello, World!' || exit 1
194 cat > tests
/built.sh
<<'END'
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
209 $AUTOMAKE --add-missing --copy
211 test -f build-aux
/compile
217 run_make
-O check VERBOSE
=x
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
225 count_test_results total
=4 pass
=4 fail
=0 xpass
=0 xfail
=0 skip
=0 error
=0