build: Add our version of VALA_CHECK_PACKAGES
[profile/ivi/rygel.git] / m4 / rygel.m4
1 dnl rygel.m4
2 dnl
3 dnl Copyright 2011 Jens Georg
4 dnl
5 dnl This library is free software; you can redistribute it and/or
6 dnl modify it under the terms of the GNU Lesser General Public
7 dnl License as published by the Free Software Foundation; either
8 dnl version 2.1 of the License, or (at your option) any later version.
9 dnl
10 dnl This library is distributed in the hope that it will be useful,
11 dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
12 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 dnl Lesser General Public License for more details.
14 dnl
15 dnl You should have received a copy of the GNU Lesser General Public
16 dnl License along with this library; if not, write to the Free Software
17 dnl Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
18
19 AC_DEFUN([RYGEL_ADD_STAMP],
20 [
21     rygel_stamp_files="$rygel_stamp_files $srcdir/$1"
22 ])
23
24 AC_DEFUN([RYGEL_ADD_VALAFLAGS],
25 [
26     VALAFLAGS="${VALAFLAGS:+$VALAFLAGS }$1"
27 ])
28
29 # RYGEL_CHECK_PACKAGES(LIST-OF-PACKAGES,
30 #   ACTION-IF-FOUND)
31 # ---------------------------------------
32 # Version of VALA_CHECK_PACKAGES that will only run if vala support is
33 # enabled. Otherwise ACTION-IF-FOUND will be run.
34 AC_DEFUN([RYGEL_CHECK_PACKAGES],
35 [
36     AS_IF([test "x$enable_vala" = "xyes"],
37           [
38                 VALA_CHECK_PACKAGES([$1],[$2])
39           ],
40           [
41                 $2
42           ])
43 ])
44
45 # _RYGEL_ADD_PLUGIN_INTERNAL(NAME-OF-PLUGIN,
46 #   NAME-OF-PLUGIN-WITH-UNDERSCORES,
47 #   NAME-OF-PLUGIN-FOR-HELP,
48 #   DEFAULT-FOR-ENABLE)
49 # --------------------------------------
50 # Add an --enable-plugin option, add its Makefile to AC_OUTPUT and set the
51 # conditional
52 AC_DEFUN([_RYGEL_ADD_PLUGIN_INTERNAL],
53 [
54     AC_ARG_ENABLE([$1-plugin],
55         AS_HELP_STRING([--enable-$1-plugin],[enable $3 plugin]),,
56         enable_$2_plugin=$4)
57     AC_CONFIG_FILES([src/plugins/$1/Makefile])
58     AM_CONDITIONAL(m4_toupper(build_$2_plugin), test "x$[]enable_$2_plugin" = "xyes")
59     RYGEL_ADD_STAMP([src/plugins/$1/librygel_$2_la_vala.stamp])
60 ])
61
62 # _RYGEL_ADD_PLUGIN_INTERNAL(NAME-OF-PLUGIN,
63 #   NAME-OF-PLUGIN-FOR-HELP,
64 #   DEFAULT-FOR-ENABLE)
65 # --------------------------------------
66 # Add an --enable-plugin option, add its Makefile to AC_OUTPUT and set the
67 # conditional
68 AC_DEFUN([RYGEL_ADD_PLUGIN],
69 [
70     _RYGEL_ADD_PLUGIN_INTERNAL([$1],
71         m4_translit([$1],[-],[_]),
72         [$2],
73         [$3])
74 ])
75
76 AC_DEFUN([RYGEL_CHECK_VALA],
77 [
78     AC_ARG_ENABLE([vala],
79         [AS_HELP_STRING([--enable-vala],[enable checks for vala])],,
80             [enable_vala=no])
81     AC_ARG_ENABLE([strict-valac],
82         [AS_HELP_STRING([--enable-strict-valac],[enable strict Vala compiler])],,
83               [enable_strict_valac=no])
84     AS_IF([test "x$enable_strict_valac" = "xyes"],
85           [RYGEL_ADD_VALAFLAGS([--fatal-warnings])])
86     AC_SUBST([VALAFLAGS])
87
88     dnl Enable check for Vala even if not asked to do so if stamp files are absent.
89     for stamp in $rygel_stamp_files
90     do
91         AS_IF([test ! -e "$stamp"],
92               [AC_MSG_WARN([Missing stamp file $[]stamp. Forcing vala mode])
93                enable_vala=yes
94               ])
95     done
96
97     dnl Vala
98     AS_IF([test x$enable_vala = xyes],
99           [dnl check for vala
100            AM_PROG_VALAC([$1])
101
102             AS_IF([test x$VALAC = "x"],
103                 [AC_MSG_ERROR([Cannot find the "valac" compiler in your PATH])],
104                 [
105                     PKG_CHECK_MODULES(GUPNP_VALA, gupnp-vala-1.0 >= $GUPNP_VALA_REQUIRED)
106
107                     VALA_CHECK_PACKAGES([$2])
108                 ])
109            ],
110            []
111     )
112
113     VAPIDIR="${datadir}/vala/vapi"
114     AC_SUBST(VAPIDIR)
115 ])