Add comment
[xapian.git] / xapian-core / xapian-config.in
blob0ca084812f2bf194e2b7d5b51306f0c789b06b1b
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 ##UNINSTONLYBEGIN
53 # Cached value. Note that this a return code, so 0 means uninstalled!
54 is_uninstalled_cache=
56 # Check if this is an uninstalled xapian-config.
57 is_uninstalled()
59 if [ -z "$is_uninstalled_cache" ]; then
60 [ -n "$builddir" -a -f "${builddir}Makefile" ]
61 is_uninstalled_cache=$?
63 return $is_uninstalled_cache
66 # -I options for compiling against an uninstalled xapian.
67 set_I_for_uninstalled() {
69 # version.h is generated by configure, so we also need builddir
70 # in the include path if it's different to srcdir.
71 [ "@abs_srcdir@" != "@abs_builddir@" ] && I="-I@abs_builddir@/include "
72 I="$I-I@abs_srcdir@/include"
74 ##UNINSTONLYEND
76 need_explicit_dependencies()
78 # For static libraries, we need to explicitly link with dependency_libs
79 # on all platforms. For shared libraries, it depends on the platform.
81 # xapian-config --static means static libraries.
82 [ no = "$static" ] || return 0 # "true"
84 # If the .la file hasn't been installed, assume there are shared libraries.
85 if [ -f "@libdir@/libxapian@LIBRARY_VERSION_SUFFIX@.la" ] ; then
86 # If "$dlname" is empty, we only have static libraries.
87 extract_dlname "@libdir@/libxapian@LIBRARY_VERSION_SUFFIX@.la"
88 [ -n "$dlname" ] || return 0 # "true"
91 # Vanilla libtool set this to either "yes" or "unknown" and then handles
92 # both of these the same way, but our configure forces this to "no" on
93 # platforms where we know that is appropriate.
94 [ no != "@link_all_deplibs_CXX@" ] || return 1 # "false"
96 return 0 # "true"
99 # Any extra ldflags needed.
100 set_F_to_extra_ldflags() {
102 [ -n "@ldflags@" ] && F="@ldflags@ "
105 # -L option required (if any).
106 set_L_to_library_path() {
108 [ /usr/lib != "@libdir@" ] && L="-L@libdir@ "
111 set_I() {
112 ##UNINSTONLYBEGIN
113 if is_uninstalled ; then
114 set_I_for_uninstalled
115 else
116 ##UNINSTONLYEND
117 # Adding -I/usr/include to CXXFLAGS causes problems with certain
118 # versions of GCC on some platforms where GCC generates "fixed"
119 # versions of vendor supplied include headers at install time.
120 # Normally these are used instead of those in /usr/include, but if
121 # you explicitly pass -I/usr/include you get the non-fixed
122 # versions. More recent GCC versions simply ignore -I/usr/include
123 # but we want to support older versions too.
124 case "@incdir@" in
125 /usr/include|/usr/include/c++) I= ;;
126 *) I="-I@incdir@" ;;
127 esac
128 ##UNINSTONLYBEGIN
130 ##UNINSTONLYEND
133 set_I_swig() {
134 ##UNINSTONLYBEGIN
135 if is_uninstalled ; then
136 set_I_for_uninstalled
137 else
138 ##UNINSTONLYEND
139 I="-I@incdir@"
140 ##UNINSTONLYBEGIN
142 ##UNINSTONLYEND
145 # Extract dlname from a libtool .la file.
146 extract_dlname() {
147 dlname=
148 # Need to quote ^ for Solaris /bin/sh.
149 assignment=`grep '^dlname=' "$1" 2>/dev/null`
150 eval "$assignment"
153 # Extract dependency_libs recursively from a libtool .la file, converting
154 # .la references into appropriate -L and -l options.
155 extract_dependency_libs() {
156 deps=
157 # Multiple whitespace (space or tab).
158 mws='[ ][ ]*'
159 la='\(/[^ ]*\)\(/lib\)\([^ ]*\).la'
160 pat='\(.* \)'"$la"'\( .*\)'
161 extract_dependency_libs_ "$1"
162 dependency_libs=`echo "$deps"|sed 's/ */ /g;s/^ //;s/ $//'`
165 # Internal helper function for extract_dependency_libs.
166 extract_dependency_libs_() {
167 dependency_libs=
168 # Need to quote ^ for Solaris /bin/sh.
169 assignment=`grep '^dependency_libs=' "$1" 2>/dev/null`
170 eval "$assignment"
171 dependency_libs=`echo " $dependency_libs "|sed "s/$mws/ /g"`
172 while true ; do
173 file=`echo "$dependency_libs"|sed "s,$pat"',\2\3\4.la,'`
174 case $file in
175 *.la)
176 # Replace "/path/to/libfoo.la" with "-L/path/to -lfoo".
177 deps="$deps "`echo "$dependency_libs"|sed "s,$pat"',\1-L\2 -l\4,'`
178 # Put the trailing part in $1 which is a local variable.
179 set "`echo "$dependency_libs"|sed "s,$pat"',\5,'`"
180 # And expand any dependency libs from libfoo.la.
181 extract_dependency_libs_ "$file"
182 # Set dependency_libs to the trailing part, ready for the
183 # next pass of the loop which checks for more .la files.
184 dependency_libs=$1
187 deps=$deps$dependency_libs
188 break
190 esac
191 done
194 builddir=`echo "$0"|sed 's![^/]*$!!'`
195 xo_lib_xapian=no
196 static=no
198 actions=
199 while [ 0 != "$#" ] ; do
200 arg=$1
201 shift
202 case $arg in
203 --help)
204 echo "$PROG_NAME - $PROG_DESC"
205 echo
206 show_usage 0
209 --version)
210 echo "$PROG_NAME - @PACKAGE_STRING@"
211 exit 0
214 --cxxflags|--swigflags|--libs|--ltlibs)
215 actions="$actions $arg"
218 --static)
219 static=yes
222 --from-xo-lib-xapian)
223 # Top Secret option which allows us to give a more helpful error
224 # message if we're asked to link with an uninstalled libxapian@LIBRARY_VERSION_SUFFIX@
225 # and libtool isn't in use.
226 xo_lib_xapian=yes
230 echo "$0: Unrecognized option: $arg" 1>&2
231 show_usage 1 1>&2
235 show_usage 1 1>&2
237 esac
238 done
240 for arg in $actions ; do
241 case $arg in
242 --cxxflags)
243 set_I
245 [ -n "@abi_affecting_cxxflags@" ] && F="@abi_affecting_cxxflags@ "
246 echo "$I$F"
249 --swigflags)
250 set_I_swig
251 echo "$I"
254 --libs)
255 ##UNINSTONLYBEGIN
256 if is_uninstalled ; then
257 if [ no = "$xo_lib_xapian" ]; then
258 echo "$0: Use libtool and '$PROG_NAME --ltlibs'" 1>&2
259 else
260 configure_ac='configure.in (or configure.ac)'
261 # If ac_top_srcdir isn't passed to us, we just end up looking
262 # in the current directory, which is a sensible fallback.
263 if [ -r "${ac_top_srcdir}configure.ac" ]; then
264 configure_ac=configure.ac
265 elif [ -r "${ac_top_srcdir}configure.in" ]; then
266 configure_ac=configure.in
268 echo "$0: Add AC_PROG_LIBTOOL to your $configure_ac" 1>&2
270 echo "to link with an uninstalled libxapian@LIBRARY_VERSION_SUFFIX@." 1>&2
271 exit 1
273 ##UNINSTONLYEND
274 set_F_to_extra_ldflags
275 set_L_to_library_path
277 if need_explicit_dependencies ; then
278 extract_dependency_libs "@libdir@/libxapian@LIBRARY_VERSION_SUFFIX@.la"
279 [ -n "$dependency_libs" ] && D=" $dependency_libs"
281 echo "$F$L-lxapian@LIBRARY_VERSION_SUFFIX@$D"
284 --ltlibs)
285 set_F_to_extra_ldflags
286 ##UNINSTONLYBEGIN
287 if is_uninstalled ; then
288 # Don't check if libxapian@LIBRARY_VERSION_SUFFIX@.la exists yet since we want to allow
289 # configuring against a xapian-core tree which hasn't been built
290 # yet (the top level bootstrap script relies on this).
291 [ ./ != "$builddir" ] && F="$F$builddir"
292 [ no = "$static" ] || F="-static-libtool-libs $F"
293 echo "${F}libxapian@LIBRARY_VERSION_SUFFIX@.la"
294 continue
296 ##UNINSTONLYEND
298 # If we need to pull in dependency_libs, we need libxapian@LIBRARY_VERSION_SUFFIX@.la.
299 # Otherwise just use the appropriate -L and -l options.
300 # Upstream libtool currently never sets link_all_deplibs_CXX=no.
301 # Some Linux distros patch libtool to return no, and some have an
302 # unhelpful policy of not packaging .la files in an attempt to work
303 # around this. So avoiding using libtool here gives more consistent
304 # behaviour.
305 if need_explicit_dependencies ; then
306 if [ -f "@libdir@/libxapian@LIBRARY_VERSION_SUFFIX@.la" ]; then
307 echo "${F}@libdir@/libxapian@LIBRARY_VERSION_SUFFIX@.la"
308 continue
311 echo "$0: Can't find libxapian@LIBRARY_VERSION_SUFFIX@.la to link against." 1>&2
312 exit 1
315 set_L_to_library_path
316 echo "$F$L-lxapian@LIBRARY_VERSION_SUFFIX@"
318 esac
319 done
320 exit 0