2 # Copyright (C) 2013 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 <http://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)
145 AM_TESTS_ENVIRONMENT += EXEEXT='$(EXEEXT)'; export EXEEXT;
148 cat > lib/tests/safe-print-test.c <<'END'
149 #include "safe-print.h"
153 safe_print (stdout, "dummy\n");
160 cat > tests/check.am <<'END'
161 TEST_EXTENSIONS = .sh
162 SH_LOG_COMPILER = $(SHELL)
164 handwritten_TESTS = \
167 TESTS += $(handwritten_TESTS)
168 EXTRA_DIST += $(handwritten_TESTS)
170 TESTS += %D%/goodbye.sh
171 CLEANFILES += %D%/goodbye.sh
172 %D%/goodbye.sh: %D%/hello.sh
175 sed -e 's/hello/goodbye/' \
176 -e 's/Hello/Goodbye/' \
177 < $(srcdir)/%D%/hello.sh >$@-t
178 chmod a-w,a+x $@-t && mv -f $@-t $@
181 cat > tests/hello.sh <<'END'
184 if test "$WE_ARE_CROSS_COMPILING" = yes; then
185 echo Skipping: cannot run in cross-compilation mode
189 test "`hello`" = 'Hello, World!' || exit 1
193 cat > tests/built.sh <<'END'
196 test -n "$PROGDIR" || exit 99
197 test -f "$PROGDIR/hello$EXEEXT" || exit 1
198 test -x "$PROGDIR/hello$EXEEXT" || exit 1
199 test -f "$PROGDIR/goodbye$EXEEXT" || exit 1
200 test -x "$PROGDIR/goodbye$EXEEXT" || exit 1
208 $AUTOMAKE --add-missing --copy
210 test -f build-aux/compile
216 VERBOSE=x $MAKE check >stdout || { cat stdout; exit 1; }
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