pkg-meson.mk 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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. -Dstrip=false \
  84. -Dbuild.pkg_config_path=$$(HOST_DIR)/lib/pkgconfig \
  85. $$($$(PKG)_CONF_OPTS) \
  86. $$($$(PKG)_SRCDIR) $$($$(PKG)_SRCDIR)/build
  87. endef
  88. else
  89. # Configure package for host
  90. define $(2)_CONFIGURE_CMDS
  91. rm -rf $$($$(PKG)_SRCDIR)/build
  92. mkdir -p $$($$(PKG)_SRCDIR)/build
  93. $$(HOST_CONFIGURE_OPTS) \
  94. $$($$(PKG)_CONF_ENV) $$(MESON) \
  95. --prefix=$$(HOST_DIR) \
  96. --libdir=lib \
  97. --sysconfdir=$$(HOST_DIR)/etc \
  98. --localstatedir=$$(HOST_DIR)/var \
  99. --default-library=shared \
  100. --buildtype=release \
  101. -Dstrip=true \
  102. $$($$(PKG)_CONF_OPTS) \
  103. $$($$(PKG)_SRCDIR) $$($$(PKG)_SRCDIR)/build
  104. endef
  105. endif
  106. endif
  107. $(2)_DEPENDENCIES += host-meson
  108. #
  109. # Build step. Only define it if not already defined by the package .mk
  110. # file.
  111. #
  112. ifndef $(2)_BUILD_CMDS
  113. ifeq ($(4),target)
  114. define $(2)_BUILD_CMDS
  115. $$(TARGET_MAKE_ENV) $$($$(PKG)_NINJA_ENV) \
  116. $$(NINJA) $$(NINJA_OPTS) $$($$(PKG)_NINJA_OPTS) -C $$($$(PKG)_SRCDIR)/build
  117. endef
  118. else
  119. define $(2)_BUILD_CMDS
  120. $$(HOST_MAKE_ENV) $$($$(PKG)_NINJA_ENV) \
  121. $$(NINJA) $$(NINJA_OPTS) $$($$(PKG)_NINJA_OPTS) -C $$($$(PKG)_SRCDIR)/build
  122. endef
  123. endif
  124. endif
  125. #
  126. # Host installation step. Only define it if not already defined by the
  127. # package .mk file.
  128. #
  129. ifndef $(2)_INSTALL_CMDS
  130. define $(2)_INSTALL_CMDS
  131. $$(HOST_MAKE_ENV) $$($$(PKG)_NINJA_ENV) \
  132. $$(NINJA) $$(NINJA_OPTS) -C $$($$(PKG)_SRCDIR)/build install
  133. endef
  134. endif
  135. #
  136. # Staging installation step. Only define it if not already defined by
  137. # the package .mk file.
  138. #
  139. ifndef $(2)_INSTALL_STAGING_CMDS
  140. define $(2)_INSTALL_STAGING_CMDS
  141. $$(TARGET_MAKE_ENV) $$($$(PKG)_NINJA_ENV) DESTDIR=$$(STAGING_DIR) \
  142. $$(NINJA) $$(NINJA_OPTS) -C $$($$(PKG)_SRCDIR)/build install
  143. endef
  144. endif
  145. #
  146. # Target installation step. Only define it if not already defined by
  147. # the package .mk file.
  148. #
  149. ifndef $(2)_INSTALL_TARGET_CMDS
  150. define $(2)_INSTALL_TARGET_CMDS
  151. $$(TARGET_MAKE_ENV) $$($$(PKG)_NINJA_ENV) DESTDIR=$$(TARGET_DIR) \
  152. $$(NINJA) $$(NINJA_OPTS) -C $$($$(PKG)_SRCDIR)/build install
  153. endef
  154. endif
  155. # Call the generic package infrastructure to generate the necessary
  156. # make targets
  157. $(call inner-generic-package,$(1),$(2),$(3),$(4))
  158. endef
  159. ################################################################################
  160. # meson-package -- the target generator macro for Meson packages
  161. ################################################################################
  162. meson-package = $(call inner-meson-package,$(pkgname),$(call UPPERCASE,$(pkgname)),$(call UPPERCASE,$(pkgname)),target)
  163. host-meson-package = $(call inner-meson-package,host-$(pkgname),$(call UPPERCASE,host-$(pkgname)),$(call UPPERCASE,$(pkgname)),host)
  164. ################################################################################
  165. # Generation of the Meson cross-compilation.conf file
  166. ################################################################################
  167. # Generate a Meson cross-compilation.conf suitable for use with the
  168. # SDK; also install the file as a template for users to add their
  169. # own flags if they need to.
  170. define PKG_MESON_INSTALL_CROSS_CONF
  171. mkdir -p $(HOST_DIR)/etc/meson
  172. sed -e 's%@TARGET_CROSS@%$(TARGET_CROSS)%g' \
  173. -e 's%@TARGET_ARCH@%$(HOST_MESON_TARGET_CPU_FAMILY)%g' \
  174. -e 's%@TARGET_CPU@%$(HOST_MESON_TARGET_CPU)%g' \
  175. -e 's%@TARGET_ENDIAN@%$(HOST_MESON_TARGET_ENDIAN)%g' \
  176. -e "s%@TARGET_CFLAGS@%$(call make-sq-comma-list,$(TARGET_CFLAGS))@PKG_TARGET_CFLAGS@%g" \
  177. -e "s%@TARGET_LDFLAGS@%$(call make-sq-comma-list,$(TARGET_LDFLAGS))@PKG_TARGET_CFLAGS@%g" \
  178. -e "s%@TARGET_CXXFLAGS@%$(call make-sq-comma-list,$(TARGET_CXXFLAGS))@PKG_TARGET_CFLAGS@%g" \
  179. -e 's%@HOST_DIR@%$(HOST_DIR)%g' \
  180. -e 's%@STAGING_DIR@%$(STAGING_DIR)%g' \
  181. -e 's%@STATIC@%$(if $(BR2_STATIC_LIBS),true,false)%g' \
  182. $(HOST_MESON_PKGDIR)/cross-compilation.conf.in \
  183. > $(HOST_DIR)/etc/meson/cross-compilation.conf.in
  184. sed -e 's%@PKG_TARGET_CFLAGS@%%g' \
  185. -e 's%@PKG_TARGET_LDFLAGS@%%g' \
  186. -e 's%@PKG_TARGET_CXXFLAGS@%%g' \
  187. $(HOST_DIR)/etc/meson/cross-compilation.conf.in \
  188. > $(HOST_DIR)/etc/meson/cross-compilation.conf
  189. endef
  190. TOOLCHAIN_TARGET_FINALIZE_HOOKS += PKG_MESON_INSTALL_CROSS_CONF