1#!/bin/sh
2# Licensed to the Apache Software Foundation (ASF) under one or more
3# contributor license agreements.  See the NOTICE file distributed with
4# this work for additional information regarding copyright ownership.
5# The ASF licenses this file to You under the Apache License, Version 2.0
6# (the "License"); you may not use this file except in compliance with
7# the License.  You may obtain a copy of the License at
8# 
9#    http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16#
17#
18
19# buildconf: Build the support scripts needed to compile from a
20#            checked-out version of the source code.
21
22if [ "$1" = "--verbose" -o "$1" = "-v" ]; then
23    verbose="--verbose"
24    shift
25fi
26
27# Verify that the builder has the right config tools installed
28#
29build/buildcheck.sh $verbose || exit 1
30
31libtoolize=`build/PrintPath glibtoolize1 glibtoolize libtoolize15 libtoolize14 libtoolize`
32if [ "x$libtoolize" = "x" ]; then
33    echo "libtoolize not found in path"
34    exit 1
35fi
36
37# Create the libtool helper files
38#
39# Note: we copy (rather than link) them to simplify distribution.
40# Note: APR supplies its own config.guess and config.sub -- we do not
41#       rely on libtool's versions
42#
43echo "buildconf: copying libtool helper files using $libtoolize"
44
45# Remove any libtool files so one can switch between libtool versions
46# by simply rerunning the buildconf script.
47rm -f aclocal.m4 libtool.m4
48(cd build ; rm -f ltconfig ltmain.sh argz.m4 libtool.m4 ltoptions.m4 ltsugar.m4 ltversion.m4 lt~obsolete.m4)
49
50# Determine libtool version, because --copy behaves differently
51# w.r.t. copying libtool.m4
52lt_pversion=`$libtoolize --version 2>/dev/null|sed -e 's/([^)]*)//g;s/^[^0-9]*//;s/[- ].*//g;q'`
53lt_version=`echo $lt_pversion|sed -e 's/\([a-z]*\)$/.\1/'`
54IFS=.; set $lt_version; IFS=' '
55
56# libtool 1
57if test "$1" = "1"; then
58  $libtoolize --copy --automake
59  # Unlikely, maybe for old versions the file exists
60  if [ -f libtool.m4 ]; then 
61    ltfile=`pwd`/libtool.m4
62  else
63
64    # Extract all lines setting variables from libtoolize up until
65    # libtool_m4 gets set
66    ltfindcmd="`sed -n \"/=[^\\\`]/p;/libtool_m4=/{s/.*=/echo /p;q;}\" \
67                   < $libtoolize`"
68
69    # Get path to libtool.m4 either from LIBTOOL_M4 env var or our libtoolize based script
70    ltfile=${LIBTOOL_M4-`eval "$ltfindcmd"`}
71
72    # Expecting the code above to be very portable, but just in case...
73    if [ -z "$ltfile" -o ! -f "$ltfile" ]; then
74      ltpath=`dirname $libtoolize`
75      ltfile=`cd $ltpath/../share/aclocal ; pwd`/libtool.m4
76    fi
77  fi
78  if [ ! -f $ltfile ]; then
79    echo "$ltfile not found"
80    exit 1
81  fi
82  # Do we need this anymore?
83  echo "buildconf: Using libtool.m4 at ${ltfile}."
84  rm -f build/libtool.m4
85  cp -p $ltfile build/libtool.m4
86
87# libtool 2
88elif test "$1" = "2"; then
89  $libtoolize --copy --quiet $verbose
90fi
91
92# Replace top_builddir by apr_builddir.
93# Wouldn't it just be better to define top_builddir??
94# Not sure, would it interfere with httpd top_builddir when bundled?
95mv build/libtool.m4 build/libtool.m4.$$
96sed -e 's/\(LIBTOOL=.*\)top_build/\1apr_build/' < build/libtool.m4.$$ > build/libtool.m4
97rm -f build/libtool.m4.$$
98
99# Clean up any leftovers
100rm -f aclocal.m4 libtool.m4
101
102#
103# Generate the autoconf header and ./configure
104#
105echo "buildconf: creating include/arch/unix/apr_private.h.in ..."
106${AUTOHEADER:-autoheader} $verbose
107
108echo "buildconf: creating configure ..."
109### do some work to toss config.cache?
110${AUTOCONF:-autoconf} $verbose
111
112# Remove autoconf 2.5x's cache directory
113rm -rf autom4te*.cache
114
115PYTHON=${PYTHON-`build/PrintPath python3 python2 python`}
116
117echo "buildconf: generating 'make' outputs ..."
118${PYTHON} build/gen-build.py $verbose make
119
120# Create RPM Spec file
121if [ -f `which cut` ]; then
122  echo "buildconf: rebuilding rpm spec file"
123  ( REVISION=`build/get-version.sh all include/apr_version.h APR`
124    VERSION=`echo $REVISION | cut -d- -s -f1`
125    RELEASE=`echo $REVISION | cut -d- -s -f2`
126    if [ "x$VERSION" = "x" ]; then
127      VERSION=$REVISION
128      RELEASE=1
129    fi
130    cat ./build/rpm/apr.spec.in | \
131    sed -e "s/APR_VERSION/$VERSION/" \
132        -e "s/APR_RELEASE/$RELEASE/" \
133    > apr.spec )
134fi
135
136exit 0
137