diff options
| author | BELHADJ SALEM Talel <bhstalel@gmail.com> | 2023-11-01 09:40:20 +0100 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2023-11-06 22:52:27 +0000 |
| commit | 5abd1e19451e21e59b64538d1a9ccf9fd46eba40 (patch) | |
| tree | 4e84992af9072d22732a3e2a8a67fd57f10fe8b6 /documentation/overview-manual/concepts.rst | |
| parent | 1081a2617afc34d0d864125109517b04de20e200 (diff) | |
| download | poky-5abd1e19451e21e59b64538d1a9ccf9fd46eba40.tar.gz | |
overview-manual: concepts: Add Bitbake Tasks Map
Create a Map to detail how BitBake handles a recipe's tasks
and its compile/runtime dependencies along with detailed comments.
(From yocto-docs rev: 7f0ab56aa302babab6c9d600a8d8a91708cf75f7)
Signed-off-by: Talel BELHAJSALEM <bhstalel@gmail.com>
Reviewed-by: Michael Opdenacker <michael.opdenacker@bootlin.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'documentation/overview-manual/concepts.rst')
| -rw-r--r-- | documentation/overview-manual/concepts.rst | 170 |
1 files changed, 170 insertions, 0 deletions
diff --git a/documentation/overview-manual/concepts.rst b/documentation/overview-manual/concepts.rst index 4e3f6425a4..d335c2fcdd 100644 --- a/documentation/overview-manual/concepts.rst +++ b/documentation/overview-manual/concepts.rst | |||
| @@ -2189,3 +2189,173 @@ For more information, see the | |||
| 2189 | BitBake User Manual. You can also reference the "`Why Not | 2189 | BitBake User Manual. You can also reference the "`Why Not |
| 2190 | Fakeroot? <https://github.com/wrpseudo/pseudo/wiki/WhyNotFakeroot>`__" | 2190 | Fakeroot? <https://github.com/wrpseudo/pseudo/wiki/WhyNotFakeroot>`__" |
| 2191 | article for background information on Fakeroot and Pseudo. | 2191 | article for background information on Fakeroot and Pseudo. |
| 2192 | |||
| 2193 | BitBake Tasks Map | ||
| 2194 | ================= | ||
| 2195 | |||
| 2196 | To understand how BitBake operates in the build directory and environment | ||
| 2197 | we can consider the following recipes and diagram, to have full picture | ||
| 2198 | about the tasks that BitBake runs to generate the final package file | ||
| 2199 | for the recipe. | ||
| 2200 | |||
| 2201 | We will have two recipes as an example: | ||
| 2202 | |||
| 2203 | - ``libhello``: A recipe that provides a shared library | ||
| 2204 | - ``sayhello``: A recipe that uses ``libhello`` library to do its job | ||
| 2205 | |||
| 2206 | .. note:: | ||
| 2207 | |||
| 2208 | ``sayhello`` depends on ``libhello`` at compile time as it needs the shared | ||
| 2209 | library to do the dynamic linking process. It also depends on it at runtime | ||
| 2210 | as the shared library loader needs to find the library. | ||
| 2211 | For more details about dependencies check :ref:`ref-varlocality-recipe-dependencies`. | ||
| 2212 | |||
| 2213 | ``libhello`` sources are as follows: | ||
| 2214 | |||
| 2215 | - ``LICENSE``: This is the license associated with this library | ||
| 2216 | - ``Makefile``: The file used by ``make`` to build the library | ||
| 2217 | - ``hellolib.c``: The implementation of the library | ||
| 2218 | - ``hellolib.h``: The C header of the library | ||
| 2219 | |||
| 2220 | ``sayhello`` sources are as follows: | ||
| 2221 | |||
| 2222 | - ``LICENSE``: This is the license associated with this project | ||
| 2223 | - ``Makefile``: The file used by ``make`` to build the project | ||
| 2224 | - ``sayhello.c``: The source file of the project | ||
| 2225 | |||
| 2226 | Before presenting the contents of each file, here are the steps | ||
| 2227 | that we need to follow to accomplish what we want in the first place, | ||
| 2228 | which is integrating ``sayhello`` in our root file system: | ||
| 2229 | |||
| 2230 | #. Create a Git repository for each project with the corresponding files | ||
| 2231 | |||
| 2232 | #. Create a recipe for each project | ||
| 2233 | |||
| 2234 | #. Make sure that ``sayhello`` recipe :term:`DEPENDS` on ``libhello`` | ||
| 2235 | |||
| 2236 | #. Make sure that ``sayhello`` recipe :term:`RDEPENDS` on ``libhello`` | ||
| 2237 | |||
| 2238 | #. Add ``sayhello`` to :term:`IMAGE_INSTALL` to integrate it into | ||
| 2239 | the root file system | ||
| 2240 | |||
| 2241 | The following are the contents of ``libhello/Makefile``:: | ||
| 2242 | |||
| 2243 | LIB=libhello.so | ||
| 2244 | |||
| 2245 | all: $(LIB) | ||
| 2246 | |||
| 2247 | $(LIB): hellolib.o | ||
| 2248 | $(CC) $< -Wl,-soname,$(LIB).1 -fPIC $(LDFLAGS) -shared -o $(LIB).1.0 | ||
| 2249 | |||
| 2250 | %.o: %.c | ||
| 2251 | $(CC) -c $< | ||
| 2252 | |||
| 2253 | clean: | ||
| 2254 | rm -rf *.o *.so* | ||
| 2255 | |||
| 2256 | .. note:: | ||
| 2257 | |||
| 2258 | When creating shared libraries, it is strongly recommended to follow the Linux | ||
| 2259 | conventions and guidelines (see `this article | ||
| 2260 | <https://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html>`__ | ||
| 2261 | for some background). | ||
| 2262 | |||
| 2263 | .. note:: | ||
| 2264 | |||
| 2265 | When creating ``Makefile`` files, it is strongly recommended to use ``CC``, ``LDFLAGS`` | ||
| 2266 | and ``CFLAGS`` as BitBake will set them as environment variables according | ||
| 2267 | to your build configuration. | ||
| 2268 | |||
| 2269 | The following are the contents of ``libhello/hellolib.h``:: | ||
| 2270 | |||
| 2271 | #ifndef HELLOLIB_H | ||
| 2272 | #define HELLOLIB_H | ||
| 2273 | |||
| 2274 | void Hello(); | ||
| 2275 | |||
| 2276 | #endif | ||
| 2277 | |||
| 2278 | The following are the contents of ``libhello/hellolib.c``:: | ||
| 2279 | |||
| 2280 | #include <stdio.h> | ||
| 2281 | |||
| 2282 | void Hello(){ | ||
| 2283 | puts("Hello from a Yocto demo \n"); | ||
| 2284 | } | ||
| 2285 | |||
| 2286 | The following are the contents of ``sayhello/Makefile``:: | ||
| 2287 | |||
| 2288 | EXEC=sayhello | ||
| 2289 | LDFLAGS += -lhello | ||
| 2290 | |||
| 2291 | all: $(EXEC) | ||
| 2292 | |||
| 2293 | $(EXEC): sayhello.c | ||
| 2294 | $(CC) $< $(LDFLAGS) $(CFLAGS) -o $(EXEC) | ||
| 2295 | |||
| 2296 | clean: | ||
| 2297 | rm -rf $(EXEC) *.o | ||
| 2298 | |||
| 2299 | The following are the contents of ``sayhello/sayhello.c``:: | ||
| 2300 | |||
| 2301 | #include <hellolib.h> | ||
| 2302 | |||
| 2303 | int main(){ | ||
| 2304 | Hello(); | ||
| 2305 | return 0; | ||
| 2306 | } | ||
| 2307 | |||
| 2308 | The following are the contents of ``libhello_0.1.bb``:: | ||
| 2309 | |||
| 2310 | SUMMARY = "Hello demo library" | ||
| 2311 | DESCRIPTION = "Hello shared library used in Yocto demo" | ||
| 2312 | |||
| 2313 | # NOTE: Set the License according to the LICENSE file of your project | ||
| 2314 | # and then add LIC_FILES_CHKSUM accordingly | ||
| 2315 | LICENSE = "CLOSED" | ||
| 2316 | |||
| 2317 | # Assuming the branch is main | ||
| 2318 | # Change <username> accordingly | ||
| 2319 | SRC_URI = "git://github.com/<username>/libhello;branch=main;protocol=https" | ||
| 2320 | |||
| 2321 | S = "${WORKDIR}/git" | ||
| 2322 | |||
| 2323 | do_install(){ | ||
| 2324 | install -d ${D}${includedir} | ||
| 2325 | install -d ${D}${libdir} | ||
| 2326 | |||
| 2327 | install hellolib.h ${D}${includedir} | ||
| 2328 | oe_soinstall ${PN}.so.${PV} ${D}${libdir} | ||
| 2329 | } | ||
| 2330 | |||
| 2331 | The following are the contents of ``sayhello_0.1.bb``:: | ||
| 2332 | |||
| 2333 | SUMMARY = "SayHello demo" | ||
| 2334 | DESCRIPTION = "SayHello project used in Yocto demo" | ||
| 2335 | |||
| 2336 | # NOTE: Set the License according to the LICENSE file of your project | ||
| 2337 | # and then add LIC_FILES_CHKSUM accordingly | ||
| 2338 | LICENSE = "CLOSED" | ||
| 2339 | |||
| 2340 | # Assuming the branch is main | ||
| 2341 | # Change <username> accordingly | ||
| 2342 | SRC_URI = "git://github.com/<username>/sayhello;branch=main;protocol=https" | ||
| 2343 | |||
| 2344 | DEPENDS += "libhello" | ||
| 2345 | RDEPENDS:${PN} += "libhello" | ||
| 2346 | |||
| 2347 | S = "${WORKDIR}/git" | ||
| 2348 | |||
| 2349 | do_install(){ | ||
| 2350 | install -d ${D}/usr/bin | ||
| 2351 | install -m 0700 sayhello ${D}/usr/bin | ||
| 2352 | } | ||
| 2353 | |||
| 2354 | After placing the recipes in a custom layer we can run ``bitbake sayhello`` | ||
| 2355 | to build the recipe. | ||
| 2356 | |||
| 2357 | The following diagram shows the sequences of tasks that BitBake | ||
| 2358 | executes to accomplish that. | ||
| 2359 | |||
| 2360 | .. image:: svg/bitbake_tasks_map.* | ||
| 2361 | :width: 100% | ||
