summaryrefslogtreecommitdiff
path: root/bootstrap
blob: e8e29fda4280ff178f36b69d8ded2fce00ba6801 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
#!/bin/sh -e

# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License.  You may obtain a copy of
# the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
# License for the specific language governing permissions and limitations under
# the License.

# Bootstrap the pristine source ready for distribution.

SCRIPT_OK=0
SCRIPT_ERROR=1

ACINCLUDE_FILE="acinclude.m4"
ACINCLUDE_IN_FILE="acinclude.m4.in"
AC_CHECK_ICU_COMPRESSED_FILE="build-contrib/ac_check_icu.m4_2008-06-07.gz"
AUTHORS_FILE="authors.xml"
BUILD_AUX_DIRECTORY="build-aux"
CONFIG_GUESS_COMPRESSED_FILE="build-contrib/config.guess_2008-06-07.gz"
CONFIG_GUESS_FILE="build-aux/config.guess"
CONFIG_SUB_COMPRESSED_FILE="build-contrib/config.sub_2008-06-07.gz"
CONFIG_SUB_FILE="build-aux/config.sub"
M4_DIRECTORY="m4"
M4_AC_CHECK_ICU_FILE="m4/ac_check_icu.m4"
REPOSITORY_URI="http://svn.apache.org/repos/asf/incubator/couchdb/trunk"

ACLOCAL_EXECUTABLE=`which aclocal || true`
AUTOCONF_EXECUTABLE=`which autoconf || true`
AUTOHEADER_EXECUTABLE=`which autoheader || true`
AUTOMAKE_EXECUTABLE=`which automake || true`
GLIBTOOLIZE_EXECUTABLE=`which glibtoolize || true`
LIBTOOLIZE_EXECUTABLE=`which libtoolize || true`
SVN_EXECUTABLE=`which svn || true`

basename=`basename $0`

extract_configuration_variable () {
    # Extract variables from the local M4 configuration.

    variable_name=$1
    temporary_file=`mktemp`
    echo "changequote(\`[', \`]')" > $temporary_file
    sed "s/m4_//" < $ACINCLUDE_IN_FILE >> $temporary_file
    echo $variable_name >> $temporary_file
    m4 $temporary_file | grep -v "^$"
    rm -f $temporary_file
}

display_version () {
    # Display version and copyright information.

    package_name=`extract_configuration_variable LOCAL_PACKAGE_NAME`
    version=`extract_configuration_variable LOCAL_VERSION`
    cat << EOF
$basename - $package_name $version

Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License.  You may obtain a copy of the
License at

  http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied.  See the License for the
specific language governing permissions and limitations under the License.
EOF
}

display_help () {
    # Display a short description of the script's behaviour.

    bug_uri=`extract_configuration_variable LOCAL_BUG_URI`
    cat << EOF
Usage: $basename [OPTION]...

The $basename script bootstraps the pristeen source so that it can be built.

The exit status is 0 for success or 1 for failure.

Options:

  -h  display a short help message and exit
  -v  display version information and exit

Environment variables:

  REPOSITORY_REVISION  manual override for revision information

Report bugs at <$bug_uri>.
EOF
}

display_error () {
    # Display a short instruction referring users to further documentation.

    if test -n "$1"; then
        echo $1 >&2
    fi
    echo >&2
    echo "Try \`"$basename" -h' for more information." >&2
    exit $SCRIPT_ERROR
}

check_svn_environment () {
    # Check the Subversion environment for sanity.

    if test -z "$SVN_EXECUTABLE"; then
        echo "Warning: Unable to find the svn command."
        return $SCRIPT_ERROR
    fi
    if test -n "$REPOSITORY_REVISION"; then
        return
    fi
    if test -n "`$SVN_EXECUTABLE info . 2> /dev/null`"; then
       SVN_CHECKOUT_BOOLEAN="true"
    fi
    if test "$SVN_CHECKOUT_BOOLEAN" != "true"; then
        echo "Warning: Unable to determine checkout information."
    fi
}

generate_acinclude () {
    # Generate the acinclude.m4 file using the Subversion repository.

    release_code=`sed -e "s/\[//g" -e "s/\]//g" -e "s/(//g" -e "s/)//g" \
        < $ACINCLUDE_IN_FILE | awk "/LOCAL_VERSION_STAGE, /{print \$2}"`
    repository_boolean=false
    if test -n "$REPOSITORY_REVISION" -o "$SVN_CHECKOUT_BOOLEAN" = "true"; then
        repository_boolean=true
    fi
    if test -z "$release_code" -o "$repository_boolean" = "false"; then
        sed "s/%release%//" < $ACINCLUDE_IN_FILE > $ACINCLUDE_FILE
    else
        if test "$SVN_CHECKOUT_BOOLEAN" = "true"; then
            revision_number=`$SVN_EXECUTABLE info . | \
                awk "/Revision:/{print \\$2}"`
        fi
        if test -n "$REPOSITORY_REVISION"; then
            revision_number="$REPOSITORY_REVISION"
        fi
        sed "s/%release%/$revision_number/" \
            < $ACINCLUDE_IN_FILE > $ACINCLUDE_FILE
    fi
}

process_file_collection () {
    # Process files required to complete the bootstrap.

    echo "Installing \`"$BUILD_AUX_DIRECTORY"'"
    mkdir -p $BUILD_AUX_DIRECTORY
    echo "Installing \`"$CONFIG_GUESS_FILE"'"
    gzip --decompress --stdout \
        $CONFIG_GUESS_COMPRESSED_FILE > $CONFIG_GUESS_FILE
    echo "Installing \`"$CONFIG_SUB_FILE"'"
    gzip --decompress --stdout \
        $CONFIG_SUB_COMPRESSED_FILE > $CONFIG_SUB_FILE
    echo "Installing \`"$M4_DIRECTORY"'"
    mkdir -p $M4_DIRECTORY
    echo "Installing \`"$M4_AC_CHECK_ICU_FILE"'"
    gzip --decompress --stdout \
        $AC_CHECK_ICU_COMPRESSED_FILE > $M4_AC_CHECK_ICU_FILE
}

run_aclocal () {
    # Run the correct version of aclocal.

    if test -x "$ACLOCAL_EXECUTABLE"; then
        echo "Running $ACLOCAL_EXECUTABLE"
        $ACLOCAL_EXECUTABLE -I m4
    else
        echo "Can't find aclocal"
        exit $SCRIPT_ERROR
    fi
}

run_libtoolize () {
    # Run the correct version of libtoolize.

    if test -x "$LIBTOOLIZE_EXECUTABLE"; then
        echo "Running $LIBTOOLIZE_EXECUTABLE"
        $LIBTOOLIZE_EXECUTABLE -f -c
    else
        if test -x "`which $GLIBTOOLIZE_EXECUTABLE`"; then
            echo "Running $GLIBTOOLIZE_EXECUTABLE"
            $GLIBTOOLIZE_EXECUTABLE -f -c
        else
            echo "Can't find libtoolize or glibtoolize"
            exit $SCRIPT_ERROR
        fi
    fi
}

run_autoheader () {
    # Run the correct version of autoheader.

    if test -x "$AUTOHEADER_EXECUTABLE"; then
        echo "Running $AUTOHEADER_EXECUTABLE"
        $AUTOHEADER_EXECUTABLE -f
    else
        echo "Can't find autoheader"
        exit $SCRIPT_ERROR
    fi
}

run_automake () {
    # Run the correct version of automake.

    AUTOMAKE_OPTION_COLLECTION=""
    if test -x "$AUTOMAKE_EXECUTABLE"; then
        echo "Running $AUTOMAKE_EXECUTABLE"
        $AUTOMAKE_EXECUTABLE -f -c -a --gnits
    else
        echo "Can't find automake"
        exit $SCRIPT_ERROR
    fi
}

run_autoconf () {
    # Run the correct version of autoconf.

    if test -x "$AUTOCONF_EXECUTABLE"; then
        echo "Running $AUTOCONF_EXECUTABLE"
        $AUTOCONF_EXECUTABLE -f
    else
        echo "Can't find autoconf"
        exit $SCRIPT_ERROR
    fi
}

run_command_collection () {
    # Run commands required to complete the bootstrap.

    run_libtoolize
    run_aclocal
    run_autoheader
    run_automake
    run_autoconf
    cat << EOF

You have bootstrapped Apache CouchDB. Time to relax.

Run \`./configure' to configure the source before you install.
EOF
}

parse_script_option_list () {
    # Parse the script option list and take the appropriate action.

    if test ! argument_list=`getopt vhC $@`; then
        display_error
    fi
    eval set -- "$argument_list"
    while [ $# -gt 0 ]; do
        case "$1" in
            -v) shift; display_version; exit $SCRIPT_OK;;
            -h) shift; display_help; exit $SCRIPT_OK;;
            --) shift; break;;
            *) display_error "Unknown option: $1" >&2;;
        esac
    done
    cd `dirname $0`
    process_file_collection
    check_svn_environment || true
    generate_acinclude
    run_command_collection
}

parse_script_option_list $@