Merge branch 'fix-pr14560' into micro
[platform/upstream/automake.git] / t / vala-vapi.sh
1 #! /bin/sh
2 # Copyright (C) 2012-2013 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 # Test and that vapi files are correctly handled by Vala support.
18
19 required='pkg-config valac cc GNUmake'
20 . test-init.sh
21
22 cat >> configure.ac <<'END'
23 AC_PROG_CC
24 AM_PROG_CC_C_O
25 AM_PROG_VALAC([0.7.3])
26 PKG_CHECK_MODULES([GOBJECT], [gobject-2.0 >= 2.4])
27 AC_OUTPUT
28 END
29
30 cat > Makefile.am <<'END'
31 bin_PROGRAMS = zardoz
32 AM_CFLAGS = $(GOBJECT_CFLAGS)
33 LDADD = $(GOBJECT_LIBS)
34 zardoz_SOURCES = zardoz.vala foo.vapi foo.h
35 END
36
37 cat > zardoz.vala <<'END'
38 using GLib;
39 public class Zardoz {
40   public static void main () {
41     stdout.printf (BARBAR);
42   }
43 }
44 END
45
46 # Use printf, not echo, to avoid '\n' being considered and escape
47 # sequence and printed as a newline in 'foo.h'.
48 printf '%s\n' '#define BARBAR "Zardoz!\n"' > foo.h
49
50 cat > foo.vapi <<'END'
51 [CCode (cprefix="", lower_case_cprefix="", cheader_filename="foo.h")]
52 public const string BARBAR;
53 END
54
55 if ! cross_compiling; then
56   unindent >> Makefile.am <<'END'
57     check-local: test2
58     .PHONY: test1 test2
59     test1:
60         ./zardoz
61         ./zardoz | grep 'Zardoz!'
62     test2:
63         ./zardoz
64         ./zardoz | grep 'Quux!'
65 END
66 fi
67
68 $ACLOCAL
69 $AUTOMAKE -a
70 $AUTOCONF
71
72 ./configure --enable-dependency-tracking
73
74 $MAKE
75 ls -l        # For debugging.
76 cat zardoz.c # Likewise.
77 grep 'BARBAR' zardoz.c
78 cross_compiling || $MAKE test1 || exit 1
79
80 # Simple check on remake rules.
81 $sleep
82 # Use printf, not echo, to avoid '\n' being considered and escape
83 # sequence and printed as a newline in 'foo.h'.
84 printf '%s\n' '#define BAZBAZ "Quux!\n"' > foo.h
85 sed 's/BARBAR/BAZBAZ/' zardoz.vala > t && mv -f t zardoz.vala || exit 99
86 $MAKE && exit 1
87 sed 's/BARBAR/BAZBAZ/' foo.vapi > t && mv -f t foo.vapi || exit 99
88 $MAKE
89 cat zardoz.c # For debugging.
90 grep 'BAZBAZ' zardoz.c
91 cross_compiling || $MAKE test2 || exit 1
92
93 # Check the distribution.
94 $MAKE distcheck
95
96 :