#!/bin/bash ############################################################################### # Copyright (c) 2014-2015 libbitcoin-server developers (see COPYING). # # GENERATED SOURCE CODE, DO NOT EDIT EXCEPT EXPERIMENTALLY # ############################################################################### # Script to build and install libbitcoin-server. # # Script options: # --build-boost Builds Boost libraries. # --build-dir= Location of downloaded and intermediate files. # --prefix= Library install location (defaults to /usr/local). # --disable-shared Disables shared library builds. # --disable-static Disables static library builds. # # Verified on Ubuntu 14.04, requires gcc-4.8 or newer. # Verified on OSX 10.10, using MacPorts and Homebrew repositories, requires # Apple LLVM version 6.0 (clang-600.0.54) (based on LLVM 3.5svn) or newer. # This script does not like spaces in the --prefix or --build-dir, sorry. # Values (e.g. yes|no) in the '--disable-' options are not supported. # All command line options are passed to 'configure' of each repo, with # the exception of the --build- options, which are for the script only. # Depending on the caller's permission to the --prefix or --build-dir # directory, the script may need to be sudo'd. # Define constants. #============================================================================== # The default build directory. #------------------------------------------------------------------------------ BUILD_DIR="build-libbitcoin-server" # Boost archive. #------------------------------------------------------------------------------ BOOST_URL="http://downloads.sourceforge.net/project/boost/boost/1.57.0/boost_1_57_0.tar.bz2" BOOST_ARCHIVE="boost_1_57_0.tar.bz2" # Define utility functions. #============================================================================== configure_options() { display_message "configure options:" for OPTION in "$@"; do if [[ $OPTION ]]; then display_message $OPTION fi done ./configure "$@" } configure_links() { # Configure dynamic linker run-time bindings when installing to system. if [[ ($OS == Linux) && ($PREFIX == "/usr/local") ]]; then ldconfig fi } create_directory() { local DIRECTORY="$1" rm -rf "$DIRECTORY" mkdir "$DIRECTORY" } display_heading_message() { local MESSAGE="$1" echo echo "********************** $MESSAGE **********************" echo } display_message() { local MESSAGE="$1" echo "$MESSAGE" } display_error() { local MESSAGE="$1" >&2 echo "$MESSAGE" } initialize_git() { # Initialize git repository at the root of the current directory. git init git config user.name anonymous } # make_current_directory jobs [configure_options] make_current_directory() { local JOBS=$1 shift 1 ./autogen.sh configure_options "$@" make_jobs $JOBS make install configure_links } # make_jobs jobs [make_options] make_jobs() { local JOBS=$1 shift 1 # Avoid setting -j1 (causes problems on Travis). if [[ $JOBS > $SEQUENTIAL ]]; then make -j$JOBS "$@" else make "$@" fi } # make_tests jobs make_tests() { local JOBS=$1 # Disable exit on error. set +e # 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" local RESULT=$? # Test runners emit to the test.log file. if [[ -e "test.log" ]]; then cat "test.log" fi if [[ $RESULT -ne 0 ]]; then exit $RESULT fi # Reenable exit on error. set -e } pop_directory() { popd >/dev/null } push_directory() { local DIRECTORY="$1" pushd "$DIRECTORY" >/dev/null } # Initialize the build environment. #============================================================================== # Exit this script on the first build error. #------------------------------------------------------------------------------ set -e # Configure build parallelism. #------------------------------------------------------------------------------ SEQUENTIAL=1 OS=`uname -s` if [[ $PARALLEL ]]; then display_message "Using shell-defined PARALLEL value." elif [[ $OS == Linux ]]; then PARALLEL=`nproc` elif [[ ($OS == Darwin) || ($OS == OpenBSD) ]]; then PARALLEL=`sysctl -n hw.ncpu` else display_error "Unsupported system: $OS" exit 1 fi # Define operating system specific settings. #------------------------------------------------------------------------------ if [[ $OS == Darwin ]]; then export CC="clang" export CXX="clang++" STDLIB="c++" elif [[ $OS == OpenBSD ]]; then make() { gmake "$@"; } export CC="egcc" export CXX="eg++" STDLIB="estdc++" else # Linux STDLIB="stdc++" fi # Link to appropriate standard library in non-default scnearios. #------------------------------------------------------------------------------ if [[ ($OS == Linux && $CC == "clang") || ($OS == OpenBSD) ]]; then export LDLIBS="-l$STDLIB $LDLIBS" export CXXFLAGS="-stdlib=lib$STDLIB $CXXFLAGS" fi # Parse command line options that are handled by this script. #------------------------------------------------------------------------------ for OPTION in "$@"; do case $OPTION in # Custom build options (in the form of --build-