Copter: version to 4.5.0
[ardupilot.git] / BUILD.md
blob5e11d2c83808ee849c6f4bae518d022242f8ed5a
1 # Building ArduPilot #
3 ## Get the Source
5 Clone the project from GitHub:
6 ```sh
7 git clone --recursive https://github.com/ArduPilot/ardupilot.git
8 cd ardupilot
9 ```
11 You can also read more about the build system in the
12 [Waf Book](https://waf.io/book/).
14 waf should always be called from the locally cloned ardupilot root directory for the local branch you are trying to build from.
16 **Note**
17 Do not run `waf` with `sudo`!  This leads to permission and environment problems.
19 ## Basic usage ##
21 There are several commands in the build system for advanced usage, but here we
22 list some basic and more used commands as example.
24 * **Build ArduCopter**
26     Below shows how to build ArduCopter for the Pixhawk2/Cube. Many other boards are
27     supported and the next section shows how to get a full list of them.
29     ```sh
30     ./waf configure --board CubeBlack
31     ./waf copter
32     ```
34     The first command should be called only once or when you want to change a
35     configuration option. One configuration often used is the `--board` option to
36     switch from one board to another one. For example we could switch to
37     SkyViper GPS drone and build again:
39     ```sh
40     ./waf configure --board skyviper-v2450
41     ./waf copter
42     ```
44     If building for the bebop2 the binary must be built statically:
46     ```sh
47     ./waf configure --board bebop --static
48     ./waf copter
49     ```    
51     The "arducopter" binary should appear in the `build/<board-name>/bin` directory.
53 * **List available boards**
56     It's possible to get a list of supported boards on ArduPilot with the command
57     below
59     ```sh
60     ./waf list_boards
62     ```
64     Here are some commands to configure waf for commonly used boards:
66     ```sh
67     ./waf configure --board bebop --static # Bebop or Bebop2
68     ./waf configure --board edge           # emlid edge
69     ./waf configure --board fmuv3          # 3DR Pixhawk 2 boards
70     ./waf configure --board navio2         # emlid navio2
71     ./waf configure --board Pixhawk1       # Pixhawk1
72     ./waf configure --board CubeBlack      # Hex/ProfiCNC Cube Black (formerly known as Pixhawk 2.1)
73     ./waf configure --board Pixracer       # Pixracer
74     ./waf configure --board skyviper-v2450 # SkyRocket's SkyViper GPS drone using ChibiOS
75     ./waf configure --board sitl           # software-in-the-loop simulator
76     ./waf configure --board sitl --debug   # software-in-the-loop simulator with debug symbols
78     ```
80 * **List of available vehicle types**
82     Here is a list of the most common vehicle build targets:
84     ```sh
85     ./waf copter                            # All multirotor types
86     ./waf heli                              # Helicopter types
87     ./waf plane                             # Fixed wing airplanes including VTOL
88     ./waf rover                             # Ground-based rovers and surface boats
89     ./waf sub                               # ROV and other submarines
90     ./waf antennatracker                    # Antenna trackers
91     ./waf AP_Periph                         # AP Peripheral
92     
93     ```
95 * **Clean the build**
97     Commands `clean` and `distclean` can be used to clean the objects produced by
98     the build. The first keeps the `configure` information, cleaning only the
99     objects for the current board. The second cleans everything for every board,
100     including the saved `configure` information.
102     Cleaning the build is very often not necessary and discouraged. We do
103     incremental builds reducing the build time by orders of magnitude.
105     If submodules are failing to be synchronized, `submodulesync` may be used
106     to resync the submodules. This is usually necessary when shifting development
107     between stable releases or a stable release and the master branch.
109     In some some cases `submodule_force_clean` may be necessary. This removes all submodules and then performs a `submodulesync`. (Note whitelisted modules like esp_idf is not removed.)
111 * **Upload or install**
113     Build commands have a `--upload` option in order to upload the binary built
114     to a connected board. This option is supported by Pixhawk and Linux-based boards.
115     The command below uses the `--targets` option that is explained in the next item.
117     ```sh
118     ./waf --targets bin/arducopter --upload
119     ```
121     For Linux boards you need first to configure the IP of the board you
122     are going to upload to. This is done on configure phase with:
124     ```sh
125     ./waf configure --board <board> --rsync-dest <destination>
126     ```
128     The commands below give a concrete example (board and destination
129     IP will change according to the board used):
131     ```sh
132     ./waf configure --board navio2 --rsync-dest root@192.168.1.2:/
133     ./waf --target bin/arducopter --upload
134     ```
136     This allows to set a destination to which the `--upload` option will upload
137     the binary.  Under the hood  it installs to a temporary location and calls
138     `rsync <temp_install_location>/ <destination>`.
140     On Linux boards there's also an install command, which will install to a certain
141     directory, just like the temporary install above does. This can be
142     used by distributors to create .deb, .rpm or other package types:
144     ```sh
145     ./waf copter
146     DESTDIR=/my/temporary/location ./waf install
147     ```
149 * **Use different targets**
151     The build commands in the items above use `copter` as argument. This
152     builds all binaries that fall under the "copter" group. See the
153     section [Advanced usage](#advanced-usage) below for more details regarding
154     groups.
156     This shows a list of all possible targets:
158     ```
159     ./waf list
160     ```
162     For example, to build only a single binary:
164     ```
165     # Quad frame of ArduCopter
166     ./waf --targets bin/arducopter
168     # unit test of our math functions
169     ./waf --targets tests/test_math
170     ```
172 * **Use clang instead of gcc**
174     Currently, gcc is the default on linux, and clang is used for MacOS.
175     Building with clang on linux can be accomplished by setting the CXX
176     environment variables during the configure step, e.g.:
178     ```
179     CXX=clang++ CC=clang ./waf configure --board=sitl
180     ```
182     Note: Your clang binary names may differ.
184 * **Other options**
186     It's possible to see all available commands and options:
188     ```
189     ./waf -h
190     ```
192     Also, take a look on the [Advanced section](#advanced-usage) below.
194 ## Advanced usage ##
196 This section contains some explanations on how the Waf build system works
197 and how you can use more advanced features.
199 Waf build system is composed of commands. For example, the command below
200 (`configure`) is for configuring the build with all the options used by this
201 particular build.
203 ```bash
204 # Configure the Linux board
205 ./waf configure --board=linux
208 Consequently, in order to build, a "build" command is issued, thus `waf build`.
209 That is the default command, so calling just `waf` is enough:
211 ```bash
212 # Build programs from bin group
213 ./waf
215 # Waf also accepts '-j' option to parallelize the build.
216 ./waf -j8
219 By default waf tries to parallelize the build automatically to all processors
220 so the `-j` option is usually not needed, unless you are using icecc (thus
221 you want a bigger value) or you don't want to stress your machine with
222 the build.
224 ### Program groups ###
226 Program groups are used to represent a class of programs. They can be used to
227 build all programs of a certain class without having to specify each program.
228 It's possible for two groups to overlap, except when both groups are main
229 groups. In other words, a program can belong to more than one group, but only
230 to one main group.
232 There's a special group, called "all", that comprises all programs.
234 #### Main groups ####
236 The main groups form a partition of all programs. Besides separating the
237 programs logically, they also define where they are built.
239 The main groups are:
241  - bin: *the main binaries, that is, ardupilot's main products - the vehicles and
242    Antenna Tracker*
243  - tools
244  - examples: *programs that show how certain libraries are used or to simply
245    test their operation*
246  - benchmarks: *requires `--enable-benchmarks` during configurarion*
247  - tests: *basically unit tests to ensure changes don't break the system's
248    logic*
250 All build files are placed under `build/<board>/`, where `<board>` represents
251 the board/platform you selected during configuration. Each main program group
252 has a folder with its name directly under `build/<board>/`. Thus, a program
253 will be stored in `build/<board>/<main_group>/`, where `<main_group>` is the
254 main group the program belongs to. For example, for a linux build, arduplane,
255 which belongs to the main group "bin", will be located at
256 `build/linux/bin/arduplane`.
258 #### Main product groups ####
260 Those are groups for ardupilot's main products. They contain programs for the
261 product they represent. Currently only the "copter" group has more than one
262 program - one for each frame type.
264 The main product groups are:
266  - antennatracker
267  - copter
268  - plane
269  - rover
271 #### Building a program group ####
273 Ardupilot adds to waf an option called `--program-group`, which receives as
274 argument the group you want it to build. For a build command, if you don't pass
275 any of `--targets` or `--program-group`, then the group "bin" is selected by
276 default. The option `--program-group` can be passed multiple times.
278 Examples:
280 ```bash
281 # Group bin is the default one
282 ./waf
284 # Build all vehicles and Antenna Tracker
285 ./waf --program-group bin
287 # Build all benchmarks and tests
288 ./waf --program-group benchmarks --program-group tests
290 #### Shortcut for program groups ####
292 For less typing, you can use the group name as the command to waf. Examples:
294 ```bash
295 # Build all vehicles and Antenna Tracker
296 ./waf bin
298 # Build all examples
299 ./waf examples
301 # Build arducopter binaries
302 ./waf copter
305 ### Building a specific program ###
307 In order to build a specific program, you just need to pass its path relative
308 to `build/<board>/` to the option `--targets`. Example:
310 ```bash
311 # Build arducopter for quad frame
312 ./waf --targets bin/arducopter
314 # Build vectors unit test
315 ./waf --targets tests/test_vectors
318 ### Checking ###
320 The command `check` builds all programs and then executes the relevant tests.
321 In that context, a relevant test is a program from the group "tests" that makes
322 one of the following statements true:
324  - it's the first time the test is built since the last cleanup or when the
325    project was cloned.
326  - the program had to be rebuilt (due to modifications in the code or
327    dependencies, for example)
328  - the test program failed in the previous check.
330 That is, the tests are run only if necessary. If you want waf to run all tests,
331 then you can use either option `--alltests` or the shortcut command
332 `check-all`.
334 Examples:
336 ```bash
337 # Build everything and run relevant tests
338 ./waf check
340 # Build everything and run all tests
341 ./waf check --alltests
343 # Build everything and run all tests
344 ./waf check-all
347 ### Debugging ###
349 It's possible to pass the option `--debug` to the `configure` command. That
350 will set compiler flags to store debugging information in the binaries so that
351 you can use them with `gdb`, for example. That option might come handy when using SITL.
353 ### Build-system wrappers ###
355 The `waf` binary on root tree is actually a wrapper to the real `waf` that's
356 maintained in its own submodule.  It's possible to call the latter directly via
357 `./modules/waf/waf-light` or to use an alias if you prefer typing `waf` over
358 `./waf`.
360 ```sh
361 alias waf="<ardupilot-directory>/modules/waf/waf-light"
365 There's also a make wrapper called `Makefile.waf`. You can use
366 `make -f Makefile.waf help` for instructions on how to use it.
368 ### Command line help ###
370 You can use `waf --help` to see information about commands and options built-in
371 to waf as well as some quick help on those added by ardupilot.