diff options
author | Rosen Penev <rosenp@gmail.com> | 2021-06-17 14:21:44 -0700 |
---|---|---|
committer | Paul Spooren <mail@aparcar.org> | 2021-09-16 16:31:28 -1000 |
commit | c4dfdde2eaa399025de1032bed8ee8a5f8babb24 (patch) | |
tree | 246f3da0c888fb1a60b1c999b50dee1b454f3829 /include | |
parent | 4b898afdd2fd9dbbc99dbedca0d50785e3ec063d (diff) | |
download | openwrt-c4dfdde2eaa399025de1032bed8ee8a5f8babb24.tar.gz openwrt-c4dfdde2eaa399025de1032bed8ee8a5f8babb24.tar.bz2 openwrt-c4dfdde2eaa399025de1032bed8ee8a5f8babb24.zip |
tools: add meson
meson is a next generation build system designed to have good defaults,
simpler build files, and fast compilation.
It is built upon python and uses ninja for compilation. The latter
provides fast by default (parallel) and problem free compilation.
There are over 40 packages already successfully using meson. The next
commit will convert pkgconf to use meson compilation.
Signed-off-by: Rosen Penev <rosenp@gmail.com>
Diffstat (limited to 'include')
-rw-r--r-- | include/meson.mk | 143 |
1 files changed, 143 insertions, 0 deletions
diff --git a/include/meson.mk b/include/meson.mk new file mode 100644 index 0000000000..01d0ce0280 --- /dev/null +++ b/include/meson.mk @@ -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 || true +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) |