AP_TECS: Remove duplicate setting of flare pitch upper limit
[ardupilot.git] / BUILD.md
blob0143d70da6258a4443feb7df972d330062a65a1b
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 Ardupilot is gradually moving from the make-based build system to
12 [Waf](https://waf.io/). The instructions below should be enough for you to
13 build Ardupilot, but you can also read more about the build system in the
14 [Waf Book](https://waf.io/book/).
16 Waf should always be called from the ardupilot's root directory. Differently
17 from the make-based build, with Waf there's a configure step to choose the
18 board to be used (default is `sitl`).
20 ## Basic usage ##
22 There are several commands in the build system for advanced usages, but here we
23 list some basic and more used commands as example.
25 * **Build ArduCopter**
27     Below shows how to build ArduCopter for the Pixhawk2/Cube. Many other boards are
28     supported and the next section shows how to get a full list of them.
30     ```sh
31     ./waf configure --board CubeBlack
32     ./waf copter
33     ```
35     The first command should be called only once or when you want to change a
36     configuration option. One configuration often used is the `--board` option to
37     switch from one board to another one. For example we could switch to
38     SkyViper GPS drone and build again:
40     ```sh
41     ./waf configure --board skyviper-v2450
42     ./waf copter
43     ```
45     If building for the bebop2 the binary must be built statically:
47     ```sh
48     ./waf configure --board bebop --static
49     ./waf copter
50     ```    
52     The "arducopter" binary should appear in the `build/<board-name>/bin` directory.
54 * **List available boards**
57     It's possible to get a list of supported boards on ArduPilot with the command
58     below
60     ```sh
61     ./waf list_boards
63     ```
65     Here are some commands to configure waf for commonly used boards:
67     ```sh
68     ./waf configure --board bebop --static # Bebop or Bebop2
69     ./waf configure --board edge           # emlid edge
70     ./waf configure --board fmuv3          # 3DR Pixhawk 2 boards
71     ./waf configure --board navio2         # emlid navio2
72     ./waf configure --board Pixhawk1       # Pixhawk1
73     ./waf configure --board CubeBlack      # Hex/ProfiCNC Cube Black (formerly known as Pixhawk 2.1)
74     ./waf configure --board Pixracer       # Pixracer
75     ./waf configure --board skyviper-v2450 # SkyRocket's SkyViper GPS drone using ChibiOS
76     ./waf configure --board sitl           # software-in-the-loop simulator
77     ./waf configure --board sitl --debug   # software-in-the-loop simulator with debug symbols
79     ```
81 * **List of available vehicle types**
83     Here is a list of the most common vehicle build targets:
85     ```sh
86     ./waf copter                            # All multirotor types
87     ./waf heli                              # Helicopter types
88     ./waf plane                             # Fixed wing airplanes including VTOL
89     ./waf rover                             # Ground-based rovers and surface boats
90     ./waf sub                               # ROV and other submarines
91     ./waf antennatracker                    # Antenna trackers
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.
106 * **Upload or install**
108     Build commands have a `--upload` option in order to upload the binary built
109     to a connected board. This option is supported by Pixhawk and Linux-based boards.
110     The command below uses the `--targets` option that is explained in the next item.
112     ```sh
113     ./waf --targets bin/arducopter --upload
114     ```
116     For Linux boards you need first to configure the IP of the board you
117     are going to upload to. This is done on configure phase with:
119     ```sh
120     ./waf configure --board <board> --rsync-dest <destination>
121     ```
123     The commands below give a concrete example (board and destination
124     IP will change according to the board used):
126     ```sh
127     ./waf configure --board navio2 --rsync-dest root@192.168.1.2:/
128     ./waf --target bin/arducopter --upload
129     ```
131     This allows to set a destination to which the `--upload` option will upload
132     the binary.  Under the hood  it installs to a temporary location and calls
133     `rsync <temp_install_location>/ <destination>`.
135     On Linux boards there's also an install command, which will install to a certain
136     directory, just like the temporary install above does. This can be
137     used by distributors to create .deb, .rpm or other package types:
139     ```sh
140     ./waf copter
141     DESTDIR=/my/temporary/location ./waf install
142     ```
144 * **Use different targets**
146     The build commands in the items above use `copter` as argument. This
147     builds all binaries that fall under the "copter" group. See the
148     section [Advanced usage](#advanced-usage) below for more details regarding
149     groups.
151     This shows a list of all possible targets:
153     ```
154     ./waf list
155     ```
157     For example, to build only a single binary:
159     ```
160     # Quad frame of ArduCopter
161     ./waf --targets bin/arducopter
163     # unit test of our math functions
164     ./waf --targets tests/test_math
165     ```
167 * **Other options**
169     It's possible to see all available commands and options:
171     ```
172     ./waf -h
173     ```
175     Also, take a look on the [Advanced section](#advanced-usage) below.
177 ## Advanced usage ##
179 This section contains some explanations on how the Waf build system works
180 and how you can use more advanced features.
182 Waf build system is composed of commands. For example, the command below
183 (`configure`) is for configuring the build with all the options used by this
184 particular build.
186 ```bash
187 # Configure the Linux board
188 ./waf configure --board=linux
191 Consequently, in order to build, a "build" command is issued, thus `waf build`.
192 That is the default command, so calling just `waf` is enough:
194 ```bash
195 # Build programs from bin group
196 ./waf
198 # Waf also accepts '-j' option to parallelize the build.
199 ./waf -j8
202 By default waf tries to parallelize the build automatically to all processors
203 so the `-j` option is usually not needed, unless you are using icecc (thus
204 you want a bigger value) or you don't want to stress your machine with
205 the build.
207 ### Program groups ###
209 Program groups are used to represent a class of programs. They can be used to
210 build all programs of a certain class without having to specify each program.
211 It's possible for two groups to overlap, except when both groups are main
212 groups. In other words, a program can belong to more than one group, but only
213 to one main group.
215 There's a special group, called "all", that comprises all programs.
217 #### Main groups ####
219 The main groups form a partition of all programs. Besides separating the
220 programs logically, they also define where they are built.
222 The main groups are:
224  - bin: *the main binaries, that is, ardupilot's main products - the vehicles and
225    Antenna Tracker*
226  - tools
227  - examples: *programs that show how certain libraries are used or to simply
228    test their operation*
229  - benchmarks: *requires `--enable-benchmarks` during configurarion*
230  - tests: *basically unit tests to ensure changes don't break the system's
231    logic*
233 All build files are placed under `build/<board>/`, where `<board>` represents
234 the board/platform you selected during configuration. Each main program group
235 has a folder with its name directly under `build/<board>/`. Thus, a program
236 will be stored in `build/<board>/<main_group>/`, where `<main_group>` is the
237 main group the program belongs to. For example, for a linux build, arduplane,
238 which belongs to the main group "bin", will be located at
239 `build/linux/bin/arduplane`.
241 #### Main product groups ####
243 Those are groups for ardupilot's main products. They contain programs for the
244 product they represent. Currently only the "copter" group has more than one
245 program - one for each frame type.
247 The main product groups are:
249  - antennatracker
250  - copter
251  - plane
252  - rover
254 #### Building a program group ####
256 Ardupilot adds to waf an option called `--program-group`, which receives as
257 argument the group you want it to build. For a build command, if you don't pass
258 any of `--targets` or `--program-group`, then the group "bin" is selected by
259 default. The option `--program-group` can be passed multiple times.
261 Examples:
263 ```bash
264 # Group bin is the default one
265 ./waf
267 # Build all vehicles and Antenna Tracker
268 ./waf --program-group bin
270 # Build all benchmarks and tests
271 ./waf --program-group benchmarks --program-group tests
273 #### Shortcut for program groups ####
275 For less typing, you can use the group name as the command to waf. Examples:
277 ```bash
278 # Build all vehicles and Antenna Tracker
279 ./waf bin
281 # Build all examples
282 ./waf examples
284 # Build arducopter binaries
285 ./waf copter
288 ### Building a specific program ###
290 In order to build a specific program, you just need to pass its path relative
291 to `build/<board>/` to the option `--targets`. Example:
293 ```bash
294 # Build arducopter for quad frame
295 ./waf --targets bin/arducopter
297 # Build vectors unit test
298 ./waf --targets tests/test_vectors
301 ### Checking ###
303 The command `check` builds all programs and then executes the relevant tests.
304 In that context, a relevant test is a program from the group "tests" that makes
305 one of the following statements true:
307  - it's the first time the test is built since the last cleanup or when the
308    project was cloned.
309  - the program had to be rebuilt (due to modifications in the code or
310    dependencies, for example)
311  - the test program failed in the previous check.
313 That is, the tests are run only if necessary. If you want waf to run all tests,
314 then you can use either option `--alltests` or the shortcut command
315 `check-all`.
317 Examples:
319 ```bash
320 # Build everything and run relevant tests
321 ./waf check
323 # Build everything and run all tests
324 ./waf check --alltests
326 # Build everything and run all tests
327 ./waf check-all
330 ### Debugging ###
332 It's possible to pass the option `--debug` to the `configure` command. That
333 will set compiler flags to store debugging information in the binaries so that
334 you can use them with `gdb`, for example. That option might come handy when using SITL.
336 ### Build-system wrappers ###
338 The `waf` binary on root tree is actually a wrapper to the real `waf` that's
339 maintained in its own submodule.  It's possible to call the latter directly via
340 `./modules/waf/waf-light` or to use an alias if you prefer typing `waf` over
341 `./waf`.
343 ```sh
344 alias waf="<ardupilot-directory>/modules/waf/waf-light"
348 There's also a make wrapper called `Makefile.waf`. You can use
349 `make -f Makefile.waf help` for instructions on how to use it.
351 ### Command line help ###
353 You can use `waf --help` to see information about commands and options built-in
354 to waf as well as some quick help on those added by ardupilot.