diff options
author | Simon Marchi | 2017-03-23 15:06:23 +0000 |
---|---|---|
committer | Simon Marchi | 2017-03-23 17:33:45 +0000 |
commit | 184747164d6926c24cca475ae2d46faa5d9ffb87 (patch) | |
tree | 40bf2a004adfbe5c5fdaed3d48c15d0d0f7e4315 /dsf-gdb | |
parent | 5bec70f68f91fc3ded3f78d6bf28c8d5ddaddf8f (diff) | |
download | org.eclipse.cdt-184747164d6926c24cca475ae2d46faa5d9ffb87.tar.gz org.eclipse.cdt-184747164d6926c24cca475ae2d46faa5d9ffb87.tar.xz org.eclipse.cdt-184747164d6926c24cca475ae2d46faa5d9ffb87.zip |
Various enhancements to download-build-gdb.sh
I ran shellcheck [1] on the script and it found various minor things to
improve.
- Use $(...) instead of `...` to run commands in a subshell.
- Wrap all variables in quotes, in case there are spaces.
At the same time, I noticed a few other things:
- Use "#!/usr/bin/env bash" instead of "#!/bin/bash", in case the user
uses a bash not at /bin/bash.
- Use "set -o errexit" instead of "set -e" for better readability.
- Use "set -o nounset" to generate errors if trying to read unset
variables.
- Pass CXXFLAGS in addition to CFLAGS, since GDB is now in C++.
- Use ${CFLAGS:-} instead of ${CFLAGS}, in case CFLAGS is not set
(because of "set -o nounset").
- Don't check for result of getopt. If it fails, the script ends
immediatly due to errexit.
[1] http://www.shellcheck.net/
Change-Id: If73f3510e46ca80d542d47c29c55b48b8b0bc697
Signed-off-by: Simon Marchi <simon.marchi@polymtl.ca>
Diffstat (limited to 'dsf-gdb')
-rwxr-xr-x | dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/scripts/download-build-gdb.sh | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/scripts/download-build-gdb.sh b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/scripts/download-build-gdb.sh index 2e06d17005b..e61c3df3615 100755 --- a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/scripts/download-build-gdb.sh +++ b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/scripts/download-build-gdb.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # * Copyright (c) 2015 Ericsson and others. # * All rights reserved. This program and the accompanying materials @@ -10,10 +10,13 @@ # * Simon Marchi (Ericsson) - Initial implementation # Stop the script if any command fails -set -e +set -o errexit + +# Consider using an unset variable as an error +set -o nounset # Make sure getopt is the command and not the bash built-in -if [[ `getopt --version` != *"getopt"* ]]; then +if [[ $(getopt --version) != *"getopt"* ]]; then echo "getopt command not found." exit 1 fi @@ -63,7 +66,7 @@ function help_and_exit() { echo " $ $0 all" echo "" - exit $1 + exit "$1" } # Output a visible header @@ -89,7 +92,7 @@ function check_supported() { *) echo "Error: version ${version} is not supported by this script." echo "" - help_and_exit + help_and_exit 1 ;; esac } @@ -163,7 +166,8 @@ function configure_gdb() { local version="$1" local build="${build_dir}/gdb-${version}" - local cflags="-Wno-error -g -O0" + local cflags="-Wno-error -g3 -O0" + local cxxflags="-Wno-error -g3 -O0" echo_header "Configuring in ${build}" @@ -175,11 +179,12 @@ function configure_gdb() { ;; esac - # Let the user specify some CFLAGS - cflags="${cflags} ${CFLAGS}" + # If there is already some CFLAGS/CXXFLAGS in the environment, add them to the mix. + cflags="${cflags} ${CFLAGS:-}" + cxxflags="${cxxflags} ${CXXFLAGS:-}" # Need to use eval to allow the ${dryrun} trick to work with the env var command at the start. - eval ${dryrun} 'CFLAGS="${cflags}" ./configure --prefix="${install_dir}/gdb-${version}"' + eval ${dryrun} 'CFLAGS="${cflags}" CXXFLAGS="${cxxflags}" ./configure --prefix="${install_dir}/gdb-${version}"' ${dryrun} popd } @@ -245,14 +250,9 @@ function symlink_gdb() { fi } -# Start argument parsing +# Start argument parsing. The script will exit (thanks to errexit) if bad arguments are passed. args=$(getopt -o b:dhj: -l "base-dir:,dry-run,help,jobs" -n "$0" -- "$@"); -# Bad arguments ? -if [ $? -ne 0 ]; then - exit 1 -fi - eval set -- "$args" while true; do |