]> git.lyx.org Git - lyx.git/blob - config/spell.m4
Support new hunspell C++ ABI if LyX is built against hunspell >= 1.5
[lyx.git] / config / spell.m4
1 # Macro to add for using aspell spellchecker libraries!     -*- sh -*-
2 # Only checks for "new" aspell, > 0.50
3 AC_DEFUN([CHECK_WITH_ASPELL],
4 [
5         lyx_use_aspell=true
6         AC_ARG_WITH(aspell, AC_HELP_STRING([--without-aspell],[do not check for ASpell library]))
7         test "$with_aspell" = "no" && lyx_use_aspell=false
8
9         if $lyx_use_aspell ; then
10         AC_CHECK_HEADERS(aspell.h,
11                 [lyx_use_aspell=true; break;],
12                 [lyx_use_aspell=false])
13         AC_CHECK_LIB(aspell, new_aspell_config, LIBS="-laspell $LIBS", lyx_use_aspell=false)
14
15         AC_MSG_CHECKING([whether to use aspell])
16         if $lyx_use_aspell ; then
17                 AC_MSG_RESULT(yes)
18                 AC_DEFINE(USE_ASPELL, 1, [Define as 1 to use the aspell library])
19                 lyx_flags="$lyx_flags use-aspell"
20         else
21                 AC_MSG_RESULT(no)
22         fi
23         fi
24         ])
25
26 # Macro to add for using enchant spellchecker libraries!     -*- sh -*-
27 AC_DEFUN([CHECK_WITH_ENCHANT],
28 [
29         lyx_use_enchant=true
30         AC_ARG_WITH(enchant, AC_HELP_STRING([--without-enchant],[do not check for Enchant library]))
31         test "$with_enchant" = "no" && lyx_use_enchant=false
32
33         if $lyx_use_enchant; then
34         PKG_CHECK_MODULES([ENCHANT], [enchant], [], [lyx_use_enchant=false])
35         AC_MSG_CHECKING([whether to use enchant])
36         if $lyx_use_enchant ; then
37             AC_MSG_RESULT(yes)
38             AC_DEFINE(USE_ENCHANT, 1, [Define as 1 to use the enchant library])
39             lyx_flags="$lyx_flags use-enchant"
40         else
41             AC_MSG_RESULT(no)
42         fi
43     fi
44     ])
45
46 AC_DEFUN([LYX_HAVE_HUNSPELL_CXXABI],
47 [
48   AC_MSG_CHECKING([whether hunspell C++ (rather than C) ABI is provided])
49   save_CXXFLAGS=$CXXFLAGS
50   CXXFLAGS="$ENCHANT_CFLAGS $AM_CXXFLAGS $CXXFLAGS"
51
52 # in the C++ ABI, stem() returns a vector, in the C ABI, it returns an int
53   AC_TRY_COMPILE([#include <hunspell/hunspell.hxx>],
54       [Hunspell sp("foo", "bar");
55        int i = sp.stem("test").size();],
56       [AC_MSG_RESULT(yes)
57        AC_DEFINE(HAVE_HUNSPELL_CXXABI, 1, [Define to 1 if hunspell C++ (rather than C) ABI is detected])
58        have_hunspell_cxx_abi=yes
59       ],
60       [AC_MSG_RESULT(no)])
61   CXXFLAGS=$save_CXXFLAGS
62 ])
63
64 # Macro to add for using hunspell spellchecker libraries!     -*- sh -*-
65 AC_DEFUN([CHECK_WITH_HUNSPELL],
66 [
67         lyx_use_hunspell=true
68         AC_ARG_WITH(hunspell, AC_HELP_STRING([--without-hunspell],[do not check for Hunspell library]))
69         test "$with_hunspell" = "no" && lyx_use_hunspell=false
70
71         if $lyx_use_hunspell ; then
72         PKG_CHECK_MODULES([HUNSPELL], [hunspell], [], [
73                   AC_CHECK_HEADERS(hunspell/hunspell.hxx,
74                     [lyx_use_hunspell=true; break;],
75                          [lyx_use_hunspell=false])
76                          AC_CHECK_LIB(hunspell, main, LIBS="-lhunspell $LIBS", lyx_use_hunspell=false)
77                 ])
78         AC_MSG_CHECKING([whether to use hunspell])
79         if $lyx_use_hunspell ; then
80                 AC_MSG_RESULT(yes)
81                 AC_DEFINE(USE_HUNSPELL, 1, [Define as 1 to use the hunspell library])
82                 lyx_flags="$lyx_flags use-hunspell"
83         else
84                 AC_MSG_RESULT(no)
85         fi
86     fi
87         LYX_HAVE_HUNSPELL_CXXABI
88         if test $enable_stdlib_debug = "yes" -a -n "$have_hunspell_cxx_abi" ; then
89                 LYX_WARNING([Compiling LyX with stdlib-debug and system hunspell libraries may lead to
90    crashes. Consider using --disable-stdlib-debug or --with-included-hunspell.])
91               fi
92
93     ])
94
95 dnl Usage: LYX_USE_INCLUDED_HUNSPELL : select if the included hunspell should
96 dnl        be used.
97 AC_DEFUN([LYX_USE_INCLUDED_HUNSPELL],[
98         AC_MSG_CHECKING([whether to use included hunspell library])
99         AC_ARG_WITH(included-hunspell,
100                 [AC_HELP_STRING([--with-included-hunspell], [use the hunspell lib supplied with LyX instead of the system one])],
101                 [lyx_cv_with_included_hunspell=$withval],
102                 [lyx_cv_with_included_hunspell=no])
103         AM_CONDITIONAL(USE_INCLUDED_HUNSPELL, test x$lyx_cv_with_included_hunspell = xyes)
104         AC_MSG_RESULT([$lyx_cv_with_included_hunspell])
105         if test x$lyx_cv_with_included_hunspell = xyes ; then
106                 lyx_included_libs="$lyx_included_libs hunspell"
107                 HUNSPELL_CFLAGS='-I$(top_srcdir)/3rdparty/hunspell/1.6.2/src'
108                 HUNSPELL_LIBS='$(top_builddir)/3rdparty/hunspell/liblyxhunspell.a'
109                 AC_SUBST(HUNSPELL_CFLAGS)
110                 AC_SUBST(HUNSPELL_LIBS)
111         fi
112         ])
113
114
115 ### Check if we want spell libraries, prefer new aspell or hunspell
116 AC_DEFUN([LYX_CHECK_SPELL_ENGINES],
117 [
118         LYX_USE_INCLUDED_HUNSPELL
119         if test x$lyx_cv_with_included_hunspell = xyes ; then
120 dnl the user wanted to use the included hunspell, so do not check for external hunspell
121                 lyx_use_hunspell=true
122                 AC_DEFINE(USE_HUNSPELL, 1, [Define as 1 to use the hunspell library])
123                 AC_DEFINE(HAVE_HUNSPELL_CXXABI, 1, [Define to 1 if hunspell C++ (rather than C) ABI is detected])
124                 lyx_flags="$lyx_flags use-hunspell"
125         else
126                 CHECK_WITH_HUNSPELL
127         fi
128         CHECK_WITH_ASPELL
129         CHECK_WITH_ENCHANT
130
131         AM_CONDITIONAL(USE_ASPELL, $lyx_use_aspell)
132         AM_CONDITIONAL(USE_ENCHANT, $lyx_use_enchant)
133         AM_CONDITIONAL(USE_HUNSPELL, $lyx_use_hunspell)
134         ])
135