AP_GPS: add checking of instance number before update with incoming data
[ardupilot.git] / BUILD.md
blob4a221bef832f1666effa939d12edcddc3c495a96
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 ### Using Docker ###
196 A docker environment is provided which may be helpful for building in a clean
197 environment and avoiding modification of the host environment.
199 To build the docker image (should only need to be done once), run:
201 ```bash
202 docker build --rm -t ardupilot-dev .
205 To build inside the container, prefix your `waf` commands, e.g.:
207 ```bash
208 docker run --rm -it -v $PWD:/ardupilot ardupilot-dev ./waf configure --board=sitl
209 docker run --rm -it -v $PWD:/ardupilot ardupilot-dev ./waf copter
212 Alternatively, simply run `docker run --rm -it -v $PWD:/ardupilot ardupilot-dev` to
213 start a `bash` shell in which you can run other commands from this document.
215 ## Advanced usage ##
217 This section contains some explanations on how the Waf build system works
218 and how you can use more advanced features.
220 Waf build system is composed of commands. For example, the command below
221 (`configure`) is for configuring the build with all the options used by this
222 particular build.
224 ```bash
225 # Configure the Linux board
226 ./waf configure --board=linux
229 Consequently, in order to build, a "build" command is issued, thus `waf build`.
230 That is the default command, so calling just `waf` is enough:
232 ```bash
233 # Build programs from bin group
234 ./waf
236 # Waf also accepts '-j' option to parallelize the build.
237 ./waf -j8
240 By default waf tries to parallelize the build automatically to all processors
241 so the `-j` option is usually not needed, unless you are using icecc (thus
242 you want a bigger value) or you don't want to stress your machine with
243 the build.
245 ### Program groups ###
247 Program groups are used to represent a class of programs. They can be used to
248 build all programs of a certain class without having to specify each program.
249 It's possible for two groups to overlap, except when both groups are main
250 groups. In other words, a program can belong to more than one group, but only
251 to one main group.
253 There's a special group, called "all", that comprises all programs.
255 #### Main groups ####
257 The main groups form a partition of all programs. Besides separating the
258 programs logically, they also define where they are built.
260 The main groups are:
262  - bin: *the main binaries, that is, ardupilot's main products - the vehicles and
263    Antenna Tracker*
264  - tools
265  - examples: *programs that show how certain libraries are used or to simply
266    test their operation*
267  - benchmarks: *requires `--enable-benchmarks` during configurarion*
268  - tests: *basically unit tests to ensure changes don't break the system's
269    logic*
271 All build files are placed under `build/<board>/`, where `<board>` represents
272 the board/platform you selected during configuration. Each main program group
273 has a folder with its name directly under `build/<board>/`. Thus, a program
274 will be stored in `build/<board>/<main_group>/`, where `<main_group>` is the
275 main group the program belongs to. For example, for a linux build, arduplane,
276 which belongs to the main group "bin", will be located at
277 `build/linux/bin/arduplane`.
279 #### Main product groups ####
281 Those are groups for ardupilot's main products. They contain programs for the
282 product they represent. Currently only the "copter" group has more than one
283 program - one for each frame type.
285 The main product groups are:
287  - antennatracker
288  - copter
289  - plane
290  - rover
292 #### Building a program group ####
294 Ardupilot adds to waf an option called `--program-group`, which receives as
295 argument the group you want it to build. For a build command, if you don't pass
296 any of `--targets` or `--program-group`, then the group "bin" is selected by
297 default. The option `--program-group` can be passed multiple times.
299 Examples:
301 ```bash
302 # Group bin is the default one
303 ./waf
305 # Build all vehicles and Antenna Tracker
306 ./waf --program-group bin
308 # Build all benchmarks and tests
309 ./waf --program-group benchmarks --program-group tests
311 #### Shortcut for program groups ####
313 For less typing, you can use the group name as the command to waf. Examples:
315 ```bash
316 # Build all vehicles and Antenna Tracker
317 ./waf bin
319 # Build all examples
320 ./waf examples
322 # Build arducopter binaries
323 ./waf copter
326 ### Building a specific program ###
328 In order to build a specific program, you just need to pass its path relative
329 to `build/<board>/` to the option `--targets`. Example:
331 ```bash
332 # Build arducopter for quad frame
333 ./waf --targets bin/arducopter
335 # Build vectors unit test
336 ./waf --targets tests/test_vectors
339 ### Checking ###
341 The command `check` builds all programs and then executes the relevant tests.
342 In that context, a relevant test is a program from the group "tests" that makes
343 one of the following statements true:
345  - it's the first time the test is built since the last cleanup or when the
346    project was cloned.
347  - the program had to be rebuilt (due to modifications in the code or
348    dependencies, for example)
349  - the test program failed in the previous check.
351 That is, the tests are run only if necessary. If you want waf to run all tests,
352 then you can use either option `--alltests` or the shortcut command
353 `check-all`.
355 Examples:
357 ```bash
358 # Build everything and run relevant tests
359 ./waf check
361 # Build everything and run all tests
362 ./waf check --alltests
364 # Build everything and run all tests
365 ./waf check-all
368 ### Debugging ###
370 It's possible to pass the option `--debug` to the `configure` command. That
371 will set compiler flags to store debugging information in the binaries so that
372 you can use them with `gdb`, for example. That option might come handy when using SITL.
374 ### Build-system wrappers ###
376 The `waf` binary on root tree is actually a wrapper to the real `waf` that's
377 maintained in its own submodule.  It's possible to call the latter directly via
378 `./modules/waf/waf-light` or to use an alias if you prefer typing `waf` over
379 `./waf`.
381 ```sh
382 alias waf="<ardupilot-directory>/modules/waf/waf-light"
386 There's also a make wrapper called `Makefile.waf`. You can use
387 `make -f Makefile.waf help` for instructions on how to use it.
389 ### Command line help ###
391 You can use `waf --help` to see information about commands and options built-in
392 to waf as well as some quick help on those added by ardupilot.