2 # Copyright (C) 2012-2015 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 on C support, also testing automatic dependency tracking,
18 # conditional SUBDIRS and convenience libraries.
21 am_create_testdir
=empty
24 cat > configure.ac
<< 'END'
25 AC_INIT
([GNU C Demo
], [22.3.2], [bug-automake@gnu.org
])
26 AC_CONFIG_SRCDIR
([tests
/test.
test])
27 AC_CONFIG_AUX_DIR
([build-aux
])
32 AM_CONDITIONAL
([RUN_TESTS
], [test x
"$run_tests" != x
"no"])
33 AC_CONFIG_FILES
([Makefile src
/Makefile lib
/Makefile
tests
/Makefile
])
37 if cross_compiling
; then
44 mkdir build-aux lib src tests
46 cat > Makefile.am
<<'END'
54 check-local: test-objs
56 test -f src/zardoz-main.$(OBJEXT)
57 test -f lib/foo.$(OBJEXT)
58 test -f lib/bar.$(OBJEXT)
61 cat > src
/Makefile.am
<< 'END'
63 zardoz_SOURCES
= main.c
64 zardoz_LDADD
= $
(top_builddir
)/lib
/lib-convenience.a
65 zardoz_CPPFLAGS
= -I$
(top_builddir
)/lib
-I$
(top_srcdir
)/lib
68 cat > lib
/Makefile.am
<< 'END'
69 noinst_LIBRARIES
= lib-convenience.a
70 lib_convenience_a_SOURCES
= foo.c
71 lib_convenience_a_SOURCES
+= bar.c
72 dist_lib_convenience_a_SOURCES
= bar.h
73 nodist_lib_convenience_a_SOURCES
= foo.h
75 # We want this to be auto-generated an removed by "make clean", to
76 # ensure that cleaning rules work correctly; an older implementation
77 # of automatic dependency tracking support suffered of weaknesses in
78 # this situation, see the "historical comments" reported in:
79 # http://lists.gnu.org/archive/html/automake-patches/2012-06/msg00033.html
80 foo.h
: $
(srcdir
)/foo.c
81 sed -n 's/.*foo *(.*/&;/p' "$(srcdir)/foo.c" >$@
-t
82 test 1 -eq `wc -l <$@-t`
83 chmod a-w $@
-t && mv -f $@
-t $@
85 CLEANFILES
= $
(BUILT_SOURCES
)
88 test -f ${top_srcdir}/tests
/test.
test
91 cat > tests
/Makefile.am
<< 'END'
92 AUTOMAKE_OPTIONS
= parallel-tests
93 TEST_LOG_COMPILER
= $
(SHELL
)
98 cat > tests
/test.
test << 'END'
102 test "`../src/zardoz`" = 'Foo, Bar!'
107 $AUTOMAKE --add-missing
109 test -f build-aux
/depcomp
110 test -f build-aux
/compile
# We have per-target flags on C sources.
112 # Don't reject slow dependency extractors.
113 .
/configure
--enable-dependency-tracking
115 cat > src
/main.c
<< 'END'
120 printf ("%s, %s!\n", foo
(), bar
());
125 cat > lib
/foo.c
<< 'END'
128 volatile char
*foo
(void
)
137 cat > lib
/bar.c
<< 'END'
139 const char
*bar
(void
)
145 cat > lib
/bar.h
<< 'END'
147 const char
*bar
(void
);
151 ls -l . src lib
# For debugging.
154 VERBOSE
=x
$MAKE check
155 if cross_compiling
; then
156 test ! -e tests
/test-suite.log
157 test ! -e tests
/test.log
159 test -f tests
/test-suite.log
160 grep 'Foo, Bar!' tests
/test.log
165 if ! cross_compiling
&& ! grep "[ $tab]depmode=none" Makefile
; then
166 # Let's check automatic dependency tracking.
167 sed 's/^\(#define BARBAR \).*/\1 "Zap"/' lib
/bar.h
> t
171 test "$(./src/zardoz)" = 'Foo, Zap!'