pkg-meson.mk 7.5 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. $(2)_MESON_SED_CFLAGS = $$(if $$(strip $$($(2)_CFLAGS)),`printf '"%s"$$(comma) ' $$($(2)_CFLAGS)`)
  58. $(2)_MESON_SED_LDFLAGS = $$(if $$(strip $$($(2)_LDFLAGS)),`printf '"%s"$$(comma) ' $$($(2)_LDFLAGS)`)
  59. $(2)_MESON_SED_CXXFLAGS = $$(if $$(strip $$($(2)_CXXFLAGS)),`printf '"%s"$$(comma) ' $$($(2)_CXXFLAGS)`)
  60. # Configure package for target
  61. #
  62. #
  63. define $(2)_CONFIGURE_CMDS
  64. rm -rf $$($$(PKG)_SRCDIR)/build
  65. mkdir -p $$($$(PKG)_SRCDIR)/build
  66. sed -e "s%@TARGET_CROSS@%$$(TARGET_CROSS)%g" \
  67. -e "s%@TARGET_ARCH@%$$(HOST_MESON_TARGET_CPU_FAMILY)%g" \
  68. -e "s%@TARGET_CPU@%$$(GCC_TARGET_CPU)%g" \
  69. -e "s%@TARGET_ENDIAN@%$$(call LOWERCASE,$$(BR2_ENDIAN))%g" \
  70. -e "s%@TARGET_CFLAGS@%$$($(2)_MESON_SED_CFLAGS)%g" \
  71. -e "s%@TARGET_LDFLAGS@%$$($(2)_MESON_SED_LDFLAGS)%g" \
  72. -e "s%@TARGET_CXXFLAGS@%$$($(2)_MESON_SED_CXXFLAGS)%g" \
  73. -e "s%@HOST_DIR@%$$(HOST_DIR)%g" \
  74. $$(foreach x,$$($(2)_MESON_EXTRA_BINARIES), \
  75. -e "/^\[binaries\]$$$$/s:$$$$:\n$$(x):" \
  76. ) \
  77. package/meson/cross-compilation.conf.in \
  78. > $$($$(PKG)_SRCDIR)/build/cross-compilation.conf
  79. PATH=$$(BR_PATH) $$($$(PKG)_CONF_ENV) $$(MESON) \
  80. --prefix=/usr \
  81. --libdir=lib \
  82. --default-library=$(if $(BR2_STATIC_LIBS),static,shared) \
  83. --buildtype=$(if $(BR2_ENABLE_DEBUG),debug,release) \
  84. --cross-file=$$($$(PKG)_SRCDIR)/build/cross-compilation.conf \
  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. $$($$(PKG)_CONF_OPTS) \
  102. $$($$(PKG)_SRCDIR) $$($$(PKG)_SRCDIR)/build
  103. endef
  104. endif
  105. endif
  106. $(2)_DEPENDENCIES += host-meson
  107. #
  108. # Build step. Only define it if not already defined by the package .mk
  109. # file.
  110. #
  111. ifndef $(2)_BUILD_CMDS
  112. ifeq ($(4),target)
  113. define $(2)_BUILD_CMDS
  114. $$(TARGET_MAKE_ENV) $$($$(PKG)_NINJA_ENV) \
  115. $$(NINJA) $$(NINJA_OPTS) $$($$(PKG)_NINJA_OPTS) -C $$($$(PKG)_SRCDIR)/build
  116. endef
  117. else
  118. define $(2)_BUILD_CMDS
  119. $$(HOST_MAKE_ENV) $$($$(PKG)_NINJA_ENV) \
  120. $$(NINJA) $$(NINJA_OPTS) $$($$(PKG)_NINJA_OPTS) -C $$($$(PKG)_SRCDIR)/build
  121. endef
  122. endif
  123. endif
  124. #
  125. # Host installation step. Only define it if not already defined by the
  126. # package .mk file.
  127. #
  128. ifndef $(2)_INSTALL_CMDS
  129. define $(2)_INSTALL_CMDS
  130. $$(HOST_MAKE_ENV) $$($$(PKG)_NINJA_ENV) \
  131. $$(NINJA) $$(NINJA_OPTS) -C $$($$(PKG)_SRCDIR)/build install
  132. endef
  133. endif
  134. #
  135. # Staging installation step. Only define it if not already defined by
  136. # the package .mk file.
  137. #
  138. ifndef $(2)_INSTALL_STAGING_CMDS
  139. define $(2)_INSTALL_STAGING_CMDS
  140. $$(TARGET_MAKE_ENV) $$($$(PKG)_NINJA_ENV) DESTDIR=$$(STAGING_DIR) \
  141. $$(NINJA) $$(NINJA_OPTS) -C $$($$(PKG)_SRCDIR)/build install
  142. endef
  143. endif
  144. #
  145. # Target installation step. Only define it if not already defined by
  146. # the package .mk file.
  147. #
  148. ifndef $(2)_INSTALL_TARGET_CMDS
  149. define $(2)_INSTALL_TARGET_CMDS
  150. $$(TARGET_MAKE_ENV) $$($$(PKG)_NINJA_ENV) DESTDIR=$$(TARGET_DIR) \
  151. $$(NINJA) $$(NINJA_OPTS) -C $$($$(PKG)_SRCDIR)/build install
  152. endef
  153. endif
  154. # Call the generic package infrastructure to generate the necessary
  155. # make targets
  156. $(call inner-generic-package,$(1),$(2),$(3),$(4))
  157. endef
  158. ################################################################################
  159. # meson-package -- the target generator macro for Meson packages
  160. ################################################################################
  161. meson-package = $(call inner-meson-package,$(pkgname),$(call UPPERCASE,$(pkgname)),$(call UPPERCASE,$(pkgname)),target)
  162. host-meson-package = $(call inner-meson-package,host-$(pkgname),$(call UPPERCASE,host-$(pkgname)),$(call UPPERCASE,$(pkgname)),host)
  163. ################################################################################
  164. # Generation of the Meson cross-compilation.conf file
  165. ################################################################################
  166. # Generate a Meson cross-compilation.conf suitable for use with the
  167. # SDK; also install the file as a template for users to add their
  168. # own flags if they need to.
  169. define PKG_MESON_INSTALL_CROSS_CONF
  170. mkdir -p $(HOST_DIR)/etc/meson
  171. sed -e "s%@TARGET_CROSS@%$(TARGET_CROSS)%g" \
  172. -e "s%@TARGET_ARCH@%$(HOST_MESON_TARGET_CPU_FAMILY)%g" \
  173. -e "s%@TARGET_CPU@%$(HOST_MESON_TARGET_CPU)%g" \
  174. -e "s%@TARGET_ENDIAN@%$(HOST_MESON_TARGET_ENDIAN)%g" \
  175. -e "s%@TARGET_CFLAGS@%$(HOST_MESON_SED_CFLAGS)@PKG_TARGET_CFLAGS@%g" \
  176. -e "s%@TARGET_LDFLAGS@%$(HOST_MESON_SED_LDFLAGS)@PKG_TARGET_CFLAGS@%g" \
  177. -e "s%@TARGET_CXXFLAGS@%$(HOST_MESON_SED_CXXFLAGS)@PKG_TARGET_CFLAGS@%g" \
  178. -e "s%@HOST_DIR@%$(HOST_DIR)%g" \
  179. $(HOST_MESON_PKGDIR)/cross-compilation.conf.in \
  180. > $(HOST_DIR)/etc/meson/cross-compilation.conf.in
  181. sed -e "s%@PKG_TARGET_CFLAGS@%%g" \
  182. -e "s%@PKG_TARGET_LDFLAGS@%%g" \
  183. -e "s%@PKG_TARGET_CXXFLAGS@%%g" \
  184. $(HOST_DIR)/etc/meson/cross-compilation.conf.in \
  185. > $(HOST_DIR)/etc/meson/cross-compilation.conf
  186. endef
  187. TOOLCHAIN_POST_INSTALL_STAGING_HOOKS += HOST_MESON_INSTALL_CROSS_CONF