Support: quest -f cjk_ngram
[xapian.git] / xapian-core / xapian-config.in
blobcff4a9630d48ad6cb2d182ccb72a020caf5296d9
1 #!/bin/sh
2 # @configure_input@
4 # Copyright (C) 2002,2003,2004,2005,2006,2007,2009,2010,2012,2014,2015 Olly Betts
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License as
8 # published by the Free Software Foundation; either version 2 of the
9 # License, or (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
19 # USA
21 PROG_NAME=xapian-config
22 PROG_DESC="report information about the installed version of xapian"
24 # ${prefix} and ${exec_prefix} are used in some @-substitutions, and
25 # ${prefix} is usually used in the exec_prefix @-substitution.
26 prefix="@prefix@"
27 exec_prefix="@exec_prefix@"
29 # Show usage information and exit with the specified exit status.
30 show_usage() {
31 cat <<EOF
32 Usage: $PROG_NAME OPTION...
34 Options:
35 --cxxflags output all preprocessor and C++ compiler flags
36 --libs output all linker flags
37 --ltlibs output linker flags for linking using GNU libtool
38 --static make other options report values for static linking
39 --swigflags output preprocessor flags for use with SWIG
40 --help output this help and exit
41 --version output version information and exit
43 Report bugs to <@PACKAGE_BUGREPORT@>.
44 EOF
46 exit "$1"
49 # This script requires at least one argument.
50 [ 0 != "$#" ] || show_usage 1 1>&2
52 # Cached value. Note that this a return code, so 0 means uninstalled!
53 is_uninstalled_cache=
55 # Check if this is an uninstalled xapian-config.
56 is_uninstalled()
58 if [ -z "$is_uninstalled_cache" ]; then
59 [ -n "$builddir" -a -f "${builddir}Makefile" ]
60 is_uninstalled_cache=$?
62 return $is_uninstalled_cache
65 need_explicit_dependencies()
67 # For static libraries, we need to explicitly link with dependency_libs
68 # on all platforms. For shared libraries, it depends on the platform.
70 # xapian-config --static means static libraries.
71 [ no = "$static" ] || return 0 # "true"
73 # If the .la file hasn't been installed, assume there are shared libraries.
74 if [ -f "@libdir@/libxapian@LIBRARY_VERSION_SUFFIX@.la" ] ; then
75 # If "$dlname" is empty, we only have static libraries.
76 extract_dlname "@libdir@/libxapian@LIBRARY_VERSION_SUFFIX@.la"
77 [ -n "$dlname" ] || return 0 # "true"
80 # Vanilla libtool set this to either "yes" or "unknown" and then handles
81 # both of these the same way, but our configure forces this to "no" on
82 # platforms where we know that is appropriate.
83 [ no != "@link_all_deplibs_CXX@" ] || return 1 # "false"
85 return 0 # "true"
88 # Any extra ldflags needed.
89 set_F_to_extra_ldflags() {
91 [ -n "@ldflags@" ] && F="@ldflags@ "
94 # -L option required (if any).
95 set_L_to_library_path() {
97 [ /usr/lib != "@libdir@" ] && L="-L@libdir@ "
100 # -I options for compiling against an uninstalled xapian.
101 set_I_for_uninstalled() {
103 # version.h is generated by configure, so we also need builddir
104 # in the include path if it's different to srcdir.
105 [ "@abs_srcdir@" != "@abs_builddir@" ] && I="-I@abs_builddir@/include "
106 I="$I-I@abs_srcdir@/include"
109 # Extract dlname from a libtool .la file.
110 extract_dlname() {
111 dlname=
112 # Need to quote ^ for Solaris /bin/sh.
113 assignment=`grep '^dlname=' "$1" 2>/dev/null`
114 eval "$assignment"
117 # Extract dependency_libs recursively from a libtool .la file, converting
118 # .la references into appropriate -L and -l options.
119 extract_dependency_libs() {
120 deps=
121 # Multiple whitespace (space or tab).
122 mws='[ ][ ]*'
123 la='\(/[^ ]*\)\(/lib\)\([^ ]*\).la'
124 pat='\(.* \)'"$la"'\( .*\)'
125 extract_dependency_libs_ "$1"
126 dependency_libs=`echo "$deps"|sed 's/ */ /g;s/^ //;s/ $//'`
129 # Internal helper function for extract_dependency_libs.
130 extract_dependency_libs_() {
131 dependency_libs=
132 # Need to quote ^ for Solaris /bin/sh.
133 assignment=`grep '^dependency_libs=' "$1" 2>/dev/null`
134 eval "$assignment"
135 dependency_libs=`echo " $dependency_libs "|sed "s/$mws/ /g"`
136 while true ; do
137 file=`echo "$dependency_libs"|sed "s,$pat"',\2\3\4.la,'`
138 case $file in
139 *.la)
140 # Replace "/path/to/libfoo.la" with "-L/path/to -lfoo".
141 deps="$deps "`echo "$dependency_libs"|sed "s,$pat"',\1-L\2 -l\4,'`
142 # Put the trailing part in $1 which is a local variable.
143 set "`echo "$dependency_libs"|sed "s,$pat"',\5,'`"
144 # And expand any dependency libs from libfoo.la.
145 extract_dependency_libs_ "$file"
146 # Set dependency_libs to the trailing part, ready for the
147 # next pass of the loop which checks for more .la files.
148 dependency_libs=$1
151 deps=$deps$dependency_libs
152 break
154 esac
155 done
158 builddir=`echo "$0"|sed 's![^/]*$!!'`
159 xo_lib_xapian=no
160 static=no
162 actions=
163 while [ 0 != "$#" ] ; do
164 arg=$1
165 shift
166 case $arg in
167 --help)
168 echo "$PROG_NAME - $PROG_DESC"
169 echo
170 show_usage 0
173 --version)
174 echo "$PROG_NAME - @PACKAGE_STRING@"
175 exit 0
178 --cxxflags|--swigflags|--libs|--ltlibs)
179 actions="$actions $arg"
182 --static)
183 static=yes
186 --from-xo-lib-xapian)
187 # Top Secret option which allows us to give a more helpful error
188 # message if we're asked to link with an uninstalled libxapian@LIBRARY_VERSION_SUFFIX@
189 # and libtool isn't in use.
190 xo_lib_xapian=yes
194 echo "$0: Unrecognized option: $arg" 1>&2
195 show_usage 1 1>&2
199 show_usage 1 1>&2
201 esac
202 done
204 for arg in $actions ; do
205 case $arg in
206 --cxxflags)
207 if is_uninstalled ; then
208 set_I_for_uninstalled
209 else
210 # Adding -I/usr/include to CXXFLAGS causes problems with certain
211 # versions of GCC on some platforms where GCC generates "fixed"
212 # versions of vendor supplied include headers at install time.
213 # Normally these are used instead of those in /usr/include, but if
214 # you explicitly pass -I/usr/include you get the non-fixed
215 # versions. More recent GCC versions simply ignore -I/usr/include
216 # but we want to support older versions too.
217 case "@incdir@" in
218 /usr/include|/usr/include/c++) I= ;;
219 *) I="-I@incdir@" ;;
220 esac
223 [ -n "@abi_affecting_cxxflags@" ] && F="@abi_affecting_cxxflags@ "
224 echo "$I$F"
227 --swigflags)
228 if is_uninstalled ; then
229 set_I_for_uninstalled
230 else
231 I="-I@incdir@"
233 echo "$I"
236 --libs)
237 if is_uninstalled ; then
238 if [ no = "$xo_lib_xapian" ]; then
239 echo "$0: Use libtool and '$PROG_NAME --ltlibs'" 1>&2
240 else
241 configure_ac='configure.in (or configure.ac)'
242 # If ac_top_srcdir isn't passed to us, we just end up looking
243 # in the current directory, which is a sensible fallback.
244 if [ -r "${ac_top_srcdir}configure.ac" ]; then
245 configure_ac=configure.ac
246 elif [ -r "${ac_top_srcdir}configure.in" ]; then
247 configure_ac=configure.in
249 echo "$0: Add AC_PROG_LIBTOOL to your $configure_ac" 1>&2
251 echo "to link with an uninstalled libxapian@LIBRARY_VERSION_SUFFIX@." 1>&2
252 exit 1
254 set_F_to_extra_ldflags
255 set_L_to_library_path
257 if need_explicit_dependencies ; then
258 extract_dependency_libs "@libdir@/libxapian@LIBRARY_VERSION_SUFFIX@.la"
259 [ -n "$dependency_libs" ] && D=" $dependency_libs"
261 echo "$F$L-lxapian@LIBRARY_VERSION_SUFFIX@$D"
264 --ltlibs)
265 set_F_to_extra_ldflags
266 if is_uninstalled ; then
267 # Don't check if libxapian@LIBRARY_VERSION_SUFFIX@.la exists yet since we want to allow
268 # configuring against a xapian-core tree which hasn't been built
269 # yet (the top level bootstrap script relies on this).
270 [ ./ != "$builddir" ] && F="$F$builddir"
271 [ no = "$static" ] || F="-static-libtool-libs $F"
272 echo "${F}libxapian@LIBRARY_VERSION_SUFFIX@.la"
273 continue
276 # If we need to pull in dependency_libs, we need libxapian@LIBRARY_VERSION_SUFFIX@.la.
277 # Otherwise just use the appropriate -L and -l options.
278 # Upstream libtool currently never sets link_all_deplibs_CXX=no.
279 # Some Linux distros patch libtool to return no, and some have an
280 # unhelpful policy of not packaging .la files in an attempt to work
281 # around this. So avoiding using libtool here gives more consistent
282 # behaviour.
283 if need_explicit_dependencies ; then
284 if [ -f "@libdir@/libxapian@LIBRARY_VERSION_SUFFIX@.la" ]; then
285 echo "${F}@libdir@/libxapian@LIBRARY_VERSION_SUFFIX@.la"
286 continue
289 echo "$0: Can't find libxapian@LIBRARY_VERSION_SUFFIX@.la to link against." 1>&2
290 exit 1
293 set_L_to_library_path
294 echo "$F$L-lxapian@LIBRARY_VERSION_SUFFIX@"
296 esac
297 done
298 exit 0