1251876Speter#!/bin/sh
2251876Speter# Licensed to the Apache Software Foundation (ASF) under one or more
3251876Speter# contributor license agreements.  See the NOTICE file distributed with
4251876Speter# this work for additional information regarding copyright ownership.
5251876Speter# The ASF licenses this file to You under the Apache License, Version 2.0
6251876Speter# (the "License"); you may not use this file except in compliance with
7251876Speter# the License.  You may obtain a copy of the License at
8251876Speter#
9251876Speter#     http://www.apache.org/licenses/LICENSE-2.0
10251876Speter#
11251876Speter# Unless required by applicable law or agreed to in writing, software
12251876Speter# distributed under the License is distributed on an "AS IS" BASIS,
13251876Speter# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14251876Speter# See the License for the specific language governing permissions and
15251876Speter# limitations under the License.
16251876Speter#
17251876Speter
18251876Speter# APR-util script designed to allow easy command line access to APR-util
19251876Speter# configuration parameters.
20251876Speter
21251876SpeterAPRUTIL_MAJOR_VERSION="@APRUTIL_MAJOR_VERSION@"
22251876SpeterAPRUTIL_DOTTED_VERSION="@APRUTIL_DOTTED_VERSION@"
23251876Speter
24251876Speterprefix="@prefix@"
25251876Speterexec_prefix="@exec_prefix@"
26251876Speterbindir="@bindir@"
27251876Speterlibdir="@libdir@"
28251876Speterincludedir="@includedir@"
29251876Speter
30251876SpeterLIBS="@APRUTIL_EXPORT_LIBS@"
31251876SpeterINCLUDES="@APRUTIL_INCLUDES@"
32251876SpeterLDFLAGS="@APRUTIL_LDFLAGS@"
33251876SpeterLDAP_LIBS="@LDADD_ldap@"
34251876SpeterDBM_LIBS="@LDADD_dbm_db@ @LDADD_dbm_gdbm@ @LDADD_dbm_ndbm@"
35251876Speter
36251876SpeterAPRUTIL_LIBNAME="@APRUTIL_LIBNAME@"
37251876Speter
38251876SpeterAPU_SOURCE_DIR="@abs_srcdir@"
39251876SpeterAPU_BUILD_DIR="@abs_builddir@"
40251876SpeterAPR_XML_EXPAT_OLD="@APR_XML_EXPAT_OLD@"
41251876SpeterAPU_DB_VERSION="@apu_db_version@"
42251876Speter
43251876Speter# NOTE: the following line is modified during 'make install': alter with care!
44251876Speterlocation=@APU_CONFIG_LOCATION@
45251876Speter
46251876Spetershow_usage()
47251876Speter{
48251876Speter    cat << EOF
49251876SpeterUsage: apu-$APRUTIL_MAJOR_VERSION-config [OPTION]
50251876Speter
51251876SpeterKnown values for OPTION are:
52251876Speter  --prefix[=DIR]    change prefix to DIR
53251876Speter  --bindir          print location where binaries are installed
54251876Speter  --includes        print include information
55251876Speter  --includedir      print location where headers are installed
56251876Speter  --ldflags         print linker flags
57251876Speter  --libs            print library information
58251876Speter  --avoid-ldap      do not include ldap library information with --libs
59251876Speter  --ldap-libs       print library information to link with ldap
60251876Speter  --avoid-dbm       do not include DBM library information with --libs
61251876Speter  --dbm-libs        print additional library information to link with DBM
62251876Speter  --srcdir          print APR-util source directory
63251876Speter  --link-ld         print link switch(es) for linking to APR-util
64251876Speter  --link-libtool    print the libtool inputs for linking to APR-util
65251876Speter  --apu-la-file     print the path to the .la file, if available
66251876Speter  --old-expat       indicate if APR-util was built against an old expat
67251876Speter  --db-version      print the DB version
68251876Speter  --version         print APR-util's version as a dotted triple
69251876Speter  --help            print this help
70251876Speter
71251876SpeterWhen linking with libtool, an application should do something like:
72251876Speter  APU_LIBS="\`apu-$APRUTIL_MAJOR_VERSION-config --link-libtool --libs\`"
73251876Speteror when linking directly:
74251876Speter  APU_LIBS="\`apu-$APRUTIL_MAJOR_VERSION-config --link-ld --libs\`"
75251876Speter
76251876SpeterAn application should use the results of --includes, and --ldflags in
77251876Spetertheir build process.
78251876SpeterEOF
79251876Speter}
80251876Speter
81251876Speterif test $# -eq 0; then
82251876Speter    show_usage
83251876Speter    exit 1
84251876Speterfi
85251876Speter
86251876Speterif test "$location" = "installed"; then
87251876Speter    LA_FILE="$libdir/lib${APRUTIL_LIBNAME}.la"
88251876Speterelse
89251876Speter    LA_FILE="$APU_BUILD_DIR/lib${APRUTIL_LIBNAME}.la"
90251876Speterfi
91251876Speter
92251876Speterflags=""
93251876Speter
94251876Speterwhile test $# -gt 0; do
95251876Speter    # Normalize the prefix.
96251876Speter    case "$1" in
97251876Speter    -*=*) optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
98251876Speter    *) optarg= ;;
99251876Speter    esac
100251876Speter
101251876Speter    case "$1" in
102251876Speter    # It is possible for the user to override our prefix.
103251876Speter    --prefix=*)
104251876Speter    prefix=$optarg
105251876Speter    ;;
106251876Speter    --prefix)
107251876Speter    echo $prefix
108251876Speter    exit 0
109251876Speter    ;;
110251876Speter    --bindir)
111251876Speter    echo $bindir
112251876Speter    exit 0
113251876Speter    ;;
114251876Speter    --avoid-ldap)
115251876Speter    LDAP_LIBS=""
116251876Speter    ;;
117251876Speter    --avoid-dbm)
118251876Speter    DBM_LIBS=""
119251876Speter    ;;
120251876Speter    --libs)
121251876Speter    flags="$flags $LDAP_LIBS $DBM_LIBS $LIBS"
122251876Speter    ;;
123251876Speter    --ldap-libs)
124251876Speter    flags="$flags $LDAP_LIBS"
125251876Speter    ;;
126251876Speter    --dbm-libs)
127251876Speter    flags="$flags $DBM_LIBS"
128251876Speter    ;;
129251876Speter    --includedir)
130251876Speter    if test "$location" = "installed"; then
131251876Speter        flags="$includedir"
132251876Speter    elif test "$location" = "source"; then
133251876Speter        flags="$APU_SOURCE_DIR/include"
134251876Speter    else
135251876Speter        # this is for VPATH builds
136251876Speter        flags="$APU_BUILD_DIR/include $APU_SOURCE_DIR/include"
137251876Speter    fi
138251876Speter    echo $flags
139251876Speter    exit 0
140251876Speter    ;;
141251876Speter    --includes)
142251876Speter    if test "$location" = "installed"; then
143251876Speter        flags="$flags -I$includedir $INCLUDES"
144251876Speter    elif test "$location" = "source"; then
145251876Speter        flags="$flags -I$APU_SOURCE_DIR/include $INCLUDES"
146251876Speter    else
147251876Speter        # this is for VPATH builds
148251876Speter        flags="$flags -I$APU_BUILD_DIR/include -I$APU_SOURCE_DIR/include $INCLUDES"
149251876Speter    fi
150251876Speter    ;;
151251876Speter    --ldflags)
152251876Speter    flags="$flags $LDFLAGS"
153251876Speter    ;;
154251876Speter    --srcdir)
155251876Speter    echo $APU_SOURCE_DIR
156251876Speter    exit 0
157251876Speter    ;;
158251876Speter    --version)
159251876Speter    echo $APRUTIL_DOTTED_VERSION
160251876Speter    exit 0
161251876Speter    ;;
162251876Speter    --link-ld)
163251876Speter    if test "$location" = "installed"; then
164251876Speter        ### avoid using -L if libdir is a "standard" location like /usr/lib
165251876Speter        flags="$flags -L$libdir -l$APRUTIL_LIBNAME"
166251876Speter    else
167251876Speter        flags="$flags -L$APU_BUILD_DIR -l$APRUTIL_LIBNAME"
168251876Speter    fi
169251876Speter    ;;
170251876Speter    --link-libtool)
171251876Speter    # If the LA_FILE exists where we think it should be, use it.  If we're
172251876Speter    # installed and the LA_FILE does not exist, assume to use -L/-l
173251876Speter    # (the LA_FILE may not have been installed).  If we're building ourselves,
174251876Speter    # we'll assume that at some point the .la file be created.
175251876Speter    if test -f "$LA_FILE"; then
176251876Speter        flags="$flags $LA_FILE"
177251876Speter    elif test "$location" = "installed"; then
178251876Speter        ### avoid using -L if libdir is a "standard" location like /usr/lib
179251876Speter        # Since the user is specifying they are linking with libtool, we
180251876Speter        # *know* that -R will be recognized by libtool.
181251876Speter        flags="$flags -L$libdir -R$libdir -l$APRUTIL_LIBNAME"
182251876Speter    else
183251876Speter        flags="$flags $LA_FILE"
184251876Speter    fi
185251876Speter    ;;
186251876Speter    --apu-la-file)
187251876Speter    if test -f "$LA_FILE"; then
188251876Speter        flags="$flags $LA_FILE"
189251876Speter    fi
190251876Speter    ;;
191251876Speter    --old-expat)
192251876Speter    if test ! -n "$APR_XML_EXPAT_OLD"; then
193251876Speter        echo "no"
194251876Speter    else
195251876Speter        echo "$APR_XML_EXPAT_OLD"
196251876Speter    fi
197251876Speter    exit 0
198251876Speter    ;;
199251876Speter    --db-version)
200251876Speter    echo $APU_DB_VERSION
201251876Speter    exit 0
202251876Speter    ;;
203251876Speter    --help)
204251876Speter    show_usage
205251876Speter    exit 0
206251876Speter    ;;
207251876Speter    *)
208251876Speter    show_usage
209251876Speter    exit 1
210251876Speter    ;;
211251876Speter    esac
212251876Speter
213251876Speter    # Next please.
214251876Speter    shift
215251876Speterdone
216251876Speter
217251876Speterif test -n "$flags"; then
218251876Speter  echo "$flags"
219251876Speterfi
220251876Speter
221251876Speterexit 0
222