Jonathan Hui | 6930dd3 | 2020-06-30 08:47:01 -0700 | [diff] [blame] | 1 | #!/bin/bash |
Neal Jackson | a8105f7 | 2017-08-16 09:56:51 -0700 | [diff] [blame] | 2 | # |
| 3 | # Copyright (c) 2017, The OpenThread Authors. |
| 4 | # All rights reserved. |
| 5 | # |
| 6 | # Redistribution and use in source and binary forms, with or without |
| 7 | # modification, are permitted provided that the following conditions are met: |
| 8 | # 1. Redistributions of source code must retain the above copyright |
| 9 | # notice, this list of conditions and the following disclaimer. |
| 10 | # 2. Redistributions in binary form must reproduce the above copyright |
| 11 | # notice, this list of conditions and the following disclaimer in the |
| 12 | # documentation and/or other materials provided with the distribution. |
| 13 | # 3. Neither the name of the copyright holder nor the |
| 14 | # names of its contributors may be used to endorse or promote products |
| 15 | # derived from this software without specific prior written permission. |
| 16 | # |
| 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 18 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 19 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 20 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
| 21 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 22 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 23 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 24 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 25 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 26 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 27 | # POSSIBILITY OF SUCH DAMAGE. |
| 28 | # |
| 29 | # Description: |
| 30 | # This file installs all needed dependencies and toolchains needed for |
| 31 | # example compilation and programming. |
| 32 | # |
| 33 | |
Jonathan Hui | 6930dd3 | 2020-06-30 08:47:01 -0700 | [diff] [blame] | 34 | set -euxo pipefail |
Neal Jackson | a8105f7 | 2017-08-16 09:56:51 -0700 | [diff] [blame] | 35 | |
Li Cao | 8625603 | 2021-01-15 02:17:27 +0800 | [diff] [blame] | 36 | install_packages_pretty_format() |
Li Cao | df047ed | 2021-01-05 00:57:20 +0800 | [diff] [blame] | 37 | { |
| 38 | echo 'Installing pretty tools useful for code contributions...' |
| 39 | |
| 40 | # add clang-format and clang-tidy for pretty |
| 41 | sudo apt-get --no-install-recommends install -y clang-format-9 clang-tidy-9 || echo 'WARNING: could not install clang-format-9 and clang-tidy-9, which is useful if you plan to contribute C/C++ code to the OpenThread project.' |
| 42 | |
| 43 | # add yapf for pretty |
Simon Lin | d5855ab | 2021-04-12 22:30:27 +0800 | [diff] [blame] | 44 | 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.' |
Li Cao | df047ed | 2021-01-05 00:57:20 +0800 | [diff] [blame] | 45 | |
| 46 | # add mdv for local size report |
Li Cao | 1c0d295 | 2021-01-21 06:12:00 +0800 | [diff] [blame] | 47 | python3 -m pip install mdv || echo 'WARNING: could not install mdv, which is required to post markdown size report for OpenThread.' |
Li Cao | df047ed | 2021-01-05 00:57:20 +0800 | [diff] [blame] | 48 | |
| 49 | # add shfmt for shell pretty, try brew only because snap does not support home directory not being /home and doesn't work in docker. |
| 50 | command -v shfmt || brew install shfmt || echo 'WARNING: could not install shfmt, which is useful if you plan to contribute shell scripts to the OpenThread project.' |
| 51 | } |
| 52 | |
Neal Jackson | a8105f7 | 2017-08-16 09:56:51 -0700 | [diff] [blame] | 53 | install_packages_apt() |
| 54 | { |
Jonathan Hui | 6930dd3 | 2020-06-30 08:47:01 -0700 | [diff] [blame] | 55 | echo 'Installing toolchain dependencies...' |
| 56 | |
Yakun Xu | ba0b896 | 2020-06-02 08:03:33 +0800 | [diff] [blame] | 57 | # apt-get update and install dependencies |
Yakun Xu | c034fd0 | 2020-04-22 06:37:46 +0800 | [diff] [blame] | 58 | sudo apt-get update |
Simon Lin | 9aadfd0 | 2020-06-12 09:26:18 +0800 | [diff] [blame] | 59 | sudo apt-get --no-install-recommends install -y automake g++ libtool lsb-release make cmake ninja-build shellcheck |
Neal Jackson | a8105f7 | 2017-08-16 09:56:51 -0700 | [diff] [blame] | 60 | |
Jonathan Hui | 6930dd3 | 2020-06-30 08:47:01 -0700 | [diff] [blame] | 61 | echo 'Installing GNU Arm Embedded Toolchain...' |
| 62 | |
Jonathan Hui | 4ababdc | 2018-12-27 15:44:26 -0800 | [diff] [blame] | 63 | PLATFORM=$(lsb_release -is) |
| 64 | |
Yakun Xu | c034fd0 | 2020-04-22 06:37:46 +0800 | [diff] [blame] | 65 | if [ "$PLATFORM" = "Raspbian" ]; then |
| 66 | 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 |
Jonathan Hui | 5806432 | 2020-10-07 12:19:46 -0700 | [diff] [blame] | 67 | elif [ "$PLATFORM" = "Ubuntu" ]; then |
| 68 | sudo apt-get --no-install-recommends install -y ca-certificates wget |
Simon Lin | de6d0e8 | 2020-10-24 01:25:55 +0800 | [diff] [blame] | 69 | (cd /tmp \ |
Jonathan Hui | 5806432 | 2020-10-07 12:19:46 -0700 | [diff] [blame] | 70 | && wget -c https://developer.arm.com/-/media/Files/downloads/gnu-rm/9-2020q2/gcc-arm-none-eabi-9-2020-q2-update-x86_64-linux.tar.bz2 \ |
Leon Steenkamp | b507527 | 2021-01-17 19:34:51 +0200 | [diff] [blame] | 71 | && tar xjf gcc-arm-none-eabi-9-2020-q2-update-x86_64-linux.tar.bz2 -C /opt \ |
Jonathan Hui | 5806432 | 2020-10-07 12:19:46 -0700 | [diff] [blame] | 72 | && rm gcc-arm-none-eabi-9-2020-q2-update-x86_64-linux.tar.bz2 \ |
Matthias Deimbacher | ba97f96 | 2021-01-19 19:32:39 +0100 | [diff] [blame] | 73 | && sudo ln -s -f /opt/gcc-arm-none-eabi-9-2020-q2-update/bin/* /usr/local/bin/.) |
Jonathan Hui | 4ababdc | 2018-12-27 15:44:26 -0800 | [diff] [blame] | 74 | fi |
Yakun Xu | ab55bec | 2018-04-05 00:28:00 +0800 | [diff] [blame] | 75 | |
Li Cao | df047ed | 2021-01-05 00:57:20 +0800 | [diff] [blame] | 76 | if [ "$PLATFORM" != "Raspbian" ]; then |
Li Cao | 8625603 | 2021-01-15 02:17:27 +0800 | [diff] [blame] | 77 | install_packages_pretty_format |
Li Cao | df047ed | 2021-01-05 00:57:20 +0800 | [diff] [blame] | 78 | fi |
Neal Jackson | a8105f7 | 2017-08-16 09:56:51 -0700 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | install_packages_opkg() |
| 82 | { |
| 83 | echo 'opkg not supported currently' && false |
| 84 | } |
| 85 | |
| 86 | install_packages_rpm() |
| 87 | { |
| 88 | echo 'rpm not supported currently' && false |
| 89 | } |
| 90 | |
| 91 | install_packages_brew() |
| 92 | { |
Jonathan Hui | 6930dd3 | 2020-06-30 08:47:01 -0700 | [diff] [blame] | 93 | echo 'Installing toolchain dependencies...' |
| 94 | |
Yakun Xu | 08c7113 | 2020-03-12 23:40:23 +0800 | [diff] [blame] | 95 | # add build tools |
Simon Lin | 9aadfd0 | 2020-06-12 09:26:18 +0800 | [diff] [blame] | 96 | brew install automake libtool cmake ninja shfmt shellcheck |
Jonathan Hui | d9b4980 | 2017-12-13 05:48:51 +0000 | [diff] [blame] | 97 | |
Jonathan Hui | 6930dd3 | 2020-06-30 08:47:01 -0700 | [diff] [blame] | 98 | echo 'Installing GNU Arm Embedded Toolchain...' |
| 99 | |
Jonathan Hui | d9b4980 | 2017-12-13 05:48:51 +0000 | [diff] [blame] | 100 | # add ARM toolchain |
Neal Jackson | 45d78d7 | 2020-01-29 22:14:17 -0800 | [diff] [blame] | 101 | brew tap ArmMbed/homebrew-formulae |
| 102 | brew install arm-none-eabi-gcc |
Jonathan Hui | d9b4980 | 2017-12-13 05:48:51 +0000 | [diff] [blame] | 103 | |
Yakun Xu | a551133 | 2020-02-28 04:55:56 +0800 | [diff] [blame] | 104 | # check for gcc for simulation |
Yakun Xu | c034fd0 | 2020-04-22 06:37:46 +0800 | [diff] [blame] | 105 | if ! command -v gcc; then |
Yakun Xu | a551133 | 2020-02-28 04:55:56 +0800 | [diff] [blame] | 106 | echo 'warning: clang/gcc needed for simulation' |
Jonathan Hui | d9b4980 | 2017-12-13 05:48:51 +0000 | [diff] [blame] | 107 | echo 'warning: please install Command Line Tools from https://developer.apple.com/download/more/' |
| 108 | fi |
Yakun Xu | aa0c3a7 | 2018-11-01 01:18:08 +0800 | [diff] [blame] | 109 | |
Jonathan Hui | 6930dd3 | 2020-06-30 08:47:01 -0700 | [diff] [blame] | 110 | echo 'Installing pretty tools useful for code contributions...' |
| 111 | |
Yakun Xu | aa0c3a7 | 2018-11-01 01:18:08 +0800 | [diff] [blame] | 112 | # add clang-format for pretty |
Simon Lin | 1671adc | 2020-11-05 11:26:16 +0800 | [diff] [blame] | 113 | CLANG_FORMAT_VERSION="clang-format version 9" |
Jonathan Hui | 0eecd1c | 2020-11-02 13:23:53 -0800 | [diff] [blame] | 114 | command -v clang-format-9 || (command -v clang-format && (clang-format --version | grep -q "${CLANG_FORMAT_VERSION}")) || { |
| 115 | brew install llvm@9 |
| 116 | sudo ln -s "$(brew --prefix llvm@9)/bin/clang-format" /usr/local/bin/clang-format-9 |
Simon Lin | 1671adc | 2020-11-05 11:26:16 +0800 | [diff] [blame] | 117 | } || echo 'WARNING: could not install llvm@9, which is useful if you plan to contribute C/C++ code to the OpenThread project.' |
Yakun Xu | 33808eb | 2020-02-05 02:27:51 +0800 | [diff] [blame] | 118 | |
| 119 | # add yapf for pretty |
| 120 | python3 -m pip install yapf || echo 'Failed to install python code formatter yapf. Install it manually if you need.' |
Neal Jackson | a8105f7 | 2017-08-16 09:56:51 -0700 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | install_packages_source() |
| 124 | { |
| 125 | echo 'source not supported currently' && false |
| 126 | } |
| 127 | |
| 128 | install_packages() |
| 129 | { |
| 130 | PM=source |
Yakun Xu | c034fd0 | 2020-04-22 06:37:46 +0800 | [diff] [blame] | 131 | if command -v apt-get; then |
Neal Jackson | a8105f7 | 2017-08-16 09:56:51 -0700 | [diff] [blame] | 132 | PM=apt |
Yakun Xu | c034fd0 | 2020-04-22 06:37:46 +0800 | [diff] [blame] | 133 | elif command -v rpm; then |
Neal Jackson | a8105f7 | 2017-08-16 09:56:51 -0700 | [diff] [blame] | 134 | PM=rpm |
Yakun Xu | c034fd0 | 2020-04-22 06:37:46 +0800 | [diff] [blame] | 135 | elif command -v opkg; then |
Neal Jackson | a8105f7 | 2017-08-16 09:56:51 -0700 | [diff] [blame] | 136 | PM=opkg |
Yakun Xu | c034fd0 | 2020-04-22 06:37:46 +0800 | [diff] [blame] | 137 | elif command -v brew; then |
Neal Jackson | a8105f7 | 2017-08-16 09:56:51 -0700 | [diff] [blame] | 138 | PM=brew |
| 139 | fi |
| 140 | install_packages_$PM |
| 141 | } |
| 142 | |
| 143 | main() |
| 144 | { |
Neal Jackson | a8105f7 | 2017-08-16 09:56:51 -0700 | [diff] [blame] | 145 | install_packages |
Jonathan Hui | 6930dd3 | 2020-06-30 08:47:01 -0700 | [diff] [blame] | 146 | echo 'bootstrap completed successfully.' |
Neal Jackson | a8105f7 | 2017-08-16 09:56:51 -0700 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | main |