]> granicus.if.org Git - apache/blob - buildconf
buildconf: merge apr-config mode from its feature branch
[apache] / buildconf
1 #!/bin/sh
2 #
3 # Licensed to the Apache Software Foundation (ASF) under one or more
4 # contributor license agreements.  See the NOTICE file distributed with
5 # this work for additional information regarding copyright ownership.
6 # The ASF licenses this file to You under the Apache License, Version 2.0
7 # (the "License"); you may not use this file except in compliance with
8 # the License.  You may obtain a copy of the License at
9 #
10 #     http://www.apache.org/licenses/LICENSE-2.0
11 #
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17 #
18 #
19 # buildconf: Build the support scripts needed to compile from a
20 #            checked-out version of the source code.
21
22 # version check for AC_PROG_CC_C99
23 ac_version=`${AUTOCONF:-autoconf} --version 2>/dev/null|sed -e 's/^[^0-9]*//;s/[a-z]* *$//;q'`
24 case "$ac_version" in
25 # versions older than 2.50 are denied by AC_PREREQ
26 2.5*)
27     echo WARNING: You are using an outdated version of autoconf.
28     echo WARNING: This may lead to less than optimal performance of httpd.
29     echo WARNING: You should use autoconf 2.60 or newer.
30     sleep 1
31     ;;
32 esac
33
34 # set a couple of defaults for where we should be looking for our support libs.
35 # can be overridden with --with-apr=[dir] and --with-apr-util=[dir]
36
37 apr_src_dir="srclib/apr ../apr"
38 apu_src_dir=""
39
40 while test $# -gt 0 
41 do
42     # Normalize
43     case "$1" in
44     -*=*) optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
45     *) optarg= ;;
46     esac
47
48     case "$1" in
49     --with-apr=*)
50         apr_src_dir=$optarg
51         ;;
52
53     --with-apr-util=*)
54         apu_src_dir=$optarg
55         ;;
56
57     -h|--help)
58         cat <<EOF
59 buildconf: generates the files needed to configure httpd.
60
61 Usage: $0 [OPTION]...
62
63 Configuration:
64   -h, --help               display this help and exit
65
66   --with-apr=SRCDIR        define a space-separated list of directories to
67                            search for the APR source code. If, instead of a
68                            directory, an apr-config executable name is passed,
69                            APR-Config Mode is enabled (see below). Defaults to
70                            "srclib/apr ../apr"
71   --with-apr-util=SRCDIR   define a space-separated list of directories to
72                            search for the APR-util source code. Defaults to the
73                            same location as the --with-apr SRCDIR, but with
74                            "apr" replaced with "apr-util" or "aprutil". Ignored
75                            in APR-Config Mode.
76
77 APR-Config Mode:
78
79   When passing an apr-config executable to --with-apr, buildconf will attempt to
80   copy build scripts from various installed locations on your system instead of
81   an APR source tree. This allows you to configure httpd from source without
82   also requiring you to download the APR and/or APR-util sources.
83
84   For example:
85
86       ./buildconf --with-apr=apr-1-config
87
88   For this functionality to work reliably, you must have automake >= 1.12 and be
89   using a distribution that includes both find_apr.m4 and find_apu.m4 in the
90   --installbuilddir pointed to by apr-config.
91
92 Environment variables used by buildconf:
93   AUTOCONF           autoconf executable name [autoconf]
94   AUTOMAKE           automake executable name [automake]
95   AUTOHEADER         autoheader executable name [autoheader]
96 EOF
97         exit
98         ;;
99
100     *)
101         echo "unknown option $1 (try --help for usage)"
102         exit 1
103         ;;
104     esac
105
106     shift
107 done
108
109 #
110 # Check to be sure that we have the srclib dependencies checked-out, or that a
111 # working apr-config installation has been specified.
112 #
113
114 should_exit=0
115 apr_config=         # path to apr-config (empty if using a source directory)
116 apr_found=0
117 apu_found=0
118 apr_major_version=2
119
120 for dir in $apr_src_dir
121 do
122     if [ -f "${dir}/build/apr_common.m4" ]; then
123         echo "found apr source: ${dir}"
124         apr_src_dir=$dir
125         apr_found=1
126         break
127     elif which "${dir}" >/dev/null 2>&1; then
128         # We're using apr-config. Do a sanity check.
129         apr_config=`which "${dir}"`
130         echo "testing apr-config executable: ${apr_config}"
131
132         version=`"${apr_config}" --version`
133         version=`echo "${version}" | sed -n '/^[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*$/p'`
134
135         if [ -z "${version}" ]; then
136             echo "apr-config gave us an invalid --version"
137             apr_config=
138             continue
139         fi
140
141         echo "using apr-config version ${version}"
142         apr_major_version=${version} # we'll make a real "major version" later
143         apr_src_dir=`"${apr_config}" --installbuilddir`
144         apr_found=1
145         break
146     fi
147 done
148
149 if [ $apr_found -lt 1 ]; then
150     echo ""
151     echo "APR could not be found automatically."
152     echo ""
153     echo "Please refer to the documentation on APR in the httpd INSTALL file."
154     echo ""
155     should_exit=1
156 elif [ -n "${apr_config}" ]; then
157     apr_major_version=`echo "${apr_major_version}" | sed 's/\..*//'`
158 else
159     apr_major_version=`grep "#define APR_MAJOR_VERSION" \
160                       $apr_src_dir/include/apr_version.h | sed 's/[^0-9]//g'`
161 fi
162
163 # Find APR-util. Note: if we're using apr-config, we can completely skip this,
164 # even if APR is version 1. That's because we only end up caring about
165 # find_apu.m4, which is not actually installed in the standard APR-util
166 # distribution to begin with.
167 if [ -z "${apr_config}" -a $apr_major_version -lt 2 ] ; then
168     if test -z "$apu_src_dir"; then
169         apu_src_dir=`echo $apr_src_dir | sed -e 's#/apr#/apr-util#g;'`
170         apu_src_dir="$apu_src_dir `echo $apr_src_dir | sed -e 's#/apr#/aprutil#;g'`"
171         apu_src_dir="$apu_src_dir srclib/apr-util ../apr-util"
172     fi
173
174     for dir in $apu_src_dir
175     do
176         if [ -f "${dir}/Makefile.in" ]; then
177             echo "found apr-util source: ${dir}"
178             apu_src_dir=$dir
179             apu_found=1
180             break
181         fi
182     done
183
184     if [ $apu_found -lt 1 ]; then
185         echo ""
186         echo "You are using APR 1.x but APR-util 1.x was not found."
187         echo ""
188         echo "Please refer to the documentation on APR in the httpd INSTALL file."
189         echo ""
190         should_exit=1
191     fi
192 fi
193
194 if [ $should_exit -gt 0 ]; then
195     exit 1
196 fi
197
198 # These are temporary until Roy finishes the other build changes
199 #
200 touch .deps
201 rm -f aclocal.m4
202 rm -f generated_lists
203
204 # Remove autoconf 2.5x cache directories
205 rm -rf autom4te*.cache
206
207 case "`uname`" in
208 *BSD/OS*)
209     ./build/bsd_makefile;;
210 esac
211 #
212 # end temporary stuff
213
214 apr_configure="$apr_src_dir/configure"
215 if [ $apr_major_version -lt 2 ] ; then
216     aprutil_configure="$apu_src_dir/configure"
217 fi
218 config_h_in="include/ap_config_auto.h.in"
219
220 cross_compile_warning="warning: AC_TRY_RUN called without default to allow cross compiling"
221
222 if [ "$apr_src_dir" = "srclib/apr" ]; then
223     echo rebuilding $apr_configure
224     (cd srclib/apr && ./buildconf) || {
225         echo "./buildconf failed for apr"
226         exit 1
227     }
228     rm -f srclib/apr/apr.spec
229 fi
230
231 apr_src_dir=`cd $apr_src_dir && pwd` 
232
233 if [ $apr_major_version -lt 2 ] ; then
234     if [ "$apu_src_dir" = "srclib/apr-util" ]; then
235         echo rebuilding $aprutil_configure
236         (cd srclib/apr-util && ./buildconf --with-apr=$apr_src_dir) || {
237             echo "./buildconf failed for apr-util" 
238             exit 1
239         }
240         rm -f srclib/apr-util/apr-util.spec
241     fi
242
243     apu_src_dir=`cd $apu_src_dir && pwd`
244 fi
245
246 echo copying build files
247 if [ -n "${apr_config}" ]; then
248     # If we're using apr-config, we switch things up a little bit:
249     # - use automake's config.* scripts instead of APR's
250     # - use the included PrintPath instead of copying from APR
251     # - assume find_apu.m4 is also in APR's --installbuilddir
252
253     # Figure out where to copy config.* from.
254     automake=${AUTOMAKE:-automake}
255     am_libdir=`"${automake}" --print-libdir`
256     cp "${am_libdir}/config.guess" "${am_libdir}/config.sub" build
257
258     # Remember that in this case, $apr_src_dir points to the build directory.
259     cp "$apr_src_dir/apr_common.m4" "$apr_src_dir/find_apr.m4" build
260     if [ $apr_major_version -lt 2 ] ; then
261         cp "$apr_src_dir/find_apu.m4" build
262     fi
263 else
264     cp $apr_src_dir/build/config.guess $apr_src_dir/build/config.sub \
265        $apr_src_dir/build/PrintPath $apr_src_dir/build/apr_common.m4 \
266        $apr_src_dir/build/find_apr.m4 build
267     if [ $apr_major_version -lt 2 ] ; then
268         cp $apu_src_dir/build/find_apu.m4 build
269     fi
270 fi
271
272 # Remove any libtool files so one can switch between libtool 1.3
273 # and libtool 1.4 by simply rerunning the buildconf script.
274 (cd build ; rm -f ltconfig ltmain.sh)
275
276 if [ -z "${apr_config}" ]; then
277     # Optionally copy libtool-1.3.x files
278     if [ -f $apr_src_dir/build/ltconfig ]; then
279         cp $apr_src_dir/build/ltconfig build
280     fi
281     if [ -f $apr_src_dir/build/ltmain.sh ]; then
282         cp $apr_src_dir/build/ltmain.sh build
283     fi
284 fi
285
286 echo rebuilding $config_h_in
287 rm -f $config_h_in
288 ${AUTOHEADER:-autoheader} 2>&1 | grep -v "$cross_compile_warning"
289
290 echo rebuilding configure
291 rm -f config.cache
292 ${AUTOCONF:-autoconf} 2>&1 | grep -v "$cross_compile_warning"
293
294 # Remove autoconf 2.5x cache directories
295 rm -rf autom4te*.cache
296
297 # Remove possible bsd_converted file
298 rm -rf bsd_converted
299
300 if [ -f `which cut` ]; then
301   echo rebuilding rpm spec file
302   ( VMMN=`build/get-version.sh mmn include/ap_mmn.h MODULE_MAGIC_NUMBER`
303     EPOCH=`build/get-version.sh epoch include/ap_release.h AP_SERVER`
304     REVISION=`build/get-version.sh all include/ap_release.h AP_SERVER`
305     VERSION=`echo $REVISION | cut -d- -s -f1`
306     RELEASE=`echo $REVISION | cut -d- -s -f2`
307     if [ "x$VERSION" = "x" ]; then
308       VERSION=$REVISION
309       RELEASE=1
310     fi
311     cat ./build/rpm/httpd.spec.in | \
312     sed -e "s/APACHE_VERSION/$VERSION/" \
313         -e "s/APACHE_RELEASE/$RELEASE/" \
314         -e "s/APACHE_MMN/$VMMN/" \
315         -e "s/APACHE_EPOCH/$EPOCH/" \
316     > httpd.spec )
317 fi
318
319 # ensure that the ap_expr expression parser sources are never regenerated
320 # when running make
321 echo fixing timestamps for ap_expr sources
322 cd server
323 touch util_expr_parse.y util_expr_scan.l
324 sleep 1
325 touch util_expr_parse.c util_expr_parse.h util_expr_scan.c
326 cd ..
327
328 exit 0