2 // vim: set syntax=asciidoc:
4 === Infrastructure for virtual packages
6 [[virtual-package-tutorial]]
8 In Buildroot, a virtual package is a package whose functionalities are
9 provided by one or more packages, referred to as 'providers'. The virtual
10 package management is an extensible mechanism allowing the user to choose
11 the provider used in the rootfs.
13 For example, 'OpenGL ES' is an API for 2D and 3D graphics on embedded systems.
14 The implementation of this API is different for the 'Allwinner Tech Sunxi' and
15 the 'Texas Instruments OMAP35xx' platforms. So +libgles+ will be a virtual
16 package and +sunxi-mali+ and +ti-gfx+ will be the providers.
18 ==== +virtual-package+ tutorial
20 In the following example, we will explain how to add a new virtual package
21 ('something-virtual') and a provider for it ('some-provider').
23 First, let's create the virtual package.
25 ==== Virtual package's +Config.in+ file
27 The +Config.in+ file of virtual package 'something-virtual' should contain:
29 ---------------------------
30 01: config BR2_PACKAGE_HAS_SOMETHING_VIRTUAL
33 04: config BR2_PACKAGE_PROVIDES_SOMETHING_VIRTUAL
34 05: depends on BR2_PACKAGE_HAS_SOMETHING_VIRTUAL
36 ---------------------------
38 In this file, we declare two options, +BR2_PACKAGE_HAS_SOMETHING_VIRTUAL+ and
39 +BR2_PACKAGE_PROVIDES_SOMETHING_VIRTUAL+, whose values will be used by the
42 ==== Virtual package's +.mk+ file
44 The +.mk+ for the virtual package should just evaluate the +virtual-package+ macro:
46 ---------------------------
47 01: ################################################################################
49 03: # something-virtual
51 05: ################################################################################
53 07: $(eval $(virtual-package))
54 ---------------------------
56 The ability to have target and host packages is also available, with the
57 +host-virtual-package+ macro.
59 ==== Provider's +Config.in+ file
61 When adding a package as a provider, only the +Config.in+ file requires some
64 The +Config.in+ file of the package 'some-provider', which provides the
65 functionalities of 'something-virtual', should contain:
67 ---------------------------
68 01: config BR2_PACKAGE_SOME_PROVIDER
69 02: bool "some-provider"
70 03: select BR2_PACKAGE_HAS_SOMETHING_VIRTUAL
72 05: This is a comment that explains what some-provider is.
74 07: http://foosoftware.org/some-provider/
76 09: if BR2_PACKAGE_SOME_PROVIDER
77 10: config BR2_PACKAGE_PROVIDES_SOMETHING_VIRTUAL
78 11: default "some-provider"
80 ---------------------------
82 On line 3, we select +BR2_PACKAGE_HAS_SOMETHING_VIRTUAL+, and on line 11, we
83 set the value of +BR2_PACKAGE_PROVIDES_SOMETHING_VIRTUAL+ to the name of the
84 provider, but only if it is selected.
86 ==== Provider's +.mk+ file
88 The +.mk+ file should also declare an additional variable
89 +SOME_PROVIDER_PROVIDES+ to contain the names of all the virtual
90 packages it is an implementation of:
92 ---------------------------
93 01: SOME_PROVIDER_PROVIDES = something-virtual
94 ---------------------------
96 Of course, do not forget to add the proper build and runtime dependencies for
99 ==== Notes on depending on a virtual package
101 When adding a package that requires a certain +FEATURE+ provided by a virtual
102 package, you have to use +depends on BR2_PACKAGE_HAS_FEATURE+, like so:
104 ---------------------------
105 config BR2_PACKAGE_HAS_FEATURE
108 config BR2_PACKAGE_FOO
110 depends on BR2_PACKAGE_HAS_FEATURE
111 ---------------------------
113 ==== Notes on depending on a specific provider
115 If your package really requires a specific provider, then you'll have to
116 make your package +depends on+ this provider; you can _not_ +select+ a
119 Let's take an example with two providers for a +FEATURE+:
121 ---------------------------
122 config BR2_PACKAGE_HAS_FEATURE
125 config BR2_PACKAGE_FOO
127 select BR2_PACKAGE_HAS_FEATURE
129 config BR2_PACKAGE_BAR
131 select BR2_PACKAGE_HAS_FEATURE
132 ---------------------------
134 And you are adding a package that needs +FEATURE+ as provided by +foo+,
135 but not as provided by +bar+.
137 If you were to use +select BR2_PACKAGE_FOO+, then the user would still
138 be able to select +BR2_PACKAGE_BAR+ in the menuconfig. This would create
139 a configuration inconsistency, whereby two providers of the same +FEATURE+
140 would be enabled at once, one explicitly set by the user, the other
141 implicitly by your +select+.
143 Instead, you have to use +depends on BR2_PACKAGE_FOO+, which avoids any
144 implicit configuration inconsistency.