tools: add meson
authorRosen Penev <rosenp@gmail.com>
Thu, 17 Jun 2021 21:21:44 +0000 (14:21 -0700)
committerPaul Spooren <mail@aparcar.org>
Thu, 24 Jun 2021 17:42:38 +0000 (07:42 -1000)
Signed-off-by: Rosen Penev <rosenp@gmail.com>
include/meson.mk [new file with mode: 0644]
tools/Makefile
tools/meson/Makefile [new file with mode: 0644]
tools/meson/src/openwrt-cross.txt.in [new file with mode: 0644]
tools/meson/src/openwrt-native.txt.in [new file with mode: 0644]

diff --git a/include/meson.mk b/include/meson.mk
new file mode 100644 (file)
index 0000000..c30e5d9
--- /dev/null
@@ -0,0 +1,143 @@
+# To build your package using meson:
+#
+# include $(INCLUDE_DIR)/meson.mk
+# MESON_ARGS+=-Dfoo -Dbar=baz
+#
+# To pass additional environment variables to meson:
+#
+# MESON_VARS+=FOO=bar
+#
+# Default configure/compile/install targets are provided, but can be
+# overwritten if required:
+#
+# define Build/Configure
+#   $(call Build/Configure/Meson)
+#   ...
+# endef
+#
+# same for Build/Compile and Build/Install
+#
+# Host packages are built in the same fashion, just use these vars instead:
+#
+# HOST_BUILD_DEPENDS:=meson/host
+# MESON_HOST_ARGS+=-Dfoo -Dbar=baz
+# MESON_HOST_VARS+=FOO=bar
+
+MESON_DIR:=$(STAGING_DIR_HOST)/lib/meson
+
+MESON_HOST_BUILD_DIR:=$(HOST_BUILD_DIR)/openwrt-build
+MESON_HOST_VARS:=
+MESON_HOST_ARGS:=
+
+MESON_BUILD_DIR:=$(PKG_BUILD_DIR)/openwrt-build
+MESON_VARS:=
+MESON_ARGS:=
+
+ifneq ($(findstring i386,$(CONFIG_ARCH)),)
+MESON_ARCH:="x86"
+else ifneq ($(findstring powerpc64,$(CONFIG_ARCH)),)
+MESON_ARCH:="ppc64"
+else ifneq ($(findstring powerpc,$(CONFIG_ARCH)),)
+MESON_ARCH:="ppc"
+else ifneq ($(findstring mips64el,$(CONFIG_ARCH)),)
+MESON_ARCH:="mips64"
+else ifneq ($(findstring mipsel,$(CONFIG_ARCH)),)
+MESON_ARCH:="mips"
+else ifneq ($(findstring armeb,$(CONFIG_ARCH)),)
+MESON_ARCH:="arm"
+else
+MESON_ARCH:=$(CONFIG_ARCH)
+endif
+
+# this is undefined for just x64_64
+ifeq ($(origin CPU_TYPE),undefined)
+MESON_CPU:="generic"
+else
+MESON_CPU:="$(CPU_TYPE)$(if $(CPU_SUBTYPE),+$(CPU_SUBTYPE))"
+endif
+
+define Meson
+       $(2) $(STAGING_DIR_HOST)/bin/$(PYTHON) $(MESON_DIR)/meson.py $(1)
+endef
+
+define Meson/CreateNativeFile
+       $(STAGING_DIR_HOST)/bin/sed \
+               -e "s|@CC@|$(foreach BIN,$(HOSTCC),'$(BIN)',)|" \
+               -e "s|@CXX@|$(foreach BIN,$(HOSTCXX),'$(BIN)',)|" \
+               -e "s|@PKGCONFIG@|$(PKG_CONFIG)|" \
+               -e "s|@CFLAGS@|$(foreach FLAG,$(HOST_CFLAGS) $(HOST_CPPFLAGS),'$(FLAG)',)|" \
+               -e "s|@CXXFLAGS@|$(foreach FLAG,$(HOST_CXXFLAGS) $(HOST_CPPFLAGS),'$(FLAG)',)|" \
+               -e "s|@LDFLAGS@|$(foreach FLAG,$(HOST_LDFLAGS),'$(FLAG)',)|" \
+               -e "s|@PREFIX@|$(HOST_BUILD_PREFIX)|" \
+               < $(MESON_DIR)/openwrt-native.txt.in \
+               > $(1)
+endef
+
+define Meson/CreateCrossFile
+       $(STAGING_DIR_HOST)/bin/sed \
+               -e "s|@CC@|$(foreach BIN,$(TARGET_CC),'$(BIN)',)|" \
+               -e "s|@CXX@|$(foreach BIN,$(TARGET_CXX),'$(BIN)',)|" \
+               -e "s|@AR@|$(TARGET_AR)|" \
+               -e "s|@STRIP@|$(TARGET_CROSS)strip|" \
+               -e "s|@NM@|$(TARGET_NM)|" \
+               -e "s|@PKGCONFIG@|$(PKG_CONFIG)|" \
+               -e "s|@CFLAGS@|$(foreach FLAG,$(TARGET_CFLAGS) $(EXTRA_CFLAGS) $(TARGET_CPPFLAGS) $(EXTRA_CPPFLAGS),'$(FLAG)',)|" \
+               -e "s|@CXXFLAGS@|$(foreach FLAG,$(TARGET_CXXFLAGS) $(EXTRA_CXXFLAGS) $(TARGET_CPPFLAGS) $(EXTRA_CPPFLAGS),'$(FLAG)',)|" \
+               -e "s|@LDFLAGS@|$(foreach FLAG,$(TARGET_LDFLAGS) $(EXTRA_LDFLAGS),'$(FLAG)',)|" \
+               -e "s|@ARCH@|$(MESON_ARCH)|" \
+               -e "s|@CPU@|$(MESON_CPU)|" \
+               -e "s|@ENDIAN@|$(if $(CONFIG_BIG_ENDIAN),big,little)|" \
+               < $(MESON_DIR)/openwrt-cross.txt.in \
+               > $(1)
+endef
+
+define Host/Configure/Meson
+       $(call Meson/CreateNativeFile,$(HOST_BUILD_DIR)/openwrt-native.txt)
+       $(call Meson, \
+               --native-file $(HOST_BUILD_DIR)/openwrt-native.txt \
+               $(MESON_HOST_ARGS) \
+               $(MESON_HOST_BUILD_DIR) \
+               $(HOST_BUILD_DIR), \
+               $(MESON_HOST_VARS))
+endef
+
+define Host/Compile/Meson
+       +$(NINJA) -C $(MESON_HOST_BUILD_DIR) $(1)
+endef
+
+define Host/Install/Meson
+       +$(NINJA) -C $(MESON_HOST_BUILD_DIR) install
+endef
+
+define Host/Uninstall/Meson
+       +$(NINJA) -C $(MESON_HOST_BUILD_DIR) uninstall
+endef
+
+define Build/Configure/Meson
+       $(call Meson/CreateNativeFile,$(PKG_BUILD_DIR)/openwrt-native.txt)
+       $(call Meson/CreateCrossFile,$(PKG_BUILD_DIR)/openwrt-cross.txt)
+       $(call Meson, \
+               --buildtype plain \
+               --native-file $(PKG_BUILD_DIR)/openwrt-native.txt \
+               --cross-file $(PKG_BUILD_DIR)/openwrt-cross.txt \
+               $(MESON_ARGS) \
+               $(MESON_BUILD_DIR) \
+               $(MESON_BUILD_DIR)/.., \
+               $(MESON_VARS))
+endef
+
+define Build/Compile/Meson
+       +$(NINJA) -C $(MESON_BUILD_DIR) $(1)
+endef
+
+define Build/Install/Meson
+       +DESTDIR="$(PKG_INSTALL_DIR)" $(NINJA) -C $(MESON_BUILD_DIR) install
+endef
+
+Host/Configure=$(call Host/Configure/Meson)
+Host/Compile=$(call Host/Compile/Meson)
+Host/Install=$(call Host/Install/Meson)
+Host/Uninstall=$(call Host/Uninstall/Meson)
+Build/Configure=$(call Build/Configure/Meson)
+Build/Compile=$(call Build/Compile/Meson)
+Build/Install=$(call Build/Install/Meson)
index a48aa80db3ad88eb1a9371f8cf34bb24b22d3260..c9a7547b582e7fbcae4aa45525ded761f19fc441 100644 (file)
@@ -23,7 +23,7 @@ endif
 
 tools-y += autoconf autoconf-archive automake bc bison cmake cpio dosfstools
 tools-y += e2fsprogs fakeroot findutils firmware-utils flex gengetopt
-tools-y += libressl libtool lzma m4 make-ext4fs missing-macros mkimage
+tools-y += libressl libtool lzma m4 make-ext4fs meson missing-macros mkimage
 tools-y += mklibs mm-macros mtd-utils mtools ninja padjffs2 patch-image
 tools-y += patchelf pkgconf quilt squashfskit4 sstrip xxd zip zlib zstd
 tools-$(BUILD_B43_TOOLS) += b43-tools
diff --git a/tools/meson/Makefile b/tools/meson/Makefile
new file mode 100644 (file)
index 0000000..f8e2bca
--- /dev/null
@@ -0,0 +1,32 @@
+include $(TOPDIR)/rules.mk
+
+PKG_NAME:=meson
+PKG_VERSION:=0.57.2
+
+PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
+PKG_SOURCE_URL:=https://github.com/mesonbuild/meson/releases/download/$(PKG_VERSION)
+PKG_HASH:=3a83e7b1c5de94fa991ec34d9b198d94f38ed699d3524cb0fdf3b99fd23d4cc5
+
+PKG_MAINTAINER:=Andre Heider <a.heider@gmail.com>
+PKG_LICENSE:=Apache-2.0
+PKG_LICENSE_FILES:=COPYING
+
+include $(INCLUDE_DIR)/host-build.mk
+
+define Host/Configure
+endef
+
+define Host/Compile
+endef
+
+define Host/Install
+       $(INSTALL_DIR) $(STAGING_DIR_HOST)/lib/meson
+       $(CP) $(HOST_BUILD_DIR)/* $(STAGING_DIR_HOST)/lib/meson/
+endef
+
+define Host/Clean
+       $(call Host/Clean/Default)
+       rm -rf $(STAGING_DIR_HOST)/lib/meson
+endef
+
+$(eval $(call HostBuild))
diff --git a/tools/meson/src/openwrt-cross.txt.in b/tools/meson/src/openwrt-cross.txt.in
new file mode 100644 (file)
index 0000000..30b4c11
--- /dev/null
@@ -0,0 +1,23 @@
+[binaries]
+c = [@CC@]
+cpp = [@CXX@]
+ar = '@AR@'
+strip = '@STRIP@'
+nm = '@NM@'
+pkgconfig = '@PKGCONFIG@'
+
+[built-in options]
+c_args = [@CFLAGS@]
+c_link_args = [@LDFLAGS@]
+cpp_args = [@CXXFLAGS@]
+cpp_link_args = [@LDFLAGS@]
+prefix = '/usr'
+
+[host_machine]
+system = 'linux'
+cpu_family = '@ARCH@'
+cpu = '@CPU@'
+endian = '@ENDIAN@'
+
+[properties]
+needs_exe_wrapper = true
diff --git a/tools/meson/src/openwrt-native.txt.in b/tools/meson/src/openwrt-native.txt.in
new file mode 100644 (file)
index 0000000..50308ec
--- /dev/null
@@ -0,0 +1,13 @@
+[binaries]
+c = [@CC@]
+cpp = [@CXX@]
+pkgconfig = '@PKGCONFIG@'
+
+[built-in options]
+c_args = [@CFLAGS@]
+c_link_args = [@LDFLAGS@]
+cpp_args = [@CXXFLAGS@]
+cpp_link_args = [@LDFLAGS@]
+prefix = '@PREFIX@'
+sbindir = 'bin'
+libdir = 'lib'