merged GNU_aspell_branch
[claws.git] / ac / 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 and ASPELL_LIBS
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   fi
40   if test x$aspell_includes == x ; then
41      aspell_includes=/usr/local/include
42   fi
43   if test x$aspell_libs == x ; then
44      aspell_libs=/usr/local/lib
45   fi
46   AC_PATH_PROG(ASPELL, aspell, no)
47   min_aspell_version=ifelse([$1], ,.50,$1)
48   AC_MSG_CHECKING(for GNU/aspell - version >= $min_aspell_version)
49   no_aspell=""
50   if test "$ASPELL" = "no" ; then
51     no_aspell=yes
52   else
53     ASPELL_CFLAGS="-I$aspell_includes"
54     ASPELL_LIBS="-L$aspell_libs -laspell"
55     aspell_version=`$ASPELL version|sed -e "s/\(@(#) International Ispell Version 3.1.20 (but really Aspell \)\(.*\))/\2/"`
56     if test "x$enable_aspelltest" = "xyes" ; then
57       ac_save_CFLAGS="$CFLAGS"
58       ac_save_LIBS="$LIBS"
59       CFLAGS="$CFLAGS $ASPELL_CFLAGS"
60       LIBS="$LIBS $ASPELL_LIBS"
61 dnl
62 dnl 
63 dnl
64       rm -f conf.aspelltest
65       AC_TRY_RUN([
66 #include <stdio.h>
67 #include <stdlib.h>
68 #include <string.h>
69 #include <aspell.h>
70
71 int
72 main ()
73 {
74  system ("touch conf.aspelltest");
75  if(strcmp("$aspell_version","$min_aspell_version")<0){
76    printf("no\n");
77    return 1;
78    }
79  return 0;
80 }
81 ],, no_aspell=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"])
82        CFLAGS="$ac_save_CFLAGS"
83        LIBS="$ac_save_LIBS"
84      fi
85   fi
86   if test "x$no_aspell" = x ; then
87      AC_MSG_RESULT(yes)
88      ifelse([$2], , :, [$2])
89   else
90      if test -f conf.aspelltest ; then
91         :
92      else
93         AC_MSG_RESULT(no)
94      fi
95      if test "$ASPELL" = "no" ; then
96        echo "*** The aspell executable could not be found"
97        echo "*** If aspell was installed in PREFIX, make sure PREFIX/bin is in"
98        echo "*** your path, or set the ASPELL environment variable to the"
99        echo "*** full path to aspell."
100      else
101        if test -f conf.aspelltest ; then
102         :
103        else
104           echo "*** Could not run aspell test program, checking why..."
105           CFLAGS="$CFLAGS $ASPELL_CFLAGS"
106           LIBS="$LIBS $ASPELL_LIBS"
107           AC_TRY_LINK([
108 #include <stdio.h>
109 #include <stdlib.h>
110 #include <string.h>
111 #include <aspell.h>
112 ],      [ AspellConfig * aspellconfig= new_aspell_config(); return 0 ],
113         [ 
114 echo "*** The test program compiled, but did not run. This usually means"
115 echo "*** that the run-time linker is not finding GNU/aspell or finding the wrong"
116 echo "*** version of GNU/aspell. If it is not finding GNU/aspell, you'll need to set"
117 echo "*** your LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point"
118 echo "*** to the installed location  Also, make sure you have run ldconfig if"
119 echo "*** that is required on your system"
120 echo "***"
121 echo "*** If you have an old version installed, it is best to remove it,"
122 echo "*** although you may also be able to get things to work by"
123 echo "*** modifying LD_LIBRARY_PATH"
124 echo "***"
125         ],
126         [
127 echo "*** The test program failed to compile or link. See the file config.log"
128 echo "*** for the exact error that occured. This usually means GNU/aspell was"
129 echo "*** incorrectly installed or that you have moved GNU/aspell since it was"
130 echo "*** installed. "
131         ])
132           CFLAGS="$ac_save_CFLAGS"
133           LIBS="$ac_save_LIBS"
134        fi
135      fi
136      ASPELL_CFLAGS=""
137      ASPELL_LIBS=""
138      ifelse([$3], , :, [$3])
139   fi
140   AC_SUBST(ASPELL_CFLAGS)
141   AC_SUBST(ASPELL_LIBS)
142   rm -f conf.aspelltest
143 ])
144