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
20if [ "$1" = "--verbose" -o "$1" = "-v" ]; then
21    verbose="--verbose"
22    shift
23fi
24
25# Default place to look for apr source.  Can be overridden with 
26#   --with-apr=[directory]
27apr_src_dir=../apr
28
29while test $# -gt 0 
30do
31  # Normalize
32  case "$1" in
33  -*=*) optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
34  *) optarg= ;;
35  esac
36
37  case "$1" in
38  --with-apr=*)
39  apr_src_dir=$optarg
40  ;;
41  esac
42
43  shift
44done
45
46if [ -f "$apr_src_dir/build/apr_common.m4" ]; then
47  apr_src_dir=`cd $apr_src_dir; pwd`
48  echo ""
49  echo "Looking for apr source in $apr_src_dir"
50else
51  echo ""
52  echo "Problem finding apr source in $apr_src_dir."
53  echo "Use:"
54  echo "  --with-apr=[directory]" 
55  exit 1
56fi
57
58set -e
59
60# Remove some files, then copy them from apr source tree
61rm -f build/apr_common.m4 build/find_apr.m4 build/install.sh \
62      build/config.guess build/config.sub build/get-version.sh
63cp -p $apr_src_dir/build/apr_common.m4 $apr_src_dir/build/find_apr.m4 \
64      $apr_src_dir/build/install.sh $apr_src_dir/build/config.guess \
65      $apr_src_dir/build/config.sub $apr_src_dir/build/get-version.sh \
66      build/
67
68# Remove aclocal.m4 as it'll break some builds...
69rm -rf aclocal.m4 autom4te*.cache
70
71#
72# Generate the autoconf header (include/apu_config.h) and ./configure
73#
74echo "Creating include/private/apu_config.h ..."
75${AUTOHEADER:-autoheader} $verbose
76
77echo "Creating configure ..."
78### do some work to toss config.cache?
79if ${AUTOCONF:-autoconf} $verbose; then
80  :
81else
82  echo "autoconf failed"
83  exit 1
84fi
85
86#
87# Generate build-outputs.mk for the build system
88#
89echo "Generating 'make' outputs ..."
90$apr_src_dir/build/gen-build.py $verbose make
91
92# Remove autoconf cache again
93rm -rf autom4te*.cache
94
95# Create RPM Spec file
96if [ -f `which cut` ]; then
97  echo rebuilding rpm spec file
98  REVISION=`build/get-version.sh all include/apu_version.h APU`
99  VERSION=`echo $REVISION | cut -d- -s -f1`
100  RELEASE=`echo $REVISION | cut -d- -s -f2`
101  if [ "x$VERSION" = "x" ]; then
102      VERSION=$REVISION
103      RELEASE=1
104  fi
105  sed -e "s/APU_VERSION/$VERSION/" -e "s/APU_RELEASE/$RELEASE/" \
106    ./build/rpm/apr-util.spec.in > apr-util.spec
107fi
108
109# Verify the tree was clean, notify user if not (normal in development)
110#
111if [ -f "include/apu.h" -o -f "include/private/apu_config.h" -o \
112     -f "include/apu_want.h" -o -f "include/private/apu_select_dbm.h" ]; then
113    echo ""
114    echo "Generated include files already exist, the tree is not clean."
115    echo "The resulting build-outputs.mk file is incorrect"
116fi
117
118exit 0
119