pspell autoconf support
[claws.git] / ac / pspell.m4
1 dnl Autoconf macros for libpspell
2 dnl $Id$
3
4 # Configure paths for PSPELL
5 # Shamelessly stolen from the one of GPGME by Werner Koch 
6 # Melvin Hadasht  2001-09-17
7
8 dnl AM_PATH_PSPELL([MINIMUM-VERSION,
9 dnl               [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND ]]])
10 dnl Test for pspell, and define PSPELL_CFLAGS and PSPELL_LIBS
11 dnl
12 AC_DEFUN(AM_PATH_PSPELL,
13 [dnl
14 dnl Get the cflags and libraries from the pspell-config script
15 dnl
16   AC_ARG_WITH(pspell-prefix,
17    [  --with-pspell-prefix=PFX           Prefix where pspell-config is installed (optional)],
18           pspell_config_prefix="$withval", pspell_config_prefix="")
19   AC_ARG_ENABLE(pspelltest,
20    [  --disable-pspelltest               Do not try to compile and run a test pspell program],
21           , enable_pspelltest=yes)
22   AC_ARG_WITH(pspelllibs,
23    [  --with-pspell-libs=LIBS            Where pspell library reside (/usr/local/lib)],
24           pspell_libs=$pspelllibs, pspell_libs='/usr/local/lib')
25   AC_ARG_WITH(pspellincludes,
26    [  --with-pspell-includes=INCLUDES    Where pspell headers reside (/usr/local/include)],
27           pspell_includes=$pspelllibs, pspell_includes='/usr/local/include')
28
29
30   if test x$pspell_config_prefix != x ; then
31      if test x${PSPELL_CONFIG+set} != xset ; then
32         PSPELL_CONFIG=$pspell_config_prefix/bin/pspell-config
33      fi
34   fi
35
36   AC_PATH_PROG(PSPELL_CONFIG, pspell-config, no)
37   min_pspell_version=ifelse([$1], ,.12.2,$1)
38   AC_MSG_CHECKING(for pspell - version >= $min_pspell_version)
39   no_pspell=""
40   if test "$PSPELL_CONFIG" = "no" ; then
41     no_pspell=yes
42   else
43     PSPELL_CFLAGS="-I$pspell_includes"
44     PSPELL_LIBS="-L$pspell_libs -lpspell"
45     pspell_config_version=`$PSPELL_CONFIG version`
46     PSPELL_PATH=`$PSPELL_CONFIG pkgdatadir`
47     if test "x$enable_pspelltest" = "xyes" ; then
48       ac_save_CFLAGS="$CFLAGS"
49       ac_save_LIBS="$LIBS"
50       CFLAGS="$CFLAGS $PSPELL_CFLAGS"
51       LIBS="$LIBS $PSPELL_LIBS"
52 dnl
53 dnl 
54 dnl
55       rm -f conf.pspelltest
56       AC_TRY_RUN([
57 #include <stdio.h>
58 #include <stdlib.h>
59 #include <string.h>
60 #include <pspell/pspell.h>
61
62 int
63 main ()
64 {
65  system ("touch conf.pspelltest");
66  if(strcmp("$pspell_config_version","$min_pspell_version")<0){
67    printf("no\n");
68    return 1;
69    }
70  return 0;
71 }
72 ],, no_pspell=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"])
73        CFLAGS="$ac_save_CFLAGS"
74        LIBS="$ac_save_LIBS"
75      fi
76   fi
77   if test "x$no_pspell" = x ; then
78      AC_MSG_RESULT(yes)
79      ifelse([$2], , :, [$2])
80   else
81      if test -f conf.pspelltest ; then
82         :
83      else
84         AC_MSG_RESULT(no)
85      fi
86      if test "$PSPELL_CONFIG" = "no" ; then
87        echo "*** The pspell-config script installed by pspell could not be found"
88        echo "*** If pspell was installed in PREFIX, make sure PREFIX/bin is in"
89        echo "*** your path, or set the PSPELL_CONFIG environment variable to the"
90        echo "*** full path to pspell-config."
91      else
92        if test -f conf.pspelltest ; then
93         :
94        else
95           echo "*** Could not run pspell test program, checking why..."
96           CFLAGS="$CFLAGS $PSPELL_CFLAGS"
97           LIBS="$LIBS $PSPELL_LIBS"
98           AC_TRY_LINK([
99 #include <stdio.h>
100 #include <stdlib.h>
101 #include <string.h>
102 #include <pspell/pspell.h>
103 ],      [ PspellConfig * pspellconfig= new_pspell_config(); return 0 ],
104         [ 
105 echo "*** The test program compiled, but did not run. This usually means"
106 echo "*** that the run-time linker is not finding pspell or finding the wrong"
107 echo "*** version of pspell. If it is not finding pspell, you'll need to set your"
108 echo "*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point"
109 echo "*** to the installed location  Also, make sure you have run ldconfig if"
110 echo "*** that is required on your system"
111 echo "***"
112 echo "*** If you have an old version installed, it is best to remove it,"
113 echo "*** although you may also be able to get things to work by"
114 echo "*** modifying LD_LIBRARY_PATH"
115 echo "***"
116         ],
117         [
118 echo "*** The test program failed to compile or link. See the file config.log"
119 echo "*** for the exact error that occured. This usually means pspell was"
120 echo "*** incorrectly installed or that you have moved pspell since it was"
121 echo "*** installed. In the latter case, you may want to edit the"
122 echo "*** pspell-config script: $PSPELL_CONFIG" 
123         ])
124           CFLAGS="$ac_save_CFLAGS"
125           LIBS="$ac_save_LIBS"
126        fi
127      fi
128      PSPELL_CFLAGS=""
129      PSPELL_LIBS=""
130      ifelse([$3], , :, [$3])
131   fi
132   AC_SUBST(PSPELL_CFLAGS)
133   AC_SUBST(PSPELL_LIBS)
134   AC_SUBST(PSPELL_PATH)
135   rm -f conf.pspelltest
136 ])
137