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.

146 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. include $(dir $(lastword $(MAKEFILE_LIST)))/../../devel/ninja/ninja.mk
  27. MESON_DIR:=$(STAGING_DIR_HOSTPKG)/lib/meson
  28. MESON_HOST_BUILD_DIR:=$(HOST_BUILD_DIR)/openwrt-build
  29. MESON_HOST_VARS:=
  30. MESON_HOST_ARGS:=
  31. MESON_BUILD_DIR:=$(PKG_BUILD_DIR)/openwrt-build
  32. MESON_VARS:=
  33. MESON_ARGS:=
  34. ifneq ($(findstring i386,$(CONFIG_ARCH)),)
  35. MESON_ARCH:="x86"
  36. else ifneq ($(findstring powerpc64,$(CONFIG_ARCH)),)
  37. MESON_ARCH:="ppc64"
  38. else ifneq ($(findstring powerpc,$(CONFIG_ARCH)),)
  39. MESON_ARCH:="ppc"
  40. else ifneq ($(findstring mips64el,$(CONFIG_ARCH)),)
  41. MESON_ARCH:="mips64"
  42. else ifneq ($(findstring mipsel,$(CONFIG_ARCH)),)
  43. MESON_ARCH:="mips"
  44. else ifneq ($(findstring armeb,$(CONFIG_ARCH)),)
  45. MESON_ARCH:="arm"
  46. else
  47. MESON_ARCH:=$(CONFIG_ARCH)
  48. endif
  49. # this is undefined for just x64_64
  50. ifeq ($(origin CPU_TYPE),undefined)
  51. MESON_CPU:="generic"
  52. else
  53. MESON_CPU:="$(CPU_TYPE)$(if $(CPU_SUBTYPE),+$(CPU_SUBTYPE))"
  54. endif
  55. define Meson
  56. $(2) $(STAGING_DIR_HOST)/bin/$(PYTHON) $(MESON_DIR)/meson.py $(1)
  57. endef
  58. define Meson/CreateNativeFile
  59. $(STAGING_DIR_HOST)/bin/sed \
  60. -e "s|@CC@|$(foreach BIN,$(HOSTCC),'$(BIN)',)|" \
  61. -e "s|@CXX@|$(foreach BIN,$(HOSTCXX),'$(BIN)',)|" \
  62. -e "s|@PKGCONFIG@|$(PKG_CONFIG)|" \
  63. -e "s|@CFLAGS@|$(foreach FLAG,$(HOST_CFLAGS) $(HOST_CPPFLAGS),'$(FLAG)',)|" \
  64. -e "s|@CXXFLAGS@|$(foreach FLAG,$(HOST_CXXFLAGS) $(HOST_CPPFLAGS),'$(FLAG)',)|" \
  65. -e "s|@LDFLAGS@|$(foreach FLAG,$(HOST_LDFLAGS),'$(FLAG)',)|" \
  66. -e "s|@PREFIX@|$(STAGING_DIR_HOSTPKG)|" \
  67. < $(MESON_DIR)/openwrt-native.txt.in \
  68. > $(1)
  69. endef
  70. define Meson/CreateCrossFile
  71. $(STAGING_DIR_HOST)/bin/sed \
  72. -e "s|@CC@|$(foreach BIN,$(TARGET_CC),'$(BIN)',)|" \
  73. -e "s|@CXX@|$(foreach BIN,$(TARGET_CXX),'$(BIN)',)|" \
  74. -e "s|@AR@|$(TARGET_AR)|" \
  75. -e "s|@STRIP@|$(TARGET_CROSS)strip|" \
  76. -e "s|@NM@|$(TARGET_NM)|" \
  77. -e "s|@PKGCONFIG@|$(PKG_CONFIG)|" \
  78. -e "s|@CFLAGS@|$(foreach FLAG,$(TARGET_CFLAGS) $(EXTRA_CFLAGS) $(TARGET_CPPFLAGS) $(EXTRA_CPPFLAGS),'$(FLAG)',)|" \
  79. -e "s|@CXXFLAGS@|$(foreach FLAG,$(TARGET_CXXFLAGS) $(EXTRA_CXXFLAGS) $(TARGET_CPPFLAGS) $(EXTRA_CPPFLAGS),'$(FLAG)',)|" \
  80. -e "s|@LDFLAGS@|$(foreach FLAG,$(TARGET_LDFLAGS) $(EXTRA_LDFLAGS),'$(FLAG)',)|" \
  81. -e "s|@ARCH@|$(MESON_ARCH)|" \
  82. -e "s|@CPU@|$(MESON_CPU)|" \
  83. -e "s|@ENDIAN@|$(if $(CONFIG_BIG_ENDIAN),big,little)|" \
  84. < $(MESON_DIR)/openwrt-cross.txt.in \
  85. > $(1)
  86. endef
  87. define Host/Configure/Meson
  88. $(call Meson/CreateNativeFile,$(HOST_BUILD_DIR)/openwrt-native.txt)
  89. $(call Meson, \
  90. --native-file $(HOST_BUILD_DIR)/openwrt-native.txt \
  91. $(MESON_HOST_ARGS) \
  92. $(MESON_HOST_BUILD_DIR) \
  93. $(HOST_BUILD_DIR), \
  94. $(MESON_HOST_VARS))
  95. endef
  96. define Host/Compile/Meson
  97. $(call Ninja,-C $(MESON_HOST_BUILD_DIR),)
  98. endef
  99. define Host/Install/Meson
  100. $(call Ninja,-C $(MESON_HOST_BUILD_DIR) install,)
  101. endef
  102. define Host/Uninstall/Meson
  103. -$(call Ninja,-C $(MESON_HOST_BUILD_DIR) uninstall,)
  104. endef
  105. define Build/Configure/Meson
  106. $(call Meson/CreateNativeFile,$(PKG_BUILD_DIR)/openwrt-native.txt)
  107. $(call Meson/CreateCrossFile,$(PKG_BUILD_DIR)/openwrt-cross.txt)
  108. $(call Meson, \
  109. --buildtype plain \
  110. --native-file $(PKG_BUILD_DIR)/openwrt-native.txt \
  111. --cross-file $(PKG_BUILD_DIR)/openwrt-cross.txt \
  112. $(MESON_ARGS) \
  113. $(MESON_BUILD_DIR) \
  114. $(MESON_BUILD_DIR)/.., \
  115. $(MESON_VARS))
  116. endef
  117. define Build/Compile/Meson
  118. $(call Ninja,-C $(MESON_BUILD_DIR),)
  119. endef
  120. define Build/Install/Meson
  121. $(call Ninja,-C $(MESON_BUILD_DIR) install,DESTDIR="$(PKG_INSTALL_DIR)")
  122. endef
  123. Host/Configure=$(call Host/Configure/Meson)
  124. Host/Compile=$(call Host/Compile/Meson)
  125. Host/Install=$(call Host/Install/Meson)
  126. Host/Uninstall=$(call Host/Uninstall/Meson)
  127. Build/Configure=$(call Build/Configure/Meson)
  128. Build/Compile=$(call Build/Compile/Meson)
  129. Build/Install=$(call Build/Install/Meson)