Merge branch 'vala-work' into maint
[platform/upstream/automake.git] / t / c-demo.sh
1 #! /bin/sh
2 # Copyright (C) 2012 Free Software Foundation, Inc.
3 #
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.
8 #
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.
13 #
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/>.
16
17 # Demo on C support, also testing automatic dependency tracking,
18 # conditional SUBDIRS and convenience libraries.
19
20 required=cc
21 am_create_testdir=empty
22 . test-init.sh
23
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])
28 AM_INIT_AUTOMAKE
29 AC_PROG_CC
30 AM_PROG_CC_C_O
31 AM_PROG_AR
32 AC_PROG_RANLIB
33 AM_CONDITIONAL([RUN_TESTS], [test x"$run_tests" != x"no"])
34 AC_CONFIG_FILES([Makefile src/Makefile lib/Makefile tests/Makefile])
35 AC_OUTPUT
36 END
37
38 if cross_compiling; then
39   run_tests=no
40 else
41   run_tests=yes
42 fi
43 export run_tests
44
45 mkdir build-aux lib src tests
46
47 cat > Makefile.am <<'END'
48 SUBDIRS = lib src
49
50 if RUN_TESTS
51 SUBDIRS += tests
52 endif
53
54 .PHONY: test-objs
55 check-local: test-objs
56 test-objs:
57         test -f src/zardoz-main.$(OBJEXT)
58         test -f lib/foo.$(OBJEXT)
59         test -f lib/bar.$(OBJEXT)
60 END
61
62 cat > src/Makefile.am << 'END'
63 bin_PROGRAMS = zardoz
64 zardoz_SOURCES = main.c
65 zardoz_LDADD = $(top_builddir)/lib/lib-convenience.a
66 zardoz_CPPFLAGS = -I$(top_builddir)/lib -I$(top_srcdir)/lib
67 END
68
69 cat > lib/Makefile.am << 'END'
70 noinst_LIBRARIES = lib-convenience.a
71 lib_convenience_a_SOURCES = foo.c
72 lib_convenience_a_SOURCES += bar.c
73 dist_lib_convenience_a_SOURCES = bar.h
74 nodist_lib_convenience_a_SOURCES = foo.h
75
76 # We want this to be auto-generated an removed by "make clean", to
77 # ensure that cleaning rules work correctly; an older implementation
78 # of automatic dependency tracking support suffered of weaknesses in
79 # this situation, see the "historical comments" reported in:
80 # http://lists.gnu.org/archive/html/automake-patches/2012-06/msg00033.html
81 foo.h: $(srcdir)/foo.c
82         sed -n 's/.*foo *(.*/&;/p' "$(srcdir)/foo.c" >$@-t
83         test 1 -eq `wc -l <$@-t`
84         chmod a-w $@-t && mv -f $@-t $@
85 BUILT_SOURCES = foo.h
86 CLEANFILES = $(BUILT_SOURCES)
87
88 check-local:
89         test -f ${top_srcdir}/tests/test.test
90 END
91
92 cat > tests/Makefile.am << 'END'
93 AUTOMAKE_OPTIONS = parallel-tests
94 TEST_LOG_COMPILER = $(SHELL)
95 TESTS = test.test
96 EXTRA_DIST = $(TESTS)
97 END
98
99 cat > tests/test.test << 'END'
100 #!/bin/sh
101 set -x; set -e;
102 ../src/zardoz
103 test "`../src/zardoz`" = 'Foo, Bar!'
104 END
105
106 $ACLOCAL
107 $AUTOCONF
108 $AUTOMAKE --add-missing
109
110 test -f build-aux/depcomp
111 test -f build-aux/compile # We have per-target flags on C sources.
112
113 # Don't reject slow dependency extractors.
114 ./configure --enable-dependency-tracking
115
116 cat > src/main.c << 'END'
117 #include "foo.h"
118 #include "bar.h"
119 int main (void)
120 {
121   printf ("%s, %s!\n", foo (), bar ());
122   return 0;
123 }
124 END
125
126 cat > lib/foo.c << 'END'
127 #include "foo.h"
128 static char s[4];
129 volatile char *foo (void)
130 {
131   s[0] = 'F';
132   s[1] = s[2] = 'o';
133   s[3] = '\0';
134   return s;
135 }
136 END
137
138 cat > lib/bar.c << 'END'
139 #include "bar.h"
140 const char *bar (void)
141 {
142   return BARBAR;
143 }
144 END
145
146 cat > lib/bar.h << 'END'
147 #define BARBAR "Bar"
148 const char *bar (void);
149 END
150
151 $MAKE
152 ls -l . src lib # For debugging.
153 $MAKE test-objs
154
155 VERBOSE=x $MAKE check
156 if cross_compiling; then
157   test ! -e tests/test-suite.log
158   test ! -e tests/test.log
159 else
160   test -f tests/test-suite.log
161   grep 'Foo, Bar!' tests/test.log
162 fi
163
164 $MAKE distcheck
165
166 if ! cross_compiling && ! grep "[ $tab]depmode=none" Makefile; then
167   # Let's check automatic dependency tracking.
168   sed 's/^\(#define BARBAR \).*/\1 "Zap"/'  lib/bar.h > t
169   mv -f t lib/bar.h
170   $MAKE
171   ./src/zardoz
172   test "$(./src/zardoz)" = 'Foo, Zap!'
173 fi
174
175 $MAKE clean
176 test ! -e lib/foo.h
177 test -f lib/bar.h
178
179 :