Setting up the Build Environment (MacOSX)¶
This article shows how to set up a build environment on macOS. It is written for Apple Silicon Macs; Intel Macs can only use it if Homebrew is already installed (see below).
The setup is done by the install-prereqs-mac.sh script in the ArduPilot repository. If you prefer to set up the environment by hand, read the script and follow the steps it takes.
Install Xcode Command Line Tools¶
These provide git and the compilers. Open a terminal and run:
xcode-select --install
Clone ArduPilot repository¶
“Cloning” is git’s term for making a local copy of a remote repository (i.e. one held on the GitHub servers).
Developers should clone the main ArduPilot repository (if they simply want to download and compile the latest code) or their own fork (if they want to make changes to the source code and potentially submit changes back).
Instructions for commonly used tools are below but whichever tool is used, the URL for the source repo will be required. This can be found on the right side of the screen on each Github repository home page but in general the URL is:
https://github.com/ArduPilot/ardupilot.gitfor the main ardupilot repohttps://github.com/your-github-account/ardupilotfor your fork of the ardupilot repo
Cloning with the command line¶
open a terminal and navigate to the directory where you would like the clone to be stored
clone your fork:
git clone --recurse-submodules https://github.com/your-github-userid/ardupilot cd ardupilot
or the main project repo:
git clone --recurse-submodules https://github.com/ArduPilot/ardupilot cd ardupilot
Run the install script¶
On Apple Silicon Macs:
install Homebrew first and run the
eval "$(/opt/homebrew/bin/brew shellenv)"step it prints at the end, otherwise the script stops withbrew: command not foundif you will build firmware for autopilots, install Rosetta 2, which the ARM toolchain needs:
softwareupdate --install-rosetta
On Intel Macs, Homebrew’s installer no longer supports Intel processors and stops with “Homebrew on macOS is only supported on Apple Silicon processors!”. The script therefore only works on an Intel Mac where Homebrew is already installed.
Do not run the script with sudo. From your ardupilot directory, run:
Tools/environment_install/install-prereqs-mac.sh -y
The script:
installs Homebrew if it is not already installed (Apple Silicon only), then uses it to install gawk, coreutils, wget and ccache
optionally installs Python 3.10 using pyenv. This is recommended if your system Python is causing build errors
optionally installs the ARM toolchain, which is needed to build firmware for autopilots but not for SITL
installs the Python packages needed to build ArduPilot and run MAVProxy and SITL
adds the toolchain, the ArduPilot tools and ccache to your PATH in
~/.zshrc(or~/.bash_profileif you use bash)updates the git submodules
-y answers yes to every question. Without it the script asks before installing pyenv, before installing the ARM toolchain, and before each change to your PATH. It will ask for your password when installing the ARM toolchain.
When it finishes, close and reopen the terminal (or run source ~/.zshrc, or source ~/.bash_profile if you use bash) so the PATH changes take effect.
Now you should be able to build with waf as described in BUILD.md.
Follow the MAVProxy documentation if you plan to use the simulator.
Cleaning¶
If there have been updates to some git submodules you may need to do a full clean build. To do that use:
./waf distclean
Commands clean and distclean can be used to clean the objects produced by the build. clean keeps the configure information, cleaning only the objects for the current board. distclean cleans everything for every board, including the saved configure information.