1*4882a593Smuzhiyun// -*- mode:doc; -*- 2*4882a593Smuzhiyun// vim: set syntax=asciidoc: 3*4882a593Smuzhiyun 4*4882a593Smuzhiyun=== Infrastructure for virtual packages 5*4882a593Smuzhiyun 6*4882a593Smuzhiyun[[virtual-package-tutorial]] 7*4882a593Smuzhiyun 8*4882a593SmuzhiyunIn Buildroot, a virtual package is a package whose functionalities are 9*4882a593Smuzhiyunprovided by one or more packages, referred to as 'providers'. The virtual 10*4882a593Smuzhiyunpackage management is an extensible mechanism allowing the user to choose 11*4882a593Smuzhiyunthe provider used in the rootfs. 12*4882a593Smuzhiyun 13*4882a593SmuzhiyunFor example, 'OpenGL ES' is an API for 2D and 3D graphics on embedded systems. 14*4882a593SmuzhiyunThe implementation of this API is different for the 'Allwinner Tech Sunxi' and 15*4882a593Smuzhiyunthe 'Texas Instruments OMAP35xx' platforms. So +libgles+ will be a virtual 16*4882a593Smuzhiyunpackage and +sunxi-mali+ and +ti-gfx+ will be the providers. 17*4882a593Smuzhiyun 18*4882a593Smuzhiyun==== +virtual-package+ tutorial 19*4882a593Smuzhiyun 20*4882a593SmuzhiyunIn the following example, we will explain how to add a new virtual package 21*4882a593Smuzhiyun('something-virtual') and a provider for it ('some-provider'). 22*4882a593Smuzhiyun 23*4882a593SmuzhiyunFirst, let's create the virtual package. 24*4882a593Smuzhiyun 25*4882a593Smuzhiyun==== Virtual package's +Config.in+ file 26*4882a593Smuzhiyun 27*4882a593SmuzhiyunThe +Config.in+ file of virtual package 'something-virtual' should contain: 28*4882a593Smuzhiyun 29*4882a593Smuzhiyun--------------------------- 30*4882a593Smuzhiyun01: config BR2_PACKAGE_HAS_SOMETHING_VIRTUAL 31*4882a593Smuzhiyun02: bool 32*4882a593Smuzhiyun03: 33*4882a593Smuzhiyun04: config BR2_PACKAGE_PROVIDES_SOMETHING_VIRTUAL 34*4882a593Smuzhiyun05: depends on BR2_PACKAGE_HAS_SOMETHING_VIRTUAL 35*4882a593Smuzhiyun06: string 36*4882a593Smuzhiyun--------------------------- 37*4882a593Smuzhiyun 38*4882a593SmuzhiyunIn this file, we declare two options, +BR2_PACKAGE_HAS_SOMETHING_VIRTUAL+ and 39*4882a593Smuzhiyun+BR2_PACKAGE_PROVIDES_SOMETHING_VIRTUAL+, whose values will be used by the 40*4882a593Smuzhiyunproviders. 41*4882a593Smuzhiyun 42*4882a593Smuzhiyun==== Virtual package's +.mk+ file 43*4882a593Smuzhiyun 44*4882a593SmuzhiyunThe +.mk+ for the virtual package should just evaluate the +virtual-package+ macro: 45*4882a593Smuzhiyun 46*4882a593Smuzhiyun--------------------------- 47*4882a593Smuzhiyun01: ################################################################################ 48*4882a593Smuzhiyun02: # 49*4882a593Smuzhiyun03: # something-virtual 50*4882a593Smuzhiyun04: # 51*4882a593Smuzhiyun05: ################################################################################ 52*4882a593Smuzhiyun06: 53*4882a593Smuzhiyun07: $(eval $(virtual-package)) 54*4882a593Smuzhiyun--------------------------- 55*4882a593Smuzhiyun 56*4882a593SmuzhiyunThe ability to have target and host packages is also available, with the 57*4882a593Smuzhiyun+host-virtual-package+ macro. 58*4882a593Smuzhiyun 59*4882a593Smuzhiyun==== Provider's +Config.in+ file 60*4882a593Smuzhiyun 61*4882a593SmuzhiyunWhen adding a package as a provider, only the +Config.in+ file requires some 62*4882a593Smuzhiyunmodifications. 63*4882a593Smuzhiyun 64*4882a593SmuzhiyunThe +Config.in+ file of the package 'some-provider', which provides the 65*4882a593Smuzhiyunfunctionalities of 'something-virtual', should contain: 66*4882a593Smuzhiyun 67*4882a593Smuzhiyun--------------------------- 68*4882a593Smuzhiyun01: config BR2_PACKAGE_SOME_PROVIDER 69*4882a593Smuzhiyun02: bool "some-provider" 70*4882a593Smuzhiyun03: select BR2_PACKAGE_HAS_SOMETHING_VIRTUAL 71*4882a593Smuzhiyun04: help 72*4882a593Smuzhiyun05: This is a comment that explains what some-provider is. 73*4882a593Smuzhiyun06: 74*4882a593Smuzhiyun07: http://foosoftware.org/some-provider/ 75*4882a593Smuzhiyun08: 76*4882a593Smuzhiyun09: if BR2_PACKAGE_SOME_PROVIDER 77*4882a593Smuzhiyun10: config BR2_PACKAGE_PROVIDES_SOMETHING_VIRTUAL 78*4882a593Smuzhiyun11: default "some-provider" 79*4882a593Smuzhiyun12: endif 80*4882a593Smuzhiyun--------------------------- 81*4882a593Smuzhiyun 82*4882a593SmuzhiyunOn line 3, we select +BR2_PACKAGE_HAS_SOMETHING_VIRTUAL+, and on line 11, we 83*4882a593Smuzhiyunset the value of +BR2_PACKAGE_PROVIDES_SOMETHING_VIRTUAL+ to the name of the 84*4882a593Smuzhiyunprovider, but only if it is selected. 85*4882a593Smuzhiyun 86*4882a593Smuzhiyun==== Provider's +.mk+ file 87*4882a593Smuzhiyun 88*4882a593SmuzhiyunThe +.mk+ file should also declare an additional variable 89*4882a593Smuzhiyun+SOME_PROVIDER_PROVIDES+ to contain the names of all the virtual 90*4882a593Smuzhiyunpackages it is an implementation of: 91*4882a593Smuzhiyun 92*4882a593Smuzhiyun--------------------------- 93*4882a593Smuzhiyun01: SOME_PROVIDER_PROVIDES = something-virtual 94*4882a593Smuzhiyun--------------------------- 95*4882a593Smuzhiyun 96*4882a593SmuzhiyunOf course, do not forget to add the proper build and runtime dependencies for 97*4882a593Smuzhiyunthis package! 98*4882a593Smuzhiyun 99*4882a593Smuzhiyun==== Notes on depending on a virtual package 100*4882a593Smuzhiyun 101*4882a593SmuzhiyunWhen adding a package that requires a certain +FEATURE+ provided by a virtual 102*4882a593Smuzhiyunpackage, you have to use +depends on BR2_PACKAGE_HAS_FEATURE+, like so: 103*4882a593Smuzhiyun 104*4882a593Smuzhiyun--------------------------- 105*4882a593Smuzhiyunconfig BR2_PACKAGE_HAS_FEATURE 106*4882a593Smuzhiyun bool 107*4882a593Smuzhiyun 108*4882a593Smuzhiyunconfig BR2_PACKAGE_FOO 109*4882a593Smuzhiyun bool "foo" 110*4882a593Smuzhiyun depends on BR2_PACKAGE_HAS_FEATURE 111*4882a593Smuzhiyun--------------------------- 112*4882a593Smuzhiyun 113*4882a593Smuzhiyun==== Notes on depending on a specific provider 114*4882a593Smuzhiyun 115*4882a593SmuzhiyunIf your package really requires a specific provider, then you'll have to 116*4882a593Smuzhiyunmake your package +depends on+ this provider; you can _not_ +select+ a 117*4882a593Smuzhiyunprovider. 118*4882a593Smuzhiyun 119*4882a593SmuzhiyunLet's take an example with two providers for a +FEATURE+: 120*4882a593Smuzhiyun 121*4882a593Smuzhiyun--------------------------- 122*4882a593Smuzhiyunconfig BR2_PACKAGE_HAS_FEATURE 123*4882a593Smuzhiyun bool 124*4882a593Smuzhiyun 125*4882a593Smuzhiyunconfig BR2_PACKAGE_FOO 126*4882a593Smuzhiyun bool "foo" 127*4882a593Smuzhiyun select BR2_PACKAGE_HAS_FEATURE 128*4882a593Smuzhiyun 129*4882a593Smuzhiyunconfig BR2_PACKAGE_BAR 130*4882a593Smuzhiyun bool "bar" 131*4882a593Smuzhiyun select BR2_PACKAGE_HAS_FEATURE 132*4882a593Smuzhiyun--------------------------- 133*4882a593Smuzhiyun 134*4882a593SmuzhiyunAnd you are adding a package that needs +FEATURE+ as provided by +foo+, 135*4882a593Smuzhiyunbut not as provided by +bar+. 136*4882a593Smuzhiyun 137*4882a593SmuzhiyunIf you were to use +select BR2_PACKAGE_FOO+, then the user would still 138*4882a593Smuzhiyunbe able to select +BR2_PACKAGE_BAR+ in the menuconfig. This would create 139*4882a593Smuzhiyuna configuration inconsistency, whereby two providers of the same +FEATURE+ 140*4882a593Smuzhiyunwould be enabled at once, one explicitly set by the user, the other 141*4882a593Smuzhiyunimplicitly by your +select+. 142*4882a593Smuzhiyun 143*4882a593SmuzhiyunInstead, you have to use +depends on BR2_PACKAGE_FOO+, which avoids any 144*4882a593Smuzhiyunimplicit configuration inconsistency. 145