blob: 9754dd30f7105ea0831cae8446ab7f139f99a08c [file] [log] [blame]
Neal Jacksona8105f72017-08-16 09:56:51 -07001#!/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 Xuc034fd02020-04-22 06:37:46 +080034set -e
Neal Jacksona8105f72017-08-16 09:56:51 -070035
Neal Jacksona8105f72017-08-16 09:56:51 -070036install_packages_apt()
37{
Yakun Xuba0b8962020-06-02 08:03:33 +080038 # apt-get update and install dependencies
Yakun Xuc034fd02020-04-22 06:37:46 +080039 sudo apt-get update
40 sudo apt-get --no-install-recommends install -y automake g++ libtool lsb-release make cmake ninja-build
Neal Jacksona8105f72017-08-16 09:56:51 -070041
Jonathan Hui4ababdc2018-12-27 15:44:26 -080042 PLATFORM=$(lsb_release -is)
43
Yakun Xuc034fd02020-04-22 06:37:46 +080044 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 Xu50cfda12020-05-28 07:12:22 +080046 elif ! command -v arm-none-eabi-g++; then
Jonathan Hui4ababdc2018-12-27 15:44:26 -080047 # add gcc-arm-embedded ppa
Yakun Xuc034fd02020-04-22 06:37:46 +080048 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 Hui4ababdc2018-12-27 15:44:26 -080051 fi
Yakun Xuab55bec2018-04-05 00:28:00 +080052
53 # add clang-format for pretty
Pratik Raj2e095312020-03-11 04:04:02 +053054 sudo apt-get --no-install-recommends install -y clang-format-6.0
Yakun Xu33808eb2020-02-05 02:27:51 +080055
56 # add yapf for pretty
Jonathan Huic0075d42020-04-23 17:14:58 -070057 python3 -m pip install yapf==0.29.0 || echo 'Failed to install python code formatter yapf. Install it manually if you need.'
Yakun Xuc034fd02020-04-22 06:37:46 +080058
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 Xu50cfda12020-05-28 07:12:22 +080061
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 Jacksona8105f72017-08-16 09:56:51 -070064}
65
66install_packages_opkg()
67{
68 echo 'opkg not supported currently' && false
69}
70
71install_packages_rpm()
72{
73 echo 'rpm not supported currently' && false
74}
75
76install_packages_brew()
77{
Yakun Xu08c71132020-03-12 23:40:23 +080078 # add build tools
Yakun Xu50cfda12020-05-28 07:12:22 +080079 brew install automake libtool cmake ninja shfmt
Jonathan Huid9b49802017-12-13 05:48:51 +000080
81 # add ARM toolchain
Neal Jackson45d78d72020-01-29 22:14:17 -080082 brew tap ArmMbed/homebrew-formulae
83 brew install arm-none-eabi-gcc
Jonathan Huid9b49802017-12-13 05:48:51 +000084
Yakun Xua5511332020-02-28 04:55:56 +080085 # check for gcc for simulation
Yakun Xuc034fd02020-04-22 06:37:46 +080086 if ! command -v gcc; then
Yakun Xua5511332020-02-28 04:55:56 +080087 echo 'warning: clang/gcc needed for simulation'
Jonathan Huid9b49802017-12-13 05:48:51 +000088 echo 'warning: please install Command Line Tools from https://developer.apple.com/download/more/'
89 fi
Yakun Xuaa0c3a72018-11-01 01:18:08 +080090
91 # add clang-format for pretty
92 CLANG_FORMAT_VERSION="clang-format version 6.0"
Yakun Xuc034fd02020-04-22 06:37:46 +080093 command -v clang-format-6.0 || (command -v clang-format && (clang-format --version | grep -q "${CLANG_FORMAT_VERSION}")) || {
Yakun Xuaa0c3a72018-11-01 01:18:08 +080094 brew install llvm@6
kangping420479d2019-12-18 00:52:26 +080095 sudo ln -s "$(brew --prefix llvm@6)/bin/clang-format" /usr/local/bin/clang-format-6.0
Yakun Xuaa0c3a72018-11-01 01:18:08 +080096 }
Yakun Xu33808eb2020-02-05 02:27:51 +080097
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 Jacksona8105f72017-08-16 09:56:51 -0700100}
101
102install_packages_source()
103{
104 echo 'source not supported currently' && false
105}
106
107install_packages()
108{
109 PM=source
Yakun Xuc034fd02020-04-22 06:37:46 +0800110 if command -v apt-get; then
Neal Jacksona8105f72017-08-16 09:56:51 -0700111 PM=apt
Yakun Xuc034fd02020-04-22 06:37:46 +0800112 elif command -v rpm; then
Neal Jacksona8105f72017-08-16 09:56:51 -0700113 PM=rpm
Yakun Xuc034fd02020-04-22 06:37:46 +0800114 elif command -v opkg; then
Neal Jacksona8105f72017-08-16 09:56:51 -0700115 PM=opkg
Yakun Xuc034fd02020-04-22 06:37:46 +0800116 elif command -v brew; then
Neal Jacksona8105f72017-08-16 09:56:51 -0700117 PM=brew
118 fi
119 install_packages_$PM
120}
121
122main()
123{
Neal Jacksona8105f72017-08-16 09:56:51 -0700124 install_packages
Neal Jacksona8105f72017-08-16 09:56:51 -0700125}
126
127main