1dnl
2dnl $ Id: $
3dnl
4
5PHP_ARG_WITH(mecab, [whether to enable MeCab support],
6[  --with-mecab[[=PATH]]     Enable MeCab support.
7                          PATH is the optional pathname to mecab-config], yes, yes)
8
9if test "$PHP_MECAB" != "no"; then
10
11  if test -z "$AWK"; then
12    AC_PATH_PROGS(AWK, awk gawk nawk, [no])
13  fi
14  if test -z "$SED"; then
15    AC_PATH_PROGS(SED, sed gsed, [no])
16  fi
17
18  dnl
19  dnl Check the location of mecab-config
20  dnl
21  if test "$PHP_MECAB" != "yes"; then
22    AC_MSG_CHECKING([for mecab-config])
23    if test -f "$PHP_MECAB"; then
24      MECAB_CONFIG="$PHP_MECAB"
25    elif test -f "$PHP_MECAB/mecab-config"; then
26      MECAB_CONFIG="$PHP_MECAB/mecab-config"
27    elif test -f "$PHP_MECAB/bin/mecab-config"; then
28      MECAB_CONFIG="$PHP_MECAB/bin/mecab-config"
29    else
30      AC_MSG_ERROR([not found])
31    fi
32    AC_MSG_RESULT([$MECAB_CONFIG])
33  else
34    AC_PATH_PROGS(MECAB_CONFIG, mecab-config, [])
35    if test -z "$MECAB_CONFIG"; then
36      AC_MSG_ERROR([mecab-config not found])
37    fi
38  fi
39
40  dnl
41  dnl Get the version number, CFLAGS and LIBS by mecab-config
42  dnl
43  AC_MSG_CHECKING([for MeCab library version])
44
45  MECAB_VERSION_STRING=`$MECAB_CONFIG --version 2> /dev/null`
46  MECAB_CFLAGS=`$MECAB_CONFIG --cflags 2> /dev/null`
47  MECAB_LIBS=`$MECAB_CONFIG --libs 2> /dev/null`
48
49  if test -z "$MECAB_VERSION_STRING"; then
50    AC_MSG_ERROR([invalid mecab-config passed to --with-mecab])
51  fi
52
53  MECAB_VERSION_NUMBER=`echo $MECAB_VERSION_STRING | $AWK -F. '{ printf "%d", $1 * 1000 + $2 }'`
54
55  if test "$MECAB_VERSION_NUMBER" -ne 99 -a "$MECAB_VERSION_NUMBER" -lt 99; then
56    AC_MSG_RESULT([$MECAB_VERSION_STRING])
57    AC_MSG_ERROR([MeCab version 0.99 or later is required to compile php with MeCab support])
58  fi
59
60  AC_DEFINE_UNQUOTED(PHP_MECAB_VERSION_NUMBER, $MECAB_VERSION_NUMBER, [MeCab library version number])
61  AC_DEFINE_UNQUOTED(PHP_MECAB_VERSION_STRING, "$MECAB_VERSION_STRING", [MeCab library version string])
62  AC_MSG_RESULT([$MECAB_VERSION_STRING (ok)])
63
64  dnl
65  dnl Check the headers and types
66  dnl
67  export OLD_CPPFLAGS="$CPPFLAGS"
68  export CPPFLAGS="$CPPFLAGS $MECAB_CFLAGS"
69  AC_CHECK_HEADER([mecab.h], [], AC_MSG_ERROR([mecab.h header not found]))
70  export CPPFLAGS="$OLD_CPPFLAGS"
71
72  dnl
73  dnl Check the library
74  dnl
75  export OLD_LIBS="$LIBS"
76  export LIBS="$OLD_LIBS -lpthread"
77  PHP_CHECK_LIBRARY(mecab, mecab_new2,
78    [
79      PHP_EVAL_INCLINE($MECAB_CFLAGS)
80      PHP_EVAL_LIBLINE($MECAB_LIBS, MECAB_SHARED_LIBADD)
81    ],[
82      AC_MSG_ERROR([wrong MeCab library version or lib not found. Check config.log for more information])
83    ],[
84      $MECAB_LIBS
85    ])
86  export LIBS="$OLD_LIBS"
87
88  PHP_SUBST(MECAB_SHARED_LIBADD)
89  PHP_MECAB_PHP_VERSION=`$PHP_CONFIG --version 2>/dev/null`
90  PHP_MECAB_PHP_VERNUM=`$PHP_CONFIG --vernum 2>/dev/null`
91  AC_MSG_CHECKING([for PHP version])
92  AC_MSG_RESULT([build for $PHP_MECAB_PHP_VERSION])
93  if test "$PHP_MECAB_PHP_VERNUM" -ge 70000; then
94    PHP_NEW_EXTENSION(mecab, mecab7.c , $ext_shared)
95  else
96    PHP_NEW_EXTENSION(mecab, mecab5.c , $ext_shared)
97  fi
98fi
99