updated changelog
[platform/upstream/evolution-data-server.git] / m4 / evo_phonenumber.m4
1 dnl EVO_PHONENUMBER_ARGS([default])
2 dnl
3 dnl Checks configure script options for requesting libphonenumber support.
4 dnl Adds a --with-phonenumber option to explicitly enable and disable
5 dnl phonenumber support, but also for pointing to libphonenumber's install
6 dnl prefix.
7 dnl
8 dnl Must be called before any other macro that might use the C++ compiler.
9 AC_DEFUN([EVO_PHONENUMBER_ARGS],[
10         AC_BEFORE([$0], [AC_COMPILE_IFELSE])
11         AC_BEFORE([$0], [AC_LINK_IFELSE])
12         AC_BEFORE([$0], [AC_PROG_CXX])
13         AC_BEFORE([$0], [AC_RUN_IFELSE])
14         AC_BEFORE([$0], [LT_INIT])
15
16         evo_phonenumber_prefix=
17
18         AC_MSG_CHECKING([whether to enable phonenumber support])
19
20         AC_ARG_WITH([phonenumber],
21                 [AS_HELP_STRING([--with-phonenumber@<:@=PREFIX@:>@],
22                                 [use libphonenumber at PREFIX])],
23                 [evo_phonenumber_prefix=$withval],
24                 [with_phonenumber=m4_default([$1],[check])])
25
26         AC_MSG_RESULT([$with_phonenumber])
27
28         AS_VAR_IF([with_phonenumber],[no],,[evo_with_cxx=yes])
29 ])
30
31 dnl EVO_PHONENUMBER_SUPPORT
32 dnl
33 dnl Check for Google's libphonenumber. Adds a --with-phonenumber option
34 dnl to explicitly enable and disable phonenumber support, but also for
35 dnl pointing to libphonenumber's install prefix.
36 dnl
37 dnl You most probably want to place a call to EVO_PHONENUMBER_ARGS near
38 dnl to the top of your configure script.
39 AC_DEFUN([EVO_PHONENUMBER_SUPPORT],[
40         AC_REQUIRE([EVO_PHONENUMBER_ARGS])
41
42         msg_phonenumber=no
43
44         PHONENUMBER_INCLUDES=
45         PHONENUMBER_LIBS=
46
47         AS_VAR_IF([with_phonenumber], [no],, [
48                 AC_LANG_PUSH(C++)
49
50                 PHONENUMBER_INCLUDES="-DI18N_PHONENUMBERS_USE_BOOST"
51                 PHONENUMBER_LIBS="-lphonenumber"
52
53                 AS_VAR_IF([evo_phonenumber_prefix],,,[
54                         PHONENUMBER_INCLUDES="-I$evo_phonenumber_prefix/include $PHONENUMBER_INCLUDES"
55                         PHONENUMBER_LIBS="-L$evo_phonenumber_prefix/lib $PHONENUMBER_LIBS"
56                 ])
57
58                 evo_cxxflags_saved="$CXXFLAGS"
59                 CXXFLAGS="$CXXFLAGS $PHONENUMBER_INCLUDES"
60
61                 evo_libs_saved="$LIBS"
62                 evo_libphonenumber_usable=no
63
64                 AC_MSG_CHECKING([if libphonenumber is usable])
65
66                 for lib in boost_thread-mt boost_thread; do
67                         LIBS="$evo_libs_saved $PHONENUMBER_LIBS -l$lib"
68
69                         AC_LINK_IFELSE(
70                                 [AC_LANG_PROGRAM(
71                                         [[#include <phonenumbers/phonenumberutil.h>]],
72                                         [[i18n::phonenumbers::PhoneNumberUtil::GetInstance();]])],
73                                 [with_phonenumber=yes
74                                  evo_libphonenumber_usable=yes
75                                  PHONENUMBER_LIBS="$PHONENUMBER_LIBS -l$lib"
76                                  break])
77                 done
78
79                 AS_VAR_IF([evo_libphonenumber_usable], [no],
80                         [AS_VAR_IF(
81                                 [with_phonenumber], [check], [with_phonenumber=no],
82                                 [AC_MSG_ERROR([libphonenumber cannot be used. Use --with-phonenumber to specify the library prefix.])])
83                         ])
84
85                 AS_VAR_IF([evo_phonenumber_prefix],,
86                           [msg_phonenumber=$with_phonenumber],
87                           [msg_phonenumber=$evo_phonenumber_prefix])
88
89                 AC_MSG_RESULT([$with_phonenumber])
90
91                 AS_VAR_IF(
92                         [with_phonenumber],[yes],
93                         [AC_MSG_CHECKING([whether ParseAndKeepRawInput() is needed])
94                          AC_RUN_IFELSE(
95                                 [AC_LANG_PROGRAM(
96                                         [[#include <phonenumbers/phonenumberutil.h>]],
97                                         [[namespace pn = i18n::phonenumbers;
98
99                                           pn::PhoneNumber n;
100
101                                           if (pn::PhoneNumberUtil::GetInstance ()->
102                                                 Parse("049(800)46663", "DE", &n) == pn::PhoneNumberUtil::NO_PARSING_ERROR
103                                                         && n.has_country_code_source ()
104                                                         && n.country_code_source () == 49)
105                                                 return EXIT_SUCCESS;
106
107                                           return EXIT_FAILURE;]]
108                                         )],
109
110                                 [AC_MSG_RESULT([no])],
111                                 [AC_MSG_RESULT([yes])
112
113                                  AC_DEFINE_UNQUOTED(
114                                         [PHONENUMBER_RAW_INPUT_NEEDED], 1,
115                                         [Whether Parse() or ParseAndKeepRawInput() must be used to get the country-code source])
116                                 ])
117                         ])
118
119
120                 CXXFLAGS="$evo_cxxflags_saved"
121                 LIBS="$evo_libs_saved"
122
123                 AC_LANG_POP(C++)
124         ])
125
126         AM_CONDITIONAL([ENABLE_PHONENUMBER],
127                        [test "x$with_phonenumber" != "xno"])
128
129         AS_VAR_IF([with_phonenumber], [yes],
130                   [AC_DEFINE([ENABLE_PHONENUMBER], 1, [Enable phonenumber parsing])])
131
132         AC_SUBST([PHONENUMBER_INCLUDES])
133         AC_SUBST([PHONENUMBER_LIBS])
134 ])