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 |
Jonathan Hui | 49c5736 | 2022-12-06 14:41:07 -0800 | [diff] [blame] | 41 | 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.' |
Li Cao | df047ed | 2021-01-05 00:57:20 +0800 | [diff] [blame] | 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 | |
canisLupus1313 | 593c2b0 | 2022-11-17 17:52:22 +0100 | [diff] [blame] | 49 | # add shfmt for shell pretty |
| 50 | 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.' |
Li Cao | df047ed | 2021-01-05 00:57:20 +0800 | [diff] [blame] | 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) |
Łukasz Duda | 8b63efe | 2021-05-20 04:35:14 +0200 | [diff] [blame] | 64 | ARCH=$(arch) |
Jonathan Hui | 4ababdc | 2018-12-27 15:44:26 -0800 | [diff] [blame] | 65 | |
Yakun Xu | c034fd0 | 2020-04-22 06:37:46 +0800 | [diff] [blame] | 66 | if [ "$PLATFORM" = "Raspbian" ]; then |
| 67 | 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] | 68 | elif [ "$PLATFORM" = "Ubuntu" ]; then |
Sylvain Baubeau | 9ff2eef | 2023-02-14 22:57:41 +0100 | [diff] [blame] | 69 | sudo apt-get --no-install-recommends install -y bzip2 ca-certificates wget |
Simon Lin | de6d0e8 | 2020-10-24 01:25:55 +0800 | [diff] [blame] | 70 | (cd /tmp \ |
Jonathan Hui | b9fadd2 | 2021-09-15 19:58:03 -0700 | [diff] [blame] | 71 | && 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 \ |
Łukasz Duda | 8b63efe | 2021-05-20 04:35:14 +0200 | [diff] [blame] | 72 | && sudo tar xjf gcc-arm-none-eabi-9-2020-q2-update-"$ARCH"-linux.tar.bz2 -C /opt \ |
| 73 | && rm gcc-arm-none-eabi-9-2020-q2-update-"$ARCH"-linux.tar.bz2 \ |
Matthias Deimbacher | ba97f96 | 2021-01-19 19:32:39 +0100 | [diff] [blame] | 74 | && 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] | 75 | fi |
Yakun Xu | ab55bec | 2018-04-05 00:28:00 +0800 | [diff] [blame] | 76 | |
Li Cao | df047ed | 2021-01-05 00:57:20 +0800 | [diff] [blame] | 77 | if [ "$PLATFORM" != "Raspbian" ]; then |
Li Cao | 8625603 | 2021-01-15 02:17:27 +0800 | [diff] [blame] | 78 | install_packages_pretty_format |
Li Cao | df047ed | 2021-01-05 00:57:20 +0800 | [diff] [blame] | 79 | fi |
Neal Jackson | a8105f7 | 2017-08-16 09:56:51 -0700 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | install_packages_opkg() |
| 83 | { |
| 84 | echo 'opkg not supported currently' && false |
| 85 | } |
| 86 | |
| 87 | install_packages_rpm() |
| 88 | { |
| 89 | echo 'rpm not supported currently' && false |
| 90 | } |
| 91 | |
| 92 | install_packages_brew() |
| 93 | { |
Jonathan Hui | 6930dd3 | 2020-06-30 08:47:01 -0700 | [diff] [blame] | 94 | echo 'Installing toolchain dependencies...' |
| 95 | |
Yakun Xu | 08c7113 | 2020-03-12 23:40:23 +0800 | [diff] [blame] | 96 | # add build tools |
Simon Lin | 9aadfd0 | 2020-06-12 09:26:18 +0800 | [diff] [blame] | 97 | brew install automake libtool cmake ninja shfmt shellcheck |
Jonathan Hui | d9b4980 | 2017-12-13 05:48:51 +0000 | [diff] [blame] | 98 | |
Jonathan Hui | 6930dd3 | 2020-06-30 08:47:01 -0700 | [diff] [blame] | 99 | echo 'Installing GNU Arm Embedded Toolchain...' |
| 100 | |
Jonathan Hui | d9b4980 | 2017-12-13 05:48:51 +0000 | [diff] [blame] | 101 | # add ARM toolchain |
Neal Jackson | 45d78d7 | 2020-01-29 22:14:17 -0800 | [diff] [blame] | 102 | brew tap ArmMbed/homebrew-formulae |
Robert Quattlebaum | 8095a08 | 2022-07-19 14:35:19 -0700 | [diff] [blame] | 103 | brew install armmbed/formulae/arm-none-eabi-gcc |
Jonathan Hui | d9b4980 | 2017-12-13 05:48:51 +0000 | [diff] [blame] | 104 | |
Yakun Xu | a551133 | 2020-02-28 04:55:56 +0800 | [diff] [blame] | 105 | # check for gcc for simulation |
Yakun Xu | c034fd0 | 2020-04-22 06:37:46 +0800 | [diff] [blame] | 106 | if ! command -v gcc; then |
Yakun Xu | a551133 | 2020-02-28 04:55:56 +0800 | [diff] [blame] | 107 | echo 'warning: clang/gcc needed for simulation' |
Jonathan Hui | d9b4980 | 2017-12-13 05:48:51 +0000 | [diff] [blame] | 108 | echo 'warning: please install Command Line Tools from https://developer.apple.com/download/more/' |
| 109 | fi |
Yakun Xu | aa0c3a7 | 2018-11-01 01:18:08 +0800 | [diff] [blame] | 110 | |
Jonathan Hui | 6930dd3 | 2020-06-30 08:47:01 -0700 | [diff] [blame] | 111 | echo 'Installing pretty tools useful for code contributions...' |
| 112 | |
Yakun Xu | aa0c3a7 | 2018-11-01 01:18:08 +0800 | [diff] [blame] | 113 | # add clang-format for pretty |
Jonathan Hui | 351298e | 2022-12-06 14:38:40 -0800 | [diff] [blame] | 114 | CLANG_FORMAT_VERSION="clang-format version 14" |
| 115 | command -v clang-format-14 || (command -v clang-format && (clang-format --version | grep -q "${CLANG_FORMAT_VERSION}")) || { |
| 116 | brew install llvm@14 |
| 117 | sudo ln -s "$(brew --prefix llvm@14)/bin/clang-format" /usr/local/bin/clang-format-14 |
Mason Tran | f765e1f | 2022-12-08 17:20:22 -0500 | [diff] [blame] | 118 | sudo ln -s "$(brew --prefix llvm@14)/bin/clang-tidy" /usr/local/bin/clang-tidy-14 |
| 119 | sudo ln -s "$(brew --prefix llvm@14)/bin/clang-apply-replacements" /usr/local/bin/clang-apply-replacements-14 |
| 120 | sudo ln -s "$(brew --prefix llvm@14)/bin/run-clang-tidy" /usr/local/bin/run-clang-tidy-14 |
Jonathan Hui | 351298e | 2022-12-06 14:38:40 -0800 | [diff] [blame] | 121 | } || echo 'WARNING: could not install llvm@14, 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] | 122 | |
| 123 | # add yapf for pretty |
| 124 | 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] | 125 | } |
| 126 | |
| 127 | install_packages_source() |
| 128 | { |
| 129 | echo 'source not supported currently' && false |
| 130 | } |
| 131 | |
| 132 | install_packages() |
| 133 | { |
| 134 | PM=source |
Yakun Xu | c034fd0 | 2020-04-22 06:37:46 +0800 | [diff] [blame] | 135 | if command -v apt-get; then |
Neal Jackson | a8105f7 | 2017-08-16 09:56:51 -0700 | [diff] [blame] | 136 | PM=apt |
Yakun Xu | c034fd0 | 2020-04-22 06:37:46 +0800 | [diff] [blame] | 137 | elif command -v rpm; then |
Neal Jackson | a8105f7 | 2017-08-16 09:56:51 -0700 | [diff] [blame] | 138 | PM=rpm |
Yakun Xu | c034fd0 | 2020-04-22 06:37:46 +0800 | [diff] [blame] | 139 | elif command -v opkg; then |
Neal Jackson | a8105f7 | 2017-08-16 09:56:51 -0700 | [diff] [blame] | 140 | PM=opkg |
Yakun Xu | c034fd0 | 2020-04-22 06:37:46 +0800 | [diff] [blame] | 141 | elif command -v brew; then |
Neal Jackson | a8105f7 | 2017-08-16 09:56:51 -0700 | [diff] [blame] | 142 | PM=brew |
| 143 | fi |
| 144 | install_packages_$PM |
| 145 | } |
| 146 | |
| 147 | main() |
| 148 | { |
Neal Jackson | a8105f7 | 2017-08-16 09:56:51 -0700 | [diff] [blame] | 149 | install_packages |
Jonathan Hui | 6930dd3 | 2020-06-30 08:47:01 -0700 | [diff] [blame] | 150 | echo 'bootstrap completed successfully.' |
Neal Jackson | a8105f7 | 2017-08-16 09:56:51 -0700 | [diff] [blame] | 151 | } |
| 152 | |
| 153 | main |