You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

147 lines
4.2 KiB

  1. # To build your package using meson:
  2. #
  3. # PKG_BUILD_DEPENDS:=meson/host
  4. # include ../../devel/meson/meson.mk
  5. # MESON_ARGS+=-Dfoo -Dbar=baz
  6. #
  7. # To pass additional environment variables to meson:
  8. #
  9. # MESON_VARS+=FOO=bar
  10. #
  11. # Default configure/compile/install targets are provided, but can be
  12. # overwritten if required:
  13. #
  14. # define Build/Configure
  15. # $(call Build/Configure/Meson)
  16. # ...
  17. # endef
  18. #
  19. # same for Build/Compile and Build/Install
  20. #
  21. # Host packages are built in the same fashion, just use these vars instead:
  22. #
  23. # HOST_BUILD_DEPENDS:=meson/host
  24. # MESON_HOST_ARGS+=-Dfoo -Dbar=baz
  25. # MESON_HOST_VARS+=FOO=bar
  26. PKG_BUILD_PARALLEL ?= 1
  27. HOST_BUILD_PARALLEL ?= 1
  28. MESON_DIR:=$(STAGING_DIR_HOSTPKG)/lib/meson
  29. MESON_HOST_BUILD_DIR:=$(HOST_BUILD_DIR)/openwrt-build
  30. MESON_HOST_VARS:=
  31. MESON_HOST_ARGS:=
  32. MESON_BUILD_DIR:=$(PKG_BUILD_DIR)/openwrt-build
  33. MESON_VARS:=
  34. MESON_ARGS:=
  35. ifneq ($(findstring i386,$(CONFIG_ARCH)),)
  36. MESON_ARCH:="x86"
  37. else ifneq ($(findstring powerpc64,$(CONFIG_ARCH)),)
  38. MESON_ARCH:="ppc64"
  39. else ifneq ($(findstring powerpc,$(CONFIG_ARCH)),)
  40. MESON_ARCH:="ppc"
  41. else ifneq ($(findstring mips64el,$(CONFIG_ARCH)),)
  42. MESON_ARCH:="mips64"
  43. else ifneq ($(findstring mipsel,$(CONFIG_ARCH)),)
  44. MESON_ARCH:="mips"
  45. else ifneq ($(findstring armeb,$(CONFIG_ARCH)),)
  46. MESON_ARCH:="arm"
  47. else
  48. MESON_ARCH:=$(CONFIG_ARCH)
  49. endif
  50. # this is undefined for just x64_64
  51. ifeq ($(origin CPU_TYPE),undefined)
  52. MESON_CPU:="generic"
  53. else
  54. MESON_CPU:="$(CPU_TYPE)$(if $(CPU_SUBTYPE),+$(CPU_SUBTYPE))"
  55. endif
  56. define Meson
  57. $(2) $(STAGING_DIR_HOST)/bin/$(PYTHON) $(MESON_DIR)/meson.py $(1)
  58. endef
  59. define Meson/CreateNativeFile
  60. $(STAGING_DIR_HOST)/bin/sed \
  61. -e "s|@CC@|$(foreach BIN,$(HOSTCC),'$(BIN)',)|" \
  62. -e "s|@CXX@|$(foreach BIN,$(HOSTCXX),'$(BIN)',)|" \
  63. -e "s|@PKGCONFIG@|$(PKG_CONFIG)|" \
  64. -e "s|@CFLAGS@|$(foreach FLAG,$(HOST_CFLAGS) $(HOST_CPPFLAGS),'$(FLAG)',)|" \
  65. -e "s|@CXXFLAGS@|$(foreach FLAG,$(HOST_CXXFLAGS) $(HOST_CPPFLAGS),'$(FLAG)',)|" \
  66. -e "s|@LDFLAGS@|$(foreach FLAG,$(HOST_LDFLAGS),'$(FLAG)',)|" \
  67. -e "s|@PREFIX@|$(STAGING_DIR_HOSTPKG)|" \
  68. < $(MESON_DIR)/openwrt-native.txt.in \
  69. > $(1)
  70. endef
  71. define Meson/CreateCrossFile
  72. $(STAGING_DIR_HOST)/bin/sed \
  73. -e "s|@CC@|$(foreach BIN,$(TARGET_CC),'$(BIN)',)|" \
  74. -e "s|@CXX@|$(foreach BIN,$(TARGET_CXX),'$(BIN)',)|" \
  75. -e "s|@AR@|$(TARGET_AR)|" \
  76. -e "s|@STRIP@|$(TARGET_CROSS)strip|" \
  77. -e "s|@NM@|$(TARGET_NM)|" \
  78. -e "s|@PKGCONFIG@|$(PKG_CONFIG)|" \
  79. -e "s|@CFLAGS@|$(foreach FLAG,$(TARGET_CFLAGS) $(EXTRA_CFLAGS) $(TARGET_CPPFLAGS) $(EXTRA_CPPFLAGS),'$(FLAG)',)|" \
  80. -e "s|@CXXFLAGS@|$(foreach FLAG,$(TARGET_CXXFLAGS) $(EXTRA_CXXFLAGS) $(TARGET_CPPFLAGS) $(EXTRA_CPPFLAGS),'$(FLAG)',)|" \
  81. -e "s|@LDFLAGS@|$(foreach FLAG,$(TARGET_LDFLAGS) $(EXTRA_LDFLAGS),'$(FLAG)',)|" \
  82. -e "s|@ARCH@|$(MESON_ARCH)|" \
  83. -e "s|@CPU@|$(MESON_CPU)|" \
  84. -e "s|@ENDIAN@|$(if $(CONFIG_BIG_ENDIAN),big,little)|" \
  85. < $(MESON_DIR)/openwrt-cross.txt.in \
  86. > $(1)
  87. endef
  88. define Host/Configure/Meson
  89. $(call Meson/CreateNativeFile,$(HOST_BUILD_DIR)/openwrt-native.txt)
  90. $(call Meson, \
  91. --native-file $(HOST_BUILD_DIR)/openwrt-native.txt \
  92. $(MESON_HOST_ARGS) \
  93. $(MESON_HOST_BUILD_DIR) \
  94. $(HOST_BUILD_DIR), \
  95. $(MESON_HOST_VARS))
  96. endef
  97. define Host/Compile/Meson
  98. +$(NINJA) -C $(MESON_HOST_BUILD_DIR) $(1)
  99. endef
  100. define Host/Install/Meson
  101. +$(NINJA) -C $(MESON_HOST_BUILD_DIR) install
  102. endef
  103. define Host/Uninstall/Meson
  104. +$(NINJA) -C $(MESON_HOST_BUILD_DIR) uninstall
  105. endef
  106. define Build/Configure/Meson
  107. $(call Meson/CreateNativeFile,$(PKG_BUILD_DIR)/openwrt-native.txt)
  108. $(call Meson/CreateCrossFile,$(PKG_BUILD_DIR)/openwrt-cross.txt)
  109. $(call Meson, \
  110. --buildtype plain \
  111. --native-file $(PKG_BUILD_DIR)/openwrt-native.txt \
  112. --cross-file $(PKG_BUILD_DIR)/openwrt-cross.txt \
  113. $(MESON_ARGS) \
  114. $(MESON_BUILD_DIR) \
  115. $(MESON_BUILD_DIR)/.., \
  116. $(MESON_VARS))
  117. endef
  118. define Build/Compile/Meson
  119. +$(NINJA) -C $(MESON_BUILD_DIR) $(1)
  120. endef
  121. define Build/Install/Meson
  122. +DESTDIR="$(PKG_INSTALL_DIR)" $(NINJA) -C $(MESON_BUILD_DIR) install
  123. endef
  124. Host/Configure=$(call Host/Configure/Meson)
  125. Host/Compile=$(call Host/Compile/Meson)
  126. Host/Install=$(call Host/Install/Meson)
  127. Host/Uninstall=$(call Host/Uninstall/Meson)
  128. Build/Configure=$(call Build/Configure/Meson)
  129. Build/Compile=$(call Build/Compile/Meson)
  130. Build/Install=$(call Build/Install/Meson)