diff options
| author | BELHADJ SALEM Talel <bhstalel@gmail.com> | 2023-11-01 09:40:20 +0100 |
|---|---|---|
| committer | Steve Sakoman <steve@sakoman.com> | 2023-11-28 05:00:32 -1000 |
| commit | 6c9f29507f6e0b03a432ffde2bcc6439a7d1da99 (patch) | |
| tree | 452fb81ffe659aed1d475f28775d75288c02317e /documentation/overview-manual/concepts.rst | |
| parent | 942c66a9fbf4c8b4bc018d3994a708c5ae232a30 (diff) | |
| download | poky-6c9f29507f6e0b03a432ffde2bcc6439a7d1da99.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: 529c7bf6c434166f4d372166868d46f275eb5bea)
Signed-off-by: Talel BELHAJSALEM <bhstalel@gmail.com>
Reviewed-by: Michael Opdenacker <michael.opdenacker@bootlin.com>
Signed-off-by: Steve Sakoman <steve@sakoman.com>
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 76e02eafff..4a8ea0f611 100644 --- a/documentation/overview-manual/concepts.rst +++ b/documentation/overview-manual/concepts.rst | |||
| @@ -2230,3 +2230,173 @@ For more information, see the | |||
| 2230 | BitBake User Manual. You can also reference the "`Why Not | 2230 | BitBake User Manual. You can also reference the "`Why Not |
| 2231 | Fakeroot? <https://github.com/wrpseudo/pseudo/wiki/WhyNotFakeroot>`__" | 2231 | Fakeroot? <https://github.com/wrpseudo/pseudo/wiki/WhyNotFakeroot>`__" |
| 2232 | article for background information on Fakeroot and Pseudo. | 2232 | article for background information on Fakeroot and Pseudo. |
| 2233 | |||
| 2234 | BitBake Tasks Map | ||
| 2235 | ================= | ||
| 2236 | |||
| 2237 | To understand how BitBake operates in the build directory and environment | ||
| 2238 | we can consider the following recipes and diagram, to have full picture | ||
| 2239 | about the tasks that BitBake runs to generate the final package file | ||
| 2240 | for the recipe. | ||
| 2241 | |||
| 2242 | We will have two recipes as an example: | ||
| 2243 | |||
| 2244 | - ``libhello``: A recipe that provides a shared library | ||
| 2245 | - ``sayhello``: A recipe that uses ``libhello`` library to do its job | ||
| 2246 | |||
| 2247 | .. note:: | ||
| 2248 | |||
| 2249 | ``sayhello`` depends on ``libhello`` at compile time as it needs the shared | ||
| 2250 | library to do the dynamic linking process. It also depends on it at runtime | ||
| 2251 | as the shared library loader needs to find the library. | ||
| 2252 | For more details about dependencies check :ref:`ref-varlocality-recipe-dependencies`. | ||
| 2253 | |||
| 2254 | ``libhello`` sources are as follows: | ||
| 2255 | |||
| 2256 | - ``LICENSE``: This is the license associated with this library | ||
| 2257 | - ``Makefile``: The file used by ``make`` to build the library | ||
| 2258 | - ``hellolib.c``: The implementation of the library | ||
| 2259 | - ``hellolib.h``: The C header of the library | ||
| 2260 | |||
| 2261 | ``sayhello`` sources are as follows: | ||
| 2262 | |||
| 2263 | - ``LICENSE``: This is the license associated with this project | ||
| 2264 | - ``Makefile``: The file used by ``make`` to build the project | ||
| 2265 | - ``sayhello.c``: The source file of the project | ||
| 2266 | |||
| 2267 | Before presenting the contents of each file, here are the steps | ||
| 2268 | that we need to follow to accomplish what we want in the first place, | ||
| 2269 | which is integrating ``sayhello`` in our root file system: | ||
| 2270 | |||
| 2271 | #. Create a Git repository for each project with the corresponding files | ||
| 2272 | |||
| 2273 | #. Create a recipe for each project | ||
| 2274 | |||
| 2275 | #. Make sure that ``sayhello`` recipe :term:`DEPENDS` on ``libhello`` | ||
| 2276 | |||
| 2277 | #. Make sure that ``sayhello`` recipe :term:`RDEPENDS` on ``libhello`` | ||
| 2278 | |||
| 2279 | #. Add ``sayhello`` to :term:`IMAGE_INSTALL` to integrate it into | ||
| 2280 | the root file system | ||
| 2281 | |||
| 2282 | The following are the contents of ``libhello/Makefile``:: | ||
| 2283 | |||
| 2284 | LIB=libhello.so | ||
| 2285 | |||
| 2286 | all: $(LIB) | ||
| 2287 | |||
| 2288 | $(LIB): hellolib.o | ||
| 2289 | $(CC) $< -Wl,-soname,$(LIB).1 -fPIC $(LDFLAGS) -shared -o $(LIB).1.0 | ||
| 2290 | |||
| 2291 | %.o: %.c | ||
| 2292 | $(CC) -c $< | ||
| 2293 | |||
| 2294 | clean: | ||
| 2295 | rm -rf *.o *.so* | ||
| 2296 | |||
| 2297 | .. note:: | ||
| 2298 | |||
| 2299 | When creating shared libraries, it is strongly recommended to follow the Linux | ||
| 2300 | conventions and guidelines (see `this article | ||
| 2301 | <https://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html>`__ | ||
| 2302 | for some background). | ||
| 2303 | |||
| 2304 | .. note:: | ||
| 2305 | |||
| 2306 | When creating ``Makefile`` files, it is strongly recommended to use ``CC``, ``LDFLAGS`` | ||
| 2307 | and ``CFLAGS`` as BitBake will set them as environment variables according | ||
| 2308 | to your build configuration. | ||
| 2309 | |||
| 2310 | The following are the contents of ``libhello/hellolib.h``:: | ||
| 2311 | |||
| 2312 | #ifndef HELLOLIB_H | ||
| 2313 | #define HELLOLIB_H | ||
| 2314 | |||
| 2315 | void Hello(); | ||
| 2316 | |||
| 2317 | #endif | ||
| 2318 | |||
| 2319 | The following are the contents of ``libhello/hellolib.c``:: | ||
| 2320 | |||
| 2321 | #include <stdio.h> | ||
| 2322 | |||
| 2323 | void Hello(){ | ||
| 2324 | puts("Hello from a Yocto demo \n"); | ||
| 2325 | } | ||
| 2326 | |||
| 2327 | The following are the contents of ``sayhello/Makefile``:: | ||
| 2328 | |||
| 2329 | EXEC=sayhello | ||
| 2330 | LDFLAGS += -lhello | ||
| 2331 | |||
| 2332 | all: $(EXEC) | ||
| 2333 | |||
| 2334 | $(EXEC): sayhello.c | ||
| 2335 | $(CC) $< $(LDFLAGS) $(CFLAGS) -o $(EXEC) | ||
| 2336 | |||
| 2337 | clean: | ||
| 2338 | rm -rf $(EXEC) *.o | ||
| 2339 | |||
| 2340 | The following are the contents of ``sayhello/sayhello.c``:: | ||
| 2341 | |||
| 2342 | #include <hellolib.h> | ||
| 2343 | |||
| 2344 | int main(){ | ||
| 2345 | Hello(); | ||
| 2346 | return 0; | ||
| 2347 | } | ||
| 2348 | |||
| 2349 | The following are the contents of ``libhello_0.1.bb``:: | ||
| 2350 | |||
| 2351 | SUMMARY = "Hello demo library" | ||
| 2352 | DESCRIPTION = "Hello shared library used in Yocto demo" | ||
| 2353 | |||
| 2354 | # NOTE: Set the License according to the LICENSE file of your project | ||
| 2355 | # and then add LIC_FILES_CHKSUM accordingly | ||
| 2356 | LICENSE = "CLOSED" | ||
| 2357 | |||
| 2358 | # Assuming the branch is main | ||
| 2359 | # Change <username> accordingly | ||
| 2360 | SRC_URI = "git://github.com/<username>/libhello;branch=main;protocol=https" | ||
| 2361 | |||
| 2362 | S = "${WORKDIR}/git" | ||
| 2363 | |||
| 2364 | do_install(){ | ||
| 2365 | install -d ${D}${includedir} | ||
| 2366 | install -d ${D}${libdir} | ||
| 2367 | |||
| 2368 | install hellolib.h ${D}${includedir} | ||
| 2369 | oe_soinstall ${PN}.so.${PV} ${D}${libdir} | ||
| 2370 | } | ||
| 2371 | |||
| 2372 | The following are the contents of ``sayhello_0.1.bb``:: | ||
| 2373 | |||
| 2374 | SUMMARY = "SayHello demo" | ||
| 2375 | DESCRIPTION = "SayHello project used in Yocto demo" | ||
| 2376 | |||
| 2377 | # NOTE: Set the License according to the LICENSE file of your project | ||
| 2378 | # and then add LIC_FILES_CHKSUM accordingly | ||
| 2379 | LICENSE = "CLOSED" | ||
| 2380 | |||
| 2381 | # Assuming the branch is main | ||
| 2382 | # Change <username> accordingly | ||
| 2383 | SRC_URI = "git://github.com/<username>/sayhello;branch=main;protocol=https" | ||
| 2384 | |||
| 2385 | DEPENDS += "libhello" | ||
| 2386 | RDEPENDS:${PN} += "libhello" | ||
| 2387 | |||
| 2388 | S = "${WORKDIR}/git" | ||
| 2389 | |||
| 2390 | do_install(){ | ||
| 2391 | install -d ${D}/usr/bin | ||
| 2392 | install -m 0700 sayhello ${D}/usr/bin | ||
| 2393 | } | ||
| 2394 | |||
| 2395 | After placing the recipes in a custom layer we can run ``bitbake sayhello`` | ||
| 2396 | to build the recipe. | ||
| 2397 | |||
| 2398 | The following diagram shows the sequences of tasks that BitBake | ||
| 2399 | executes to accomplish that. | ||
| 2400 | |||
| 2401 | .. image:: svg/bitbake_tasks_map.* | ||
| 2402 | :width: 100% | ||
