Make sure EOF is defined
[xapian.git] / xapian-core / m4-macros / xapian-1.5.m4
blobabc9735d7f8dbb8405cbd6a8d98d7e0a659af6fc
1 # Get XAPIAN_CXXFLAGS, XAPIAN_LIBS, and XAPIAN_VERSION from xapian-config and
2 # AC_SUBST() them.
4 # serial 17
6 # AC_PROVIDE_IFELSE(MACRO-NAME, IF-PROVIDED, IF-NOT-PROVIDED)
7 # -----------------------------------------------------------
8 # If this macro is not defined by Autoconf, define it here.
9 m4_ifdef([AC_PROVIDE_IFELSE],
10          [],
11          [m4_define([AC_PROVIDE_IFELSE],
12                  [m4_ifdef([AC_PROVIDE_$1],
13                            [$2], [$3])])])
15 # XO_LIB_XAPIAN([ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND[ ,XAPIAN-CONFIG]]])
16 # --------------------------------------------------------
17 # AC_SUBST-s XAPIAN_CXXFLAGS, XAPIAN_LIBS, and XAPIAN_VERSION for use in
18 # Makefile.am
20 # If ACTION-IF-FOUND and ACTION-IF-NOT-FOUND are both unset, then an
21 # appropriate AC_MSG_ERROR is used as a default ACTION-IF-NOT-FOUND.
22 # This allows XO_LIB_XAPIAN to be used without any arguments in the
23 # common case where Xapian is a requirement (rather than optional).
25 # XAPIAN-CONFIG provides the default name for the xapian-config script
26 # (which the user can override with "./configure XAPIAN_CONFIG=/path/to/it").
27 # If unset, the default is xapian-config.  Support for this third parameter
28 # was added in Xapian 1.1.3.
29 AC_DEFUN([XO_LIB_XAPIAN],
31   AC_ARG_VAR(XAPIAN_CONFIG, [Location of xapian-config (default:] ifelse([$3], [], xapian-config, [$3]) [on PATH)])
32   dnl AC_PATH_PROG ignores an existing user setting of XAPIAN_CONFIG unless it
33   dnl has a full path, so add special handling for such cases.
34   xapian_config_to_check_for="ifelse([$3], [], xapian-config, [$3])"
35   case $XAPIAN_CONFIG in
36   "") ;;
37   */configure)
38     AC_MSG_ERROR([XAPIAN_CONFIG should point to a xapian-config script, not a configure script.])
39     ;;
40   [[\\/]* | ?:[\\/]*)]
41     # XAPIAN_CONFIG has an absolute path, so AC_PATH_PROG can handle it.
42     ;;
43   [*[\\/]?*)]
44     # Convert a relative path to an absolute one.
45     XAPIAN_CONFIG=`pwd`/$XAPIAN_CONFIG
46     ;;
47   *)
48     # If there's no path on XAPIAN_CONFIG, use it as the name of the tool to
49     # search PATH for, so that things like this work:
50     #   ./configure XAPIAN_CONFIG=xapian-config-1.3
51     xapian_config_to_check_for=$XAPIAN_CONFIG
52     XAPIAN_CONFIG=
53     ;;
54   esac
55   AC_PATH_PROG(XAPIAN_CONFIG, "$xapian_config_to_check_for")
56   if test -z "$XAPIAN_CONFIG"; then
57     ifelse([$2], ,
58       [ifelse([$1], , [
59         dnl Simple check to see if the problem is likely to
60         dnl be that we're using a "packaged" xapian-core but
61         dnl only have the runtime package installed.
62         for sfx in '' 32 64 ; do
63           set /usr/lib$sfx/libxapian.so.*
64           if test "/usr/lib$sfx/libxapian.so.*" != "$1" ; then
65             if test -r /etc/debian_version ; then
66               pkg="libxapian-dev"
67             else
68               pkg="xapian-core-devel"
69             fi
70             AC_MSG_ERROR([Can't find xapian-config, although the xapian-core runtime library seems to be installed.  If you've installed xapian-core from a package, you probably need to install an extra package called something like $pkg in order to be able to build code using the Xapian library.])
71           fi
72         done
73         AC_MSG_ERROR([Can't find xapian-config.  If you have installed the Xapian library, you need to add XAPIAN_CONFIG=/path/to/xapian-config to your configure command.])],
74         :)],
75       [$2])
76   else
77     AC_MSG_CHECKING([$XAPIAN_CONFIG works])
78     dnl check for --ltlibs but not --libs as "xapian-config --libs" will
79     dnl fail if xapian isn't installed...
81     dnl run with exec to avoid leaking output on "real" bourne shells
82     if (exec >&5 2>&5 ; $XAPIAN_CONFIG --ltlibs --cxxflags; exit $?) then
83       AC_MSG_RESULT(yes)
84     else
85       case $? in
86       127)
87         AC_MSG_ERROR(['$XAPIAN_CONFIG' not found, aborting])
88         ;;
89       126)
90         if test -d "$XAPIAN_CONFIG" ; then
91           AC_MSG_ERROR(['$XAPIAN_CONFIG' is a directory; it should be the filename of the xapian-config script])
92         fi
93         AC_MSG_ERROR(['$XAPIAN_CONFIG' not executable, aborting])
94         ;;
95       esac
96       AC_MSG_ERROR(['$XAPIAN_CONFIG --ltlibs --cxxflags' doesn't work, aborting])
97     fi
99 dnl If LT_INIT, AC_PROG_LIBTOOL or the deprecated older version
100 dnl AM_PROG_LIBTOOL has already been expanded, enable libtool support now.
101 dnl Otherwise add hooks to the end of LT_INIT, AC_PROG_LIBTOOL and
102 dnl AM_PROG_LIBTOOL to enable it if one of these is expanded later.
103     XAPIAN_VERSION=`$XAPIAN_CONFIG --version|sed 's/.* //;s/_.*$//'`
104     XAPIAN_CXXFLAGS=`$XAPIAN_CONFIG --cxxflags`
105     AC_PROVIDE_IFELSE([LT_INIT],
106       [XAPIAN_LIBS=`$XAPIAN_CONFIG --ltlibs`],
107       [AC_PROVIDE_IFELSE([AC_PROG_LIBTOOL],
108         [XAPIAN_LIBS=`$XAPIAN_CONFIG --ltlibs`],
109         [AC_PROVIDE_IFELSE([AM_PROG_LIBTOOL],
110           [XAPIAN_LIBS=`$XAPIAN_CONFIG --ltlibs`],
111           dnl Pass magic option so xapian-config knows we called it (so it
112           dnl can choose a more appropriate error message if asked to link
113           dnl with an uninstalled libxapian).  Also pass ac_top_srcdir
114           dnl so the error message can correctly say "configure.ac" or
115           dnl "configure.in" according to which is in use.
116           [XAPIAN_LIBS=`ac_top_srcdir="$ac_top_srcdir" $XAPIAN_CONFIG --from-xo-lib-xapian --libs`
117           m4_ifdef([LT_INIT],
118             [m4_define([LT_INIT], m4_defn([LT_INIT])
119                    [XAPIAN_LIBS=`$XAPIAN_CONFIG --ltlibs`])])
120           m4_ifdef([AC_PROG_LIBTOOL],
121             [m4_define([AC_PROG_LIBTOOL], m4_defn([AC_PROG_LIBTOOL])
122                  [XAPIAN_LIBS=`$XAPIAN_CONFIG --ltlibs`])])
123           m4_ifdef([AM_PROG_LIBTOOL],
124             [m4_define([AM_PROG_LIBTOOL], m4_defn([AM_PROG_LIBTOOL])
125                  [XAPIAN_LIBS=`$XAPIAN_CONFIG --ltlibs`])])])])])
126     ifelse([$1], , :, [$1])
127   fi
128   AC_SUBST(XAPIAN_CXXFLAGS)
129   AC_SUBST(XAPIAN_LIBS)
130   AC_SUBST(XAPIAN_VERSION)
131   m4_define([XO_LIB_XAPIAN_EXPANDED_], [])
134 # XO_REQUIRE(VERSION[, ACTION-IF-LESS-THAN[, ACTION-IF-GREATHER-THAN-OR-EQUAL]])
135 # --------------------------------------------------------
136 # Check if $XAPIAN_VERSION is at least VERSION.  This macro should
137 # be used after XO_LIB_XAPIAN.
139 # If ACTION-IF-LESS-THAN is unset, it defaults to an
140 # appropriate AC_MSG_ERROR saying that Xapian >= VERSION is needed.
142 # If ACTION-IF-GREATHER-THAN-OR-EQUAL is unset, the default is no
143 # addtional action.
144 AC_DEFUN([XO_REQUIRE],
146   m4_ifndef([XO_LIB_XAPIAN_EXPANDED_],
147       [m4_fatal([XO_REQUIRE can only be used after XO_LIB_XAPIAN])])
148 dnl [Version component '$v' is not a number]
149   AC_MSG_CHECKING([if $XAPIAN_CONFIG version >= $1])
150   old_IFS=$IFS
151   IFS=.
152   set x `echo "$XAPIAN_VERSION"|sed 's/_.*//'`
153   IFS=$old_IFS
154   res=
155   m4_foreach([min_component], m4_split([$1], [\.]), [
156 ifelse(regexp(min_component, [^[0-9][0-9]*$]), [-1], [m4_fatal(Component `min_component' not numeric)])dnl
157   if test -z "$res" ; then
158     shift
159     if test "$[]1" -gt 'min_component' ; then
160       res=1
161     elif test "$[]1" -lt 'min_component' ; then
162       res=0
163     fi
164   fi])
165   if test "$res" = 0 ; then
166     AC_MSG_RESULT([no ($XAPIAN_VERSION)])
167     m4_default([$2], [AC_ERROR([XAPIAN_VERSION is $XAPIAN_VERSION, but >= $1 required])])
168   else
169     AC_MSG_RESULT([yes ($XAPIAN_VERSION)])
170     $3
171   fi