diff --git a/install.sh b/install.sh index 4b580e3c..238aa033 100755 --- a/install.sh +++ b/install.sh @@ -52,7 +52,7 @@ configure_options() display_message "configure options:" for OPTION in "$@"; do if [[ $OPTION ]]; then - display_message $OPTION + display_message "$OPTION" fi done @@ -69,19 +69,17 @@ create_directory() display_heading_message() { - echo - echo "********************** $@ **********************" - echo + printf "\n********************** %s **********************\n" "$@" } display_message() { - echo "$@" + printf "%s\n" "$@" } display_error() { - >&2 echo "$@" + >&2 printf "%s\n" "$@" } initialize_git() @@ -101,7 +99,7 @@ make_current_directory() ./autogen.sh configure_options "$@" - make_jobs $JOBS + make_jobs "$JOBS" make install configure_links } @@ -114,7 +112,7 @@ make_jobs() # Avoid setting -j1 (causes problems on Travis). if [[ $JOBS > $SEQUENTIAL ]]; then - make -j$JOBS "$@" + make -j"$JOBS" "$@" else make "$@" fi @@ -130,7 +128,7 @@ make_tests() # Build and run unit tests relative to the primary directory. # VERBOSE=1 ensures test runner output sent to console (gcc). - make_jobs $JOBS check "VERBOSE=1" + make_jobs "$JOBS" check "VERBOSE=1" local RESULT=$? # Test runners emit to the test.log file. @@ -205,13 +203,13 @@ done # Configure build parallelism. #------------------------------------------------------------------------------ SEQUENTIAL=1 -OS=`uname -s` +OS=$(uname -s) if [[ $PARALLEL ]]; then display_message "Using shell-defined PARALLEL value." elif [[ $OS == Linux ]]; then - PARALLEL=`nproc` + PARALLEL=$(nproc) elif [[ ($OS == Darwin) || ($OS == OpenBSD) ]]; then - PARALLEL=`sysctl -n hw.ncpu` + PARALLEL=$(sysctl -n hw.ncpu) else display_error "Unsupported system: $OS" display_error " Explicit shell-definition of PARALLEL will avoid system detection." @@ -259,7 +257,7 @@ CONFIGURE_OPTIONS=("${CONFIGURE_OPTIONS[@]/--build-*/}") # Always set a prefix (required on OSX and for lib detection). #------------------------------------------------------------------------------ -if [[ !($PREFIX) ]]; then +if [[ ! ($PREFIX) ]]; then PREFIX="/usr/local" CONFIGURE_OPTIONS=( "${CONFIGURE_OPTIONS[@]}" "--prefix=$PREFIX") else @@ -386,8 +384,8 @@ build_from_tarball() shift 7 # For some platforms we need to set ICU pkg-config path. - if [[ !($BUILD) ]]; then - if [[ $ARCHIVE == $ICU_ARCHIVE ]]; then + if [[ ! ($BUILD) ]]; then + if [[ $ARCHIVE == "$ICU_ARCHIVE" ]]; then initialize_icu_packages fi return @@ -395,14 +393,14 @@ build_from_tarball() # Because libpng doesn't actually use pkg-config to locate zlib. # Because ICU tools don't know how to locate internal dependencies. - if [[ ($ARCHIVE == $ICU_ARCHIVE) || ($ARCHIVE == $PNG_ARCHIVE) ]]; then - local SAVE_LDFLAGS=$LDFLAGS + if [[ ($ARCHIVE == "$ICU_ARCHIVE") || ($ARCHIVE == "$PNG_ARCHIVE") ]]; then + local SAVE_LDFLAGS="$LDFLAGS" export LDFLAGS="-L$PREFIX/lib $LDFLAGS" fi # Because libpng doesn't actually use pkg-config to locate zlib.h. - if [[ ($ARCHIVE == $PNG_ARCHIVE) ]]; then - local SAVE_CPPFLAGS=$CPPFLAGS + if [[ ($ARCHIVE == "$PNG_ARCHIVE") ]]; then + local SAVE_CPPFLAGS="$CPPFLAGS" export CPPFLAGS="-I$PREFIX/include $CPPFLAGS" fi @@ -415,31 +413,31 @@ build_from_tarball() push_directory "$EXTRACT" # Extract the source locally. - wget --output-document $ARCHIVE $URL - tar --extract --file $ARCHIVE --$COMPRESSION --strip-components=1 + wget --output-document "$ARCHIVE" "$URL" + tar --extract --file "$ARCHIVE" "--$COMPRESSION" --strip-components=1 push_directory "$PUSH_DIR" # Enable static only zlib build. - if [[ $ARCHIVE == $ZLIB_ARCHIVE ]]; then + if [[ $ARCHIVE == "$ZLIB_ARCHIVE" ]]; then patch_zlib_configuration fi # Join generated and command line options. local CONFIGURATION=("${OPTIONS[@]}" "$@") - if [[ $ARCHIVE == $MBEDTLS_ARCHIVE ]]; then - make -j $JOBS lib + if [[ $ARCHIVE == "$MBEDTLS_ARCHIVE" ]]; then + make -j "$JOBS" lib make DESTDIR=$PREFIX install else configure_options "${CONFIGURATION[@]}" - make_jobs $JOBS --silent + make_jobs "$JOBS" --silent make install fi configure_links # Enable shared only zlib build. - if [[ $ARCHIVE == $ZLIB_ARCHIVE ]]; then + if [[ $ARCHIVE == "$ZLIB_ARCHIVE" ]]; then clean_zlib_build fi @@ -448,7 +446,7 @@ build_from_tarball() # Restore flags to prevent side effects. export LDFLAGS=$SAVE_LDFLAGS - export CPPFLAGS=$SAVE_LCPPFLAGS + export CPPFLAGS=$SAVE_CPPFLAGS pop_directory } @@ -464,8 +462,8 @@ circumvent_boost_icu_detection() local REGEX_TEST="libs/regex/build/has_icu_test.cpp" local LOCALE_TEST="libs/locale/build/has_icu_test.cpp" - echo $SUCCESS > $REGEX_TEST - echo $SUCCESS > $LOCALE_TEST + printf "%s" "$SUCCESS" > $REGEX_TEST + printf "%s" "$SUCCESS" > $LOCALE_TEST # display_message "Hack: ICU detection modified, will always indicate found." } @@ -506,20 +504,23 @@ initialize_boost_icu_configuration() BOOST_ICU_POSIX="off" # Extract ICU libs from package config variables and augment with -ldl. - ICU_LIBS="`pkg-config icu-i18n --libs` -ldl" + ICU_LIBS="$(pkg-config icu-i18n --libs) -ldl" # This is a hack for boost m4 scripts that fail with ICU dependency. # See custom edits in ax-boost-locale.m4 and ax_boost_regex.m4. - export BOOST_ICU_LIBS="${ICU_LIBS[@]}" + export BOOST_ICU_LIBS=("${ICU_LIBS[@]}") # Extract ICU prefix directory from package config variable. - ICU_PREFIX=`pkg-config icu-i18n --variable=prefix` + ICU_PREFIX=$(pkg-config icu-i18n --variable=prefix) fi } # Because boost doesn't use autoconfig. build_from_tarball_boost() { + local SAVE_IFS="$IFS" + IFS=' ' + local URL=$1 local ARCHIVE=$2 local COMPRESSION=$3 @@ -528,7 +529,7 @@ build_from_tarball_boost() local BUILD=$6 shift 6 - if [[ !($BUILD) ]]; then + if [[ ! ($BUILD) ]]; then return fi @@ -541,8 +542,8 @@ build_from_tarball_boost() push_directory "$EXTRACT" # Extract the source locally. - wget --output-document $ARCHIVE $URL - tar --extract --file $ARCHIVE --$COMPRESSION --strip-components=1 + wget --output-document "$ARCHIVE" "$URL" + tar --extract --file "$ARCHIVE" "--$COMPRESSION" --strip-components=1 initialize_boost_configuration initialize_boost_icu_configuration @@ -559,7 +560,7 @@ build_from_tarball_boost() display_message "boost.locale.posix : $BOOST_ICU_POSIX" display_message "-sNO_BZIP2 : 1" display_message "-sICU_PATH : $ICU_PREFIX" - display_message "-sICU_LINK : ${ICU_LIBS[@]}" + display_message "-sICU_LINK : " "${ICU_LIBS[*]}" display_message "-sZLIB_LIBPATH : $PREFIX/lib" display_message "-sZLIB_INCLUDE : $PREFIX/include" display_message "-j : $JOBS" @@ -567,7 +568,7 @@ build_from_tarball_boost() display_message "-q : [stop at the first error]" display_message "--reconfigure : [ignore cached configuration]" display_message "--prefix : $PREFIX" - display_message "BOOST_OPTIONS : $@" + display_message "BOOST_OPTIONS : $*" display_message "--------------------------------------------------------------------" # boost_iostreams @@ -591,7 +592,7 @@ build_from_tarball_boost() "boost.locale.posix=$BOOST_ICU_POSIX" \ "-sNO_BZIP2=1" \ "-sICU_PATH=$ICU_PREFIX" \ - "-sICU_LINK=${ICU_LIBS[@]}" \ + "-sICU_LINK=${ICU_LIBS[*]}" \ "-sZLIB_LIBPATH=$PREFIX/lib" \ "-sZLIB_INCLUDE=$PREFIX/include" \ "-j $JOBS" \ @@ -603,6 +604,8 @@ build_from_tarball_boost() pop_directory pop_directory + + IFS="$SAVE_IFS" } # Standard build from github. @@ -621,14 +624,14 @@ build_from_github() display_heading_message "Download $FORK/$BRANCH" # Clone the repository locally. - git clone --depth 1 --branch $BRANCH --single-branch "https://github.com/$FORK" + git clone --depth 1 --branch "$BRANCH" --single-branch "https://github.com/$FORK" # Join generated and command line options. local CONFIGURATION=("${OPTIONS[@]}" "$@") # Build the local repository clone. push_directory "$REPO" - make_current_directory $JOBS "${CONFIGURATION[@]}" + make_current_directory "$JOBS" "${CONFIGURATION[@]}" pop_directory pop_directory } @@ -647,7 +650,7 @@ build_from_local() local CONFIGURATION=("${OPTIONS[@]}" "$@") # Build the current directory. - make_current_directory $JOBS "${CONFIGURATION[@]}" + make_current_directory "$JOBS" "${CONFIGURATION[@]}" } # Because Travis alread has downloaded the primary repo. @@ -662,13 +665,13 @@ build_from_travis() # The primary build is not downloaded if we are running in Travis. if [[ $TRAVIS == true ]]; then - build_from_local "Local $TRAVIS_REPO_SLUG" $JOBS "${OPTIONS[@]}" "$@" - make_tests $JOBS + build_from_local "Local $TRAVIS_REPO_SLUG" "$JOBS" "${OPTIONS[@]}" "$@" + make_tests "$JOBS" else - build_from_github $ACCOUNT $REPO $BRANCH $JOBS "${OPTIONS[@]}" "$@" + build_from_github "$ACCOUNT" "$REPO" "$BRANCH" "$JOBS" "${OPTIONS[@]}" "$@" push_directory "$BUILD_DIR" push_directory "$REPO" - make_tests $JOBS + make_tests "$JOBS" pop_directory pop_directory fi @@ -679,9 +682,9 @@ build_from_travis() #============================================================================== build_all() { - build_from_tarball_boost $BOOST_URL $BOOST_ARCHIVE bzip2 . $PARALLEL "$BUILD_BOOST" "${BOOST_OPTIONS[@]}" - build_from_github libbitcoin secp256k1 version5 $PARALLEL ${SECP256K1_OPTIONS[@]} "$@" - build_from_travis libbitcoin libbitcoin-consensus master $PARALLEL ${BITCOIN_CONSENSUS_OPTIONS[@]} "$@" + build_from_tarball_boost "$BOOST_URL" "$BOOST_ARCHIVE" bzip2 . "$PARALLEL" "$BUILD_BOOST" "${BOOST_OPTIONS[@]}" + build_from_github libbitcoin secp256k1 version5 "$PARALLEL" "${SECP256K1_OPTIONS[@]}" "$@" + build_from_travis libbitcoin libbitcoin-consensus master "$PARALLEL" "${BITCOIN_CONSENSUS_OPTIONS[@]}" "$@" }