blob: 3af33a36720cf257a30b1eb01ca0ca400ca0e313 [file] [log] [blame]
Jonathan Hui6930dd32020-06-30 08:47:01 -07001#!/bin/bash
Neal Jacksona8105f72017-08-16 09:56:51 -07002#
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 Hui6930dd32020-06-30 08:47:01 -070034set -euxo pipefail
Neal Jacksona8105f72017-08-16 09:56:51 -070035
Li Cao86256032021-01-15 02:17:27 +080036install_packages_pretty_format()
Li Caodf047ed2021-01-05 00:57:20 +080037{
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 Lind5855ab2021-04-12 22:30:27 +080044 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 Caodf047ed2021-01-05 00:57:20 +080045
46 # add mdv for local size report
Li Cao1c0d2952021-01-21 06:12:00 +080047 python3 -m pip install mdv || echo 'WARNING: could not install mdv, which is required to post markdown size report for OpenThread.'
Li Caodf047ed2021-01-05 00:57:20 +080048
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 Jacksona8105f72017-08-16 09:56:51 -070053install_packages_apt()
54{
Jonathan Hui6930dd32020-06-30 08:47:01 -070055 echo 'Installing toolchain dependencies...'
56
Yakun Xuba0b8962020-06-02 08:03:33 +080057 # apt-get update and install dependencies
Yakun Xuc034fd02020-04-22 06:37:46 +080058 sudo apt-get update
Simon Lin9aadfd02020-06-12 09:26:18 +080059 sudo apt-get --no-install-recommends install -y automake g++ libtool lsb-release make cmake ninja-build shellcheck
Neal Jacksona8105f72017-08-16 09:56:51 -070060
Jonathan Hui6930dd32020-06-30 08:47:01 -070061 echo 'Installing GNU Arm Embedded Toolchain...'
62
Jonathan Hui4ababdc2018-12-27 15:44:26 -080063 PLATFORM=$(lsb_release -is)
64
Yakun Xuc034fd02020-04-22 06:37:46 +080065 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 Hui58064322020-10-07 12:19:46 -070067 elif [ "$PLATFORM" = "Ubuntu" ]; then
68 sudo apt-get --no-install-recommends install -y ca-certificates wget
Simon Linde6d0e82020-10-24 01:25:55 +080069 (cd /tmp \
Jonathan Hui58064322020-10-07 12:19:46 -070070 && 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 Steenkampb5075272021-01-17 19:34:51 +020071 && tar xjf gcc-arm-none-eabi-9-2020-q2-update-x86_64-linux.tar.bz2 -C /opt \
Jonathan Hui58064322020-10-07 12:19:46 -070072 && rm gcc-arm-none-eabi-9-2020-q2-update-x86_64-linux.tar.bz2 \
Matthias Deimbacherba97f962021-01-19 19:32:39 +010073 && sudo ln -s -f /opt/gcc-arm-none-eabi-9-2020-q2-update/bin/* /usr/local/bin/.)
Jonathan Hui4ababdc2018-12-27 15:44:26 -080074 fi
Yakun Xuab55bec2018-04-05 00:28:00 +080075
Li Caodf047ed2021-01-05 00:57:20 +080076 if [ "$PLATFORM" != "Raspbian" ]; then
Li Cao86256032021-01-15 02:17:27 +080077 install_packages_pretty_format
Li Caodf047ed2021-01-05 00:57:20 +080078 fi
Neal Jacksona8105f72017-08-16 09:56:51 -070079}
80
81install_packages_opkg()
82{
83 echo 'opkg not supported currently' && false
84}
85
86install_packages_rpm()
87{
88 echo 'rpm not supported currently' && false
89}
90
91install_packages_brew()
92{
Jonathan Hui6930dd32020-06-30 08:47:01 -070093 echo 'Installing toolchain dependencies...'
94
Yakun Xu08c71132020-03-12 23:40:23 +080095 # add build tools
Simon Lin9aadfd02020-06-12 09:26:18 +080096 brew install automake libtool cmake ninja shfmt shellcheck
Jonathan Huid9b49802017-12-13 05:48:51 +000097
Jonathan Hui6930dd32020-06-30 08:47:01 -070098 echo 'Installing GNU Arm Embedded Toolchain...'
99
Jonathan Huid9b49802017-12-13 05:48:51 +0000100 # add ARM toolchain
Neal Jackson45d78d72020-01-29 22:14:17 -0800101 brew tap ArmMbed/homebrew-formulae
102 brew install arm-none-eabi-gcc
Jonathan Huid9b49802017-12-13 05:48:51 +0000103
Yakun Xua5511332020-02-28 04:55:56 +0800104 # check for gcc for simulation
Yakun Xuc034fd02020-04-22 06:37:46 +0800105 if ! command -v gcc; then
Yakun Xua5511332020-02-28 04:55:56 +0800106 echo 'warning: clang/gcc needed for simulation'
Jonathan Huid9b49802017-12-13 05:48:51 +0000107 echo 'warning: please install Command Line Tools from https://developer.apple.com/download/more/'
108 fi
Yakun Xuaa0c3a72018-11-01 01:18:08 +0800109
Jonathan Hui6930dd32020-06-30 08:47:01 -0700110 echo 'Installing pretty tools useful for code contributions...'
111
Yakun Xuaa0c3a72018-11-01 01:18:08 +0800112 # add clang-format for pretty
Simon Lin1671adc2020-11-05 11:26:16 +0800113 CLANG_FORMAT_VERSION="clang-format version 9"
Jonathan Hui0eecd1c2020-11-02 13:23:53 -0800114 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 Lin1671adc2020-11-05 11:26:16 +0800117 } || echo 'WARNING: could not install llvm@9, which is useful if you plan to contribute C/C++ code to the OpenThread project.'
Yakun Xu33808eb2020-02-05 02:27:51 +0800118
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 Jacksona8105f72017-08-16 09:56:51 -0700121}
122
123install_packages_source()
124{
125 echo 'source not supported currently' && false
126}
127
128install_packages()
129{
130 PM=source
Yakun Xuc034fd02020-04-22 06:37:46 +0800131 if command -v apt-get; then
Neal Jacksona8105f72017-08-16 09:56:51 -0700132 PM=apt
Yakun Xuc034fd02020-04-22 06:37:46 +0800133 elif command -v rpm; then
Neal Jacksona8105f72017-08-16 09:56:51 -0700134 PM=rpm
Yakun Xuc034fd02020-04-22 06:37:46 +0800135 elif command -v opkg; then
Neal Jacksona8105f72017-08-16 09:56:51 -0700136 PM=opkg
Yakun Xuc034fd02020-04-22 06:37:46 +0800137 elif command -v brew; then
Neal Jacksona8105f72017-08-16 09:56:51 -0700138 PM=brew
139 fi
140 install_packages_$PM
141}
142
143main()
144{
Neal Jacksona8105f72017-08-16 09:56:51 -0700145 install_packages
Jonathan Hui6930dd32020-06-30 08:47:01 -0700146 echo 'bootstrap completed successfully.'
Neal Jacksona8105f72017-08-16 09:56:51 -0700147}
148
149main