Use pkg-config if available for checking libotf.
[m17n/m17n-lib.git] / configure.ac
1 dnl configure.ac -- autoconf script for the m17n library.
2
3 dnl Copyright (C) 2003, 2004, 2005, 2006
4 dnl   National Institute of Advanced Industrial Science and Technology (AIST)
5 dnl   Registration Number H15PRO112
6
7 dnl This file is part of the m17n library.
8
9 dnl The m17n library is free software; you can redistribute it and/or
10 dnl modify it under the terms of the GNU Lesser General Public License
11 dnl as published by the Free Software Foundation; either version 2.1 of
12 dnl the License, or (at your option) any later version.
13
14 dnl The m17n library is distributed in the hope that it will be useful,
15 dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
16 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 dnl Lesser General Public License for more details.
18
19 dnl You should have received a copy of the GNU Lesser General Public
20 dnl License along with the m17n library; if not, write to the Free
21 dnl Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
22 dnl 02111-1307, USA.
23
24 dnl Process this file with autoconf to produce a configure script.
25
26 AC_INIT(m17n-lib, 1.3.4, m17n-lib-bug@m17n.org)
27 AM_INIT_AUTOMAKE
28 AM_CONFIG_HEADER(src/config.h)
29 AM_MAINTAINER_MODE
30
31 API_VERSION=1:0:1
32 AC_SUBST(API_VERSION)
33
34 dnl Checks for programs for compiling.
35 AC_PROG_CC
36 AC_LIBTOOL_DLOPEN
37 AC_LIBLTDL_CONVENIENCE
38 AM_PROG_LIBTOOL
39
40 dnl Checks for X libraries.
41 AC_PATH_XTRA
42
43 dnl Checks for standard header files.
44 AC_HEADER_STDC
45 AC_HEADER_DIRENT
46 AC_HEADER_TIME
47 AC_CHECK_HEADERS([fcntl.h langinfo.h limits.h locale.h stdlib.h \
48                           string.h strings.h sys/time.h unistd.h])
49 AC_CHECK_HEADER(X11/Xaw/Command.h, HAVE_XAW=yes)
50
51 dnl Checks for typedefs, structures, and compiler characteristics.
52 AC_C_CONST
53 AC_C_INLINE
54 AC_TYPE_SIZE_T
55 AC_STRUCT_TM
56
57 dnl Checks for endian.  This influence the default UTF-16 definition.
58 AC_C_BIGENDIAN
59
60 dnl Checks for library functions.
61 AC_FUNC_ALLOCA
62 AC_FUNC_MALLOC
63 AC_FUNC_REALLOC
64 AC_FUNC_MEMCMP
65 AC_FUNC_STAT
66 AC_FUNC_STRCOLL
67 AC_FUNC_STRFTIME
68 AC_FUNC_STRTOD
69 AC_CHECK_FUNCS(memmove memset nl_langinfo putenv regcomp setlocale)
70 AC_CHECK_FUNCS(strchr strdup gettimeofday)
71
72 dnl Checks where the m17n database is installed.
73
74 AC_CHECK_PROG(HAVE_M17N_DB, m17n-db, yes)
75 if test "x$HAVE_M17N_DB" = "xyes"; then
76   M17NDIR=`m17n-db`
77 else
78   M17NDIR="${datadir}/m17n"
79 fi
80 AC_SUBST(M17NDIR)
81
82 dnl Checks which levels of APIs should be compiled.
83
84 AC_ARG_ENABLE(gui,
85               AC_HELP_STRING([--with-gui],
86                              [with GUI level APIs (default is YES)]))
87
88 AM_CONDITIONAL(WITH_GUI, test x$with_gui != xno)
89
90 if test x$with_gui != xno; then
91
92 dnl Checks if dlopen exists, and if it's in libc or libdl.
93
94 AC_SEARCH_LIBS(dlopen, dl,
95                AC_DEFINE(HAVE_DLOPEN, 1,
96                [Define to 1 if you have the function dlopen.]))
97
98 dnl Check several libraries without adding -lxxx to LIBS, without
99 dnl defining HAVE_LIBXXX nor HAVE_XXX_H because they are used only by
100 dnl some libraries (e.g. libm17n-X.so).  Instead, define XXX_LD_FLAGS
101 dnl and HAVE_XXX if library XXX is available.  CPPFLAGS will be
102 dnl augmented.
103
104 M17N_EXT_LIBS=
105
106 AC_CHECK_PROG(HAVE_PKG_CONFIG, pkg-config, yes)
107
108 if test "x$no_x" != "xyes"; then
109   AC_DEFINE(HAVE_X11, 1, [Define to 1 if you have X11.])
110   X11_LD_FLAGS="-lXt -lX11"
111   M17N_EXT_LIBS="$M17N_EXT_LIBS X11"
112
113   if test "x$HAVE_XAW" = "xyes"; then
114     AC_DEFINE(HAVE_X11_XAW_COMMAND_H, 1,
115               [Define to 1 if you have the Xaw header files.])
116     XAW_LD_FLAGS="-lXaw -lXmu"
117     CONFIG_FLAGS="$CONFIG_FLAGS -DHAVE_X11_XAW_COMMAND_H"
118     M17N_EXT_LIBS="$M17N_EXT_LIBS Xaw"
119   fi
120 fi
121 AC_SUBST(X11_LD_FLAGS)
122 AC_SUBST(XAW_LD_FLAGS)
123
124 dnl Check for fribidi library.
125 save_CPPFLAGS="$CPPFLAGS"
126 save_LIBS="$LIBS"
127 AC_CHECK_PROG(HAVE_FRIBIDI_CONFIG, fribidi-config, yes)
128 if test "x$HAVE_FRIBIDI_CONFIG" = "xyes"; then
129   CPPFLAGS="$CPPFLAGS `fribidi-config --cflags`"
130   FRIBIDI_LD_FLAGS="`fribidi-config --libs`"
131   LIBS="$LIBS $FRIBIDI_LD_FLAGS"
132 else
133   FRIBIDI_LD_FLAGS=-lfribidi
134 fi
135 AC_CHECK_LIB(fribidi, fribidi_set_mirroring, HAVE_FRIBIDI=yes, HAVE_FRIBIDI=no)
136 AC_CHECK_HEADER(fribidi/fribidi.h,, HAVE_FRIBIDI=no)
137 if test "x$HAVE_FRIBIDI" = "xyes"; then
138   AC_DEFINE(HAVE_FRIBIDI, 1, 
139             [Define to 1 if you have Fribidi library and header file.])
140   M17N_EXT_LIBS="$M17N_EXT_LIBS fribidi"
141 else
142   CPPFLAGS="$save_CPPFLAGS"
143   FRIBIDI_LD_FLAGS=
144 fi
145 LIBS="$save_LIBS"
146 AC_SUBST(FRIBIDI_LD_FLAGS)
147
148 dnl Check for otflib usability.
149 AC_ARG_WITH(libotf, 
150             AC_HELP_STRING([--with-libotf],
151                            [with OpenType font suport (default is YES)]))
152
153 if test "x$with_libotf" != "xno"; then
154   save_CPPFLAGS="$CPPFLAGS"
155   save_LIBS="$LIBS"
156   if test "x$HAVE_PKG_CONFIG" = "xyes" ; then
157     if pkg-config --exists libotf; then
158       HAVE_OTF=yes
159       CPPFLAGS="$CPPFLAGS `pkg-config --cflags libotf`"
160       OTF_LD_FLAGS="`pkg-config --libs libotf`"
161     else
162       HAVE_OTF=no
163     fi
164   else
165     AC_CHECK_PROG(HAVE_OTFLIB_CONFIG, libotf-config, yes)
166     if test "x$HAVE_OTFLIB_CONFIG" = "xyes"; then
167       CPPFLAGS="$CPPFLAGS `libotf-config --cflags`"
168       OTF_LD_FLAGS="`libotf-config --libs`"
169       LIBS="$LIBS $OTF_LD_FLAGS"
170     else
171      OTF_LD_FLAGS=-lotf
172     fi
173     ## We check the availability of OTF_check_features
174     ## because we need libotf-0.9.4 or the later.
175     AC_CHECK_LIB(otf, OTF_check_features, HAVE_OTF=yes, HAVE_OTF=no)
176     AC_CHECK_HEADER(otf.h,, HAVE_OTF=no)
177     if test "x$HAVE_OTF" = "xyes"; then
178       AC_DEFINE(HAVE_OTF, 1, 
179                 [Define to 1 if you have OTF library and header file.])
180     fi
181   fi
182   if test "x$HAVE_OTF" = "xyes"; then
183       M17N_EXT_LIBS="$M17N_EXT_LIBS libotf"
184   else
185     CPPFLAGS="$save_CPPFLAGS"
186     OTF_LD_FLAGS=
187   fi
188   LIBS="$save_LIBS"
189 fi
190 AC_SUBST(OTF_LD_FLAGS)
191
192 dnl Check for Freetype2 usability.
193 AC_CHECK_PROG(HAVE_FREETYPE_CONFIG, freetype-config, yes)
194 if test "x$HAVE_FREETYPE_CONFIG" = "xyes"; then
195   FREETYPE_INC=`freetype-config --cflags`
196   save_CPPFLAGS="$CPPFLAGS"
197   CPPFLAGS="$CPPFLAGS $FREETYPE_INC"
198   AC_CHECK_HEADER(ft2build.h, HAVE_FREETYPE=yes,
199                               HAVE_FREETYPE=no CPPFLAGS="$save_CPPFLAGS")
200   if test "x$HAVE_FREETYPE" = "xyes" ; then
201     save_LIBS="$LIBS"
202     LIBS="$LIBS `freetype-config --libs`"
203     AC_CHECK_LIB(freetype, FT_Init_FreeType, HAVE_FREETYPE=yes,
204                                              HAVE_FREETYPE=no)
205     LIBS="$save_LIBS"
206     if test "x$HAVE_FREETYPE" = "xyes"; then
207       FREETYPE_LD_FLAGS=`freetype-config --libs`
208       AC_DEFINE(HAVE_FREETYPE, 1, 
209                 [Define to 1 if you have FreeType library and header file.])
210       M17N_EXT_LIBS="$M17N_EXT_LIBS freetype"
211       AC_CHECK_HEADER(freetype/ftbdf.h, HAVE_FTBDF_H=yes, HAVE_FTBDF_H=no,
212                       [#include <ft2build.h>
213 #include FT_FREETYPE_H])
214       if test "x$HAVE_FTBDF_H" = "xyes"; then
215         AC_DEFINE(HAVE_FTBDF_H, 1,
216                   [Define to 1 if you have freetype/ftbdf.h.])
217       fi
218       CONFIG_FLAGS="$CONFIG_FLAGS -DHAVE_FREETYPE"
219     fi
220   fi
221 fi
222 AC_SUBST(FREETYPE_LD_FLAGS)
223
224 dnl Check for Xft2 usability.
225 save_CPPFLAGS="$CPPFLAGS"
226 save_LIBS="$LIBS"
227 XFT2_LD_FLAGS="-lXft -lfreetype -lfontconfig -lXrender -lX11"
228 AC_CHECK_PROG(HAVE_XFT_CONFIG, xft-config, yes)
229 if test "x$HAVE_XFT_CONFIG" = "xyes"; then
230   CPPFLAGS="$CPPFLAGS `xft-config --cflags`"
231   XFT2_LD_FLAGS="`xft-config --libs`"
232 elif test "x$HAVE_PKG_CONFIG" = "xyes" ; then
233   if pkg-config xft ; then
234     CPPFLAGS="$CPPFLAGS `pkg-config --cflags xft`"
235     XFT2_LD_FLAGS="`pkg-config --libs xft`"
236   fi
237 fi
238 LIBS="$LIBS $XFT2_LD_FLAGS"
239 AC_CHECK_LIB(Xft, XftDrawCreate, HAVE_XFT2=yes, HAVE_XFT2=no)
240 AC_CHECK_HEADER(X11/Xft/Xft.h,, HAVE_XFT2=no, 
241                 [#include <X11/Xft/Xft.h>
242 #if XftVersion >= 20000
243 #else
244 Version too old.  Compiling this line should fail.
245 #endif])
246 if test "x$HAVE_XFT2" = "xyes"; then
247   AC_DEFINE(HAVE_XFT2, 1,
248             [Define to 1 if you have Xft2 library and header file.])
249   M17N_EXT_LIBS="$M17N_EXT_LIBS xft2"
250 else
251   XFT2_LD_FLAGS=
252   CPPFLAGS="$save_CPPFLAGS"
253 fi
254 LIBS="$save_LIBS"
255 AC_SUBST(XFT2_LD_FLAGS)
256
257 dnl Check for fontconfig usability.
258 AC_ARG_WITH(fontconfig,
259             AC_HELP_STRING([--with-fontconfig],
260                            [with FontConfig library (default is YES)]))
261 if test "x$with_fontconfig" != "xno"; then
262   save_CPPFLAGS="$CPPFLAGS"
263   save_LIBS="$LIBS"
264   FONTCONFIG_LD_FLAGS=-lfontconfig
265   if test "x$HAVE_PKG_CONFIG" = "xyes"; then
266     if pkg-config --exists fontconfig; then
267       CPPFLAGS="$CPPFLAGS `pkg-config --cflags fontconfig`"
268       FONTCONFIG_LD_FLAGS="`pkg-config --libs fontconfig`"
269       LIBS="$LIBS $FONTCONFIG_LD_FLAGS"
270     fi
271   fi
272   AC_CHECK_LIB(fontconfig, FcInit, HAVE_FONTCONFIG=yes, HAVE_FONTCONFIG=no)
273   AC_CHECK_HEADER(fontconfig/fontconfig.h, , HAVE_FONTCONFIG=no)
274   if test "x$HAVE_FONTCONFIG" = "xyes"; then
275     AC_DEFINE(HAVE_FONTCONFIG, 1,
276               [Define to 1 if you have fontconfig library and header file.])
277     M17N_EXT_LIBS="$M17N_EXT_LIBS fontconfig"
278   else
279     FONTCONFIG_LD_FLAGS=
280     CPPFLAGS="$save_CPPFLAGS"
281   fi
282   LIBS="$save_LIBS"
283 fi
284 AC_SUBST(FONTCONFIG_LD_FLAGS)
285
286 dnl Check for gdlib usability.
287 AC_ARG_WITH(gd, 
288             AC_HELP_STRING([--with-gd],
289                            [suport graphic device by GD library (default is YES)]))
290
291 if test "x$with_gd" != "xno"; then
292   save_LIBS="$LIBS"
293   AC_CHECK_LIB(gd, gdImageCreate, HAVE_GD=yes, HAVE_GD=no)
294   AC_CHECK_HEADER(gd.h, , HAVE_GD=no)
295   if test "x$HAVE_GD" = "xyes"; then
296     AC_CHECK_LIB(gd, gdImageCreateTrueColor, HAVE_GD=2, HAVE_GD=1)
297     AC_DEFINE_UNQUOTED(HAVE_GD, $HAVE_GD,
298               [Define to 1 or 2 if you have gd library and header file.])
299     M17N_EXT_LIBS="$M17N_EXT_LIBS gdlib"
300     GD_LD_FLAGS=-lgd
301     CONFIG_FLAGS="$CONFIG_FLAGS -DHAVE_GD=$HAVE_GD"
302   fi
303   LIBS="$save_LIBS"
304 fi
305 AC_SUBST(GD_LD_FLAGS)
306
307 fi
308
309 dnl Check for libxml2 usability.
310 save_CPPFLAGS="$CPPFLAGS"
311 save_LIBS="$LIBS"
312 AC_CHECK_PROG(HAVE_XML2_CONFIG, xml2-config, yes)
313 if test "x$HAVE_XML2_CONFIG" = "xyes"; then
314   CPPFLAGS="$CPPFLAGS `xml2-config --cflags`"
315   XML2_LD_FLAGS="`xml2-config --libs`"
316   LIBS="$LIBS $XML2_LD_FLAGS"
317 else
318   CPPFLAGS="$CPPFLAGS -I/usr/include/libxml2"
319   XML2_LD_FLAGS="-lxml2 -lz -lpthread -lm"
320 fi
321 AC_CHECK_LIB(xml2, xmlParseMemory, HAVE_XML2=yes, HAVE_XML2=no)
322 AC_CHECK_HEADER(libxml/tree.h,, HAVE_XML2=no, /**/)
323 if test "x$HAVE_XML2" = "xyes"; then
324   AC_DEFINE(HAVE_XML2, 1,
325             [Define to 1 if you have libxml2 library and header file])
326   M17N_EXT_LIBS="$M17N_EXT_LIBS xml2"
327 else
328   XML2_LD_FLAGS=
329   CPPFLAGS="$save_CPPFLAGS"
330 fi
331 LIBS="$save_LIBS"
332 AC_SUBST(XML2_LD_FLAGS)
333
334 dnl Check for Anthy usability.
335 AC_CHECK_LIB(anthydic, anthy_init_sessions, HAVE_ANTHY=yes, HAVE_ANTHY=no)
336 if test "x$HAVE_ANTHY" = "xyes"; then
337   AC_CHECK_LIB(anthy, anthy_init, HAVE_ANTHY=yes, HAVE_ANTHY=no, -lanthydic)
338   if test "x$HAVE_ANTHY" = "xyes"; then
339     AC_CHECK_HEADER(anthy/anthy.h, HAVE_ANTHY=yes, HAVE_ANTHY=no)
340     if test "x$HAVE_ANTHY" = "xyes"; then
341       AC_DEFINE(HAVE_ANTHY, 1,
342                 [Define to 1 if you have Anthy library and header file])
343       M17N_EXT_LIBS="$M17N_EXT_LIBS anthy"
344       ANTHY_LD_FLAGS="-lanthy -lanthydic"
345       CONFIG_FLAGS="$CONFIG_FLAGS -DHAVE_ANTHY"
346     fi
347   fi
348 fi
349 AC_SUBST(ANTHY_LD_FLAGS)
350
351 dnl Check for Ispell usability.
352 AC_CHECK_PROG(HAVE_ISPELL, ispell, yes)
353 if test "x$HAVE_ISPELL" = "xyes"; then
354   AC_DEFINE(HAVE_ISPELL, 1, [Define if ispell is available.])
355   M17N_EXT_LIBS="$M17N_EXT_LIBS ispell"
356   CONFIG_FLAGS="$CONFIG_FLAGS -DHAVE_ISPELL"
357 fi
358
359 dnl Check for Thai word-segmentation library.
360 dnl If we have one, define HAVE_THAI_WORDSEG and one of these:
361 dnl   HAVE_LIBTHAI, HAVE_WORDCUT, or HAVE_WORDCUT_OLD
362 dnl In addition, set THAI_WORDSEG_LD_FLAGS to a proper value.
363
364 PKG_CHECK_MODULES(LIBTHAI, libthai, HAVE_LIBTHAI=yes, HAVE_LIBTHAI=no)
365 PKG_CHECK_MODULES(WORDCUT, wordcut, HAVE_WORDCUT=yes, HAVE_WORDCUT=no)
366
367 if test "x$HAVE_LIBTHAI" == "xyes"; then
368
369   AC_DEFINE(HAVE_LIBTHAI, 1, [Define if you have libthai])
370   THAI_WORDSEG_LD_FLAGS="$LIBTHAI_LIBS"
371   M17N_EXT_LIBS="$M17N_EXT_LIBS libthai"
372   HAVE_THAI_WORDSEG=yes
373
374 elif test "x$HAVE_WORDCUT" = "xyes"; then
375
376   save_CPPFLAGS="$CPPFLAGS"
377   CPPFLAGS="$CPPFLAGS $WORDCUT_CFLAGS"
378   AC_TRY_CPP([#include <wordcut/wcwordcut.h>], , HAVE_WORDCUT=no)
379   if test "x$HAVE_WORDCUT" = "xno"; then
380     PKG_CHECK_MODULES(GLIB_2_0, glib-2.0, HAVE_GLIB_2_0=yes, HAVE_GLIB_2_0=no)
381     if test "x$HAVE_GLIB_2_0" = "xyes"; then
382       CPPFLAGS="$CPPFLAGS $GLIB_2_0_CFLAGS"
383       AC_TRY_CPP([#include <wordcut/wcwordcut.h>], HAVE_WORDCUT=yes)
384     fi
385   fi
386   if test "x$HAVE_WORDCUT" = "xyes"; then
387     THAI_WORDSEG_LD_FLAGS="$WORDCUT_LIBS"
388     AC_DEFINE(HAVE_WORDCUT, 1,
389               [Define if you have the wordcut library and header file])
390     M17N_EXT_LIBS="$M17N_EXT_LIBS wordcut"
391     HAVE_THAI_WORDSEG=yes
392   else
393     CPPFLAGS="$save_CPPFLAGS"
394   fi
395
396 else
397
398   AC_CHECK_LIB(wordcut, wordcut_init, HAVE_WORDCUT_OLD=yes)
399   if test "x$HAVE_WORDCUT_OLD" = "xyes"; then
400     if test -f "/usr/share/wordcut/tdict.wcd"; then
401       tdict="/usr/share/wordcut/tdict.wcd"
402     elif test -f "/usr/local/share/wordcut/tdict.wcd"; then
403       tdict="/usr/local/share/wordcut/tdict.wcd"
404     fi
405     echo "TDICT=$tdict"
406     if test "x$tdict" != "x"; then
407       AC_DEFINE(HAVE_WORDCUT_OLD, 1,
408                 [Define if you have the old version of wordcut library])
409       AC_DEFINE_UNQUOTED(WORDCUT_TDICT, "$tdict", [Define tdict file name])
410       THAI_WORDSEG_LD_FLAGS=-lwordcut
411       M17N_EXT_LIBS="$M17N_EXT_LIBS wordcut-old"
412       HAVE_THAI_WORDSEG=yes
413     else
414       HAVE_WORDCUT=no
415     fi
416   fi
417 fi  
418
419 if test "x$HAVE_THAI_WORDSEG" = "xyes"; then
420   AC_DEFINE(HAVE_THAI_WORDSEG, 1,
421             [Define if you have some Thai word-segmentation library])
422 fi
423 AC_SUBST(THAI_WORDSEG_LD_FLAGS)
424
425 AC_SUBST(CONFIG_FLAGS)
426
427 dnl We can't include X_CFLAGS in AM_CPPFLAGS because the generated
428 dnl Makefile put ${AM_CPPFLAGS} before ${CPPFLAGS} and that leads to
429 dnl inclusion of an incorrect header file.  So, append X_CFLAGS to
430 dnl CPPFLAGS here directly.
431
432 CPPFLAGS="$CPPFLAGS $X_CFLAGS"
433
434 dnl AC_ARG_ENABLE(xom, 
435 dnl           [  --enable-xom            build and install XOM library.],
436 dnl           XOM="$enableval")
437
438 SHLIB_EXT=".so"
439 case $host_os in
440 darwin* | rhapsody*)
441   SHLIB_EXT=".dylib";;
442 esac
443 AC_DEFINE_UNQUOTED(DLOPEN_SHLIB_EXT, "$SHLIB_EXT",
444                    [Define to loadable module extention])
445
446 AC_CONFIG_FILES([Makefile
447                  src/Makefile
448                  example/Makefile
449                  m17n-config
450                  m17n-core.pc
451                  m17n-shell.pc
452                  m17n-gui.pc
453                  ])
454
455 dnl if test "x$XOM" = "xyes"; then
456 dnl  AC_CONFIG_FILES(omM17N/Makefile)
457 dnl fi
458
459 AC_OUTPUT
460
461 echo "The m17n library is configured with these external libraries."
462 echo " $M17N_EXT_LIBS"
463
464 dnl Local Variables:
465 dnl comment-start: "dnl "
466 dnl comment-end: ""
467 dnl comment-start-skip: "\\bdnl\\b\\s *"
468 dnl End: