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 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620
|
#!/usr/bin/env bash
#
# Copyright 2000-2008 Daniel F. Savarese
# Copyright 2009-2018 Savarese Software Research Corporation
#
# 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.savarese.com/software/ApacheLicense-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.
#
# ------------------------------------------------------------------------
#
# This script bootstraps the automatic Makefile generation process.
# It runs the necessary autotools to generate Makefile.in files,
# libtool, configure, and other support files. It then passes
# any arguments on to configure, running it from a build directory.
#
# ------------------------------------------------------------------------
PATH=$PATH:/bin:/usr/bin
export PATH
declare -r VERSION=1.1.12
declare -r BUILD="2021-01-04 17:29:30 CET"
declare -r COPYRIGHT='
Copyright 2000-2008 Daniel F. Savarese
Copyright 2009-2018 Savarese Software Research Corporation
'
declare BOOTSTRAP_CONF="bootstrap.conf"
declare -r PROGRAM=$0
declare -r PROGRAM_NAME=$(basename $PROGRAM)
declare TOP_SRCDIR="$(pwd)"
declare -r CONFIG_DIR="config"
declare -r CONFIG_GUESS="$CONFIG_DIR/config.guess"
declare -r CONFIG_FILES="compile config.guess config.sub depcomp install-sh ltmain.sh ltconfig missing mkinstalldirs test-driver"
declare -r TOPLEVEL_FILES="config.h.in aclocal.m4 stamp-h.in configure autom4te.cache"
declare -r ACLOCAL_FLAGS="-I $CONFIG_DIR"
declare -r AUTOHEADER_FLAGS="--force"
declare -r LIBTOOLIZE_FLAGS="--force --copy"
declare -r AUTOMAKE_FLAGS="--foreign --add-missing --copy"
declare GMAKE=$(type -p gmake || echo "")
declare -r MAKE=${GMAKE:-make}
declare -r GLIBTOOLIZE=$(type -p glibtoolize)
unset GMAKE
# Exporting MAKE is necessary to ensure that configure and any other
# scripts/tools use GNU make.
export MAKE
if [ -n "$GLIBTOOLIZE" ]; then
function libtoolize() {
"$GLIBTOOLIZE" "$@"
}
fi
#
# Default build directory. Is overridden by mkbuild_dir.
#
declare BUILD_DIR="${TOP_SRCDIR}/build"
declare BUILD_DIR_SET=0
#
# Configuration name. Is set by set_config_args.
#
declare CONFIG_NAME=""
#
# Exit code, set command switch.
#
declare EXIT_CODE=0
function usage() {
echo "
usage: $0
[-build-dir dir] [-config-file file] [-src-dir dir]
[-help | -init [topdir] |
-build [configure-options | config-name [make-args]]
-clean [config-name] | -config [configure-options] |
-configonly [configure-options] | -install [configure-options] |
-mkdir config-name | -rebuild [configure-options] |
-reconfig [configure-options] | -version]
OPTIONS
-build-dir dir
Sets its argument as the build directory where the
configuration-specific build directories will be created.
Overrides the default of \"build/\" in the top source
directory. This option must precede any command options such
as -config or -build.
-config-file file
Specifies the path name of the configuration file to use. If
not specified, the default value is \"bootstrap.conf\". If
-src-dir is not specified, the parent directory of the config
file is used as the location of the source tree. This option
must precede any command options such as -config or -build.
-src-dir dir
Sets the location of the source tree. This allows you to run
$PROGRAM_NAME without installing it in the top of the source
tree with -init. By default, the location of the source tree
is the current working directory or the parent directory of the
config file when -config-file is specified. The value of the
-src-dir option takes precedence. This option must precede any
command options such as -config or -build.
-help
Displays this help message.
-build [configure-options | config-name [make-args]]
Performs the same operations as -config, but additionally
builds the source. You can pass configure options after
-build just as you would with -config. Additionally, if
you specify a configuration name (see configure-options below)
any arguments after the configuration name are passed along
to the make command for building the source.
-clean [config-name}
Removes all of the configure support files created by
autotools. Specifying a configuration name will remove
the build directory for that configuration; otherwise the
default build directory is removed.
-config [configure-options]
After prepping the source tree by running the autotools,
runs configure with the specified configure options,
readying the source tree for building.
-configonly [configure-options]
Runs configure with the specified configure options without
readying the source tree for building.
-install [configure-options]
Performs the same operations as -build, but in addition
installs the resulting build.
-mkdir config-name
Preps the source tree by running the autotools and then
creates an architecture-specific build directory. Specifying
a configuration name will create a build directory with a
suffix matching the configuration name.
-rebuild [configure-options]
Like -build, but does a -reconfig before building.
You can pass configure options after -build just as
you would with -config.
-reconfig [configure-options]
Performs the same operations as:
$0 -clean
$0 -config [configure-options]
-version
Print $PROGRAM_NAME version number.
SPECIAL ARGUMENTS
configure-options Argument may be options to pass to configure or the
name of a configuration in the bootstrap config file
that predefines the arguments to pass to configure.
DEPRECATED OPTIONS
-init [topdir]
Initializes the source tree for use with $PROGRAM_NAME. This
consists merely of making a symbolic link to the $PROGRAM_NAME
script in the specified directory (or the current directory
if none is specified). $PROGRAM_NAME must be run from the link
for all other operations, or it will fail to find the
source tree unless -src-dir or -config-file are specified.
"
}
function version() {
echo "
$PROGRAM_NAME
version: $VERSION
build: $BUILD
$COPYRIGHT
"
}
function init() {
local directory="$1"
printf "\nWarning: -init is deprecated and should no longer be used.\n\n" 1>&2
if [ -n "$directory" -a ! -d "$directory" ]; then
echo "Cannot find $directory"
return 1
fi
if [ -z "$directory" ]; then
directory="."
fi
local program_dir=$(echo $(cd $(dirname $PROGRAM); pwd))
local dest="$directory/$PROGRAM_NAME"
local src="${program_dir}/${PROGRAM_NAME}"
if [ -e "$dest" -o -h "$dest" ]; then
echo "$dest already exists."
return 1
fi
if ln -s "$src" "$dest"; then
echo "Created $dest -> $src"
return 0
else
echo "Failed to create $dest -> $src"
return 1
fi
}
#
# Can't assume mkdir accepts the -p flag, so we use this function instead.
#
function mkdirs() {
local old_ifs
local directory="$1"
local root_dir="."
if [ "${directory:0:1}" = "/" ]; then
root_dir="/"
fi
old_ifs="$IFS"
IFS=/
set $directory
directory="$root_dir"
while [ $# -gt 0 ]; do
directory="$directory/$1"
if [ ! -d "$directory" ]; then
mkdir "$directory"
fi
shift 1
done
IFS="$old_ifs"
}
#
# As a side effect sets BUILD_DIR.
#
function set_build_dir() {
local build_dir
if [ $BUILD_DIR_SET -ne 0 ]; then
return 0
fi
pushd "$TOP_SRCDIR" > /dev/null 2>&1
if [ ! -x "$CONFIG_GUESS" ]; then
popd > /dev/null 2>&1
return 1
fi
build_dir="$BUILD_DIR"/$("$CONFIG_GUESS")
if [ -n "$CONFIG_NAME" ]; then
build_dir="${build_dir}.${CONFIG_NAME}"
fi
popd > /dev/null 2>&1
BUILD_DIR="$build_dir"
BUILD_DIR_SET=1
}
function mkbuild_dir() {
if set_build_dir; then
pushd "$TOP_SRCDIR" > /dev/null 2>&1
if [ ! -d "$BUILD_DIR" ]; then
mkdirs "$BUILD_DIR"
fi
popd > /dev/null 2>&1
return 0
fi
return 1
}
function bootstrap() {
local exit_code=1
pushd "$TOP_SRCDIR" > /dev/null 2>&1
if [ ! -d "$CONFIG_DIR" ]; then
mkdirs "$CONFIG_DIR"
fi
if [ "$(type -t pre_bootstrap)" = "function" ]; then
pre_bootstrap
fi
set -x
aclocal $ACLOCAL_FLAGS && autoheader $AUTOHEADER_FLAGS && libtoolize $LIBTOOLIZE_FLAGS && automake $AUTOMAKE_FLAGS && autoconf
exit_code=$?
set +x
if [ "$(type -t post_bootstrap)" = "function" ]; then
post_bootstrap
fi
popd > /dev/null 2>&1
return $exit_code
}
function configure() {
local exit_code=1
local build_dir
pushd "$TOP_SRCDIR" > /dev/null 2>&1
if ! mkbuild_dir || [ ! -x configure ]; then
popd > /dev/null 2>&1
return 1
fi
build_dir="$BUILD_DIR"
set -x
(cd "$build_dir"; "$TOP_SRCDIR"/configure "$@";)
exit_code=$?
set +x
popd > /dev/null 2>&1
return $exit_code
}
function build() {
local exit_code=1
local build_dir
pushd "$TOP_SRCDIR" > /dev/null 2>&1
if ! set_build_dir || [ ! -f "$BUILD_DIR/Makefile" ]; then
popd > /dev/null 2>&1
return 1
fi
build_dir="$BUILD_DIR"
set -x
(cd "$build_dir"; $MAKE "$@")
exit_code=$?
set +x
popd > /dev/null 2>&1
return $exit_code
}
function clean() {
pushd "$TOP_SRCDIR" > /dev/null 2>&1
if set_build_dir ; then
if [ -d "$BUILD_DIR" ]; then
set -x
rm -fr "$BUILD_DIR"
set +x
fi
fi
set -x
rm -fr $TOPLEVEL_FILES
find . -name Makefile.in -print | xargs rm -f
(cd "$CONFIG_DIR"; rm -f $CONFIG_FILES;)
set +x
popd > /dev/null 2>&1
return 0
}
#
# This is a helper that obtains the package name and version
# from the AC_INIT call in configure.ac. If successful,
# sets PACKAGE_NAME and PACKAGE_VERSION as a side effect.
#
function get_package_info() {
local ac_init
if [ -f configure.ac ]; then
ac_init="$(fgrep AC_INIT configure.ac)"
PACKAGE_NAME="${ac_init#*(}"
PACKAGE_NAME="${PACKAGE_NAME%,*}"
PACKAGE_NAME="${PACKAGE_NAME// /}"
PACKAGE_VERSION="${ac_init#*,}"
PACKAGE_VERSION="${PACKAGE_VERSION%)*}"
PACKAGE_VERSION="${PACKAGE_VERSION// /}"
fi
}
#
# Looks for bootstrap config file, sources it if it exists, and tries
# to match the stated configuration against a sourced variable name.
# If successful, sets CONFIG_FLAGS as a side effect.
#
function set_config_args() {
local bootstrap_conf="$1"
local config_name="$2"
local config_args
pushd "$TOP_SRCDIR" > /dev/null 2>&1
get_package_info
if [ -f "$bootstrap_conf" ]; then
. "$bootstrap_conf"
else
popd > /dev/null 2>&1
return 1
fi
config_args=conf_${config_name}
# We really do mean ${!config_args-x} and NOT ${!config_args:-x}
if [ "${!config_args-x}" = "x" ]; then
if [ -z "$conf_default" ]; then
popd > /dev/null 2>&1
return 1
else
config_args="$conf_default"
fi
else
config_args=${!config_args}
CONFIG_NAME="$config_name"
fi
CONFIG_ARGS="$config_args"
popd > /dev/null 2>&1
}
function detect_config_name() {
local config_name="$1"
if ! set_config_args "$BOOTSTRAP_CONF" "$config_name"; then
CONFIG_ARGS="$@"
fi
}
function configureonly() {
local exit_code=1
local old_ifs="$IFS"
IFS="
"
if ! configure $CONFIG_ARGS; then
echo "
Error. Cannot run configure. Make sure config.guess exists so
that the architecture-specific build directory can be created.
"
else
exit_code=0
fi
IFS="$old_ifs"
return $exit_code
}
function configonly() {
local exit_code=1
pushd "$TOP_SRCDIR" > /dev/null 2>&1
if set_build_dir && [ -d "$BUILD_DIR" ]; then
configureonly
exit_code=$?
else
echo "
Error. $BUILD_DIR does not exist."
fi
popd > /dev/null 2>&1
return $exit_code
}
function config() {
bootstrap && configureonly
}
stop=1
srcdir_set=0
builddir_set=0
until [[ $stop -eq 0 ]]; do
command="$1"
case "$command" in
-build-dir)
BUILD_DIR="$2"
builddir_set=1
shift 2
;;
-config-file)
BOOTSTRAP_CONF="$2"
# Force an absolute path name in case a parent path is relative.
_TOP_SRCDIR="$(echo $(cd $(dirname $BOOTSTRAP_CONF); pwd))"
BOOTSTRAP_CONF="${_TOP_SRCDIR}/$(basename $BOOTSTRAP_CONF)"
shift 2
if [[ $srcdir_set -eq 0 ]]; then
TOP_SRCDIR="${_TOP_SRCDIR}"
fi
unset _TOP_SRCDIR
;;
-src-dir)
TOP_SRCDIR="$2"
# Force an absolute path name in case a parent path is relative.
TOP_SRCDIR="$(echo $(cd $TOP_SRCDIR; pwd))"
srcdir_set=1
shift 2
;;
*)
stop=0
;;
esac
done
if [[ $builddir_set -eq 0 ]]; then
BUILD_DIR="${TOP_SRCDIR}/build"
fi
unset stop
unset srcdir_set
unset builddir_set
command="$1"
num_arguments="$#"
shift
detect_config_name "$@"
if [ -n "$CONFIG_NAME" ]; then
shift
build_args="$@"
else
build_args=""
fi
case "$command" in
-help)
usage
EXIT_CODE=1
;;
-init)
init "$@"
EXIT_CODE=$?
;;
-build | -install)
if [ "$command" = "-install" ]; then
build_args="install $build_args"
fi
config && build $build_args
EXIT_CODE=$?
;;
-clean)
clean
;;
-config | -configure)
config
EXIT_CODE=$?
;;
-configonly | -configureonly)
configonly
EXIT_CODE=$?
;;
-rebuild)
clean && config && build
EXIT_CODE=$?
;;
-reconfig)
clean && config
EXIT_CODE=$?
;;
-mkdir)
bootstrap && mkbuild_dir
EXIT_CODE=$?
;;
-version)
version
;;
*)
if [ "$num_arguments" -eq 0 ]; then
bootstrap
EXIT_CODE=$?
else
usage 1>&2
EXIT_CODE=1
fi
;;
esac
exit $EXIT_CODE
|