#!/bin/bash
## Bash script for setting up a PX4 development environment for Pixhawk/NuttX targets on Ubuntu LTS (16.04).
## It can be used for installing simulators and the NuttX toolchain.
##
## 这是用于在Ubuntu16.04s上为Pixhawk/Nuttx设置PX4开发环境的的Bash脚本
## 它可以用于安装模拟器以及Nuttx工具链
##
## Installs:
## - Common dependencies libraries, tools, and Gazebo8 simulator as defined in `ubuntu_sim.sh`
## - NuttX toolchain (i.e. gcc compiler)
## 安装说明:
## - 一般依赖库,工具,以及Gazebo8模拟器(在脚本ubuntu_sim.sh)
## - Nuttx工具链
echo "Downloading dependent script 'ubuntu_sim.sh'"
# Source the ubuntu_sim.sh script directly from github
# 从github上下载ubuntu_sim.sh脚本并source使其立即生效
ubuntu_sim=$(wget https://raw.githubusercontent.com/PX4/Devguide/master/build_scripts/ubuntu_sim.sh -O -)
wget_return_code=$?
# If there was an error downloading the dependent script, we must warn the user and exit at this point.
if [[ $wget_return_code -ne 0 ]]; then echo "Error downloading 'ubuntu_sim.sh'. Sorry but I cannot proceed further :("; exit 1; fi
# Otherwise source the downloaded script.
.
# NuttX
# 下载NuttX工具链
sudo apt-get install python-serial openocd \
flex bison libncurses5-dev autoconf texinfo \
libftdi-dev libtool zlib1g-dev -y
# Clean up old GCC
# 清除旧的GCC编译器
sudo apt-get remove gcc-arm-none-eabi gdb-arm-none-eabi binutils-arm-none-eabi gcc-arm-embedded -y
sudo add-apt-repository --remove ppa:team-gcc-arm-embedded/ppa -y
# Install GCC 5.4
# 安装GCC 5.4
gcc_dir=$HOME/gcc-arm-none-eabi-5_4-2016q2
echo "Installing GCC to: $gcc_dir"
if [ -d "$gcc_dir" ]
then
echo " GCC already installed."
else
pushd .
cd ~
wget https://developer.arm.com/-/media/Files/downloads/gnu-rm/5_4-2016q2/gccarmnoneeabi542016q220160622linuxtar.bz2
tar -jxf gccarmnoneeabi542016q220160622linuxtar.bz2
exportline="export PATH=$HOME/gcc-arm-none-eabi-5_4-2016q2/bin:\$PATH"
if grep -Fxq "$exportline" ~/.profile; then echo " GCC path already set." ; else echo $exportline >> ~/.profile; fi
. ~/.profile
popd
# Install 32 bit support libraries (ignore if fails)
# 安装32位支持库
sudo dpkg --add-architecture i386
sudo apt-get update
sudo apt-get install libc6:i386 libgcc1:i386 libstdc++5:i386 libstdc++6:i386 -y
sudo apt-get install gcc-5.4-base:i386 -y
fi
# Go to the firmware directory
# 进入固件目录,在其他上面的脚本中clone了PX4固件
cd $clone_dir/Firmware
# Reboot the computer (required before building)
# 提示重启电脑
echo RESTART YOUR COMPUTER to complete installation of PX4 development toolchain