blob: 45f2f75978d74d3ea490eab3f2d66592b711f378 [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
Jonathan Hui49c57362022-12-06 14:41:07 -080041 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 Caodf047ed2021-01-05 00:57:20 +080042
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
canisLupus1313593c2b02022-11-17 17:52:22 +010049 # 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 Caodf047ed2021-01-05 00:57:20 +080051}
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)
Łukasz Duda8b63efe2021-05-20 04:35:14 +020064 ARCH=$(arch)
Jonathan Hui4ababdc2018-12-27 15:44:26 -080065
Yakun Xuc034fd02020-04-22 06:37:46 +080066 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 Hui58064322020-10-07 12:19:46 -070068 elif [ "$PLATFORM" = "Ubuntu" ]; then
Sylvain Baubeau9ff2eef2023-02-14 22:57:41 +010069 sudo apt-get --no-install-recommends install -y bzip2 ca-certificates wget
Simon Linde6d0e82020-10-24 01:25:55 +080070 (cd /tmp \
Jonathan Huib9fadd22021-09-15 19:58:03 -070071 && 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 Duda8b63efe2021-05-20 04:35:14 +020072 && 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 Deimbacherba97f962021-01-19 19:32:39 +010074 && sudo ln -s -f /opt/gcc-arm-none-eabi-9-2020-q2-update/bin/* /usr/local/bin/.)
Jonathan Hui4ababdc2018-12-27 15:44:26 -080075 fi
Yakun Xuab55bec2018-04-05 00:28:00 +080076
Li Caodf047ed2021-01-05 00:57:20 +080077 if [ "$PLATFORM" != "Raspbian" ]; then
Li Cao86256032021-01-15 02:17:27 +080078 install_packages_pretty_format
Li Caodf047ed2021-01-05 00:57:20 +080079 fi
Neal Jacksona8105f72017-08-16 09:56:51 -070080}
81
82install_packages_opkg()
83{
84 echo 'opkg not supported currently' && false
85}
86
87install_packages_rpm()
88{
89 echo 'rpm not supported currently' && false
90}
91
92install_packages_brew()
93{
Jonathan Hui6930dd32020-06-30 08:47:01 -070094 echo 'Installing toolchain dependencies...'
95
Yakun Xu08c71132020-03-12 23:40:23 +080096 # add build tools
Simon Lin9aadfd02020-06-12 09:26:18 +080097 brew install automake libtool cmake ninja shfmt shellcheck
Jonathan Huid9b49802017-12-13 05:48:51 +000098
Jonathan Hui6930dd32020-06-30 08:47:01 -070099 echo 'Installing GNU Arm Embedded Toolchain...'
100
Jonathan Huid9b49802017-12-13 05:48:51 +0000101 # add ARM toolchain
Neal Jackson45d78d72020-01-29 22:14:17 -0800102 brew tap ArmMbed/homebrew-formulae
Robert Quattlebaum8095a082022-07-19 14:35:19 -0700103 brew install armmbed/formulae/arm-none-eabi-gcc
Jonathan Huid9b49802017-12-13 05:48:51 +0000104
Yakun Xua5511332020-02-28 04:55:56 +0800105 # check for gcc for simulation
Yakun Xuc034fd02020-04-22 06:37:46 +0800106 if ! command -v gcc; then
Yakun Xua5511332020-02-28 04:55:56 +0800107 echo 'warning: clang/gcc needed for simulation'
Jonathan Huid9b49802017-12-13 05:48:51 +0000108 echo 'warning: please install Command Line Tools from https://developer.apple.com/download/more/'
109 fi
Yakun Xuaa0c3a72018-11-01 01:18:08 +0800110
Jonathan Hui6930dd32020-06-30 08:47:01 -0700111 echo 'Installing pretty tools useful for code contributions...'
112
Yakun Xuaa0c3a72018-11-01 01:18:08 +0800113 # add clang-format for pretty
Jonathan Hui351298e2022-12-06 14:38:40 -0800114 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 Tranf765e1f2022-12-08 17:20:22 -0500118 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 Hui351298e2022-12-06 14:38:40 -0800121 } || echo 'WARNING: could not install llvm@14, which is useful if you plan to contribute C/C++ code to the OpenThread project.'
Yakun Xu33808eb2020-02-05 02:27:51 +0800122
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 Jacksona8105f72017-08-16 09:56:51 -0700125}
126
127install_packages_source()
128{
129 echo 'source not supported currently' && false
130}
131
132install_packages()
133{
134 PM=source
Yakun Xuc034fd02020-04-22 06:37:46 +0800135 if command -v apt-get; then
Neal Jacksona8105f72017-08-16 09:56:51 -0700136 PM=apt
Yakun Xuc034fd02020-04-22 06:37:46 +0800137 elif command -v rpm; then
Neal Jacksona8105f72017-08-16 09:56:51 -0700138 PM=rpm
Yakun Xuc034fd02020-04-22 06:37:46 +0800139 elif command -v opkg; then
Neal Jacksona8105f72017-08-16 09:56:51 -0700140 PM=opkg
Yakun Xuc034fd02020-04-22 06:37:46 +0800141 elif command -v brew; then
Neal Jacksona8105f72017-08-16 09:56:51 -0700142 PM=brew
143 fi
144 install_packages_$PM
145}
146
147main()
148{
Neal Jacksona8105f72017-08-16 09:56:51 -0700149 install_packages
Jonathan Hui6930dd32020-06-30 08:47:01 -0700150 echo 'bootstrap completed successfully.'
Neal Jacksona8105f72017-08-16 09:56:51 -0700151}
152
153main