Simplified doc-site generation
[AGL/documentation.git] / docs / 3_Developer_Guides / 3_Using_the_CMAKE_Applications_Module / 8_Autobuild.md
1 ---
2 edit_link: ''
3 title: Autobuild
4 origin_url: >-
5   https://git.automotivelinux.org/src/cmake-apps-module/plain/docs/dev_guide/autobuild.md?h=master
6 ---
7
8 <!-- WARNING: This file is generated by fetch_docs.js using /home/boron/Documents/AGL/docs-webtemplate/site/_data/tocs/devguides/master/cmake-apps-module-guides-devguides-book.yml -->
9
10 # Autobuild
11
12 Applications based on the AGL framework should have a
13 full build and packaging solution that is independent of the
14 [Yocto Project](https://www.yoctoproject.org) workflow.
15
16 You can create a script named **autobuild** to control applications
17 build operations.
18 AGL provides a BitBake class file (`aglwgt.bbclass`) that calls the
19 **autobuild** script for all operations.
20 The class file is located at the top level of the application repository.
21
22 You can write the **autobuild** script using any of the following languages:
23
24 * Makefile
25 * Bash
26 * Python
27
28 The script executes directly after applying a `chmod()` command.
29 The caller, which can be the `aglwgt.bbclass`, a Jenkins job, or an actual person,
30 must make the **autobuild** executable before calling it.
31 To facilitate direct execution, you need to start the script with a
32 [shebang](https://en.wikipedia.org/wiki/Shebang_(Unix)) sequence:
33
34 * '#!/usr/bin/make -f' for Makefile format
35 * '#!/usr/bin/bash' for Bash format
36
37 The calling convention is similar to the convention used in `make`.
38 To pass arguments, use environment variables.
39
40 **NOTE:** For Bash, an evaluation of the arguments
41 sets the environment variables correctly.
42
43 The following format shows the generic call:
44
45 ```bash
46 autobuild/agl/autobuild <command> [ARG1="value1" [ARG2="value2" ... ]]
47 ```
48
49 The **autobuild** script can be invoked from any directory
50 with all paths considered to be relative to the
51 script's location.
52 For makefile scripts, this is the usual behavior.
53 For Bash scripts, a `cd $(dirname $0)` command must be run at
54 the beginning of the script.
55
56 At build time, the following calls must be made in the following order:
57
58 1. Initialize the build environment (e.g if the application uses
59    `cmake` the configure step runs CMake).
60
61    ```bash
62    autobuild/agl/autobuild configure CONFIGURE_ARGS="..."
63    ```
64
65 2. Build the application (i.e. compile, link binaries, assembles javascript,
66    and so forth).
67
68    ```bash
69    autobuild/agl/autobuild build BUILD_ARGS="...."
70    ```
71
72 3. Create the widget package(s) in the specified destination path
73    prepared by the caller.
74
75    ```bash
76    autobuild/agl/autobuild package PACKAGE_ARGS="..." DEST=<path-for-resulting-wgt-files>
77    ```
78
79 4. Create the test widget package(s) in the specified destination path
80    prepared by the caller.
81
82    ```bash
83    autobuild/agl/autobuild package-test PACKAGE_ARGS="..." DEST=<path-for-resulting-wgt-files>
84    ```
85
86 5. Clean the built files by removing the result of the **autobuild** build.
87
88    ```bash
89    autobuild/agl/autobuild clean CLEAN_ARGS="..."
90    ```
91
92 6. Clean everything by removing the result of the **autobuild** build
93    and the **autobuild** configure.
94
95    ```bash
96    autobuild/agl/autobuild distclean DISTCLEAN_ARGS="..."
97    ```
98
99 ## Integrating **autobuild** into the Yocto Project Workflow
100
101 If you want to integrate the **autobuild** script into the Yocto Project
102 workflow, you need to generate the script.
103 To generate the script, use the `autobuild` target.
104
105 The following commands create the **autobuild** script in the
106 `autobuild/agl` directory:
107
108 ```bash
109 mkdir -p build
110 cd build
111 cmake .. && make autobuild
112 ```
113
114 ## Available Targets
115
116 Following are the targets available from the **autobuild** script:
117
118 - **clean**: Removes all the object files and target results generated by Makefile.
119 - **clean-{release,debug,coverage,test}**: Removes all the object files and target results generated by Makefile for the specified build type.
120 - **clean-all**: Deletes the build directories for all build types.
121 - **distclean**: Deletes the build directories for all build types.
122 - **configure**: Generates the project Makefile from the `CMakeLists.txt` files for the release build type.
123 - **configure-{release,debug,coverage,test}**: Generates the project Makefile from the `CMakeLists.txt` files for the specified build type.
124 - **build**: Compiles all project targets for the release build type.
125 - **build-{release,debug,coverage,test}**: Compiles all project targets for the specified build type.
126 - **build-all**: Compiles all project targets for all specified build types.
127 - **package**: Builds the widget (**wgt**) package for the release build type.
128 - **package-{release,debug,coverage}**: Builds the widget (**wgt**) package for the specified build type.
129 - **package-test**: Builds the test **wgt** package.
130 - **package-all**: Builds the widget (**wgt**) packages for all build types.
131 - **install**: Installs the project into your filesystem.
132
133 Note that `aglwgt.bbclass` only will use the **package-{coverage,test}** targets (and thus the **build-{coverage,test}**, etc. targets) for service bindings by default, so **autobuild** scripts for  applications may omit support for those.
134
135 Specifying the following variables lets you modify compilation behavior:
136
137 - **CLEAN_ARGS**: Variable used at **clean** time.
138 - **CONFIGURE_ARGS**: Variable used at **configure** time.
139 - **BUILD_ARGS**: Variable used at **build** time.
140 - **BUILD_DIR**: Build directory for release type build.
141   The default value is a "build" directory in the root of the project.
142 - **BUILD_DIR_DEBUG**: Build directory for debug type build.
143   The default value is a "build-debug" directory in the root of the project.
144 - **BUILD_DIR_TEST**: Build directory for test type build.
145   The default value is a "build-test" directory in the root of the project.
146 - **BUILD_DIR_COVERAGE**: Build directory for coverage type build.
147   The default value is a "build-coverage" directory in the root of the project.
148 - **DEST**: Directory in which to place the created ***wgt*** file(s).
149   The default directory is the build root directory.
150
151 Note that the values of **BUILD_DIR_{DEBUG,TEST,COVERAGE}** are defined based on the value of **BUILD_DIR**, so this needs to be kept in mind if over-riding it and building those other widget types.
152
153 When you provide a variable, use the CMake format (i.e.
154 BUILD_ARGS="-DC_FLAGS='-g -O2'").
155 Following is an example:
156
157 ```bash
158 ./autobuild/agl/autobuild package DEST=/tmp
159 ```