1*4882a593Smuzhiyun// -*- mode:doc; -*- 2*4882a593Smuzhiyun// vim: set syntax=asciidoc: 3*4882a593Smuzhiyun 4*4882a593Smuzhiyun=== Infrastructure for Meson-based packages 5*4882a593Smuzhiyun 6*4882a593Smuzhiyun[[meson-package-tutorial]] 7*4882a593Smuzhiyun 8*4882a593Smuzhiyun==== +meson-package+ tutorial 9*4882a593Smuzhiyun 10*4882a593Smuzhiyunhttp://mesonbuild.com[Meson] is an open source build system meant to be both 11*4882a593Smuzhiyunextremely fast, and, even more importantly, as user friendly as possible. It 12*4882a593Smuzhiyunuses https://ninja-build.org[Ninja] as a companion tool to perform the actual 13*4882a593Smuzhiyunbuild operations. 14*4882a593Smuzhiyun 15*4882a593SmuzhiyunLet's see how to write a +.mk+ file for a Meson-based package, with an example: 16*4882a593Smuzhiyun 17*4882a593Smuzhiyun------------------------------ 18*4882a593Smuzhiyun01: ################################################################################ 19*4882a593Smuzhiyun02: # 20*4882a593Smuzhiyun03: # foo 21*4882a593Smuzhiyun04: # 22*4882a593Smuzhiyun05: ################################################################################ 23*4882a593Smuzhiyun06: 24*4882a593Smuzhiyun07: FOO_VERSION = 1.0 25*4882a593Smuzhiyun08: FOO_SOURCE = foo-$(FOO_VERSION).tar.gz 26*4882a593Smuzhiyun09: FOO_SITE = http://www.foosoftware.org/download 27*4882a593Smuzhiyun10: FOO_LICENSE = GPL-3.0+ 28*4882a593Smuzhiyun11: FOO_LICENSE_FILES = COPYING 29*4882a593Smuzhiyun12: FOO_INSTALL_STAGING = YES 30*4882a593Smuzhiyun13: 31*4882a593Smuzhiyun14: FOO_DEPENDENCIES = host-pkgconf bar 32*4882a593Smuzhiyun15: 33*4882a593Smuzhiyun16: ifeq ($(BR2_PACKAGE_BAZ),y) 34*4882a593Smuzhiyun17: FOO_CONF_OPTS += -Dbaz=true 35*4882a593Smuzhiyun18: FOO_DEPENDENCIES += baz 36*4882a593Smuzhiyun19: else 37*4882a593Smuzhiyun20: FOO_CONF_OPTS += -Dbaz=false 38*4882a593Smuzhiyun21: endif 39*4882a593Smuzhiyun22: 40*4882a593Smuzhiyun23: $(eval $(meson-package)) 41*4882a593Smuzhiyun-------------------------------- 42*4882a593Smuzhiyun 43*4882a593SmuzhiyunThe Makefile starts with the definition of the standard variables for package 44*4882a593Smuzhiyundeclaration (lines 7 to 11). 45*4882a593Smuzhiyun 46*4882a593SmuzhiyunOn line line 23, we invoke the +meson-package+ macro that generates all the 47*4882a593SmuzhiyunMakefile rules that actually allows the package to be built. 48*4882a593Smuzhiyun 49*4882a593SmuzhiyunIn the example, +host-pkgconf+ and +bar+ are declared as dependencies in 50*4882a593Smuzhiyun+FOO_DEPENDENCIES+ at line 14 because the Meson build file of +foo+ uses 51*4882a593Smuzhiyun`pkg-config` to determine the compilation flags and libraries of package +bar+. 52*4882a593Smuzhiyun 53*4882a593SmuzhiyunNote that it is not necessary to add +host-meson+ in the +FOO_DEPENDENCIES+ 54*4882a593Smuzhiyunvariable of a package, since this basic dependency is automatically added as 55*4882a593Smuzhiyunneeded by the Meson package infrastructure. 56*4882a593Smuzhiyun 57*4882a593SmuzhiyunIf the "baz" package is selected, then support for the "baz" feature in "foo" is 58*4882a593Smuzhiyunactivated by adding +-Dbaz=true+ to +FOO_CONF_OPTS+ at line 17, as specified in 59*4882a593Smuzhiyunthe +meson_options.txt+ file in "foo" source tree. The "baz" package is also 60*4882a593Smuzhiyunadded to +FOO_DEPENDENCIES+. Note that the support for +baz+ is explicitly 61*4882a593Smuzhiyundisabled at line 20, if the package is not selected. 62*4882a593Smuzhiyun 63*4882a593SmuzhiyunTo sum it up, to add a new meson-based package, the Makefile example can be 64*4882a593Smuzhiyuncopied verbatim then edited to replace all occurences of +FOO+ with the 65*4882a593Smuzhiyunuppercase name of the new package and update the values of the standard 66*4882a593Smuzhiyunvariables. 67*4882a593Smuzhiyun 68*4882a593Smuzhiyun[[meson-package-reference]] 69*4882a593Smuzhiyun 70*4882a593Smuzhiyun==== +meson-package+ reference 71*4882a593Smuzhiyun 72*4882a593SmuzhiyunThe main macro of the Meson package infrastructure is +meson-package+. It is 73*4882a593Smuzhiyunsimilar to the +generic-package+ macro. The ability to have target and host 74*4882a593Smuzhiyunpackages is also available, with the +host-meson-package+ macro. 75*4882a593Smuzhiyun 76*4882a593SmuzhiyunJust like the generic infrastructure, the Meson infrastructure works by defining 77*4882a593Smuzhiyuna number of variables before calling the +meson-package+ macro. 78*4882a593Smuzhiyun 79*4882a593SmuzhiyunFirst, all the package metadata information variables that exist in the generic 80*4882a593Smuzhiyuninfrastructure also exist in the Meson infrastructure: +FOO_VERSION+, 81*4882a593Smuzhiyun+FOO_SOURCE+, +FOO_PATCH+, +FOO_SITE+, +FOO_SUBDIR+, +FOO_DEPENDENCIES+, 82*4882a593Smuzhiyun+FOO_INSTALL_STAGING+, +FOO_INSTALL_TARGET+. 83*4882a593Smuzhiyun 84*4882a593SmuzhiyunA few additional variables, specific to the Meson infrastructure, can also be 85*4882a593Smuzhiyundefined. Many of them are only useful in very specific cases, typical packages 86*4882a593Smuzhiyunwill therefore only use a few of them. 87*4882a593Smuzhiyun 88*4882a593Smuzhiyun* +FOO_SUBDIR+ may contain the name of a subdirectory inside the 89*4882a593Smuzhiyun package that contains the main meson.build file. This is useful, 90*4882a593Smuzhiyun if for example, the main meson.build file is not at the root of 91*4882a593Smuzhiyun the tree extracted by the tarball. If +HOST_FOO_SUBDIR+ is not 92*4882a593Smuzhiyun specified, it defaults to +FOO_SUBDIR+. 93*4882a593Smuzhiyun 94*4882a593Smuzhiyun* +FOO_CONF_ENV+, to specify additional environment variables to pass to 95*4882a593Smuzhiyun +meson+ for the configuration step. By default, empty. 96*4882a593Smuzhiyun 97*4882a593Smuzhiyun* +FOO_CONF_OPTS+, to specify additional options to pass to +meson+ for the 98*4882a593Smuzhiyun configuration step. By default, empty. 99*4882a593Smuzhiyun 100*4882a593Smuzhiyun* +FOO_CFLAGS+, to specify compiler arguments added to the package specific 101*4882a593Smuzhiyun +cross-compile.conf+ file +c_args+ property. By default, the value of 102*4882a593Smuzhiyun +TARGET_CFLAGS+. 103*4882a593Smuzhiyun 104*4882a593Smuzhiyun* +FOO_CXXFLAGS+, to specify compiler arguments added to the package specific 105*4882a593Smuzhiyun +cross-compile.conf+ file +cpp_args+ property. By default, the value of 106*4882a593Smuzhiyun +TARGET_CXXFLAGS+. 107*4882a593Smuzhiyun 108*4882a593Smuzhiyun* +FOO_LDFLAGS+, to specify compiler arguments added to the package specific 109*4882a593Smuzhiyun +cross-compile.conf+ file +c_link_args+ and +cpp_link_args+ properties. By 110*4882a593Smuzhiyun default, the value of +TARGET_LDFLAGS+. 111*4882a593Smuzhiyun 112*4882a593Smuzhiyun* +FOO_MESON_EXTRA_BINARIES+, to specify a space-separated list of programs 113*4882a593Smuzhiyun to add to the `[binaries]` section of the meson `cross-compilation.conf` 114*4882a593Smuzhiyun configuration file. The format is `program-name='/path/to/program'`, with 115*4882a593Smuzhiyun no space around the +=+ sign, and with the path of the program between 116*4882a593Smuzhiyun single quotes. By default, empty. Note that Buildroot already sets the 117*4882a593Smuzhiyun correct values for +c+, +cpp+, +ar+, +strip+, and +pkgconfig+. 118*4882a593Smuzhiyun 119*4882a593Smuzhiyun* +FOO_MESON_EXTRA_PROPERTIES+, to specify a space-separated list of 120*4882a593Smuzhiyun properties to add to the `[properties]` section of the meson 121*4882a593Smuzhiyun `cross-compilation.conf` configuration file. The format is 122*4882a593Smuzhiyun `property-name=<value>` with no space around the +=+ sign, and with 123*4882a593Smuzhiyun single quotes around string values. By default, empty. Note that 124*4882a593Smuzhiyun Buildroot already sets values for +needs_exe_wrapper+, +c_args+, 125*4882a593Smuzhiyun +c_link_args+, +cpp_args+, +cpp_link_args+, +sys_root+, and 126*4882a593Smuzhiyun +pkg_config_libdir+. 127*4882a593Smuzhiyun 128*4882a593Smuzhiyun* +FOO_NINJA_ENV+, to specify additional environment variables to pass to 129*4882a593Smuzhiyun +ninja+, meson companion tool in charge of the build operations. By default, 130*4882a593Smuzhiyun empty. 131*4882a593Smuzhiyun 132*4882a593Smuzhiyun* +FOO_NINJA_OPTS+, to specify a space-separated list of targets to build. By 133*4882a593Smuzhiyun default, empty, to build the default target(s). 134