pkg-meson.mk 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. ################################################################################
  2. # Meson package infrastructure
  3. #
  4. # This file implements an infrastructure that eases development of
  5. # package .mk files for Meson packages. It should be used for all
  6. # packages that use Meson as their build system.
  7. #
  8. # See the Buildroot documentation for details on the usage of this
  9. # infrastructure
  10. #
  11. # In terms of implementation, this Meson infrastructure requires
  12. # the .mk file to only specify metadata information about the
  13. # package: name, version, download URL, etc.
  14. #
  15. # We still allow the package .mk file to override what the different
  16. # steps are doing, if needed. For example, if <PKG>_BUILD_CMDS is
  17. # already defined, it is used as the list of commands to perform to
  18. # build the package, instead of the default Meson behaviour. The
  19. # package can also define some post operation hooks.
  20. #
  21. ################################################################################
  22. #
  23. # Pass PYTHONNOUSERSITE environment variable when invoking Meson or Ninja, so
  24. # $(HOST_DIR)/bin/python3 will not look for Meson modules in
  25. # $HOME/.local/lib/python3.x/site-packages
  26. #
  27. MESON = PYTHONNOUSERSITE=y $(HOST_DIR)/bin/meson
  28. NINJA = PYTHONNOUSERSITE=y $(HOST_DIR)/bin/ninja
  29. NINJA_OPTS = $(if $(VERBOSE),-v) -j$(PARALLEL_JOBS)
  30. ################################################################################
  31. # inner-meson-package -- defines how the configuration, compilation and
  32. # installation of a Meson package should be done, implements a few hooks to
  33. # tune the build process and calls the generic package infrastructure to
  34. # generate the necessary make targets
  35. #
  36. # argument 1 is the lowercase package name
  37. # argument 2 is the uppercase package name, including a HOST_ prefix
  38. # for host packages
  39. # argument 3 is the uppercase package name, without the HOST_ prefix
  40. # for host packages
  41. # argument 4 is the type (target or host)
  42. ################################################################################
  43. define inner-meson-package
  44. $(2)_CONF_ENV ?=
  45. $(2)_CONF_OPTS ?=
  46. $(2)_NINJA_ENV ?=
  47. #
  48. # Configure step. Only define it if not already defined by the package
  49. # .mk file. And take care of the differences between host and target
  50. # packages.
  51. #
  52. ifndef $(2)_CONFIGURE_CMDS
  53. ifeq ($(4),target)
  54. $(2)_CFLAGS ?= $$(TARGET_CFLAGS)
  55. $(2)_LDFLAGS ?= $$(TARGET_LDFLAGS)
  56. $(2)_CXXFLAGS ?= $$(TARGET_CXXFLAGS)
  57. # Configure package for target
  58. #
  59. #
  60. define $(2)_CONFIGURE_CMDS
  61. rm -rf $$($$(PKG)_SRCDIR)/build
  62. mkdir -p $$($$(PKG)_SRCDIR)/build
  63. sed -e 's%@TARGET_CROSS@%$$(TARGET_CROSS)%g' \
  64. -e 's%@TARGET_ARCH@%$$(HOST_MESON_TARGET_CPU_FAMILY)%g' \
  65. -e 's%@TARGET_CPU@%$$(HOST_MESON_TARGET_CPU)%g' \
  66. -e 's%@TARGET_ENDIAN@%$$(HOST_MESON_TARGET_ENDIAN)%g' \
  67. -e "s%@TARGET_CFLAGS@%$$(call make-sq-comma-list,$$($(2)_CFLAGS))%g" \
  68. -e "s%@TARGET_LDFLAGS@%$$(call make-sq-comma-list,$$($(2)_LDFLAGS))%g" \
  69. -e "s%@TARGET_CXXFLAGS@%$$(call make-sq-comma-list,$$($(2)_CXXFLAGS))%g" \
  70. -e 's%@HOST_DIR@%$$(HOST_DIR)%g' \
  71. -e 's%@STAGING_DIR@%$$(STAGING_DIR)%g' \
  72. -e 's%@STATIC@%$$(if $$(BR2_STATIC_LIBS),true,false)%g' \
  73. -e "/^\[binaries\]$$$$/s:$$$$:$$(foreach x,$$($(2)_MESON_EXTRA_BINARIES),\n$$(x)):" \
  74. -e "/^\[properties\]$$$$/s:$$$$:$$(foreach x,$$($(2)_MESON_EXTRA_PROPERTIES),\n$$(x)):" \
  75. package/meson/cross-compilation.conf.in \
  76. > $$($$(PKG)_SRCDIR)/build/cross-compilation.conf
  77. PATH=$$(BR_PATH) $$($$(PKG)_CONF_ENV) $$(MESON) \
  78. --prefix=/usr \
  79. --libdir=lib \
  80. --default-library=$(if $(BR2_STATIC_LIBS),static,shared) \
  81. --buildtype=$(if $(BR2_ENABLE_DEBUG),debug,release) \
  82. --cross-file=$$($$(PKG)_SRCDIR)/build/cross-compilation.conf \
  83. -Dbuild.pkg_config_path=$$(HOST_DIR)/lib/pkgconfig \
  84. $$($$(PKG)_CONF_OPTS) \
  85. $$($$(PKG)_SRCDIR) $$($$(PKG)_SRCDIR)/build
  86. endef
  87. else
  88. # Configure package for host
  89. define $(2)_CONFIGURE_CMDS
  90. rm -rf $$($$(PKG)_SRCDIR)/build
  91. mkdir -p $$($$(PKG)_SRCDIR)/build
  92. $$(HOST_CONFIGURE_OPTS) \
  93. $$($$(PKG)_CONF_ENV) $$(MESON) \
  94. --prefix=$$(HOST_DIR) \
  95. --libdir=lib \
  96. --sysconfdir=$$(HOST_DIR)/etc \
  97. --localstatedir=$$(HOST_DIR)/var \
  98. --default-library=shared \
  99. --buildtype=release \
  100. $$($$(PKG)_CONF_OPTS) \
  101. $$($$(PKG)_SRCDIR) $$($$(PKG)_SRCDIR)/build
  102. endef
  103. endif
  104. endif
  105. $(2)_DEPENDENCIES += host-meson
  106. #
  107. # Build step. Only define it if not already defined by the package .mk
  108. # file.
  109. #
  110. ifndef $(2)_BUILD_CMDS
  111. ifeq ($(4),target)
  112. define $(2)_BUILD_CMDS
  113. $$(TARGET_MAKE_ENV) $$($$(PKG)_NINJA_ENV) \
  114. $$(NINJA) $$(NINJA_OPTS) $$($$(PKG)_NINJA_OPTS) -C $$($$(PKG)_SRCDIR)/build
  115. endef
  116. else
  117. define $(2)_BUILD_CMDS
  118. $$(HOST_MAKE_ENV) $$($$(PKG)_NINJA_ENV) \
  119. $$(NINJA) $$(NINJA_OPTS) $$($$(PKG)_NINJA_OPTS) -C $$($$(PKG)_SRCDIR)/build
  120. endef
  121. endif
  122. endif
  123. #
  124. # Host installation step. Only define it if not already defined by the
  125. # package .mk file.
  126. #
  127. ifndef $(2)_INSTALL_CMDS
  128. define $(2)_INSTALL_CMDS
  129. $$(HOST_MAKE_ENV) $$($$(PKG)_NINJA_ENV) \
  130. $$(NINJA) $$(NINJA_OPTS) -C $$($$(PKG)_SRCDIR)/build install
  131. endef
  132. endif
  133. #
  134. # Staging installation step. Only define it if not already defined by
  135. # the package .mk file.
  136. #
  137. ifndef $(2)_INSTALL_STAGING_CMDS
  138. define $(2)_INSTALL_STAGING_CMDS
  139. $$(TARGET_MAKE_ENV) $$($$(PKG)_NINJA_ENV) DESTDIR=$$(STAGING_DIR) \
  140. $$(NINJA) $$(NINJA_OPTS) -C $$($$(PKG)_SRCDIR)/build install
  141. endef
  142. endif
  143. #
  144. # Target installation step. Only define it if not already defined by
  145. # the package .mk file.
  146. #
  147. ifndef $(2)_INSTALL_TARGET_CMDS
  148. define $(2)_INSTALL_TARGET_CMDS
  149. $$(TARGET_MAKE_ENV) $$($$(PKG)_NINJA_ENV) DESTDIR=$$(TARGET_DIR) \
  150. $$(NINJA) $$(NINJA_OPTS) -C $$($$(PKG)_SRCDIR)/build install
  151. endef
  152. endif
  153. # Call the generic package infrastructure to generate the necessary
  154. # make targets
  155. $(call inner-generic-package,$(1),$(2),$(3),$(4))
  156. endef
  157. ################################################################################
  158. # meson-package -- the target generator macro for Meson packages
  159. ################################################################################
  160. meson-package = $(call inner-meson-package,$(pkgname),$(call UPPERCASE,$(pkgname)),$(call UPPERCASE,$(pkgname)),target)
  161. host-meson-package = $(call inner-meson-package,host-$(pkgname),$(call UPPERCASE,host-$(pkgname)),$(call UPPERCASE,$(pkgname)),host)
  162. ################################################################################
  163. # Generation of the Meson cross-compilation.conf file
  164. ################################################################################
  165. # Generate a Meson cross-compilation.conf suitable for use with the
  166. # SDK; also install the file as a template for users to add their
  167. # own flags if they need to.
  168. define PKG_MESON_INSTALL_CROSS_CONF
  169. mkdir -p $(HOST_DIR)/etc/meson
  170. sed -e 's%@TARGET_CROSS@%$(TARGET_CROSS)%g' \
  171. -e 's%@TARGET_ARCH@%$(HOST_MESON_TARGET_CPU_FAMILY)%g' \
  172. -e 's%@TARGET_CPU@%$(HOST_MESON_TARGET_CPU)%g' \
  173. -e 's%@TARGET_ENDIAN@%$(HOST_MESON_TARGET_ENDIAN)%g' \
  174. -e "s%@TARGET_CFLAGS@%$(call make-sq-comma-list,$(TARGET_CFLAGS))@PKG_TARGET_CFLAGS@%g" \
  175. -e "s%@TARGET_LDFLAGS@%$(call make-sq-comma-list,$(TARGET_LDFLAGS))@PKG_TARGET_CFLAGS@%g" \
  176. -e "s%@TARGET_CXXFLAGS@%$(call make-sq-comma-list,$(TARGET_CXXFLAGS))@PKG_TARGET_CFLAGS@%g" \
  177. -e 's%@HOST_DIR@%$(HOST_DIR)%g' \
  178. -e 's%@STAGING_DIR@%$(STAGING_DIR)%g' \
  179. -e 's%@STATIC@%$$(if $$(BR2_STATIC_LIBS),true,false)%g' \
  180. $(HOST_MESON_PKGDIR)/cross-compilation.conf.in \
  181. > $(HOST_DIR)/etc/meson/cross-compilation.conf.in
  182. sed -e 's%@PKG_TARGET_CFLAGS@%%g' \
  183. -e 's%@PKG_TARGET_LDFLAGS@%%g' \
  184. -e 's%@PKG_TARGET_CXXFLAGS@%%g' \
  185. $(HOST_DIR)/etc/meson/cross-compilation.conf.in \
  186. > $(HOST_DIR)/etc/meson/cross-compilation.conf
  187. endef
  188. TOOLCHAIN_POST_INSTALL_STAGING_HOOKS += PKG_MESON_INSTALL_CROSS_CONF