Neal Jackson | a8105f7 | 2017-08-16 09:56:51 -0700 | [diff] [blame] | 1 | #!/bin/sh |
| 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 | |
Yakun Xu | c034fd0 | 2020-04-22 06:37:46 +0800 | [diff] [blame] | 34 | set -e |
Neal Jackson | a8105f7 | 2017-08-16 09:56:51 -0700 | [diff] [blame] | 35 | |
Neal Jackson | a8105f7 | 2017-08-16 09:56:51 -0700 | [diff] [blame] | 36 | install_packages_apt() |
| 37 | { |
Yakun Xu | ba0b896 | 2020-06-02 08:03:33 +0800 | [diff] [blame^] | 38 | # apt-get update and install dependencies |
Yakun Xu | c034fd0 | 2020-04-22 06:37:46 +0800 | [diff] [blame] | 39 | sudo apt-get update |
| 40 | sudo apt-get --no-install-recommends install -y automake g++ libtool lsb-release make cmake ninja-build |
Neal Jackson | a8105f7 | 2017-08-16 09:56:51 -0700 | [diff] [blame] | 41 | |
Jonathan Hui | 4ababdc | 2018-12-27 15:44:26 -0800 | [diff] [blame] | 42 | PLATFORM=$(lsb_release -is) |
| 43 | |
Yakun Xu | c034fd0 | 2020-04-22 06:37:46 +0800 | [diff] [blame] | 44 | if [ "$PLATFORM" = "Raspbian" ]; then |
| 45 | 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 |
Yakun Xu | 50cfda1 | 2020-05-28 07:12:22 +0800 | [diff] [blame] | 46 | elif ! command -v arm-none-eabi-g++; then |
Jonathan Hui | 4ababdc | 2018-12-27 15:44:26 -0800 | [diff] [blame] | 47 | # add gcc-arm-embedded ppa |
Yakun Xu | c034fd0 | 2020-04-22 06:37:46 +0800 | [diff] [blame] | 48 | sudo add-apt-repository ppa:team-gcc-arm-embedded/ppa -y |
| 49 | sudo apt-get update |
| 50 | sudo apt-get --no-install-recommends install -y gcc-arm-embedded |
Jonathan Hui | 4ababdc | 2018-12-27 15:44:26 -0800 | [diff] [blame] | 51 | fi |
Yakun Xu | ab55bec | 2018-04-05 00:28:00 +0800 | [diff] [blame] | 52 | |
| 53 | # add clang-format for pretty |
Pratik Raj | 2e09531 | 2020-03-11 04:04:02 +0530 | [diff] [blame] | 54 | sudo apt-get --no-install-recommends install -y clang-format-6.0 |
Yakun Xu | 33808eb | 2020-02-05 02:27:51 +0800 | [diff] [blame] | 55 | |
| 56 | # add yapf for pretty |
Jonathan Hui | c0075d4 | 2020-04-23 17:14:58 -0700 | [diff] [blame] | 57 | python3 -m pip install yapf==0.29.0 || echo 'Failed to install python code formatter yapf. Install it manually if you need.' |
Yakun Xu | c034fd0 | 2020-04-22 06:37:46 +0800 | [diff] [blame] | 58 | |
| 59 | # add mdv for local size report |
| 60 | python3 -m pip install mdv || echo 'Failed to install markdown render. Install it manually if you need.' |
Yakun Xu | 50cfda1 | 2020-05-28 07:12:22 +0800 | [diff] [blame] | 61 | |
| 62 | # add shfmt for shell pretty, try brew only because snap does not support home directory not being /home and doesn't work in docker. |
| 63 | command -v shfmt || brew install shfmt || echo 'Failed to install shfmt. Install it manually if you need.' |
Neal Jackson | a8105f7 | 2017-08-16 09:56:51 -0700 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | install_packages_opkg() |
| 67 | { |
| 68 | echo 'opkg not supported currently' && false |
| 69 | } |
| 70 | |
| 71 | install_packages_rpm() |
| 72 | { |
| 73 | echo 'rpm not supported currently' && false |
| 74 | } |
| 75 | |
| 76 | install_packages_brew() |
| 77 | { |
Yakun Xu | 08c7113 | 2020-03-12 23:40:23 +0800 | [diff] [blame] | 78 | # add build tools |
Yakun Xu | 50cfda1 | 2020-05-28 07:12:22 +0800 | [diff] [blame] | 79 | brew install automake libtool cmake ninja shfmt |
Jonathan Hui | d9b4980 | 2017-12-13 05:48:51 +0000 | [diff] [blame] | 80 | |
| 81 | # add ARM toolchain |
Neal Jackson | 45d78d7 | 2020-01-29 22:14:17 -0800 | [diff] [blame] | 82 | brew tap ArmMbed/homebrew-formulae |
| 83 | brew install arm-none-eabi-gcc |
Jonathan Hui | d9b4980 | 2017-12-13 05:48:51 +0000 | [diff] [blame] | 84 | |
Yakun Xu | a551133 | 2020-02-28 04:55:56 +0800 | [diff] [blame] | 85 | # check for gcc for simulation |
Yakun Xu | c034fd0 | 2020-04-22 06:37:46 +0800 | [diff] [blame] | 86 | if ! command -v gcc; then |
Yakun Xu | a551133 | 2020-02-28 04:55:56 +0800 | [diff] [blame] | 87 | echo 'warning: clang/gcc needed for simulation' |
Jonathan Hui | d9b4980 | 2017-12-13 05:48:51 +0000 | [diff] [blame] | 88 | echo 'warning: please install Command Line Tools from https://developer.apple.com/download/more/' |
| 89 | fi |
Yakun Xu | aa0c3a7 | 2018-11-01 01:18:08 +0800 | [diff] [blame] | 90 | |
| 91 | # add clang-format for pretty |
| 92 | CLANG_FORMAT_VERSION="clang-format version 6.0" |
Yakun Xu | c034fd0 | 2020-04-22 06:37:46 +0800 | [diff] [blame] | 93 | command -v clang-format-6.0 || (command -v clang-format && (clang-format --version | grep -q "${CLANG_FORMAT_VERSION}")) || { |
Yakun Xu | aa0c3a7 | 2018-11-01 01:18:08 +0800 | [diff] [blame] | 94 | brew install llvm@6 |
kangping | 420479d | 2019-12-18 00:52:26 +0800 | [diff] [blame] | 95 | sudo ln -s "$(brew --prefix llvm@6)/bin/clang-format" /usr/local/bin/clang-format-6.0 |
Yakun Xu | aa0c3a7 | 2018-11-01 01:18:08 +0800 | [diff] [blame] | 96 | } |
Yakun Xu | 33808eb | 2020-02-05 02:27:51 +0800 | [diff] [blame] | 97 | |
| 98 | # add yapf for pretty |
| 99 | 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] | 100 | } |
| 101 | |
| 102 | install_packages_source() |
| 103 | { |
| 104 | echo 'source not supported currently' && false |
| 105 | } |
| 106 | |
| 107 | install_packages() |
| 108 | { |
| 109 | PM=source |
Yakun Xu | c034fd0 | 2020-04-22 06:37:46 +0800 | [diff] [blame] | 110 | if command -v apt-get; then |
Neal Jackson | a8105f7 | 2017-08-16 09:56:51 -0700 | [diff] [blame] | 111 | PM=apt |
Yakun Xu | c034fd0 | 2020-04-22 06:37:46 +0800 | [diff] [blame] | 112 | elif command -v rpm; then |
Neal Jackson | a8105f7 | 2017-08-16 09:56:51 -0700 | [diff] [blame] | 113 | PM=rpm |
Yakun Xu | c034fd0 | 2020-04-22 06:37:46 +0800 | [diff] [blame] | 114 | elif command -v opkg; then |
Neal Jackson | a8105f7 | 2017-08-16 09:56:51 -0700 | [diff] [blame] | 115 | PM=opkg |
Yakun Xu | c034fd0 | 2020-04-22 06:37:46 +0800 | [diff] [blame] | 116 | elif command -v brew; then |
Neal Jackson | a8105f7 | 2017-08-16 09:56:51 -0700 | [diff] [blame] | 117 | PM=brew |
| 118 | fi |
| 119 | install_packages_$PM |
| 120 | } |
| 121 | |
| 122 | main() |
| 123 | { |
Neal Jackson | a8105f7 | 2017-08-16 09:56:51 -0700 | [diff] [blame] | 124 | install_packages |
Neal Jackson | a8105f7 | 2017-08-16 09:56:51 -0700 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | main |