|
| 1 | +#!/bin/bash |
| 2 | +# |
| 3 | +# buildcmake |
| 4 | +# |
| 5 | +# -- This script downloads and installs the CMake cross-platform Makefile generator |
| 6 | +# (http://www.cmake.org). |
| 7 | +# |
| 8 | +# OpenCoarrays is distributed under the OSI-approved BSD 3-clause License: |
| 9 | +# Copyright (c) 2015, Sourcery, Inc. |
| 10 | +# Copyright (c) 2015, Sourcery Institute |
| 11 | +# All rights reserved. |
| 12 | +# |
| 13 | +# Redistribution and use in source and binary forms, with or without modification, |
| 14 | +# are permitted provided that the following conditions are met: |
| 15 | +# |
| 16 | +# 1. Redistributions of source code must retain the above copyright notice, this |
| 17 | +# list of conditions and the following disclaimer. |
| 18 | +# 2. Redistributions in binary form must reproduce the above copyright notice, this |
| 19 | +# list of conditions and the following disclaimer in the documentation and/or |
| 20 | +# other materials provided with the distribution. |
| 21 | +# 3. Neither the names of the copyright holders nor the names of their contributors |
| 22 | +# may be used to endorse or promote products derived from this software without |
| 23 | +# specific prior written permission. |
| 24 | +# |
| 25 | +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
| 26 | +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 27 | +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 28 | +# IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, |
| 29 | +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 30 | +# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 31 | +# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 32 | +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 33 | +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 34 | +# POSSIBILITY OF SUCH DAMAGE. |
| 35 | + |
| 36 | +cmd=`basename $0` |
| 37 | +usage() |
| 38 | +{ |
| 39 | + echo "" |
| 40 | + echo " $cmd - Bash script for building CMake from source" |
| 41 | + echo "" |
| 42 | + echo " Usage (optional arguments in square brackets): " |
| 43 | + echo " $cmd <version-number> [<installation-path> <number-of-threads>]" |
| 44 | + echo " or $cmd [options] " |
| 45 | + echo "" |
| 46 | + echo " Options:" |
| 47 | + echo " --help, -h Show this help message" |
| 48 | + echo " --version, -v, -V Report version and copyright information" |
| 49 | + echo "" |
| 50 | + echo " Example usage:" |
| 51 | + echo "" |
| 52 | + echo " $cmd default" |
| 53 | + echo " $cmd 3.3" |
| 54 | + echo " $cmd 3.3 /opt/cmake/3.3 4" |
| 55 | + echo " $cmd -v" |
| 56 | + echo " $cmd --help" |
| 57 | + echo "" |
| 58 | + echo " Note: For a list of available CMake versions, visit" |
| 59 | + echo " http://www.cmake.org/files/" |
| 60 | + echo "" |
| 61 | + exit 1 |
| 62 | +} |
| 63 | + |
| 64 | +# Default to installing CMake 3.3 if no version specified in the first |
| 65 | +# command-line argument |
| 66 | +if [[ $1 == 'default' ]]; then |
| 67 | + version=3.3 |
| 68 | +else |
| 69 | + version=$1 |
| 70 | +fi |
| 71 | + |
| 72 | +# Default to installing in the present working directory if no install path is specified: |
| 73 | +if [ -z $2 ]; then |
| 74 | + install_path=${PWD} |
| 75 | +else |
| 76 | + install_path=$2 |
| 77 | +fi |
| 78 | + |
| 79 | +# Default to 2 threads if no specified thread count: |
| 80 | +if [ -z $3 ]; then |
| 81 | + num_threads=2 |
| 82 | +else |
| 83 | + num_threads=$3 |
| 84 | +fi |
| 85 | + |
| 86 | +# Make the build directory, configure, and build |
| 87 | +build() |
| 88 | +{ |
| 89 | + cd cmake-$version.0 && |
| 90 | + ./bootstrap --prefix=$install_path && |
| 91 | + make -j $num_threads |
| 92 | +} |
| 93 | + |
| 94 | +if [ $# == 0 ]; then |
| 95 | + # Print usage information if script is invoked without arguments |
| 96 | + usage | less |
| 97 | +elif [[ $1 == '--help' || $1 == '-h' ]]; then |
| 98 | + # Print usage information if script is invoked with --help or -h argument |
| 99 | + usage | less |
| 100 | +elif [[ $1 == '-v' || $1 == '-V' || $1 == '--version' ]]; then |
| 101 | + # Print script copyright if invoked with -v, -V, or --version argument |
| 102 | + echo "" |
| 103 | + echo "CMake Build Script" |
| 104 | + echo "Copyright (C) 2015 Sourcery, Inc." |
| 105 | + echo "Copyright (C) 2015 Sourcery Institute" |
| 106 | + echo "" |
| 107 | + echo "$cmd comes with NO WARRANTY, to the extent permitted by law." |
| 108 | + echo "You may redistribute copies of $cmd under the terms of the" |
| 109 | + echo "BSD 3-Clause License. For more information about these matters, see" |
| 110 | + echo "http://www.sourceryinstitute.org/license.html" |
| 111 | + echo "" |
| 112 | +else |
| 113 | + # Download and build CMake |
| 114 | + time \ |
| 115 | + { |
| 116 | + if ! type wget > /dev/null; then |
| 117 | + echo |
| 118 | + echo "$cmd requires 'wget'. Please install it. Aborting." |
| 119 | + exit 1; |
| 120 | + else |
| 121 | + # Download CMake |
| 122 | + wget http://www.cmake.org/files/v$version/cmake-$version.0-1-src.tar.bz2 && |
| 123 | + # Unpack the downloaded tape archive |
| 124 | + tar xvjf cmake-$version.0-1-src.tar.bz2 && |
| 125 | + tar xvjf cmake-$version.0.tar.bz2 && |
| 126 | + # Compile Cmake source |
| 127 | + build $version $install_path $num_threads |
| 128 | + fi |
| 129 | + } >&1 | tee build.log |
| 130 | + echo "" |
| 131 | + echo "Check build.log for results. If the build was successful, type" |
| 132 | + echo "'cd cmake-$version.0 && make install' (or 'cd cmake-$version.0 && sudo make install')" |
| 133 | + echo "to complete the installation." |
| 134 | + echo "" |
| 135 | +fi |
0 commit comments