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
20# Default place to look for apr source.  Can be overridden with
21#   --with-apr=[directory]
22apr_src_dir=`pwd`/srclib/apr-1.5.2
23
24while [ $# -gt 0 ]
25do
26  # Normalize
27  case "$1" in
28  -*=*) optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
29  *) optarg= ;;
30  esac
31
32  case "$1" in
33  --with-apr=*)
34    apr_src_dir=$optarg
35    ;;
36  esac
37
38  shift
39done
40
41if [ -d "$apr_src_dir" ]; then
42  echo ""
43  echo "Looking for apr source in $apr_src_dir"
44else
45  echo ""
46  echo "Problem finding apr source in $apr_src_dir."
47  echo "Use:"
48  echo "  --with-apr=[directory]"
49  exit 1
50fi
51
52if [ ! -d "$apr_src_dir/build" ]; then
53  echo "Directory '$apr_src_dir/build' missing - wrong apr source directory?"
54  exit 1
55fi
56
57# Remove some files, then copy them from apr source tree
58for file in apr_common.m4 find_apr.m4 install.sh config.guess config.sub
59do
60  if [ ! -f "$apr_src_dir/build/$file" ]; then
61    echo "File '$apr_src_dir/build/$file' missing - wrong apr source directory?"
62    exit 1
63  fi
64  rm -f build/$file
65  cp $apr_src_dir/build/$file build/
66done
67
68# Remove aclocal.m4 as it'll break some builds...
69rm -rf aclocal.m4 autom4te*.cache
70
71echo "Creating configure ..."
72### do some work to toss config.cache?
73${AUTOCONF:-autoconf}
74if [ $? -gt 0 ]; then
75  echo "autoconf failed"
76  exit 1
77fi
78
79#
80# Generate build-outputs.mk for the build systme
81#
82PYTHON=${PYTHON-`build/PrintPath python3 python2 python`}
83
84echo "Generating 'make' outputs ..."
85${PYTHON} $apr_src_dir/build/gen-build.py make
86if [ $? -gt 0 ]; then
87  echo "Creating build-outputs.mk failed"
88  exit 1
89fi
90
91# Remove autoconf cache again
92rm -rf autom4te*.cache
93
94# Create RPM Spec file
95echo rebuilding rpm spec file
96REVISION=`build/get-version.sh all include/tcn_version.h TCN`
97# Strip everything behind "-"
98VERSION=`echo $REVISION | sed -e 's/-.*//'`
99# Strip everything before "-"
100RELEASE=`echo $REVISION | sed -e 's/.*-//'`
101# Handle case of no "-" in REVISION
102if [ "x$RELEASE" = "x$REVISION" ]; then
103  RELEASE=1
104fi
105echo "Using version '$VERSION' and release '$RELEASE' in RPM spec file"
106sed -e "s/TCN_VERSION/$VERSION/" \
107    -e "s/TCN_RELEASE/$RELEASE/" \
108    ./build/rpm/tcnative.spec.in \
109    > tcnative.spec
110