1
0

meson.mk 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. # To build your package using meson:
  2. #
  3. # include $(INCLUDE_DIR)/meson.mk
  4. # MESON_ARGS+=-Dfoo -Dbar=baz
  5. #
  6. # To pass additional environment variables to meson:
  7. #
  8. # MESON_VARS+=FOO=bar
  9. #
  10. # Default configure/compile/install targets are provided, but can be
  11. # overwritten if required:
  12. #
  13. # define Build/Configure
  14. # $(call Build/Configure/Meson)
  15. # ...
  16. # endef
  17. #
  18. # same for Build/Compile and Build/Install
  19. #
  20. # Host packages are built in the same fashion, just use these vars instead:
  21. #
  22. # MESON_HOST_ARGS+=-Dfoo -Dbar=baz
  23. # MESON_HOST_VARS+=FOO=bar
  24. MESON_DIR:=$(STAGING_DIR_HOST)/lib/meson
  25. MESON_HOST_BUILD_DIR:=$(HOST_BUILD_DIR)/librecmc-build
  26. MESON_HOST_VARS:=
  27. MESON_HOST_ARGS:=
  28. MESON_BUILD_DIR:=$(PKG_BUILD_DIR)/librecmc-build
  29. MESON_VARS:=
  30. MESON_ARGS:=
  31. ifneq ($(findstring i386,$(CONFIG_ARCH)),)
  32. MESON_ARCH:="x86"
  33. else ifneq ($(findstring powerpc64,$(CONFIG_ARCH)),)
  34. MESON_ARCH:="ppc64"
  35. else ifneq ($(findstring powerpc,$(CONFIG_ARCH)),)
  36. MESON_ARCH:="ppc"
  37. else ifneq ($(findstring mips64el,$(CONFIG_ARCH)),)
  38. MESON_ARCH:="mips64"
  39. else ifneq ($(findstring mipsel,$(CONFIG_ARCH)),)
  40. MESON_ARCH:="mips"
  41. else ifneq ($(findstring armeb,$(CONFIG_ARCH)),)
  42. MESON_ARCH:="arm"
  43. else
  44. MESON_ARCH:=$(CONFIG_ARCH)
  45. endif
  46. # this is undefined for just x64_64
  47. ifeq ($(origin CPU_TYPE),undefined)
  48. MESON_CPU:="generic"
  49. else
  50. MESON_CPU:="$(CPU_TYPE)$(if $(CPU_SUBTYPE),+$(CPU_SUBTYPE))"
  51. endif
  52. define Meson
  53. $(2) $(STAGING_DIR_HOST)/bin/$(PYTHON) $(STAGING_DIR_HOST)/bin/meson.py $(1)
  54. endef
  55. define Meson/CreateNativeFile
  56. $(STAGING_DIR_HOST)/bin/sed \
  57. -e "s|@CC@|$(foreach BIN,$(HOSTCC),'$(BIN)',)|" \
  58. -e "s|@CXX@|$(foreach BIN,$(HOSTCXX),'$(BIN)',)|" \
  59. -e "s|@PKGCONFIG@|$(PKG_CONFIG)|" \
  60. -e "s|@CMAKE@|$(STAGING_DIR_HOST)/bin/cmake|" \
  61. -e "s|@PYTHON@|$(STAGING_DIR_HOST)/bin/python3|" \
  62. -e "s|@CFLAGS@|$(foreach FLAG,$(HOST_CFLAGS) $(HOST_CPPFLAGS),'$(FLAG)',)|" \
  63. -e "s|@CXXFLAGS@|$(foreach FLAG,$(HOST_CXXFLAGS) $(HOST_CPPFLAGS),'$(FLAG)',)|" \
  64. -e "s|@LDFLAGS@|$(foreach FLAG,$(HOST_LDFLAGS),'$(FLAG)',)|" \
  65. -e "s|@PREFIX@|$(HOST_BUILD_PREFIX)|" \
  66. < $(MESON_DIR)/librecmc-native.txt.in \
  67. > $(1)
  68. endef
  69. define Meson/CreateCrossFile
  70. $(STAGING_DIR_HOST)/bin/sed \
  71. -e "s|@CC@|$(foreach BIN,$(TARGET_CC),'$(BIN)',)|" \
  72. -e "s|@CXX@|$(foreach BIN,$(TARGET_CXX),'$(BIN)',)|" \
  73. -e "s|@AR@|$(TARGET_AR)|" \
  74. -e "s|@STRIP@|$(TARGET_CROSS)strip|" \
  75. -e "s|@NM@|$(TARGET_NM)|" \
  76. -e "s|@PKGCONFIG@|$(PKG_CONFIG)|" \
  77. -e "s|@CMAKE@|$(STAGING_DIR_HOST)/bin/cmake|" \
  78. -e "s|@PYTHON@|$(STAGING_DIR_HOST)/bin/python3|" \
  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)/librecmc-cross.txt.in \
  86. > $(1)
  87. endef
  88. define Host/Configure/Meson
  89. $(call Meson/CreateNativeFile,$(HOST_BUILD_DIR)/librecmc-native.txt)
  90. $(call Meson, \
  91. --native-file $(HOST_BUILD_DIR)/librecmc-native.txt \
  92. $(MESON_HOST_ARGS) \
  93. $(MESON_HOST_BUILD_DIR) \
  94. $(MESON_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 || true
  105. endef
  106. define Build/Configure/Meson
  107. $(call Meson/CreateNativeFile,$(PKG_BUILD_DIR)/librecmc-native.txt)
  108. $(call Meson/CreateCrossFile,$(PKG_BUILD_DIR)/librecmc-cross.txt)
  109. $(call Meson, \
  110. --buildtype plain \
  111. --native-file $(PKG_BUILD_DIR)/librecmc-native.txt \
  112. --cross-file $(PKG_BUILD_DIR)/librecmc-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)