~brianaker/libmemcached/merge-of-1.0

929.1.243 by Brian Aker
Update testing.
1
#!/bin/bash
1063.1.9 by Brian Aker
Update m4 rules.
2
# 
1079.15.1 by Brian Aker
Clarification in DNS test.
3
# Copyright (C) 2012-2013 Brian Aker
1063.1.9 by Brian Aker
Update m4 rules.
4
# All rights reserved.
5
# 
6
# Redistribution and use in source and binary forms, with or without
7
# modification, are permitted provided that the following conditions are
8
# met:
9
# 
10
#     * Redistributions of source code must retain the above copyright
11
# notice, this list of conditions and the following disclaimer.
12
# 
13
#     * Redistributions in binary form must reproduce the above
14
# copyright notice, this list of conditions and the following disclaimer
15
# in the documentation and/or other materials provided with the
16
# distribution.
17
# 
18
#     * The names of its contributors may not be used to endorse or
19
# promote products derived from this software without specific prior
20
# written permission.
21
# 
22
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
34
35
# Environment Variables that will influence the build:
36
#   AUTOMAKE
37
#   AUTORECONF
38
#   LIBTOOLIZE
39
#   MAKE
40
#   PREFIX
41
#   TESTS_ENVIRONMENT
42
#   VERBOSE
43
#   WARNINGS
44
#
45
46
command_not_found_handle ()
47
{
1079.8.9 by Brian Aker
Update for mingw compile.
48
  warn "$@: command not found"
49
50
  #if $DEBUG; then 
51
    echo ""
52
    echo "Stack trace:"
53
    local frame=0
54
    while caller $frame; do
55
      ((frame++));
56
    done
57
    echo ""
58
  #fi
59
60
  return 127
61
}
62
63
function error ()
64
{ 
65
  echo "$BASH_SOURCE:$BASH_LINENO: $@" >&2
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
66
}
67
1079.3.10 by Brian Aker
A number of small build fixes found while looking at mingw support.
68
function die ()
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
69
{ 
70
  echo "$BASH_SOURCE:$BASH_LINENO: $@" >&2
71
  exit 1; 
72
}
73
1079.8.9 by Brian Aker
Update for mingw compile.
74
function warn ()
75
{ 
76
  echo "$BASH_SOURCE:$BASH_LINENO: $@"
77
  #echo "$BASH_SOURCE:$BASH_LINENO: $@" >&1
78
}
79
1079.3.9 by Brian Aker
Update bootstrap.sh
80
function nassert ()
81
{
82
  local param_name=\$"$1"
83
  local param_value=`eval "expr \"$param_name\" "`
84
85
  if [ -n "$param_value" ]; then
86
    echo "$bash_source:$bash_lineno: assert($param_name) had value of "$param_value"" >&2
87
    exit 1
88
  fi
89
}
90
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
91
function assert ()
92
{
93
  local param_name=\$"$1"
94
  local param_value=`eval "expr \"$param_name\" "`
95
96
  if [ -z "$param_value" ]; then
1079.3.9 by Brian Aker
Update bootstrap.sh
97
    echo "$bash_source:$bash_lineno: assert($param_name)" >&2
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
98
    exit 1
99
  fi
100
}
101
1079.8.9 by Brian Aker
Update for mingw compile.
102
function assert_file ()
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
103
{
104
  if [ ! -f "$1" ]; then
105
    echo "$BASH_SOURCE:$BASH_LINENO: assert($1) does not exist: $2" >&2
106
    exit 1; 
107
  fi
108
}
109
1079.8.9 by Brian Aker
Update for mingw compile.
110
function assert_no_file ()
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
111
{
112
  if [ -f "$1" ]; then
113
    echo "$BASH_SOURCE:$BASH_LINENO: assert($1) file exists: $2" >&2
114
    exit 1;
115
  fi
116
}
117
1079.8.9 by Brian Aker
Update for mingw compile.
118
function assert_no_directory ()
119
{
120
  if [ -d "$1" ]; then
121
    echo "$BASH_SOURCE:$BASH_LINENO: assert($1) directory exists: $2" >&2
122
    exit 1;
123
  fi
124
}
125
126
function assert_exec_file ()
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
127
{
128
  if [ ! -f "$1" ]; then
129
    echo "$BASH_SOURCE:$BASH_LINENO: assert($1) does not exist: $2" >&2
130
    exit 1;
131
  fi
132
133
  if [ ! -x "$1" ]; then
134
    echo "$BASH_SOURCE:$BASH_LINENO: assert($1) exists but is not executable: $2" >&2
135
    exit 1;
136
  fi
137
}
138
1079.8.9 by Brian Aker
Update for mingw compile.
139
function command_exists ()
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
140
{
1072.1.1 by Brian Aker
Fix how we do manpages.
141
  type "$1" &> /dev/null ;
142
}
143
1079.8.9 by Brian Aker
Update for mingw compile.
144
function rebuild_host_os ()
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
145
{
146
  HOST_OS="${UNAME_MACHINE_ARCH}-${VENDOR}-${VENDOR_DISTRIBUTION}-${VENDOR_RELEASE}-${UNAME_KERNEL}-${UNAME_KERNEL_RELEASE}"
147
  if [ -z "$1" ]; then
148
    if $VERBOSE; then
149
      echo "HOST_OS=$HOST_OS"
150
    fi
151
  fi
152
}
153
1079.28.2 by Brian Aker
Update to latest ddm4
154
# Validate the distribution name, or toss an erro
155
#  values: darwin,fedora,rhel,ubuntu,debian,opensuse
1079.8.9 by Brian Aker
Update for mingw compile.
156
function set_VENDOR_DISTRIBUTION ()
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
157
{
158
  local dist=`echo "$1" | tr '[A-Z]' '[a-z]'`
159
  case "$dist" in
160
    darwin)
161
      VENDOR_DISTRIBUTION='darwin'
162
      ;;
163
    fedora)
164
      VENDOR_DISTRIBUTION='fedora'
165
      ;;
166
    rhel)
167
      VENDOR_DISTRIBUTION='rhel'
168
      ;;
1079.28.2 by Brian Aker
Update to latest ddm4
169
    debian)
170
      VENDOR_DISTRIBUTION='debian'
171
      ;;
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
172
    ubuntu)
173
      VENDOR_DISTRIBUTION='ubuntu'
174
      ;;
1079.28.2 by Brian Aker
Update to latest ddm4
175
    suse)
176
      VENDOR_DISTRIBUTION='opensuse'
177
      ;;
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
178
    opensuse)
179
      VENDOR_DISTRIBUTION='opensuse'
180
      ;;
181
    *)
182
      die "attempt to set an invalid VENDOR_DISTRIBUTION=$dist"
183
      ;;
184
  esac
185
}
186
1079.28.2 by Brian Aker
Update to latest ddm4
187
# Validate a Vendor's release name/number 
1079.8.9 by Brian Aker
Update for mingw compile.
188
function set_VENDOR_RELEASE ()
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
189
{
190
  local release=`echo "$1" | tr '[A-Z]' '[a-z]'`
1079.30.5 by Brian Aker
Update ddm4
191
192
  if $DEBUG; then 
193
    echo "VENDOR_DISTRIBUTION:$VENDOR_DISTRIBUTION"
194
    echo "VENDOR_RELEASE:$release"
195
  fi
196
197
  case $VENDOR_DISTRIBUTION in
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
198
    darwin)
1079.30.5 by Brian Aker
Update ddm4
199
      case $release in
1079.28.2 by Brian Aker
Update to latest ddm4
200
        10.6*)
201
          VENDOR_RELEASE='snow_leopard'
202
          ;;
203
        10.7*)
204
          VENDOR_RELEASE='mountain'
205
          ;;
206
        mountain)
207
          VENDOR_RELEASE='mountain'
208
          ;;
1079.30.5 by Brian Aker
Update ddm4
209
        10.8.*)
210
          echo "mountain_lion"
1079.28.2 by Brian Aker
Update to latest ddm4
211
          VENDOR_RELEASE='mountain_lion'
212
          ;;
213
        *)
1079.30.5 by Brian Aker
Update ddm4
214
          echo $VENDOR_RELEASE
1079.28.2 by Brian Aker
Update to latest ddm4
215
          VENDOR_RELEASE='unknown'
216
          ;;
217
      esac
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
218
      ;;
219
    fedora)
220
      VENDOR_RELEASE="$release"
1079.28.2 by Brian Aker
Update to latest ddm4
221
      if [[ "x$VENDOR_RELEASE" == '18' ]]; then
222
        VENDOR_RELEASE='sphericalcow'
223
      fi
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
224
      ;;
225
    rhel)
226
      VENDOR_RELEASE="$release"
227
      ;;
1079.1.82 by Brian Aker
Update to latest bootstra.
228
    debian)
229
      VENDOR_RELEASE="$release"
230
      ;;
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
231
    ubuntu)
232
      VENDOR_RELEASE="$release"
1079.28.2 by Brian Aker
Update to latest ddm4
233
      if [[ "x$VENDOR_RELEASE" == 'x12.04' ]]; then
234
        VENDOR_RELEASE="precise"
235
      elif [[ "x$VENDOR_RELEASE" == 'x12.10' ]]; then
236
        VENDOR_RELEASE="quantal"
1079.31.5 by Brian Aker
Update to latest bootstrap
237
      elif [[ "x$VENDOR_RELEASE" == 'x13.04' ]]; then
238
        VENDOR_RELEASE="raring"
1079.28.2 by Brian Aker
Update to latest ddm4
239
      fi
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
240
      ;;
241
    opensuse)
242
      VENDOR_RELEASE="$release"
243
      ;;
244
    unknown)
245
      die "attempt to set VENDOR_RELEASE without setting VENDOR_DISTRIBUTION"
246
      ;;
247
    *)
248
      die "attempt to set with an invalid VENDOR_DISTRIBUTION=$VENDOR_DISTRIBUTION"
249
      ;;
250
  esac
251
}
252
253
1079.28.2 by Brian Aker
Update to latest ddm4
254
#  Valid values are: apple, redhat, centos, canonical, oracle, suse
1079.8.9 by Brian Aker
Update for mingw compile.
255
function set_VENDOR ()
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
256
{
257
  local vendor=`echo "$1" | tr '[A-Z]' '[a-z]'`
258
259
  case $vendor in
260
    apple)
261
      VENDOR='apple'
262
      ;;
263
    redhat)
264
      VENDOR='redhat'
265
      ;;
1079.28.2 by Brian Aker
Update to latest ddm4
266
    fedora)
267
      VENDOR='redhat'
268
      ;;
269
    redhat-release-server-*)
270
      VENDOR='redhat'
271
      ;;
272
    enterprise-release-*)
273
      VENDOR='oracle'
274
      ;;
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
275
    centos)
276
      VENDOR='centos'
277
      ;;
278
    canonical)
279
      VENDOR='canonical'
280
      ;;
1079.28.2 by Brian Aker
Update to latest ddm4
281
    ubuntu)
282
      VENDOR='canonical'
283
      ;;
284
    debian)
285
      VENDOR='debian'
286
      ;;
287
    opensuse)
288
      VENDOR='suse'
289
      ;;
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
290
    suse)
291
      VENDOR='suse'
292
      ;;
293
    *)
294
      die "An attempt was made to set an invalid VENDOR=$_vendor"
295
      ;;
296
  esac
297
298
  set_VENDOR_DISTRIBUTION $2
299
  set_VENDOR_RELEASE $3
1079.28.2 by Brian Aker
Update to latest ddm4
300
301
  # Set which vendor/versions we trust for autoreconf
302
  case $VENDOR_DISTRIBUTION in
303
    fedora)
304
      if [[ "x$VENDOR_RELEASE" == 'x18' ]]; then
305
        AUTORECONF_REBUILD_HOST=true
306
      elif [[ "x$VENDOR_RELEASE" == 'xsphericalcow' ]]; then
307
        AUTORECONF_REBUILD_HOST=true
308
      elif [[ "x$VENDOR_RELEASE" == 'x19' ]]; then
309
        AUTORECONF_REBUILD_HOST=true
310
      fi
311
      ;;
312
    canonical)
313
      if [[ "x$VENDOR_RELEASE" == 'xprecise' ]]; then
314
        AUTORECONF_REBUILD_HOST=true
315
      elif [[ "x$VENDOR_RELEASE" == 'xquantal' ]]; then
316
        AUTORECONF_REBUILD_HOST=true
317
      fi
318
      ;;
319
  esac
320
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
321
}
322
1079.8.9 by Brian Aker
Update for mingw compile.
323
function determine_target_platform ()
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
324
{
325
  UNAME_MACHINE_ARCH=`(uname -m) 2>/dev/null` || UNAME_MACHINE_ARCH=unknown
326
  UNAME_KERNEL=`(uname -s) 2>/dev/null`  || UNAME_SYSTEM=unknown
327
  UNAME_KERNEL_RELEASE=`(uname -r) 2>/dev/null` || UNAME_KERNEL_RELEASE=unknown
328
1079.28.2 by Brian Aker
Update to latest ddm4
329
  if [[ -x '/usr/bin/sw_vers' ]]; then 
330
    local _VERSION=`/usr/bin/sw_vers -productVersion`
331
    set_VENDOR 'apple' 'darwin' $_VERSION
332
  elif [[ $(uname) == 'Darwin' ]]; then
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
333
    set_VENDOR 'apple' 'darwin' 'mountain'
334
  elif [[ -f '/etc/fedora-release' ]]; then 
335
    local fedora_version=`cat /etc/fedora-release | awk ' { print $3 } '`
336
    set_VENDOR 'redhat' 'fedora' $fedora_version
337
  elif [[ -f '/etc/centos-release' ]]; then
338
    local centos_version=`cat /etc/centos-release | awk ' { print $7 } '`
339
    set_VENDOR 'centos' 'rhel' $centos_version
340
  elif [[ -f '/etc/SuSE-release' ]]; then
341
    local suse_distribution=`head -1 /etc/SuSE-release | awk ' { print $1 } '`
342
    local suse_version=`head -1 /etc/SuSE-release | awk ' { print $2 } '`
343
    set_VENDOR 'suse' $suse_distribution $suse_version
344
  elif [[ -f '/etc/redhat-release' ]]; then
345
    local rhel_version=`cat /etc/redhat-release | awk ' { print $7 } '`
1079.28.2 by Brian Aker
Update to latest ddm4
346
    local _vendor=`rpm -qf /etc/redhat-release`
347
    set_VENDOR $_vendor 'rhel' $rhel_version
348
  elif [[ -f '/etc/os-release' ]]; then 
349
    source '/etc/os-release'
350
    set_VENDOR $ID $ID $VERSION_ID
351
  elif [[ -x '/usr/bin/lsb_release' ]]; then 
352
    local _ID=`/usr/bin/lsb_release -s -i`
353
    local _VERSION=`/usr/bin/lsb_release -s -r`
354
    set_VENDOR $_ID $_ID $_VERSION_ID
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
355
  elif [[ -f '/etc/lsb-release' ]]; then 
1079.28.2 by Brian Aker
Update to latest ddm4
356
    source '/etc/lsb-release'
357
    set_VENDOR 'canonical' $DISTRIB_ID $DISTRIB_CODENAME
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
358
  fi
359
360
  rebuild_host_os
361
}
362
1079.8.9 by Brian Aker
Update for mingw compile.
363
function run_configure ()
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
364
{
365
  # We will run autoreconf if we are required
366
  run_autoreconf_if_required
367
368
  # We always begin at the root of our build
369
  if [ ! popd ]; then
370
    die "Programmer error, we entered run_configure with a stacked directory"
371
  fi
372
1079.8.9 by Brian Aker
Update for mingw compile.
373
  if ! command_exists "$CONFIGURE"; then
374
    die "$CONFIGURE does not exist"
375
  fi
376
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
377
  local BUILD_DIR="$1"
378
  if [[ -n "$BUILD_DIR" ]]; then
379
    rm -r -f $BUILD_DIR
380
    mkdir -p $BUILD_DIR
381
    safe_pushd $BUILD_DIR
382
  fi
383
384
  # Arguments for configure
1079.8.9 by Brian Aker
Update for mingw compile.
385
  local BUILD_CONFIGURE_ARG= 
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
386
1079.20.1 by Brian Aker
Harmonize WIN32, and update bootstrap
387
  # If ENV DEBUG is set we enable both debug and asssert, otherwise we see if this is a VCS checkout and if so enable assert
1079.30.5 by Brian Aker
Update ddm4
388
  # Set ENV ASSERT in order to enable assert.
389
  # If we are doing a valgrind run, we always compile with assert disabled
390
  if $valgrind_run; then
1079.30.18 by Brian Aker
Update bootstrap
391
    BUILD_CONFIGURE_ARG+= '--enable-assert=no'
1079.30.5 by Brian Aker
Update ddm4
392
  else
393
    if $DEBUG; then 
394
      BUILD_CONFIGURE_ARG+=' --enable-debug --enable-assert'
395
    elif [[ -n "$VCS_CHECKOUT" ]]; then
396
      BUILD_CONFIGURE_ARG+=' --enable-assert'
397
    fi
1079.8.9 by Brian Aker
Update for mingw compile.
398
  fi
399
400
  if [[ -n "$CONFIGURE_ARG" ]]; then 
1079.20.1 by Brian Aker
Harmonize WIN32, and update bootstrap
401
    BUILD_CONFIGURE_ARG+=" $CONFIGURE_ARG"
402
  fi
403
404
  if [[ -n "$PREFIX_ARG" ]]; then 
405
    BUILD_CONFIGURE_ARG+=" $PREFIX_ARG"
1079.8.9 by Brian Aker
Update for mingw compile.
406
  fi
407
408
  ret=1;
1072.1.4 by Brian Aker
Update
409
  # If we are executing on OSX use CLANG, otherwise only use it if we find it in the ENV
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
410
  case $HOST_OS in
411
    *-darwin-*)
1079.20.1 by Brian Aker
Harmonize WIN32, and update bootstrap
412
      CC=clang CXX=clang++ $top_srcdir/configure $BUILD_CONFIGURE_ARG || die "Cannot execute CC=clang CXX=clang++ configure $BUILD_CONFIGURE_ARG"
1079.8.9 by Brian Aker
Update for mingw compile.
413
      ret=$?
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
414
      ;;
415
    rhel-5*)
1079.8.9 by Brian Aker
Update for mingw compile.
416
      command_exists 'gcc44' || die "Could not locate gcc44"
1079.20.1 by Brian Aker
Harmonize WIN32, and update bootstrap
417
      CC=gcc44 CXX=gcc44 $top_srcdir/configure $BUILD_CONFIGURE_ARG || die "Cannot execute CC=gcc44 CXX=gcc44 configure $BUILD_CONFIGURE_ARG"
1079.8.9 by Brian Aker
Update for mingw compile.
418
      ret=$?
1072.1.4 by Brian Aker
Update
419
      ;;
420
    *)
1079.20.1 by Brian Aker
Harmonize WIN32, and update bootstrap
421
      $CONFIGURE $BUILD_CONFIGURE_ARG
1079.8.9 by Brian Aker
Update for mingw compile.
422
      ret=$?
1072.1.4 by Brian Aker
Update
423
      ;;
424
  esac
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
425
1079.8.9 by Brian Aker
Update for mingw compile.
426
  if [ $ret -ne 0 ]; then
1079.20.1 by Brian Aker
Harmonize WIN32, and update bootstrap
427
    die "Could not execute $CONFIGURE $BUILD_CONFIGURE_ARG"
1079.8.9 by Brian Aker
Update for mingw compile.
428
  fi
429
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
430
  if [ ! -f 'Makefile' ]; then
1079.8.9 by Brian Aker
Update for mingw compile.
431
    die "Programmer error, configure was run but no Makefile existed after $CONFIGURE was run"
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
432
  fi
1072.1.4 by Brian Aker
Update
433
}
434
1079.8.9 by Brian Aker
Update for mingw compile.
435
function setup_gdb_command () {
1072.1.4 by Brian Aker
Update
436
  GDB_TMPFILE=$(mktemp /tmp/gdb.XXXXXXXXXX)
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
437
  echo 'set logging overwrite on' > $GDB_TMPFILE
438
  echo 'set logging on' >> $GDB_TMPFILE
439
  echo 'set environment LIBTEST_IN_GDB=1' >> $GDB_TMPFILE
440
  echo 'run' >> $GDB_TMPFILE
441
  echo 'thread apply all bt' >> $GDB_TMPFILE
442
  echo 'quit' >> $GDB_TMPFILE
1072.1.4 by Brian Aker
Update
443
  GDB_COMMAND="gdb -f -batch -x $GDB_TMPFILE"
444
}
445
1079.8.9 by Brian Aker
Update for mingw compile.
446
function setup_valgrind_command () {
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
447
  VALGRIND_PROGRAM=`type -p valgrind`
448
  if [[ -n "$VALGRIND_PROGRAM" ]]; then
1079.30.23 by Brian Aker
Fix for bootstrap
449
    VALGRIND_COMMAND="$VALGRIND_PROGRAM --error-exitcode=1 --leak-check=yes --malloc-fill=A5 --free-fill=DE --xml=yes --xml-file=\"valgrind-%p.xml\""
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
450
  fi
451
}
452
1079.8.9 by Brian Aker
Update for mingw compile.
453
function save_BUILD ()
454
{
455
  if [[ -n "$OLD_CONFIGURE" ]]; then
456
    die "OLD_CONFIGURE($OLD_CONFIGURE) was set on push, programmer error!"
457
  fi
458
459
  if [[ -n "$OLD_CONFIGURE_ARG" ]]; then
460
    die "OLD_CONFIGURE_ARG($OLD_CONFIGURE_ARG) was set on push, programmer error!"
461
  fi
462
1079.20.1 by Brian Aker
Harmonize WIN32, and update bootstrap
463
  if [[ -n "$OLD_PREFIX" ]]; then
464
    die "OLD_PREFIX($OLD_PREFIX) was set on push, programmer error!"
465
  fi
466
1079.8.9 by Brian Aker
Update for mingw compile.
467
  if [[ -n "$OLD_MAKE" ]]; then
468
    die "OLD_MAKE($OLD_MAKE) was set on push, programmer error!"
469
  fi
470
471
  if [[ -n "$OLD_TESTS_ENVIRONMENT" ]]; then
472
    die "OLD_TESTS_ENVIRONMENT($OLD_TESTS_ENVIRONMENT) was set on push, programmer error!"
473
  fi
474
475
  if [[ -n "$CONFIGURE" ]]; then
476
    OLD_CONFIGURE=$CONFIGURE
477
  fi
478
479
  if [[ -n "$CONFIGURE_ARG" ]]; then
480
    OLD_CONFIGURE_ARG=$CONFIGURE_ARG
481
  fi
482
483
  if [[ -n "$MAKE" ]]; then
484
    OLD_MAKE=$MAKE
485
  fi
486
487
  if [[ -n "$TESTS_ENVIRONMENT" ]]; then
488
    OLD_TESTS_ENVIRONMENT=$TESTS_ENVIRONMENT
489
  fi
490
}
491
492
function restore_BUILD ()
493
{
494
  if [[ -n "$OLD_CONFIGURE" ]]; then
495
    CONFIGURE=$OLD_CONFIGURE
496
  fi
497
498
  if [[ -n "$OLD_CONFIGURE_ARG" ]]; then
499
    CONFIGURE_ARG=$OLD_CONFIGURE_ARG
500
  fi
501
1079.20.1 by Brian Aker
Harmonize WIN32, and update bootstrap
502
  if [[ -n "$OLD_PREFIX" ]]; then
1079.20.2 by Brian Aker
Adding missing windows file.
503
    PREFIX_ARG=$OLD_PREFIX
1079.20.1 by Brian Aker
Harmonize WIN32, and update bootstrap
504
  fi
505
1079.8.9 by Brian Aker
Update for mingw compile.
506
  if [[ -n "$OLD_MAKE" ]]; then
507
    MAKE=$OLD_MAKE
508
  fi
509
510
  if [[ -n "$OLD_TESTS_ENVIRONMENT" ]]; then
511
    TESTS_ENVIRONMENT=$OLD_TESTS_ENVIRONMENT
512
  fi
513
514
  OLD_CONFIGURE=
515
  OLD_CONFIGURE_ARG=
1079.20.1 by Brian Aker
Harmonize WIN32, and update bootstrap
516
  OLD_PREFIX=
1079.8.9 by Brian Aker
Update for mingw compile.
517
  OLD_MAKE=
518
  OLD_TESTS_ENVIRONMENT=
1079.15.1 by Brian Aker
Clarification in DNS test.
519
520
  export -n CC CXX
1079.8.9 by Brian Aker
Update for mingw compile.
521
}
522
1079.3.9 by Brian Aker
Update bootstrap.sh
523
function safe_pushd ()
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
524
{
525
  pushd $1 &> /dev/null ;
526
1079.7.3 by Brian Aker
Update bootstrap.sh
527
  if [ -n "$BUILD_DIR" ]; then
528
    if $VERBOSE; then
529
      echo "BUILD_DIR=$BUILD_DIR"
530
    fi
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
531
  fi
532
}
533
1079.3.9 by Brian Aker
Update bootstrap.sh
534
function safe_popd ()
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
535
{
536
  local directory_to_delete=`pwd`
537
  popd &> /dev/null ;
538
  if [ $? -eq 0 ]; then
539
    if [[ "$top_srcdir" == "$directory_to_delete" ]]; then
540
      die "We almost deleted top_srcdir($top_srcdir), programmer error"
541
    fi
542
543
    rm -r -f "$directory_to_delete"
544
  fi
545
}
546
1079.3.9 by Brian Aker
Update bootstrap.sh
547
function make_valgrind ()
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
548
{
549
  # If the env VALGRIND_COMMAND is set then we assume it is valid
550
  local valgrind_was_set=false
551
  if [[ -z "$VALGRIND_COMMAND" ]]; then
552
    setup_valgrind_command
553
    if [[ -n "$VALGRIND_COMMAND" ]]; then
554
      valgrind_was_set=true
555
    fi
556
  else
557
    valgrind_was_set=true
558
  fi
559
560
  # If valgrind_was_set is set to no we bail
561
  if ! $valgrind_was_set; then
562
    echo 'valgrind was not present'
563
    return 1
564
  fi
565
1079.20.2 by Brian Aker
Adding missing windows file.
566
  save_BUILD
567
1079.30.5 by Brian Aker
Update ddm4
568
  valgrind_run=true
569
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
570
  # If we are required to run configure, do so now
1079.30.5 by Brian Aker
Update ddm4
571
  run_configure
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
572
1079.3.9 by Brian Aker
Update bootstrap.sh
573
  # If we don't have a configure, then most likely we will be missing libtool
574
  assert_file 'configure'
1079.30.18 by Brian Aker
Update bootstrap
575
  if [[ -x 'libtool' ]]; then
1079.3.9 by Brian Aker
Update bootstrap.sh
576
    TESTS_ENVIRONMENT="./libtool --mode=execute $VALGRIND_COMMAND"
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
577
  else
578
    TESTS_ENVIRONMENT="$VALGRIND_COMMAND"
579
  fi
580
1079.30.10 by Brian Aker
Adding all for bootstrap
581
  make_target 'all'
1079.30.5 by Brian Aker
Update ddm4
582
  make_target 'check'
583
  ret=$?
584
585
  # If we aren't going to error, we will clean up our environment
586
  if [ "$ret" -eq 0 ]; then
587
     make 'distclean'
588
  fi
589
590
  valgrind_run=false
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
591
1079.20.2 by Brian Aker
Adding missing windows file.
592
  restore_BUILD
1079.30.5 by Brian Aker
Update ddm4
593
594
  if [ "$ret" -ne 0 ]; then
595
    return 1
596
  fi
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
597
}
598
1079.3.9 by Brian Aker
Update bootstrap.sh
599
function make_install_system ()
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
600
{
601
  local INSTALL_LOCATION=$(mktemp -d /tmp/XXXXXXXXXX)
1079.20.2 by Brian Aker
Adding missing windows file.
602
603
  save_BUILD
604
  PREFIX_ARG="--prefix=$INSTALL_LOCATION"
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
605
606
  if [ ! -d $INSTALL_LOCATION ] ; then
607
    die "ASSERT temp directory not found '$INSTALL_LOCATION'"
608
  fi
609
610
  run_configure #install_buid_dir
611
612
  make_target 'install'
613
614
  make_target 'installcheck'
615
616
  make_target 'uninstall'
617
1072.1.4 by Brian Aker
Update
618
  rm -r -f $INSTALL_LOCATION
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
619
  make 'distclean'
620
621
  if [ -f 'Makefile' ]; then
622
    die "ASSERT Makefile should not exist"
623
  fi
624
1079.20.2 by Brian Aker
Adding missing windows file.
625
  restore_BUILD
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
626
  safe_popd
1072.1.4 by Brian Aker
Update
627
}
628
1079.3.9 by Brian Aker
Update bootstrap.sh
629
function make_darwin_malloc ()
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
630
{
631
  run_configure_if_required
632
633
  old_MallocGuardEdges=$MallocGuardEdges
1072.1.4 by Brian Aker
Update
634
  MallocGuardEdges=1
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
635
  old_MallocErrorAbort=$MallocErrorAbort
1072.1.4 by Brian Aker
Update
636
  MallocErrorAbort=1
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
637
  old_MallocScribble=$MallocScribble
1072.1.4 by Brian Aker
Update
638
  MallocScribble=1
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
639
1072.1.4 by Brian Aker
Update
640
  make_check
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
641
642
  MallocGuardEdges=$old_MallocGuardEdges
643
  MallocErrorAbort=$old_MallocErrorAbort
644
  MallocScribble=$old_MallocScribble
645
}
646
647
# This will reset our environment, and make sure built files are available.
1079.3.9 by Brian Aker
Update bootstrap.sh
648
function make_for_snapshot ()
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
649
{
1079.30.8 by Brian Aker
Import latest bootstrap.sh
650
  # Lets make sure we have a clean environment
651
  assert_no_file 'Makefile'
652
  assert_no_file 'configure'
653
  assert_no_directory 'autom4te.cache'
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
654
655
  run_configure
1079.30.13 by Brian Aker
Fixes for
656
  make_target 'all'
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
657
  make_target 'distclean'
658
659
  # We should have a configure, but no Makefile at the end of this exercise
660
  assert_no_file 'Makefile'
661
  assert_exec_file 'configure'
662
}
663
1079.8.9 by Brian Aker
Update for mingw compile.
664
function check_mingw ()
665
{
666
  command_exists 'mingw64-configure'
667
  ret=$?
668
  if [ "$ret" -ne 0 ]; then
669
    return 1
670
  fi
671
672
  command_exists 'mingw64-make'
673
  ret=$?
674
  if [ "$ret" -ne 0 ]; then
675
    return 1
676
  fi
677
678
  return 0
679
}
680
1079.15.1 by Brian Aker
Clarification in DNS test.
681
function check_clang ()
682
{
683
  command_exists 'clang'
684
  ret=$?
685
  if [ "$ret" -ne 0 ]; then
686
    return 1
687
  fi
688
689
  return 0
690
}
691
692
function check_clang_analyzer ()
693
{
694
  command_exists 'scan-build'
695
  ret=$?
696
  if [ "$ret" -ne 0 ]; then
697
    return 1
698
  fi
699
700
  return 0
701
}
702
703
function make_skeleton ()
1079.8.9 by Brian Aker
Update for mingw compile.
704
{
705
  run_configure
706
  ret=$?
707
708
  if [ $ret -eq 0 ]; then
709
    assert_file 'Makefile'
710
711
    make_target 'all' 'warn'
712
    ret=$?
713
    if [ $ret -ne 0 ]; then
714
      warn "$MAKE failed"
715
    else
716
      if [[ -n "$DISPLAY" ]]; then
717
        if command_exists 'wine'; then
718
          TESTS_ENVIRONMENT='wine'
719
        fi
720
      fi
721
722
      if [[ -n "$TESTS_ENVIRONMENT" ]]; then
723
        make_target 'check' 'warn' || warn "$MAKE check failed"
724
        ret=$?
725
      fi
726
    fi
727
728
    if $jenkins_build_environment; then
729
      make_target 'clean' 'warn'
730
    fi
731
  fi
732
733
  return $ret
734
}
735
736
function make_for_mingw ()
737
{
738
  if ! check_mingw; then
1079.15.1 by Brian Aker
Clarification in DNS test.
739
    return 1
1079.8.9 by Brian Aker
Update for mingw compile.
740
  fi
741
1079.3.10 by Brian Aker
A number of small build fixes found while looking at mingw support.
742
  # Make sure it is clean
743
  if [ -f Makefile -o -f configure ]; then
744
    make_maintainer_clean
745
  fi
1079.8.9 by Brian Aker
Update for mingw compile.
746
747
  run_autoreconf
748
749
  save_BUILD
750
751
  CONFIGURE='mingw64-configure'
752
  MAKE='mingw64-make'
1079.15.1 by Brian Aker
Clarification in DNS test.
753
  CONFIGURE_ARGS='--enable-static --disable-shared'
754
755
  make_skeleton
756
  ret=$?
757
758
  restore_BUILD
759
760
  return $ret
761
}
762
763
function make_for_clang ()
764
{
765
  if ! check_clang; then
766
    return 1
767
  fi
768
769
  # Make sure it is clean
770
  if [ -f Makefile -o -f configure ]; then
771
    make_maintainer_clean
772
  fi
773
774
  run_autoreconf
775
776
  save_BUILD
777
778
  CC=clang CXX=clang++
779
  export CC CXX
780
781
  make_skeleton
782
  ret=$?
783
784
  make_target 'check'
785
786
  restore_BUILD
787
788
  return $ret
789
}
790
791
function make_for_clang_analyzer ()
792
{
793
  if ! check_clang; then
794
    return 1
795
  fi
796
797
  if ! check_clang_analyzer; then
798
    die 'clang-analyzer was not found'
799
  fi
800
801
  # Make sure it is clean
802
  if [ -f Makefile -o -f configure ]; then
803
    make_maintainer_clean
804
  fi
805
806
  run_autoreconf
807
808
  save_BUILD
809
810
  CC=clang CXX=clang++
811
  export CC CXX
812
  CONFIGURE_ARGS='--enable-debug'
813
814
  make_skeleton
815
  ret=$?
816
817
  make_target 'clean' 'warn'
818
819
  scan-build -o clang-html make -j4 -k
1079.8.9 by Brian Aker
Update for mingw compile.
820
821
  restore_BUILD
822
823
  return $ret
1079.3.10 by Brian Aker
A number of small build fixes found while looking at mingw support.
824
}
825
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
826
# If we are locally testing, we should make sure the environment is setup correctly
1079.3.9 by Brian Aker
Update bootstrap.sh
827
function check_for_jenkins ()
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
828
{
829
  if ! $jenkins_build_environment; then
1079.30.8 by Brian Aker
Import latest bootstrap.sh
830
    echo "Not inside of jenkins, simulating environment"
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
831
832
    if [ -f 'configure' ]; then
833
      make_maintainer_clean
834
    fi
835
836
    if $BOOTSTRAP_SNAPSHOT; then
837
      make_for_snapshot
838
    fi
839
  fi
840
}
841
1079.3.10 by Brian Aker
A number of small build fixes found while looking at mingw support.
842
function make_universe ()
843
{
844
  make_for_snapshot
845
  make_valgrind
846
  make_gdb
847
  make_rpm
1079.15.1 by Brian Aker
Clarification in DNS test.
848
  make_for_clang
849
  make_for_clang_analyzer
1079.8.9 by Brian Aker
Update for mingw compile.
850
851
  if [ check_mingw -eq 0 ]; then
852
    make_for_mingw
853
  fi
854
1079.3.10 by Brian Aker
A number of small build fixes found while looking at mingw support.
855
  make_distcheck
856
  make_install_system
857
}
858
1079.30.13 by Brian Aker
Fixes for
859
function check_snapshot ()
860
{
861
  if [ -n "$BOOTSTRAP_SNAPSHOT_CHECK" ]; then
862
    assert_file "$BOOTSTRAP_SNAPSHOT_CHECK" 'snapshot check failed'
863
  fi
864
}
865
1079.3.9 by Brian Aker
Update bootstrap.sh
866
function make_for_continuus_integration ()
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
867
{
868
  # Setup the environment if we are local
869
  check_for_jenkins
870
871
  # No matter then evironment, we should not have a Makefile at this point
872
  assert_no_file 'Makefile'
873
874
  # Platforms which require bootstrap should have some setup done before we hit this stage.
875
  # If we are building locally, skip this step, unless we are just testing locally. 
876
  if $BOOTSTRAP_SNAPSHOT; then
1079.30.8 by Brian Aker
Import latest bootstrap.sh
877
    if $BOOTSTRAP_SNAPSHOT; then
878
      assert_file 'configure'
879
    fi
880
1079.30.13 by Brian Aker
Fixes for
881
    check_snapshot
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
882
  else
883
    # If we didn't require a snapshot, then we should not have a configure
884
    assert_no_file 'configure'
885
886
    run_autoreconf
887
  fi
888
889
  assert_no_file 'Makefile' 'Programmer error, Makefile existed where build state should have been clean'
890
891
  case $HOST_OS in
1072.1.4 by Brian Aker
Update
892
    *)
1079.3.9 by Brian Aker
Update bootstrap.sh
893
      make_jenkins_default
1072.1.4 by Brian Aker
Update
894
      ;;
895
  esac
896
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
897
  make_maintainer_clean
1072.1.4 by Brian Aker
Update
898
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
899
  safe_popd
1072.1.4 by Brian Aker
Update
900
}
901
1079.3.9 by Brian Aker
Update bootstrap.sh
902
# The point to this test is to test bootstrap.sh itself
903
function self_test ()
904
{
905
  # We start off with a clean env
906
  make_maintainer_clean
907
908
  eval "./bootstrap.sh jenkins" || die "failed 'jenkins'"
909
  eval "./bootstrap.sh all" || die "failed 'all'"
910
  eval "./bootstrap.sh gdb" || die "failed 'gdb'"
911
  eval "./bootstrap.sh maintainer-clean" || die "failed 'maintainer-clean'"
912
}
913
1079.8.9 by Brian Aker
Update for mingw compile.
914
function make_install_html ()
915
{
916
  run_configure_if_required
917
  assert_file 'configure'
918
919
  make_target 'install-html'
920
}
921
1079.3.9 by Brian Aker
Update bootstrap.sh
922
function make_gdb ()
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
923
{
1079.20.2 by Brian Aker
Adding missing windows file.
924
  save_BUILD
925
1079.8.9 by Brian Aker
Update for mingw compile.
926
  if command_exists 'gdb'; then
927
    run_configure_if_required
1072.1.4 by Brian Aker
Update
928
929
    # Set ENV GDB_COMMAND
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
930
    if [[ -z "$GDB_COMMAND" ]]; then
1072.1.4 by Brian Aker
Update
931
      setup_gdb_command
932
    fi
933
1079.3.9 by Brian Aker
Update bootstrap.sh
934
    # If we don't have a configure, then most likely we will be missing libtool
935
    assert_file 'configure'
936
    if [[ -f 'libtool' ]]; then
937
      TESTS_ENVIRONMENT="./libtool --mode=execute $GDB_COMMAND"
1072.1.4 by Brian Aker
Update
938
    else
939
      TESTS_ENVIRONMENT="$GDB_COMMAND"
940
    fi
941
1079.8.9 by Brian Aker
Update for mingw compile.
942
    make_target 'check'
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
943
944
    if [ -f 'gdb.txt' ]; then
945
      rm 'gdb.txt'
946
    fi
947
948
    if [ -f '.gdb_history' ]; then
949
      rm '.gdb_history'
950
    fi
1079.8.9 by Brian Aker
Update for mingw compile.
951
952
    if $jenkins_build_environment; then
953
      make_target 'clean'
954
    fi
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
955
  else
956
    echo 'gdb was not present'
957
    return 1
958
  fi
1079.20.2 by Brian Aker
Adding missing windows file.
959
960
  restore_BUILD
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
961
}
962
963
# $1 target to compile
964
# $2 to die, or not to die, based on contents
1079.3.9 by Brian Aker
Update bootstrap.sh
965
function make_target ()
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
966
{
1079.7.3 by Brian Aker
Update bootstrap.sh
967
  if [ -z "$1" ]; then
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
968
    die "Programmer error, no target provided for make"
969
  fi
970
971
  if [ ! -f 'Makefile' ]; then
972
    die "Programmer error, make was called before configure"
973
    run_configure
974
  fi
975
1079.7.3 by Brian Aker
Update bootstrap.sh
976
  if [ -n "$TESTS_ENVIRONMENT" ]; then
977
    if $VERBOSE; then
978
      echo "TESTS_ENVIRONMENT=$TESTS_ENVIRONMENT"
979
    fi
1072.1.4 by Brian Aker
Update
980
  fi
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
981
1079.7.3 by Brian Aker
Update bootstrap.sh
982
  if [ -z "$MAKE" ]; then
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
983
    die "MAKE was not set"
984
  fi
985
1079.8.9 by Brian Aker
Update for mingw compile.
986
  # $2 represents error or warn
987
  run $MAKE $1
988
  ret=$?
989
990
  if [ $ret -ne 0 ]; then
991
    if [ -n "$2" ]; then
1079.15.1 by Brian Aker
Clarification in DNS test.
992
      warn "Failed to execute $MAKE $1: $ret"
1079.8.9 by Brian Aker
Update for mingw compile.
993
    else
1079.15.1 by Brian Aker
Clarification in DNS test.
994
      die "Failed to execute $MAKE $1: $ret"
1079.8.9 by Brian Aker
Update for mingw compile.
995
    fi
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
996
  fi
1079.8.9 by Brian Aker
Update for mingw compile.
997
998
  return $ret
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
999
}
1000
1079.3.9 by Brian Aker
Update bootstrap.sh
1001
function make_distcheck ()
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
1002
{
1003
  make_target 'distcheck'
1004
}
1005
1079.3.9 by Brian Aker
Update bootstrap.sh
1006
function make_rpm ()
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
1007
{
1079.8.9 by Brian Aker
Update for mingw compile.
1008
  if command_exists 'rpmbuild'; then
1009
    if [ -f 'rpm.am' -o -d 'rpm' ]; then
1010
      run_configure_if_required
1011
      make_target 'rpm'
1012
1013
      if $jenkins_build_environment; then
1014
        make_target 'clean'
1015
      fi
1016
1017
    fi
1079.3.10 by Brian Aker
A number of small build fixes found while looking at mingw support.
1018
  fi
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
1019
}
1020
1079.3.9 by Brian Aker
Update bootstrap.sh
1021
function make_maintainer_clean ()
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
1022
{
1023
  run_configure_if_required
1024
  make_target 'maintainer-clean' 'no_error'
1079.8.9 by Brian Aker
Update for mingw compile.
1025
1026
  # Lets make sure we really cleaned up the environment
1027
  assert_no_file 'Makefile'
1028
  assert_no_file 'configure'
1029
  assert_no_directory 'autom4te.cache'
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
1030
}
1031
1079.3.9 by Brian Aker
Update bootstrap.sh
1032
function make_check ()
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
1033
{
1034
  make_target 'check'
1035
}
1036
1079.3.9 by Brian Aker
Update bootstrap.sh
1037
function make_jenkins_default ()
1038
{
1039
  run_configure
1040
  make_target 'all'
1041
}
1042
1043
function make_default ()
1044
{
1045
  run_configure_if_required
1046
  make_target 'all'
1047
}
1048
1049
function run_configure_if_required () 
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
1050
{
1051
  run_autoreconf_if_required
1052
1053
  if [ ! -f 'Makefile' ]; then
1054
    run_configure
1055
  fi
1056
1057
  assert_file 'Makefile' 'configure did not produce a Makefile'
1058
}
1059
1079.1.82 by Brian Aker
Update to latest bootstra.
1060
function run_make_maintainer_clean_if_possible () 
1061
{
1062
  if [ -f 'Makefile' ]; then
1063
    make_maintainer_clean
1064
  fi
1065
}
1066
1079.3.9 by Brian Aker
Update bootstrap.sh
1067
function run_autoreconf_if_required () 
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
1068
{
1069
  if [ ! -x 'configure' ]; then
1070
    run_autoreconf
1071
  fi
1072
1073
  assert_exec_file 'configure'
1079.28.2 by Brian Aker
Update to latest ddm4
1074
  bash -n configure
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
1075
}
1076
1079.3.9 by Brian Aker
Update bootstrap.sh
1077
function run_autoreconf () 
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
1078
{
1079
  if [[ -z "$AUTORECONF" ]]; then
1080
    die "Programmer error, tried to call run_autoreconf () but AUTORECONF was not set"
1081
  fi
1082
1079.7.3 by Brian Aker
Update bootstrap.sh
1083
  if test $use_libtool = 1; then
1084
    assert $BOOTSTRAP_LIBTOOLIZE
1085
    run $BOOTSTRAP_LIBTOOLIZE '--copy' '--install' '--force' || die "Cannot execute $BOOTSTRAP_LIBTOOLIZE"
1086
  fi
1087
1079.30.5 by Brian Aker
Update ddm4
1088
  run $AUTORECONF $AUTORECONF_ARGS || die "Cannot execute $AUTORECONF"
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
1089
1090
  eval 'bash -n configure' || die "autoreconf generated a malformed configure"
1091
}
1092
1079.2.3 by Brian Aker
Update for version 1.0.13
1093
function run ()
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
1094
{
1095
  if $VERBOSE; then
1096
    echo "\`$@' $ARGS"
1097
  fi
1098
1079.8.9 by Brian Aker
Update for mingw compile.
1099
  if [ -z "$1" ]; then
1100
    return 127;
1101
  fi
1102
1079.2.4 by Brian Aker
Update to allow rpm to be legal jenkins target.
1103
  eval $@ $ARGS
1070.1.3 by Brian Aker
Updates from ddm4
1104
} 
1105
1079.8.9 by Brian Aker
Update for mingw compile.
1106
function parse_command_line_options ()
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
1107
{
1079.3.9 by Brian Aker
Update bootstrap.sh
1108
  local SHORTOPTS=':apcmt:dvh'
1109
1110
  nassert MAKE_TARGET
1079.2.2 by Brian Aker
OSX lacks getopt long support :(
1111
1112
  while getopts "$SHORTOPTS" opt; do
1113
    case $opt in
1114
      a) #--autoreconf
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
1115
        AUTORECONF_OPTION=true
1116
        MAKE_TARGET='autoreconf'
1117
        ;;
1079.2.2 by Brian Aker
OSX lacks getopt long support :(
1118
      p) #--print-env
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
1119
        PRINT_SETUP_OPTION=true
1120
        ;;
1079.2.2 by Brian Aker
OSX lacks getopt long support :(
1121
      c) # --configure
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
1122
        CONFIGURE_OPTION=true
1123
        MAKE_TARGET='configure'
1124
        ;;
1079.2.2 by Brian Aker
OSX lacks getopt long support :(
1125
      m) # maintainer-clean
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
1126
        CLEAN_OPTION=true
1127
        MAKE_TARGET='clean_op'
1128
        ;;
1079.2.2 by Brian Aker
OSX lacks getopt long support :(
1129
      t) # target
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
1130
        TARGET_OPTION=true
1079.2.2 by Brian Aker
OSX lacks getopt long support :(
1131
        TARGET_OPTION_ARG="$OPTARG"
1132
        MAKE_TARGET="$OPTARG"
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
1133
        ;;
1079.2.2 by Brian Aker
OSX lacks getopt long support :(
1134
      d) # debug
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
1135
        DEBUG_OPTION=true
1136
        enable_debug
1137
        ;;
1079.3.9 by Brian Aker
Update bootstrap.sh
1138
      h) # help
1139
        echo "bootstrap.sh [options] optional_target ..."
1079.28.1 by Brian Aker
Fix for lp:1164442
1140
        echo "  -a # Just run autoreconf";
1141
        echo "  -p # Print ENV";
1142
        echo "  -c # Just run configure";
1143
        echo "  -m # Just run maintainer-clean";
1144
        echo "  -t # Make target";
1145
        echo "  -d # Enable debug";
1146
        echo "  -h # Show help";
1147
        echo "  -v # Be more verbose in output";
1079.3.9 by Brian Aker
Update bootstrap.sh
1148
        exit
1149
        ;;
1079.2.2 by Brian Aker
OSX lacks getopt long support :(
1150
      v) # verbose
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
1151
        VERBOSE_OPTION=true
1152
        VERBOSE=true
1079.2.2 by Brian Aker
OSX lacks getopt long support :(
1153
        ;;
1154
      :)
1155
        echo "Option -$OPTARG requires an argument." >&2
1156
        exit 1
1157
        ;;
1158
      *)
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
1159
        echo "$0: error - unrecognized option $1" 1>&2
1160
        exit 1
1161
        ;;
1072.1.8 by Brian Aker
Add new method which allows someone to "take" a value from a result object.
1162
    esac
1163
  done
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
1164
1079.3.9 by Brian Aker
Update bootstrap.sh
1165
  shift $((OPTIND-1))
1166
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
1167
  if [ -n "$1" ]; then
1079.3.9 by Brian Aker
Update bootstrap.sh
1168
    MAKE_TARGET="$@"
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
1169
  fi
1072.1.8 by Brian Aker
Add new method which allows someone to "take" a value from a result object.
1170
}
1171
1079.8.9 by Brian Aker
Update for mingw compile.
1172
function determine_vcs ()
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
1173
{
1174
  if [[ -d '.git' ]]; then
1072.1.4 by Brian Aker
Update
1175
    VCS_CHECKOUT=git
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
1176
  elif [[ -d '.bzr' ]]; then
1072.1.4 by Brian Aker
Update
1177
    VCS_CHECKOUT=bzr
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
1178
  elif [[ -d '.svn' ]]; then
1072.1.4 by Brian Aker
Update
1179
    VCS_CHECKOUT=svn
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
1180
  elif [[ -d '.hg' ]]; then
1072.1.4 by Brian Aker
Update
1181
    VCS_CHECKOUT=hg
1079.20.1 by Brian Aker
Harmonize WIN32, and update bootstrap
1182
  else
1183
    VCS_CHECKOUT=
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
1184
  fi
1185
1186
  if [[ -n "$VCS_CHECKOUT" ]]; then
1187
    VERBOSE=true
1188
  fi
1189
}
1190
1079.7.3 by Brian Aker
Update bootstrap.sh
1191
function require_libtoolise ()
1192
{
1193
  use_libtool=0
1194
  grep '^[         ]*A[CM]_PROG_LIBTOOL' configure.ac >/dev/null \
1195
    && use_libtool=1
1196
  grep '^[         ]*LT_INIT' configure.ac >/dev/null \
1197
    && use_libtool=1
1198
}
1199
1200
function autoreconf_setup ()
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
1201
{
1072.1.1 by Brian Aker
Fix how we do manpages.
1202
  # Set ENV MAKE in order to override "make"
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
1203
  if [[ -z "$MAKE" ]]; then 
1079.8.9 by Brian Aker
Update for mingw compile.
1204
    if command_exists 'gmake'; then
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
1205
      MAKE=`type -p gmake`
1079.2.4 by Brian Aker
Update to allow rpm to be legal jenkins target.
1206
    else
1079.8.9 by Brian Aker
Update for mingw compile.
1207
      if command_exists 'make'; then
1079.2.4 by Brian Aker
Update to allow rpm to be legal jenkins target.
1208
        MAKE=`type -p make`
1209
      fi
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
1210
    fi
1079.2.4 by Brian Aker
Update to allow rpm to be legal jenkins target.
1211
    
1079.3.10 by Brian Aker
A number of small build fixes found while looking at mingw support.
1212
    if [ "$VCS_CHECKOUT" ]; then
1213
      if $DEBUG; then
1214
        MAKE="$MAKE --warn-undefined-variables"
1215
      fi
1216
    fi
1217
1079.2.4 by Brian Aker
Update to allow rpm to be legal jenkins target.
1218
    if $DEBUG; then
1079.3.10 by Brian Aker
A number of small build fixes found while looking at mingw support.
1219
      MAKE="$MAKE -d"
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
1220
    fi
1221
  fi
1222
1223
  if [[ -z "$GNU_BUILD_FLAGS" ]]; then
1224
    GNU_BUILD_FLAGS="--install --force"
1225
  fi
1226
1227
  if $VERBOSE; then
1228
    GNU_BUILD_FLAGS="$GNU_BUILD_FLAGS --verbose"
1229
  fi
1230
1079.4.11 by Brian Aker
Update m4
1231
  if [ -z "$ACLOCAL_PATH" ]; then
1232
    ACLOCAL_PATH="/usr/local/share/aclocal $ACLOCAL_PATH"
1233
  fi
1234
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
1235
  if [[ -z "$WARNINGS" ]]; then
1236
    if [[ -n "$VCS_CHECKOUT" ]]; then
1237
      WARNINGS="all,error"
1238
    else
1239
      WARNINGS="all"
1240
    fi
1241
  fi
1242
1079.7.3 by Brian Aker
Update bootstrap.sh
1243
  if test $use_libtool = 1; then
1244
    if [[ -n "$LIBTOOLIZE" ]]; then
1245
      BOOTSTRAP_LIBTOOLIZE=`type -p $LIBTOOLIZE`
1246
1247
      if [[ -z "$BOOTSTRAP_LIBTOOLIZE" ]]; then
1248
        echo "Couldn't find user supplied libtoolize, it is required"
1079.28.1 by Brian Aker
Fix for lp:1164442
1249
        return 1
1079.7.3 by Brian Aker
Update bootstrap.sh
1250
      fi
1251
    else
1252
      # If we are using OSX, we first check to see glibtoolize is available
1253
      if [[ "$VENDOR_DISTRIBUTION" == "darwin" ]]; then
1254
        BOOTSTRAP_LIBTOOLIZE=`type -p glibtoolize`
1255
1256
        if [[ -z "$BOOTSTRAP_LIBTOOLIZE" ]]; then
1257
          echo "Couldn't find glibtoolize, it is required on OSX"
1079.28.1 by Brian Aker
Fix for lp:1164442
1258
          return 1
1079.7.3 by Brian Aker
Update bootstrap.sh
1259
        fi
1260
      else
1261
        BOOTSTRAP_LIBTOOLIZE=`type -p libtoolize`
1262
1263
        if [[ -z "$BOOTSTRAP_LIBTOOLIZE" ]]; then
1264
          echo "Couldn't find libtoolize, it is required"
1079.28.1 by Brian Aker
Fix for lp:1164442
1265
          return 1
1079.7.3 by Brian Aker
Update bootstrap.sh
1266
        fi
1267
      fi
1268
    fi
1079.30.5 by Brian Aker
Update ddm4
1269
1079.7.3 by Brian Aker
Update bootstrap.sh
1270
    if $VERBOSE; then
1271
      LIBTOOLIZE_OPTIONS="--verbose $BOOTSTRAP_LIBTOOLIZE_OPTIONS"
1272
    fi
1079.30.5 by Brian Aker
Update ddm4
1273
1079.7.3 by Brian Aker
Update bootstrap.sh
1274
    if $DEBUG; then
1275
      LIBTOOLIZE_OPTIONS="--debug $BOOTSTRAP_LIBTOOLIZE_OPTIONS"
1276
    fi
1079.30.5 by Brian Aker
Update ddm4
1277
1278
    # Here we set LIBTOOLIZE to true since we are going to invoke it via BOOTSTRAP_LIBTOOLIZE
1079.7.3 by Brian Aker
Update bootstrap.sh
1279
    LIBTOOLIZE=true
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
1280
  fi
1281
1282
  # Test the ENV AUTOMAKE if it exists
1283
  if [[ -n "$AUTOMAKE" ]]; then
1284
    run $AUTOMAKE '--help'    &> /dev/null    || die "Failed to run AUTOMAKE:$AUTOMAKE"
1285
  fi
1286
1287
  # Test the ENV AUTOCONF if it exists
1288
  if [[ -n "$AUTOCONF" ]]; then
1289
    run $AUTOCONF '--help'    &> /dev/null    || die "Failed to run AUTOCONF:$AUTOCONF"
1290
  fi
1291
1292
  # Test the ENV AUTOHEADER if it exists
1293
  if [[ -n "$AUTOHEADER" ]]; then
1294
    run $AUTOHEADER '--help'  &> /dev/null    || die "Failed to run AUTOHEADER:$AUTOHEADER"
1295
  fi
1296
1297
  # Test the ENV AUTOM4TE if it exists
1298
  if [[ -n "$AUTOM4TE" ]]; then
1299
    run $AUTOM4TE '--help'    &> /dev/null    || die "Failed to run AUTOM4TE:$AUTOM4TE"
1300
  fi
1301
1079.7.3 by Brian Aker
Update bootstrap.sh
1302
  # Test the ENV AUTOHEADER if it exists, if not we add one and add --install
1303
  if [[ -z "$ACLOCAL" ]]; then
1304
    ACLOCAL="aclocal --install"
1305
  fi
1306
  run $ACLOCAL '--help'  &> /dev/null    || die "Failed to run ACLOCAL:$ACLOCAL"
1307
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
1308
  if [[ -z "$AUTORECONF" ]]; then
1309
    AUTORECONF=`type -p autoreconf`
1310
1311
    if [[ -z "$AUTORECONF" ]]; then
1312
      die "Couldn't find autoreconf"
1313
    fi
1314
1315
    if [[ -n "$GNU_BUILD_FLAGS" ]]; then
1079.30.5 by Brian Aker
Update ddm4
1316
      AUTORECONF_ARGS="$GNU_BUILD_FLAGS"
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
1317
    fi
1318
  fi
1319
1320
  run $AUTORECONF '--help'  &> /dev/null    || die "Failed to run AUTORECONF:$AUTORECONF"
1321
}
1322
1079.8.9 by Brian Aker
Update for mingw compile.
1323
function print_setup ()
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
1324
{
1325
  saved_debug_status=$DEBUG
1326
  if $DEBUG; then
1327
    disable_debug
1328
  fi
1329
1330
  echo '----------------------------------------------' 
1331
  echo 'BOOTSTRAP ENV' 
1332
  echo "AUTORECONF=$AUTORECONF"
1333
  echo "HOST_OS=$HOST_OS"
1079.28.1 by Brian Aker
Fix for lp:1164442
1334
  echo "VENDOR=$VENDOR"
1335
  echo "VENDOR_DISTRIBUTION=$VENDOR_DISTRIBUTION"
1336
  echo "VENDOR_RELEASE=$VENDOR_RELEASE"
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
1337
1338
  echo "getopt()"
1339
  if $AUTORECONF_OPTION; then
1340
    echo "--autoreconf"
1341
  fi
1342
1343
  if $CLEAN_OPTION; then
1344
    echo "--clean"
1345
  fi
1346
1347
  if $CONFIGURE_OPTION; then
1348
    echo "--configure"
1349
  fi
1350
1351
  if $DEBUG_OPTION; then
1352
    echo "--debug"
1353
  fi
1354
1355
  if $PRINT_SETUP_OPTION; then
1356
    echo "--print-env"
1357
  fi
1358
1359
  if $TARGET_OPTION; then
1360
    echo "--target=$TARGET_OPTION_ARG"
1361
  fi
1362
1363
  if $VERBOSE_OPTION; then
1364
    echo "--verbose"
1365
  fi
1366
1367
  if [[ -n "$MAKE" ]]; then
1368
    echo "MAKE=$MAKE"
1369
  fi
1370
1371
  if [[ -n "$MAKE_TARGET" ]]; then
1372
    echo "MAKE_TARGET=$MAKE_TARGET"
1373
  fi
1374
1375
  if [[ -n "$PREFIX" ]]; then
1376
    echo "PREFIX=$PREFIX"
1377
  fi
1378
1379
  if [[ -n "$TESTS_ENVIRONMENT" ]]; then
1380
    echo "TESTS_ENVIRONMENT=$TESTS_ENVIRONMENT"
1381
  fi
1382
1383
  if [[ -n "$VCS_CHECKOUT" ]]; then
1384
    echo "VCS_CHECKOUT=$VCS_CHECKOUT"
1385
  fi
1386
1387
  if $VERBOSE; then
1388
    echo "VERBOSE=true"
1389
  fi
1390
1391
  if $DEBUG; then
1392
    echo "DEBUG=true"
1393
  fi
1394
1395
  if [[ -n "$WARNINGS" ]]; then
1396
    echo "WARNINGS=$WARNINGS"
1397
  fi
1398
  echo '----------------------------------------------' 
1399
1400
  if $saved_debug_status; then
1401
    enable_debug
1402
  fi
1403
}
1404
1079.8.9 by Brian Aker
Update for mingw compile.
1405
function make_clean_option ()
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
1406
{
1407
  run_configure_if_required
1408
1409
  make_maintainer_clean
1410
1411
  if [[ "$VCS_CHECKOUT" == 'git' ]]; then
1412
    run "$VCS_CHECKOUT" status --ignored
1413
  elif [[ -n "$VCS_CHECKOUT" ]]; then
1414
    run "$VCS_CHECKOUT" status
1415
  fi
1416
}
1417
1079.8.9 by Brian Aker
Update for mingw compile.
1418
function make_for_autoreconf ()
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
1419
{
1420
  if [ -f 'Makefile' ]; then
1072.1.14 by Brian Aker
Update with job builder.
1421
    make_maintainer_clean
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
1422
  fi
1423
1424
  run_autoreconf
1425
1426
  assert_no_file 'Makefile'
1427
}
1428
1079.8.9 by Brian Aker
Update for mingw compile.
1429
function check_make_target()
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
1430
{
1431
  case $1 in
1079.3.9 by Brian Aker
Update bootstrap.sh
1432
    'self')
1433
      ;;
1079.7.3 by Brian Aker
Update bootstrap.sh
1434
    'rpm')
1435
      ;;
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
1436
    'gdb')
1437
      ;;
1438
    'clean_op')
1439
      ;;
1440
    'autoreconf')
1441
      ;;
1442
    'install-system')
1443
      ;;
1444
    'configure')
1445
      ;;
1079.3.9 by Brian Aker
Update bootstrap.sh
1446
    'distcheck')
1447
      ;;
1448
    'check')
1079.2.4 by Brian Aker
Update to allow rpm to be legal jenkins target.
1449
      ;;
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
1450
    'snapshot')
1451
      ;;
1079.3.10 by Brian Aker
A number of small build fixes found while looking at mingw support.
1452
    'mingw')
1453
      ;;
1454
    'universe')
1455
      ;;
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
1456
    'valgrind')
1457
      ;;
1458
    'jenkins')
1459
      ;;
1460
    'distclean')
1461
      ;;
1462
    'maintainer-clean')
1463
      ;;
1464
    'install')
1465
      ;;
1466
    'all')
1467
      ;;
1079.7.3 by Brian Aker
Update bootstrap.sh
1468
    'make_default')
1469
      ;;
1079.15.1 by Brian Aker
Clarification in DNS test.
1470
    'clang')
1471
      ;;
1472
    'clang-analyzer')
1473
      ;;
1079.1.82 by Brian Aker
Update to latest bootstra.
1474
    test-*)
1475
      ;;
1476
    valgrind-*)
1477
      ;;
1478
    gdb-*)
1079.3.9 by Brian Aker
Update bootstrap.sh
1479
      ;;
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
1480
    'dist')
1481
      ;;
1482
    *)
1079.1.82 by Brian Aker
Update to latest bootstra.
1483
      echo "Matched default"
1484
      return 1
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
1485
      ;;
1486
  esac
1079.1.82 by Brian Aker
Update to latest bootstra.
1487
1488
  return 0
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
1489
}
1490
1079.3.9 by Brian Aker
Update bootstrap.sh
1491
function bootstrap ()
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
1492
{
1493
  determine_target_platform
1494
1495
  determine_vcs
1496
1497
  # Set up whatever we need to do to use autoreconf later
1079.7.3 by Brian Aker
Update bootstrap.sh
1498
  require_libtoolise
1079.28.1 by Brian Aker
Fix for lp:1164442
1499
  if ! autoreconf_setup; then
1500
    return 1
1501
  fi
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
1502
1079.3.9 by Brian Aker
Update bootstrap.sh
1503
  if [ -z "$MAKE_TARGET" ]; then
1504
    MAKE_TARGET="make_default"
1505
  fi
1506
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
1507
  if $PRINT_SETUP_OPTION -o  $DEBUG; then
1508
    echo 
1509
    print_setup
1510
    echo 
1511
1512
    # Exit if all we were looking for were the currently used options
1513
    if $PRINT_SETUP_OPTION; then
1514
      exit
1515
    fi
1072.1.4 by Brian Aker
Update
1516
  fi
1517
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
1518
  # Use OLD_TESTS_ENVIRONMENT for tracking the state of the variable
1519
  local OLD_TESTS_ENVIRONMENT=
1520
1521
  # Set ENV PREFIX in order to set --prefix for ./configure
1522
  if [[ -n "$PREFIX" ]]; then 
1079.20.2 by Brian Aker
Adding missing windows file.
1523
    PREFIX_ARG="--prefix=$PREFIX"
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
1524
  fi
1525
1079.3.9 by Brian Aker
Update bootstrap.sh
1526
  # We should always have a target by this point
1527
  assert MAKE_TARGET
1528
1529
  local MAKE_TARGET_ARRAY=($MAKE_TARGET)
1530
1531
  for target in "${MAKE_TARGET_ARRAY[@]}"
1532
  do
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
1533
    # If we are running inside of Jenkins, we want to only run some of the possible tests
1534
    if $jenkins_build_environment; then
1079.3.9 by Brian Aker
Update bootstrap.sh
1535
      check_make_target $target
1079.1.82 by Brian Aker
Update to latest bootstra.
1536
      ret=$?
1537
      if [ $ret -ne 0 ]; then
1538
        die "Unknown MAKE_TARGET option: $target"
1539
      fi
1072.1.4 by Brian Aker
Update
1540
    fi
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
1541
1079.1.82 by Brian Aker
Update to latest bootstra.
1542
    local snapshot_run=false
1079.30.5 by Brian Aker
Update ddm4
1543
    local valgrind_run=false
1079.1.82 by Brian Aker
Update to latest bootstra.
1544
1079.3.9 by Brian Aker
Update bootstrap.sh
1545
    case $target in
1546
      'self')
1547
        self_test
1548
        ;;
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
1549
      'gdb')
1550
        make_gdb
1551
        ;;
1079.8.9 by Brian Aker
Update for mingw compile.
1552
      'install-html')
1553
        make_install_html
1554
        ;;
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
1555
      'clean_op')
1556
        make_clean_option
1557
        ;;
1558
      'autoreconf')
1559
        make_for_autoreconf
1560
        ;;
1561
      'install-system')
1562
        make_install_system
1563
        ;;
1564
      'configure')
1565
        run_configure
1566
        ;;
1079.7.3 by Brian Aker
Update bootstrap.sh
1567
      'make_default')
1568
        make_default
1079.3.9 by Brian Aker
Update bootstrap.sh
1569
        ;;
1079.15.1 by Brian Aker
Clarification in DNS test.
1570
      'clang')
1571
        if ! check_clang; then
1572
          die "clang was not found"
1573
        fi
1574
1575
        if ! make_for_clang; then
1576
          die "Failed to build clang: $?"
1577
        fi
1578
        ;;
1579
      'clang-analyzer')
1580
        if ! check_clang_analyzer; then
1581
          die "clang-analyzer was not found"
1582
        fi
1583
        if ! check_clang; then
1584
          die "clang was not found"
1585
        fi
1586
1587
        if ! make_for_clang_analyzer; then
1588
          die "Failed to build clang-analyzer: $?"
1589
        fi
1590
        ;;
1079.3.10 by Brian Aker
A number of small build fixes found while looking at mingw support.
1591
      'mingw')
1079.8.9 by Brian Aker
Update for mingw compile.
1592
        if ! check_mingw; then
1593
          die "mingw was not found"
1594
        fi
1595
1596
        if ! make_for_mingw; then
1597
          die "Failed to build mingw: $?"
1598
        fi
1079.3.10 by Brian Aker
A number of small build fixes found while looking at mingw support.
1599
        ;;
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
1600
      'snapshot')
1601
        make_for_snapshot
1079.1.82 by Brian Aker
Update to latest bootstra.
1602
        snapshot_run=true
1079.30.13 by Brian Aker
Fixes for
1603
        check_snapshot
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
1604
        ;;
1079.2.4 by Brian Aker
Update to allow rpm to be legal jenkins target.
1605
      'rpm')
1606
        make_rpm
1607
        ;;
1079.30.5 by Brian Aker
Update ddm4
1608
      'darwin_malloc')
1609
        make_darwin_malloc
1610
        ;;
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
1611
      'valgrind')
1079.30.5 by Brian Aker
Update ddm4
1612
        make_maintainer_clean 
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
1613
        make_valgrind
1614
        ;;
1079.3.10 by Brian Aker
A number of small build fixes found while looking at mingw support.
1615
      'universe')
1616
        make_universe
1617
        ;;
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
1618
      'jenkins')
1619
        make_for_continuus_integration
1620
        ;;
1621
      *)
1622
        run_configure_if_required
1079.3.9 by Brian Aker
Update bootstrap.sh
1623
        make_target "$target"
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
1624
        ;;
1625
    esac
1079.1.82 by Brian Aker
Update to latest bootstra.
1626
1627
    if $jenkins_build_environment; then
1628
      if ! $snapshot_run; then
1629
        run_make_maintainer_clean_if_possible
1630
      fi
1631
    fi
1632
1079.3.9 by Brian Aker
Update bootstrap.sh
1633
  done
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
1634
}
1635
1079.8.9 by Brian Aker
Update for mingw compile.
1636
function main ()
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
1637
{
1638
  # Variables we export
1639
  declare -x VCS_CHECKOUT=
1640
1641
  # Variables we control globally
1642
  local MAKE_TARGET=
1079.8.9 by Brian Aker
Update for mingw compile.
1643
  local CONFIGURE=
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
1644
1645
  # Options for getopt
1646
  local AUTORECONF_OPTION=false
1647
  local CLEAN_OPTION=false
1648
  local CONFIGURE_OPTION=false
1649
  local DEBUG_OPTION=false
1650
  local PRINT_SETUP_OPTION=false
1651
  local TARGET_OPTION=false
1652
  local TARGET_OPTION_ARG=
1653
  local VERBOSE_OPTION=false
1654
1079.8.9 by Brian Aker
Update for mingw compile.
1655
  local OLD_CONFIGURE=
1656
  local OLD_CONFIGURE_ARG=
1079.20.1 by Brian Aker
Harmonize WIN32, and update bootstrap
1657
  local OLD_PREFIX=
1079.8.9 by Brian Aker
Update for mingw compile.
1658
  local OLD_MAKE=
1659
  local OLD_TESTS_ENVIRONMENT=
1660
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
1661
  # If we call autoreconf on the platform or not
1662
  local AUTORECONF_REBUILD_HOST=false
1663
  local AUTORECONF_REBUILD=false
1664
1665
  local -r top_srcdir=`pwd`
1666
1079.8.9 by Brian Aker
Update for mingw compile.
1667
  # Default configure
1668
  if [ -z "$CONFIGURE" ]; then
1669
    CONFIGURE="$top_srcdir/configure"
1670
  fi
1671
1672
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
1673
  # Variables for determine_target_platform () and rebuild_host_os ()
1674
  #   UNAME_MACHINE_ARCH= uname -m
1675
  #   VENDOR= apple, redhat, centos, canonical
1676
  #   VENDOR_RELEASE=  
1677
  #                  RHEL{rhel,Tikanga,Santiago}
1678
  #                  Ubuntu{ubuntu,Lucid,Maverick,Natty,Oneiric,Precise,Quantal}
1679
  #                  Fedora{fedora,Verne,Beefy}
1680
  #                  OSX{osx,lion,snow,mountain}
1681
  #   VENDOR_DISTRIBUTION= darwin,fedora,rhel,ubuntu
1682
  #   UNAME_KERNEL= Linux, Darwin,...
1683
  #   UNAME_KERNEL_RELEASE= Linux, Darwin,...
1684
  local UNAME_MACHINE_ARCH=unknown
1685
  local VENDOR=unknown
1686
  local VENDOR_RELEASE=unknown
1687
  local VENDOR_DISTRIBUTION=unknown
1688
  local UNAME_KERNEL=unknown
1689
  local UNAME_KERNEL_RELEASE=unknown
1690
  local HOST_OS=
1691
1692
  rebuild_host_os no_output
1072.1.4 by Brian Aker
Update
1693
1079.3.9 by Brian Aker
Update bootstrap.sh
1694
  parse_command_line_options $@
1695
1072.1.4 by Brian Aker
Update
1696
  # If we are running under Jenkins we predetermine what tests we will run against
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
1697
  # This MAKE_TARGET can be overridden by parse_command_line_options based MAKE_TARGET changes.
1698
  # We don't want Jenkins overriding other variables, so we NULL them.
1079.7.3 by Brian Aker
Update bootstrap.sh
1699
  if [ -z "$MAKE_TARGET" ]; then
1700
    if $jenkins_build_environment; then
1079.30.18 by Brian Aker
Update bootstrap
1701
      if [[ -n "$label" ]]; then
1702
        check_make_target $label
1703
        if [ $? -eq 0 ]; then
1704
          MAKE_TARGET="$label"
1705
        fi
1706
      fi
1079.30.16 by Brian Aker
Make label a bit more accurate.
1707
      if [[ -n "$LABEL" ]]; then
1708
        check_make_target $LABEL
1079.1.82 by Brian Aker
Update to latest bootstra.
1709
        if [ $? -eq 0 ]; then
1079.30.16 by Brian Aker
Make label a bit more accurate.
1710
          MAKE_TARGET="$LABEL"
1079.1.82 by Brian Aker
Update to latest bootstra.
1711
        fi
1712
      fi
1713
1714
      if [ -z "$MAKE_TARGET" ]; then
1079.30.8 by Brian Aker
Import latest bootstrap.sh
1715
        MAKE_TARGET='jenkins'
1079.1.82 by Brian Aker
Update to latest bootstra.
1716
      fi
1079.7.3 by Brian Aker
Update bootstrap.sh
1717
    fi
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
1718
  fi
1719
1720
  bootstrap
1721
1722
  jobs -l
1723
  wait
1724
1725
  exit 0
1726
}
1727
1079.7.3 by Brian Aker
Update bootstrap.sh
1728
function set_branch ()
1729
{
1730
  if [ -z "$BRANCH" ]; then 
1731
    if [ -z "$CI_PROJECT_TEAM" ]; then 
1732
      die "Variable CI_PROJECT_TEAM has not been set"
1733
    fi
1734
    if [ -z "$PROJECT" ]; then 
1735
      die "Variable PROJECT has not been set"
1736
    fi
1737
    if [ -z "$BUILD_TAG" ]; then 
1738
      die "Variable BUILD_TAG has not been set"
1739
    fi
1740
1741
    BRANCH="lp:~$CI_PROJECT_TEAM/$PROJECT/$BUILD_TAG"
1742
    export BRANCH
1743
  fi
1744
1745
  if [ -z "$BRANCH" ]; then 
1746
    die "Missing values required to build BRANCH variable."
1747
  fi
1748
}
1749
1750
function merge ()
1751
{
1752
  if [ -z "$VCS_CHECKOUT" ]; then
1753
    die "Merges require VCS_CHECKOUT."
1754
  fi
1755
1756
  set_branch
1757
1758
  if [[ "$VCS_CHECKOUT" == 'bzr' ]]; then
1759
    if test -n "$BRANCH_TO_MERGE"; then
1760
      bzr merge $BRANCH_TO_MERGE
1761
      bzr commit --message="Merge $BRANCH_TO_MERGE Build: $BUILD_TAG" --unchanged
1762
    fi
1763
1764
    bzr push "$BRANCH"
1765
  elif [[ -n "$VCS_CHECKOUT" ]]; then
1766
    die "Merge attempt occured, current VCS setup does not support this"
1767
  fi
1768
}
1769
1079.8.9 by Brian Aker
Update for mingw compile.
1770
function enable_debug ()
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
1771
{
1772
  if ! $DEBUG; then
1773
    local caller_loc=`caller`
1774
    if [ -n $1 ]; then
1775
      echo "$caller_loc Enabling debug: $1"
1776
    else
1777
      echo "$caller_loc Enabling debug"
1778
    fi
1779
    set -x
1780
    DEBUG=true
1781
  fi
1782
}
1783
1079.7.3 by Brian Aker
Update bootstrap.sh
1784
function usage ()
1785
{
1786
  cat << EOF
1787
  Usage: $program_name [OPTION]..
1788
1789
  Bootstrap this package from the checked-out sources, and optionally walk through CI run.
1790
1791
  Options:
1792
1793
EOF
1794
}
1795
1079.8.9 by Brian Aker
Update for mingw compile.
1796
function disable_debug ()
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
1797
{
1798
  set +x
1799
  DEBUG=true
1800
}
1801
1802
# Script begins here
1803
1079.7.3 by Brian Aker
Update bootstrap.sh
1804
program_name=$0
1805
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
1806
env_debug_enabled=false
1807
if [[ -n "$JENKINS_HOME" ]]; then 
1808
  declare -r jenkins_build_environment=true
1809
else
1810
  declare -r jenkins_build_environment=false
1811
fi
1812
1079.7.3 by Brian Aker
Update bootstrap.sh
1813
export ACLOCAL
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
1814
export AUTOCONF
1815
export AUTOHEADER
1816
export AUTOM4TE
1817
export AUTOMAKE
1818
export AUTORECONF
1079.20.2 by Brian Aker
Adding missing windows file.
1819
export CONFIGURE_ARG
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
1820
export DEBUG
1821
export GNU_BUILD_FLAGS
1079.7.3 by Brian Aker
Update bootstrap.sh
1822
export LIBTOOLIZE
1823
export LIBTOOLIZE_OPTIONS
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
1824
export MAKE
1079.20.2 by Brian Aker
Adding missing windows file.
1825
export PREFIX_ARG
1079.2.1 by Brian Aker
Update updates to a current version of bootstrap.
1826
export TESTS_ENVIRONMENT
1827
export VERBOSE
1828
export WARNINGS
1829
1830
case $OSTYPE in
1831
  darwin*)
1832
    export MallocGuardEdges
1833
    export MallocErrorAbort
1834
    export MallocScribble
1835
    ;;
1836
esac
1837
1838
# We check for DEBUG twice, once before we source the config file, and once afterward
1839
env_debug_enabled=false
1840
if [[ -n "$DEBUG" ]]; then
1841
  env_debug_enabled=true
1842
  enable_debug
1843
  print_setup
1844
fi
1845
1846
# Variables which only can be set by .bootstrap
1847
BOOTSTRAP_SNAPSHOT=false
1848
BOOTSTRAP_SNAPSHOT_CHECK=
1849
1850
if [ -f '.bootstrap' ]; then
1851
  source '.bootstrap'
1852
fi
1853
1854
if $env_debug_enabled; then
1855
  enable_debug
1856
else
1857
  if [[ -n "$DEBUG" ]]; then
1858
    enable_debug "Enabling DEBUG from '.bootstrap'"
1859
    print_setup
1860
  fi
1861
fi
1862
1863
# We do this in order to protect the case where DEBUG
1864
if ! $env_debug_enabled; then
1865
  DEBUG=false
1866
fi
1867
1868
main $@