Initial packaging.
[profile/ivi/log4cxx.git] / find_apu.m4
1 dnl -------------------------------------------------------- -*- autoconf -*-
2 dnl Copyright 2002-2005 The Apache Software Foundation or its licensors, as
3 dnl applicable.
4 dnl
5 dnl Licensed under the Apache License, Version 2.0 (the "License");
6 dnl you may not use this file except in compliance with the License.
7 dnl You may obtain a copy of the License at
8 dnl
9 dnl     http://www.apache.org/licenses/LICENSE-2.0
10 dnl
11 dnl Unless required by applicable law or agreed to in writing, software
12 dnl distributed under the License is distributed on an "AS IS" BASIS,
13 dnl WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 dnl See the License for the specific language governing permissions and
15 dnl limitations under the License.
16
17 dnl
18 dnl find_apu.m4 : locate the APR-util (APU) include files and libraries
19 dnl
20 dnl This macro file can be used by applications to find and use the APU
21 dnl library. It provides a standardized mechanism for using APU. It supports
22 dnl embedding APU into the application source, or locating an installed
23 dnl copy of APU.
24 dnl
25 dnl APR_FIND_APU(srcdir, builddir, implicit-install-check, acceptable-majors,
26 dnl              detailed-check)
27 dnl
28 dnl   where srcdir is the location of the bundled APU source directory, or
29 dnl   empty if source is not bundled.
30 dnl
31 dnl   where builddir is the location where the bundled APU will be built,
32 dnl   or empty if the build will occur in the srcdir.
33 dnl
34 dnl   where implicit-install-check set to 1 indicates if there is no
35 dnl   --with-apr-util option specified, we will look for installed copies.
36 dnl
37 dnl   where acceptable-majors is a space separated list of acceptable major
38 dnl   version numbers. Often only a single major version will be acceptable.
39 dnl   If multiple versions are specified, and --with-apr-util=PREFIX or the
40 dnl   implicit installed search are used, then the first (leftmost) version
41 dnl   in the list that is found will be used.  Currently defaults to [0 1].
42 dnl
43 dnl   where detailed-check is an M4 macro which sets the apu_acceptable to
44 dnl   either "yes" or "no". The macro will be invoked for each installed
45 dnl   copy of APU found, with the apu_config variable set appropriately.
46 dnl   Only installed copies of APU which are considered acceptable by
47 dnl   this macro will be considered found. If no installed copies are
48 dnl   considered acceptable by this macro, apu_found will be set to either
49 dnl   either "no" or "reconfig".
50 dnl
51 dnl Sets the following variables on exit:
52 dnl
53 dnl   apu_found : "yes", "no", "reconfig"
54 dnl
55 dnl   apu_config : If the apu-config tool exists, this refers to it.  If
56 dnl                apu_found is "reconfig", then the bundled directory
57 dnl                should be reconfigured *before* using apu_config.
58 dnl
59 dnl Note: this macro file assumes that apr-config has been installed; it
60 dnl       is normally considered a required part of an APR installation.
61 dnl
62 dnl Note: At this time, we cannot find *both* a source dir and a build dir.
63 dnl       If both are available, the build directory should be passed to
64 dnl       the --with-apr-util switch.
65 dnl
66 dnl Note: the installation layout is presumed to follow the standard
67 dnl       PREFIX/lib and PREFIX/include pattern. If the APU config file
68 dnl       is available (and can be found), then non-standard layouts are
69 dnl       possible, since it will be described in the config file.
70 dnl
71 dnl If a bundled source directory is available and needs to be (re)configured,
72 dnl then apu_found is set to "reconfig". The caller should reconfigure the
73 dnl (passed-in) source directory, placing the result in the build directory,
74 dnl as appropriate.
75 dnl
76 dnl If apu_found is "yes" or "reconfig", then the caller should use the
77 dnl value of apu_config to fetch any necessary build/link information.
78 dnl
79
80 AC_DEFUN([APR_FIND_APU], [
81   apu_found="no"
82
83   if test "$target_os" = "os2-emx"; then
84     # Scripts don't pass test -x on OS/2
85     TEST_X="test -f"
86   else
87     TEST_X="test -x"
88   fi
89
90   ifelse([$4], [],
91   [
92     ifdef(AC_WARNING,([$0: missing argument 4 (acceptable-majors): Defaulting to APU 0.x then APU 1.x]))
93     acceptable_majors="0 1"
94   ], [acceptable_majors="$4"])
95
96   apu_temp_acceptable_apu_config=""
97   for apu_temp_major in $acceptable_majors
98   do
99     case $apu_temp_major in
100       0)
101       apu_temp_acceptable_apu_config="$apu_temp_acceptable_apu_config apu-config"
102       ;;
103       *)
104       apu_temp_acceptable_apu_config="$apu_temp_acceptable_apu_config apu-$apu_temp_major-config"
105       ;;
106     esac
107   done
108
109   AC_MSG_CHECKING(for APR-util)
110   AC_ARG_WITH(apr-util,
111   [  --with-apr-util=PATH    prefix for installed APU or the full path to 
112                              apu-config],
113   [
114     if test "$withval" = "no" || test "$withval" = "yes"; then
115       AC_MSG_ERROR([--with-apr-util requires a directory or file to be provided])
116     fi
117
118     for apu_temp_apu_config_file in $apu_temp_acceptable_apu_config
119     do
120       for lookdir in "$withval/bin" "$withval"
121       do
122         if $TEST_X "$lookdir/$apu_temp_apu_config_file"; then
123           apu_config="$lookdir/$apu_temp_apu_config_file"
124           ifelse([$5], [], [], [
125           apu_acceptable="yes"
126           $5
127           if test "$apu_acceptable" != "yes"; then
128             AC_MSG_WARN([Found APU in $apu_config, but it is considered unacceptable])
129             continue
130           fi])
131           apu_found="yes"
132           break 2
133         fi
134       done
135     done
136
137     if test "$apu_found" != "yes" && $TEST_X "$withval" && $withval --help > /dev/null 2>&1 ; then
138       apu_config="$withval"
139       ifelse([$5], [], [apu_found="yes"], [
140           apu_acceptable="yes"
141           $5
142           if test "$apu_acceptable" = "yes"; then
143                 apu_found="yes"
144           fi])
145     fi
146
147     dnl if --with-apr-util is used, it is a fatal error for its argument
148     dnl to be invalid
149     if test "$apu_found" != "yes"; then
150       AC_MSG_ERROR([the --with-apr-util parameter is incorrect. It must specify an install prefix, a build directory, or an apu-config file.])
151     fi
152   ],[
153     if test -n "$3" && test "$3" = "1"; then
154       for apu_temp_apu_config_file in $apu_temp_acceptable_apu_config
155       do
156         if $apu_temp_apu_config_file --help > /dev/null 2>&1 ; then
157           apu_config="$apu_temp_apu_config_file" 
158           ifelse([$5], [], [], [
159           apu_acceptable="yes"
160           $5
161           if test "$apu_acceptable" != "yes"; then
162             AC_MSG_WARN([skipped APR-util at $apu_config, version not acceptable])
163             continue
164           fi])
165           apu_found="yes"
166           break
167         else
168           dnl look in some standard places (apparently not in builtin/default)
169           for lookdir in /usr /usr/local /usr/local/apr /opt/apr; do
170             if $TEST_X "$lookdir/bin/$apu_temp_apu_config_file"; then
171               apu_config="$lookdir/bin/$apu_temp_apu_config_file"
172               ifelse([$5], [], [], [
173               apu_acceptable="yes"
174               $5
175               if test "$apu_acceptable" != "yes"; then
176                 AC_MSG_WARN([skipped APR-util at $apu_config, version not acceptable])
177                 continue
178               fi])
179               apu_found="yes"
180               break 2
181             fi
182           done
183         fi
184       done
185     fi
186     dnl if we have not found anything yet and have bundled source, use that
187     if test "$apu_found" = "no" && test -d "$1"; then
188       apu_temp_abs_srcdir="`cd $1 && pwd`"
189       apu_found="reconfig"
190       apu_bundled_major="`sed -n '/#define.*APU_MAJOR_VERSION/s/^[^0-9]*\([0-9]*\).*$/\1/p' \"$1/include/apu_version.h\"`"
191       case $apu_bundled_major in
192         "")
193           AC_MSG_ERROR([failed to find major version of bundled APU])
194         ;;
195         0)
196           apu_temp_apu_config_file="apu-config"
197         ;;
198         *)
199           apu_temp_apu_config_file="apu-$apu_bundled_major-config"
200         ;;
201       esac
202       if test -n "$2"; then
203         apu_config="$2/$apu_temp_apu_config_file"
204       else
205         apu_config="$1/$apu_temp_apu_config_file"
206       fi
207     fi
208   ])
209
210   AC_MSG_RESULT($apu_found)
211 ])