adding-packages-meson.txt 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. // -*- mode:doc; -*-
  2. // vim: set syntax=asciidoc:
  3. === Integration of Meson-based packages
  4. [[meson-package-tutorial]]
  5. ==== +meson-package+ tutorial
  6. http://mesonbuild.com[Meson] is an open source build system meant to be both
  7. extremely fast, and, even more importantly, as user friendly as possible.
  8. Buildroot does not (yet) provide a dedicated package infrastructure for
  9. meson-based packages. So, we will explain how to write a +.mk+ file for such a
  10. package. Let's start with an example:
  11. ------------------------------
  12. 01: ################################################################################
  13. 02: #
  14. 03: # foo
  15. 04: #
  16. 05: ################################################################################
  17. 06:
  18. 07: FOO_VERSION = 1.0
  19. 08: FOO_SOURCE = foo-$(FOO_VERSION).tar.gz
  20. 09: FOO_SITE = http://www.foosoftware.org/download
  21. 10: FOO_LICENSE = GPL-3.0+
  22. 11: FOO_LICENSE_FILES = COPYING
  23. 12: FOO_INSTALL_STAGING = YES
  24. 13:
  25. 14: FOO_DEPENDENCIES = host-meson host-pkgconf bar
  26. 15:
  27. 16: FOO_CONF_OPTS += \
  28. 17: --prefix=/usr \
  29. 18: --buildtype $(if $(BR2_ENABLE_DEBUG),debug,release) \
  30. 19: --cross-file $(HOST_DIR)/etc/meson/cross-compilation.conf
  31. 20:
  32. 21: FOO_NINJA_OPTS = $(if $(VERBOSE),-v) -j$(PARALLEL_JOBS)
  33. 22:
  34. 23: ifeq ($(BR2_PACKAGE_BAZ),y)
  35. 24: FOO_CONF_OPTS += -Dbaz
  36. 25: endif
  37. 26:
  38. 27: define FOO_CONFIGURE_CMDS
  39. 28: rm -rf $(@D)/build
  40. 29: mkdir -p $(@D)/build
  41. 30: $(TARGET_MAKE_ENV) meson $(FOO_CONF_OPTS) $(@D) $(@D)/build
  42. 31: endef
  43. 32:
  44. 33: define FOO_BUILD_CMDS
  45. 34: $(TARGET_MAKE_ENV) ninja $(FOO_NINJA_OPTS) -C $(@D)/build
  46. 35: endef
  47. 36:
  48. 37: define FOO_INSTALL_TARGET_CMDS
  49. 38: $(TARGET_MAKE_ENV) DESTDIR=$(TARGET_DIR) ninja $(FOO_NINJA_OPTS) \
  50. 39: -C $(@D)/build install
  51. 40: endef
  52. 41:
  53. 42: define FOO_INSTALL_STAGING_CMDS
  54. 43: $(TARGET_MAKE_ENV) DESTDIR=$(STAGING_DIR) ninja $(FOO_NINJA_OPTS) \
  55. 44: -C $(@D)/build install
  56. 45: endef
  57. 46:
  58. 47: $(eval $(generic-package))
  59. --------------------------------
  60. The Makefile starts with the definition of the standard variables for package
  61. declaration (lines 7 to 11).
  62. As seen in line 47, it is based on the
  63. xref:generic-package-tutorial[+generic-package+ infrastructure]. So, it defines
  64. the variables required by this particular infrastructure, where Meson and its
  65. companion tool, Ninja, are invoked:
  66. * +FOO_CONFIGURE_CMDS+: the build directory required by Meson is created, and
  67. Meson is invoked to generate the Ninja build file. The options required to
  68. configure the cross-compilation of the package are passed via
  69. +FOO_CONF_OPTS+.
  70. * +FOO_BUILD_CMDS+: Ninja is invoked to perform the build.
  71. * +FOO_INSTALL_TARGET_CMDS+: Ninja is invoked to install the files generated
  72. during the build step in the target directory.
  73. * +FOO_INSTALL_STAGING_CMDS+: Ninja is invoked to install the files generated
  74. during the build step in the staging directory, as +FOO_INSTALL_STAGING+ is
  75. set to "YES".
  76. In order to have Meson available for the build, +FOO_DEPENDENCIES+ needs to
  77. contain +host-meson+. In the example, +host-pkgconf+ and +bar+ are also
  78. declared as dependencies because the Meson build file of +foo+ uses `pkg-config`
  79. to determine the compilation flags and libraries of package +bar+.
  80. If the "baz" package is selected, then support for the "baz" feature in "foo"
  81. is activated by adding +-Dbaz+ to +FOO_CONF_OPTS+, as specified in the
  82. +meson_options.txt+ file in "foo" source tree.
  83. To sum it up, to add a new meson-based package, the Makefile example can be
  84. copied verbatim then edited to replace all occurences of +FOO+ with the
  85. uppercase name of the new package and update the values of the standard
  86. variables.