Simplify Jack and DCA detection
[vlc.git] / m4 / with_pkg.m4
1 dnl with_pkg.m4 - Macros to ease the usage of pkg-config.    -*- Autoconf -*-
2 dnl
3 dnl Copyright ¬© 2008 Luca Barbato <lu_zero@gentoo.org>,
4 dnl                  Diego Petten√≤ <flameeyes@gentoo.org>
5 dnl                  Jean-Baptiste Kempf
6 dnl
7 dnl This program is free software; you can redistribute it and/or modify
8 dnl it under the terms of the GNU General Public License as published by
9 dnl the Free Software Foundation; either version 2 of the License, or
10 dnl (at your option) any later version.
11 dnl
12 dnl This program is distributed in the hope that it will be useful, but
13 dnl WITHOUT ANY WARRANTY; without even the implied warranty of
14 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 dnl General Public License for more details.
16 dnl
17 dnl You should have received a copy of the GNU General Public License
18 dnl along with this program; if not, write to the Free Software
19 dnl Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 dnl
21 dnl As a special exception to the GNU General Public License, if you
22 dnl distribute this file as part of a program that contains a
23 dnl configuration script generated by Autoconf, you may include it under
24 dnl the same distribution terms that you use for the rest of that program.
25
26 dnl PKG_WITH_MODULES(VARIABLE-PREFIX, MODULES,
27 dnl                  [ACTION-IF-FOUND],[ACTION-IF-NOT-FOUND],
28 dnl                  [DESCRIPTION], [DEFAULT])
29 dnl
30 dnl Prepare a --with-variable-prefix triggered check for module,
31 dnl disable by default.
32 dnl
33
34 AC_DEFUN([PKG_WITH_MODULES],
35 [
36 AC_REQUIRE([PKG_PROG_PKG_CONFIG])
37 m4_pushdef([with_arg], m4_tolower([$1]))
38
39 m4_pushdef([description],
40            [m4_default([$5], [build with ]with_arg[ support enabled])])
41
42 m4_pushdef([def_arg], [m4_default([$6], [auto])])
43 m4_pushdef([def_action_if_found], [AS_TR_SH([enable_]with_arg)=yes])
44 m4_pushdef([def_action_if_not_found], [AS_TR_SH([enable_]with_arg)=no])
45
46 m4_case(def_arg,
47             [yes],[m4_pushdef([with_without], [--disable-]with_arg)],
48             [m4_pushdef([with_without],[--enable-]with_arg)])
49
50 AC_ARG_ENABLE(with_arg,
51      AS_HELP_STRING(with_without, description[ @<:@default=]def_arg[@:>@]),,
52     [AS_TR_SH([enable_]with_arg)=def_arg])
53
54 AS_CASE([$AS_TR_SH([enable_]with_arg)],
55             [yes],[PKG_CHECK_MODULES([$1],[$2],$3,$4)],
56             [auto],[PKG_CHECK_MODULES([$1],[$2],
57                                         [m4_n([def_action_if_found]) $3],
58                                         [m4_n([def_action_if_not_found]) $4])])
59
60 m4_popdef([with_arg])
61 m4_popdef([description])
62 m4_popdef([def_arg])
63
64 ]) dnl PKG_WITH_MODULES
65
66 dnl PKG_HAVE_WITH_MODULES(VARIABLE-PREFIX, MODULES,
67 dnl                       [DESCRIPTION], [DEFAULT])
68 dnl
69
70 AC_DEFUN([PKG_HAVE_WITH_MODULES],
71 [
72 PKG_WITH_MODULES([$1],[$2],,,[$3],[$4])
73
74 AM_CONDITIONAL([HAVE_][$1],
75                [test "$AS_TR_SH([with_]m4_tolower([$1]))" = "yes"])
76 ])
77
78 dnl PKG_ENABLE_MODULES_VLC(VARIABLE-PREFIX,
79 dnl                         VLC_MODULE_NAME  dnl (if empty, same as VARIABLE-PREFIX)
80 dnl                         PKG MODULES,
81 dnl                         [DESCRIPTION], [DEFAULT],
82 dnl                         [EXTRA_CFLAGS], [EXTRA_LIBS])
83 AC_DEFUN([PKG_ENABLE_MODULES_VLC],
84 [
85 m4_pushdef([module_name], AS_TR_SH(m4_default(m4_tolower([$2]),m4_tolower([$1]))))
86 m4_pushdef([enable_arg], m4_tolower([$1]))
87
88 PKG_WITH_MODULES([$1],[$3],
89     VLC_ADD_PLUGIN(module_name)
90     VLC_ADD_CFLAGS(module_name,[$$1_CFLAGS] [$6])
91     VLC_ADD_LIBS(module_name,[$$1_LIBS] [$7]),
92     AS_IF([test x"$AS_TR_SH([enable_]enable_arg)" = "xyes"],
93         [AC_MSG_ERROR(Library [$3] needed for [m4_tolower([$1])] was not found)],
94         [AC_MSG_WARN(Library [$3] needed for [m4_tolower([$1])] was not found)]
95          ),
96     [$4],[$5])
97
98 AM_CONDITIONAL([HAVE_][$1],
99                [test "$AS_TR_SH([with_]enable_arg)" = "yes"])
100
101 m4_popdef([module_name])
102 m4_popdef([enable_arg])
103
104 ])
105