1*cfb92d14SAndroid Build Coastguard Worker#!/bin/bash 2*cfb92d14SAndroid Build Coastguard Worker# 3*cfb92d14SAndroid Build Coastguard Worker# Copyright (c) 2017, The OpenThread Authors. 4*cfb92d14SAndroid Build Coastguard Worker# All rights reserved. 5*cfb92d14SAndroid Build Coastguard Worker# 6*cfb92d14SAndroid Build Coastguard Worker# Redistribution and use in source and binary forms, with or without 7*cfb92d14SAndroid Build Coastguard Worker# modification, are permitted provided that the following conditions are met: 8*cfb92d14SAndroid Build Coastguard Worker# 1. Redistributions of source code must retain the above copyright 9*cfb92d14SAndroid Build Coastguard Worker# notice, this list of conditions and the following disclaimer. 10*cfb92d14SAndroid Build Coastguard Worker# 2. Redistributions in binary form must reproduce the above copyright 11*cfb92d14SAndroid Build Coastguard Worker# notice, this list of conditions and the following disclaimer in the 12*cfb92d14SAndroid Build Coastguard Worker# documentation and/or other materials provided with the distribution. 13*cfb92d14SAndroid Build Coastguard Worker# 3. Neither the name of the copyright holder nor the 14*cfb92d14SAndroid Build Coastguard Worker# names of its contributors may be used to endorse or promote products 15*cfb92d14SAndroid Build Coastguard Worker# derived from this software without specific prior written permission. 16*cfb92d14SAndroid Build Coastguard Worker# 17*cfb92d14SAndroid Build Coastguard Worker# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18*cfb92d14SAndroid Build Coastguard Worker# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19*cfb92d14SAndroid Build Coastguard Worker# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20*cfb92d14SAndroid Build Coastguard Worker# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 21*cfb92d14SAndroid Build Coastguard Worker# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22*cfb92d14SAndroid Build Coastguard Worker# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23*cfb92d14SAndroid Build Coastguard Worker# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24*cfb92d14SAndroid Build Coastguard Worker# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25*cfb92d14SAndroid Build Coastguard Worker# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26*cfb92d14SAndroid Build Coastguard Worker# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27*cfb92d14SAndroid Build Coastguard Worker# POSSIBILITY OF SUCH DAMAGE. 28*cfb92d14SAndroid Build Coastguard Worker# 29*cfb92d14SAndroid Build Coastguard Worker# Description: 30*cfb92d14SAndroid Build Coastguard Worker# This file installs all needed dependencies and toolchains needed for 31*cfb92d14SAndroid Build Coastguard Worker# example compilation and programming. 32*cfb92d14SAndroid Build Coastguard Worker# 33*cfb92d14SAndroid Build Coastguard Worker 34*cfb92d14SAndroid Build Coastguard Workerset -euxo pipefail 35*cfb92d14SAndroid Build Coastguard Worker 36*cfb92d14SAndroid Build Coastguard Workerinstall_packages_pretty_format() 37*cfb92d14SAndroid Build Coastguard Worker{ 38*cfb92d14SAndroid Build Coastguard Worker echo 'Installing pretty tools useful for code contributions...' 39*cfb92d14SAndroid Build Coastguard Worker 40*cfb92d14SAndroid Build Coastguard Worker # add clang-format and clang-tidy for pretty 41*cfb92d14SAndroid Build Coastguard Worker sudo apt-get --no-install-recommends install -y clang-format-14 clang-tidy-14 || echo 'WARNING: could not install clang-format-14 and clang-tidy-14, which is useful if you plan to contribute C/C++ code to the OpenThread project.' 42*cfb92d14SAndroid Build Coastguard Worker 43*cfb92d14SAndroid Build Coastguard Worker # add yapf for pretty 44*cfb92d14SAndroid Build Coastguard Worker python3 -m pip install yapf==0.31.0 || echo 'WARNING: could not install yapf, which is useful if you plan to contribute python code to the OpenThread project.' 45*cfb92d14SAndroid Build Coastguard Worker 46*cfb92d14SAndroid Build Coastguard Worker # add mdv for local size report 47*cfb92d14SAndroid Build Coastguard Worker python3 -m pip install mdv || echo 'WARNING: could not install mdv, which is required to post markdown size report for OpenThread.' 48*cfb92d14SAndroid Build Coastguard Worker 49*cfb92d14SAndroid Build Coastguard Worker # add shfmt for shell pretty 50*cfb92d14SAndroid Build Coastguard Worker command -v shfmt || sudo apt-get install shfmt || echo 'WARNING: could not install shfmt, which is useful if you plan to contribute shell scripts to the OpenThread project.' 51*cfb92d14SAndroid Build Coastguard Worker} 52*cfb92d14SAndroid Build Coastguard Worker 53*cfb92d14SAndroid Build Coastguard Workerinstall_packages_apt() 54*cfb92d14SAndroid Build Coastguard Worker{ 55*cfb92d14SAndroid Build Coastguard Worker echo 'Installing toolchain dependencies...' 56*cfb92d14SAndroid Build Coastguard Worker 57*cfb92d14SAndroid Build Coastguard Worker # apt-get update and install dependencies 58*cfb92d14SAndroid Build Coastguard Worker sudo apt-get update 59*cfb92d14SAndroid Build Coastguard Worker sudo apt-get --no-install-recommends install -y g++ lsb-release cmake ninja-build shellcheck 60*cfb92d14SAndroid Build Coastguard Worker 61*cfb92d14SAndroid Build Coastguard Worker echo 'Installing GNU Arm Embedded Toolchain...' 62*cfb92d14SAndroid Build Coastguard Worker 63*cfb92d14SAndroid Build Coastguard Worker PLATFORM=$(lsb_release -is) 64*cfb92d14SAndroid Build Coastguard Worker ARCH=$(arch) 65*cfb92d14SAndroid Build Coastguard Worker 66*cfb92d14SAndroid Build Coastguard Worker if [ "$PLATFORM" = "Raspbian" ]; then 67*cfb92d14SAndroid Build Coastguard Worker sudo apt-get --no-install-recommends install -y binutils-arm-none-eabi gcc-arm-none-eabi gdb-arm-none-eabi libnewlib-arm-none-eabi libstdc++-arm-none-eabi-newlib 68*cfb92d14SAndroid Build Coastguard Worker elif [ "$PLATFORM" = "Ubuntu" ]; then 69*cfb92d14SAndroid Build Coastguard Worker sudo apt-get --no-install-recommends install -y bzip2 ca-certificates wget 70*cfb92d14SAndroid Build Coastguard Worker (cd /tmp \ 71*cfb92d14SAndroid Build Coastguard Worker && wget --tries 4 --no-check-certificate --quiet -c https://developer.arm.com/-/media/Files/downloads/gnu-rm/9-2020q2/gcc-arm-none-eabi-9-2020-q2-update-"$ARCH"-linux.tar.bz2 \ 72*cfb92d14SAndroid Build Coastguard Worker && sudo tar xjf gcc-arm-none-eabi-9-2020-q2-update-"$ARCH"-linux.tar.bz2 -C /opt \ 73*cfb92d14SAndroid Build Coastguard Worker && rm gcc-arm-none-eabi-9-2020-q2-update-"$ARCH"-linux.tar.bz2 \ 74*cfb92d14SAndroid Build Coastguard Worker && sudo ln -s -f /opt/gcc-arm-none-eabi-9-2020-q2-update/bin/* /usr/local/bin/.) 75*cfb92d14SAndroid Build Coastguard Worker fi 76*cfb92d14SAndroid Build Coastguard Worker 77*cfb92d14SAndroid Build Coastguard Worker if [ "$PLATFORM" != "Raspbian" ]; then 78*cfb92d14SAndroid Build Coastguard Worker install_packages_pretty_format 79*cfb92d14SAndroid Build Coastguard Worker fi 80*cfb92d14SAndroid Build Coastguard Worker} 81*cfb92d14SAndroid Build Coastguard Worker 82*cfb92d14SAndroid Build Coastguard Workerinstall_packages_opkg() 83*cfb92d14SAndroid Build Coastguard Worker{ 84*cfb92d14SAndroid Build Coastguard Worker echo 'opkg not supported currently' && false 85*cfb92d14SAndroid Build Coastguard Worker} 86*cfb92d14SAndroid Build Coastguard Worker 87*cfb92d14SAndroid Build Coastguard Workerinstall_packages_rpm() 88*cfb92d14SAndroid Build Coastguard Worker{ 89*cfb92d14SAndroid Build Coastguard Worker echo 'rpm not supported currently' && false 90*cfb92d14SAndroid Build Coastguard Worker} 91*cfb92d14SAndroid Build Coastguard Worker 92*cfb92d14SAndroid Build Coastguard Workerinstall_packages_brew() 93*cfb92d14SAndroid Build Coastguard Worker{ 94*cfb92d14SAndroid Build Coastguard Worker echo 'Installing toolchain dependencies...' 95*cfb92d14SAndroid Build Coastguard Worker 96*cfb92d14SAndroid Build Coastguard Worker # add build tools 97*cfb92d14SAndroid Build Coastguard Worker brew install cmake ninja shfmt shellcheck 98*cfb92d14SAndroid Build Coastguard Worker 99*cfb92d14SAndroid Build Coastguard Worker echo 'Installing GNU Arm Embedded Toolchain...' 100*cfb92d14SAndroid Build Coastguard Worker 101*cfb92d14SAndroid Build Coastguard Worker # add ARM toolchain 102*cfb92d14SAndroid Build Coastguard Worker brew tap ArmMbed/homebrew-formulae 103*cfb92d14SAndroid Build Coastguard Worker brew install armmbed/formulae/arm-none-eabi-gcc 104*cfb92d14SAndroid Build Coastguard Worker 105*cfb92d14SAndroid Build Coastguard Worker # check for gcc for simulation 106*cfb92d14SAndroid Build Coastguard Worker if ! command -v gcc; then 107*cfb92d14SAndroid Build Coastguard Worker echo 'warning: clang/gcc needed for simulation' 108*cfb92d14SAndroid Build Coastguard Worker echo 'warning: please install Command Line Tools from https://developer.apple.com/download/more/' 109*cfb92d14SAndroid Build Coastguard Worker fi 110*cfb92d14SAndroid Build Coastguard Worker 111*cfb92d14SAndroid Build Coastguard Worker echo 'Installing pretty tools useful for code contributions...' 112*cfb92d14SAndroid Build Coastguard Worker 113*cfb92d14SAndroid Build Coastguard Worker # add clang-format for pretty 114*cfb92d14SAndroid Build Coastguard Worker CLANG_FORMAT_VERSION="clang-format version 14" 115*cfb92d14SAndroid Build Coastguard Worker command -v clang-format-14 || (command -v clang-format && (clang-format --version | grep -q "${CLANG_FORMAT_VERSION}")) || { 116*cfb92d14SAndroid Build Coastguard Worker brew install llvm@14 117*cfb92d14SAndroid Build Coastguard Worker sudo ln -s "$(brew --prefix llvm@14)/bin/clang-format" /usr/local/bin/clang-format-14 118*cfb92d14SAndroid Build Coastguard Worker sudo ln -s "$(brew --prefix llvm@14)/bin/clang-tidy" /usr/local/bin/clang-tidy-14 119*cfb92d14SAndroid Build Coastguard Worker sudo ln -s "$(brew --prefix llvm@14)/bin/clang-apply-replacements" /usr/local/bin/clang-apply-replacements-14 120*cfb92d14SAndroid Build Coastguard Worker sudo ln -s "$(brew --prefix llvm@14)/bin/run-clang-tidy" /usr/local/bin/run-clang-tidy-14 121*cfb92d14SAndroid Build Coastguard Worker } || echo 'WARNING: could not install llvm@14, which is useful if you plan to contribute C/C++ code to the OpenThread project.' 122*cfb92d14SAndroid Build Coastguard Worker 123*cfb92d14SAndroid Build Coastguard Worker # add yapf for pretty 124*cfb92d14SAndroid Build Coastguard Worker python3 -m pip install yapf || echo 'Failed to install python code formatter yapf. Install it manually if you need.' 125*cfb92d14SAndroid Build Coastguard Worker} 126*cfb92d14SAndroid Build Coastguard Worker 127*cfb92d14SAndroid Build Coastguard Workerinstall_packages_source() 128*cfb92d14SAndroid Build Coastguard Worker{ 129*cfb92d14SAndroid Build Coastguard Worker echo 'source not supported currently' && false 130*cfb92d14SAndroid Build Coastguard Worker} 131*cfb92d14SAndroid Build Coastguard Worker 132*cfb92d14SAndroid Build Coastguard Workerinstall_packages() 133*cfb92d14SAndroid Build Coastguard Worker{ 134*cfb92d14SAndroid Build Coastguard Worker PM=source 135*cfb92d14SAndroid Build Coastguard Worker if command -v apt-get; then 136*cfb92d14SAndroid Build Coastguard Worker PM=apt 137*cfb92d14SAndroid Build Coastguard Worker elif command -v rpm; then 138*cfb92d14SAndroid Build Coastguard Worker PM=rpm 139*cfb92d14SAndroid Build Coastguard Worker elif command -v opkg; then 140*cfb92d14SAndroid Build Coastguard Worker PM=opkg 141*cfb92d14SAndroid Build Coastguard Worker elif command -v brew; then 142*cfb92d14SAndroid Build Coastguard Worker PM=brew 143*cfb92d14SAndroid Build Coastguard Worker fi 144*cfb92d14SAndroid Build Coastguard Worker install_packages_$PM 145*cfb92d14SAndroid Build Coastguard Worker} 146*cfb92d14SAndroid Build Coastguard Worker 147*cfb92d14SAndroid Build Coastguard Workermain() 148*cfb92d14SAndroid Build Coastguard Worker{ 149*cfb92d14SAndroid Build Coastguard Worker install_packages 150*cfb92d14SAndroid Build Coastguard Worker echo 'bootstrap completed successfully.' 151*cfb92d14SAndroid Build Coastguard Worker} 152*cfb92d14SAndroid Build Coastguard Worker 153*cfb92d14SAndroid Build Coastguard Workermain 154