b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame] | 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 | |
| 25 | MESON_DIR:=$(STAGING_DIR_HOST)/lib/meson |
| 26 | |
| 27 | MESON_HOST_BUILD_DIR:=$(HOST_BUILD_DIR)/openwrt-build |
| 28 | MESON_HOST_VARS:= |
| 29 | MESON_HOST_ARGS:= |
| 30 | |
| 31 | MESON_BUILD_DIR:=$(PKG_BUILD_DIR)/openwrt-build |
| 32 | MESON_VARS:= |
| 33 | MESON_ARGS:= |
| 34 | |
| 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 | |
| 51 | # this is undefined for just x64_64 |
| 52 | ifeq ($(origin CPU_TYPE),undefined) |
| 53 | MESON_CPU:="generic" |
| 54 | else |
| 55 | MESON_CPU:="$(CPU_TYPE)$(if $(CPU_SUBTYPE),+$(CPU_SUBTYPE))" |
| 56 | endif |
| 57 | |
| 58 | define Meson |
| 59 | $(2) $(STAGING_DIR_HOST)/bin/$(PYTHON) $(STAGING_DIR_HOST)/bin/meson.py $(1) |
| 60 | endef |
| 61 | |
| 62 | define Meson/CreateNativeFile |
| 63 | $(STAGING_DIR_HOST)/bin/sed \ |
| 64 | -e "s|@CC@|$(foreach BIN,$(HOSTCC),'$(BIN)',)|" \ |
| 65 | -e "s|@CXX@|$(foreach BIN,$(HOSTCXX),'$(BIN)',)|" \ |
| 66 | -e "s|@PKGCONFIG@|$(PKG_CONFIG)|" \ |
| 67 | -e "s|@CMAKE@|$(STAGING_DIR_HOST)/bin/cmake|" \ |
| 68 | -e "s|@PYTHON@|$(STAGING_DIR_HOST)/bin/python3|" \ |
| 69 | -e "s|@CFLAGS@|$(foreach FLAG,$(HOST_CFLAGS) $(HOST_CPPFLAGS),'$(FLAG)',)|" \ |
| 70 | -e "s|@CXXFLAGS@|$(foreach FLAG,$(HOST_CXXFLAGS) $(HOST_CPPFLAGS),'$(FLAG)',)|" \ |
| 71 | -e "s|@LDFLAGS@|$(foreach FLAG,$(HOST_LDFLAGS),'$(FLAG)',)|" \ |
| 72 | -e "s|@PREFIX@|$(HOST_BUILD_PREFIX)|" \ |
| 73 | < $(MESON_DIR)/openwrt-native.txt.in \ |
| 74 | > $(1) |
| 75 | endef |
| 76 | |
| 77 | define Meson/CreateCrossFile |
| 78 | $(STAGING_DIR_HOST)/bin/sed \ |
| 79 | -e "s|@CC@|$(foreach BIN,$(TARGET_CC),'$(BIN)',)|" \ |
| 80 | -e "s|@CXX@|$(foreach BIN,$(TARGET_CXX),'$(BIN)',)|" \ |
| 81 | -e "s|@LD@|$(foreach FLAG,$(TARGET_LINKER),'$(FLAG)',)|" \ |
| 82 | -e "s|@AR@|$(TARGET_AR)|" \ |
| 83 | -e "s|@STRIP@|$(TARGET_CROSS)strip|" \ |
| 84 | -e "s|@NM@|$(TARGET_NM)|" \ |
| 85 | -e "s|@PKGCONFIG@|$(PKG_CONFIG)|" \ |
| 86 | -e "s|@CMAKE@|$(STAGING_DIR_HOST)/bin/cmake|" \ |
| 87 | -e "s|@PYTHON@|$(STAGING_DIR_HOST)/bin/python3|" \ |
| 88 | -e "s|@CFLAGS@|$(foreach FLAG,$(TARGET_CFLAGS) $(EXTRA_CFLAGS) $(TARGET_CPPFLAGS) $(EXTRA_CPPFLAGS),'$(FLAG)',)|" \ |
| 89 | -e "s|@CXXFLAGS@|$(foreach FLAG,$(TARGET_CXXFLAGS) $(EXTRA_CXXFLAGS) $(TARGET_CPPFLAGS) $(EXTRA_CPPFLAGS),'$(FLAG)',)|" \ |
| 90 | -e "s|@LDFLAGS@|$(foreach FLAG,$(TARGET_LDFLAGS) $(EXTRA_LDFLAGS),'$(FLAG)',)|" \ |
| 91 | -e "s|@ARCH@|$(MESON_ARCH)|" \ |
| 92 | -e "s|@CPU@|$(MESON_CPU)|" \ |
| 93 | -e "s|@ENDIAN@|$(if $(CONFIG_BIG_ENDIAN),big,little)|" \ |
| 94 | < $(MESON_DIR)/openwrt-cross.txt.in \ |
| 95 | > $(1) |
| 96 | endef |
| 97 | |
| 98 | define Host/Configure/Meson |
| 99 | $(call Meson/CreateNativeFile,$(HOST_BUILD_DIR)/openwrt-native.txt) |
| 100 | $(call Meson, \ |
| 101 | setup \ |
| 102 | --native-file $(HOST_BUILD_DIR)/openwrt-native.txt \ |
| 103 | -Ddefault_library=static \ |
| 104 | $(MESON_HOST_ARGS) \ |
| 105 | $(MESON_HOST_BUILD_DIR) \ |
| 106 | $(MESON_HOST_BUILD_DIR)/.., \ |
| 107 | $(MESON_HOST_VARS)) |
| 108 | endef |
| 109 | |
| 110 | define Host/Compile/Meson |
| 111 | +$(NINJA) -C $(MESON_HOST_BUILD_DIR) $(1) |
| 112 | endef |
| 113 | |
| 114 | define Host/Install/Meson |
| 115 | +$(NINJA) -C $(MESON_HOST_BUILD_DIR) install |
| 116 | endef |
| 117 | |
| 118 | define Host/Uninstall/Meson |
| 119 | +$(NINJA) -C $(MESON_HOST_BUILD_DIR) uninstall || true |
| 120 | endef |
| 121 | |
| 122 | define Build/Configure/Meson |
| 123 | $(call Meson/CreateNativeFile,$(PKG_BUILD_DIR)/openwrt-native.txt) |
| 124 | $(call Meson/CreateCrossFile,$(PKG_BUILD_DIR)/openwrt-cross.txt) |
| 125 | $(call Meson, \ |
| 126 | setup \ |
| 127 | --buildtype $(if $(CONFIG_DEBUG),debug,plain) \ |
| 128 | --native-file $(PKG_BUILD_DIR)/openwrt-native.txt \ |
| 129 | --cross-file $(PKG_BUILD_DIR)/openwrt-cross.txt \ |
| 130 | -Ddefault_library=both \ |
| 131 | $(MESON_ARGS) \ |
| 132 | $(MESON_BUILD_DIR) \ |
| 133 | $(MESON_BUILD_DIR)/.., \ |
| 134 | $(MESON_VARS)) |
| 135 | endef |
| 136 | |
| 137 | define Build/Compile/Meson |
| 138 | +$(NINJA) -C $(MESON_BUILD_DIR) $(1) |
| 139 | endef |
| 140 | |
| 141 | define Build/Install/Meson |
| 142 | +DESTDIR="$(PKG_INSTALL_DIR)" $(NINJA) -C $(MESON_BUILD_DIR) install |
| 143 | endef |
| 144 | |
| 145 | Host/Configure=$(call Host/Configure/Meson) |
| 146 | Host/Compile=$(call Host/Compile/Meson) |
| 147 | Host/Install=$(call Host/Install/Meson) |
| 148 | Host/Uninstall=$(call Host/Uninstall/Meson) |
| 149 | Build/Configure=$(call Build/Configure/Meson) |
| 150 | Build/Compile=$(call Build/Compile/Meson) |
| 151 | Build/Install=$(call Build/Install/Meson) |