2006-04-17 [colin] 2.1.1cvs3
[claws.git] / m4 / aspell.m4
1 dnl Autoconf macros for libaspell
2 dnl $Id$
3
4 # Configure paths for ASPELL
5 # Shamelessly stolen from the one of GPGME by Werner Koch 
6 # Melvin Hadasht  2001-09-17, 2002
7
8 dnl AM_PATH_ASPELL([MINIMUM-VERSION,
9 dnl               [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND ]]])
10 dnl Test for aspell, and define ASPELL_CFLAGS, ASPELL_LIBS and ASPELL_PATH
11 dnl
12 AC_DEFUN([AM_PATH_ASPELL],
13 [dnl
14 dnl Get the cflags and libraries from the aspell-config script
15 dnl
16    AC_ARG_WITH(aspell-prefix,
17       [  --with-aspell-prefix=PFX           Prefix where aspell is installed (optional)],
18       aspell_prefix="$withval", aspell_prefix="")
19    AC_ARG_ENABLE(aspell-test,
20       [  --disable-aspell-test   Do not try to compile and run a test GNU/aspell program],
21       , enable_aspelltest=yes)
22    AC_ARG_WITH(aspell-libs,
23       [  --with-aspell-libs=LIBS            Where GNU/aspell library reside (/usr/local/lib)],
24       aspell_libs="$withval", aspell_libs="")
25    AC_ARG_WITH(aspell-includes,
26       [  --with-aspell-includes=INCLUDES    Where GNU/aspell headers reside (/usr/local/include)],
27       aspell_includes="$withval", aspell_includes="")
28
29   if test x$aspell_prefix != x ; then
30      if test x${ASPELL+set} != xset ; then
31         ASPELL=$aspell_prefix/bin/aspell
32      fi
33      if test x$aspell_includes = x ; then
34         aspell_includes=$aspell_prefix/include
35      fi
36      if test x$aspell_libs = x ; then
37         aspell_libs=$aspell_prefix/lib
38      fi
39      aspell_path=$aspell_prefix/lib/aspell
40   fi
41   if test x$aspell_includes = x ; then
42      aspell_includes=/usr/local/include
43   fi
44   if test x$aspell_libs = x ; then
45      aspell_libs=/usr/local/lib
46   fi
47   if test x$aspell_path = x ; then
48      aspell_path=/usr/local/lib/aspell
49   fi
50   if test "x$enable_aspelltest" != "xyes" ; then
51      echo "*** Disabling GNU/aspell tests upon user request" 
52      ASPELL_CFLAGS="-I$aspell_includes"
53      ASPELL_LIBS="-L$aspell_libs -laspell"
54      AC_DEFINE_UNQUOTED(ASPELL_PATH, "${aspell_path}/", Define ASPELL's default directory)
55      ifelse([$2], , :, [$2])
56   else   
57      AC_PATH_PROG(ASPELL, aspell, no)
58      min_aspell_version=ifelse([$1], ,.50,$1)
59      AC_MSG_CHECKING(for GNU/aspell - version >= $min_aspell_version)
60      no_aspell=""
61      if test "$ASPELL" = "no" ; then
62         echo "*** The aspell executable could not be found"
63         echo "*** If aspell was installed in PREFIX, make sure PREFIX/bin is in"
64         echo "*** your path, or set the ASPELL environment variable to the"
65         echo "*** full path to aspell or configure with --with-aspell-prefix=PREFIX."
66         ASPELL_CFLAGS=""
67         ASPELL_LIBS=""
68         ASPELL_PATH=""
69         no_aspell=yes
70         ifelse([$3], , :, [$3])
71      else
72         ASPELL_CFLAGS="-I$aspell_includes"
73         ASPELL_LIBS="-L$aspell_libs -laspell"
74         aspell_version=`$ASPELL version|sed -e "s/\(@(#) International Ispell Version 3.1.20 (but really Aspell \)\(.*\))/\2/"`
75         rm -f conf.aspelltest
76         AC_TRY_RUN([
77 #include <stdio.h>
78 #include <stdlib.h>
79 #include <string.h>
80
81 int
82 main ()
83 {
84  system ("touch conf.aspelltest");
85  if(strcmp("$aspell_version","$min_aspell_version")<0){
86    return 1;
87    }
88  return 0;
89 }
90         ],, no_aspell=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"])
91         rm -f conf.aspelltest
92         if test "x$no_aspell" = x ; then
93            AC_MSG_RESULT(yes)
94            AC_MSG_CHECKING(for GNU/aspell dictionaries location)
95            aspell_path="`$ASPELL config dict-dir`"
96            AC_DEFINE_UNQUOTED(ASPELL_PATH, "${aspell_path}/", Define ASPELL's default directory)
97            AC_MSG_RESULT($aspell_path)
98            AC_MSG_CHECKING(if GNU/aspell is correctly installed)
99            ac_save_CFLAGS="$CFLAGS"
100            ac_save_LIBS="$LIBS"
101            CFLAGS="$CFLAGS $ASPELL_CFLAGS"
102            LIBS="$LIBS $ASPELL_LIBS"
103            AC_TRY_RUN([
104 #include <stdio.h>
105 #include <stdlib.h>
106 #include <string.h>
107 #include <aspell.h>
108
109 int
110 main()
111 {
112  AspellConfig * aspellconfig = new_aspell_config();
113  return 0;
114 }
115            ],, aspell_failure=yes,)
116            rm -f conftest.c
117            CFLAGS="$ac_save_CFLAGS"
118            LIBS="$ac_save_LIBS"
119            if test "x$aspell_failure" = x ; then     
120               AC_MSG_RESULT(yes)
121               ifelse([$2], , :, [$2])
122            else
123               AC_MSG_RESULT(no)
124               echo "*** The GNU/aspell test program did not succeed. This usually means that "
125               echo "*** the headers and the libraries could not be found. Check config.log"
126               echo "*** for detailed error message and add the relevant options"
127               echo "*** --with-aspell-prefix, --with-aspell-includes or --with-aspell-libs"
128               echo "*** to the configure command."
129               echo "*** This can also mean that the library was not found at runtime. In that case"
130               echo "*** add its path to LD_LIBRARY_PATH environment variable or in /etc/ld.so.conf"
131               ASPELL_CFLAGS=""
132               ASPELL_LIBS=""
133               ASPELL_PATH=""
134               ifelse([$3], , :, [$3])
135            fi
136         else
137            AC_MSG_RESULT(no)
138            ASPELL_CFLAGS=""
139            ASPELL_LIBS=""
140            ASPELL_PATH=""
141            ifelse([$3], , :, [$3])
142         fi   
143      fi 
144   fi
145   AC_SUBST(ASPELL_CFLAGS)
146   AC_SUBST(ASPELL_LIBS)
147   AC_SUBST(ASPELL_PATH)
148 ])
149