diff mbox series

[v2] libtraceevent: Add meson build targets to Makefile

Message ID 20240724132632.33d49bc2@gandalf.local.home (mailing list archive)
State Accepted
Commit d4c1fb44fafdf063d02d73a81845c4ae14ec051e
Headers show
Series [v2] libtraceevent: Add meson build targets to Makefile | expand

Commit Message

Steven Rostedt July 24, 2024, 5:26 p.m. UTC
From: "Steven Rostedt (Google)" <rostedt@goodmis.org>

Add make targets for building with meson:

  make meson
  make meson_install
  make meson_docs

Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
Changes since v1: https://lore.kernel.org/all/20231228215122.48c933ba@rorschach.local.home/

- use "meson setup [options]" instead of deprecated "meson [options]"

 Makefile       | 15 ++++++++++++++-
 Makefile.meson | 40 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 54 insertions(+), 1 deletion(-)
 create mode 100644 Makefile.meson
diff mbox series

Patch

diff --git a/Makefile b/Makefile
index 0ff8e9c3d981..fbb4422e4b3b 100644
--- a/Makefile
+++ b/Makefile
@@ -352,7 +352,7 @@  install_headers:
 
 install: install_libs
 
-clean: clean_plugins clean_src
+clean: clean_plugins clean_src clean_meson
 	$(Q)$(call do_clean,\
 	    $(VERSION_FILE) $(obj)/tags $(obj)/TAGS $(PKG_CONFIG_FILE) \
 	    $(LIBTRACEEVENT_STATIC) $(LIBTRACEEVENT_SHARED) \
@@ -436,6 +436,19 @@  PHONY += clean_src
 clean_src:
 	$(Q)$(call descend_clean,src)
 
+meson:
+	$(MAKE) -f Makefile.meson
+
+meson_install:
+	$(MAKE) -f Makefile.meson install
+
+meson_docs:
+	$(MAKE) -f Makefile.meson docs
+
+PHONY += clean_meson
+clean_meson:
+	$(Q)$(MAKE) -f Makefile.meson $@
+
 force:
 
 # Declare the contents of the .PHONY variable as phony.  We keep that
diff --git a/Makefile.meson b/Makefile.meson
new file mode 100644
index 000000000000..71d6bf36c654
--- /dev/null
+++ b/Makefile.meson
@@ -0,0 +1,40 @@ 
+# SPDX-License-Identifier: GPL-2.0
+
+undefine CFLAGS
+
+# Makefiles suck: This macro sets a default value of $(2) for the
+# variable named by $(1), unless the variable has been set by
+# environment or command line. This is necessary for CC and AR
+# because make sets default values, so the simpler ?= approach
+# won't work as expected.
+define allow-override
+  $(if $(or $(findstring environment,$(origin $(1))),\
+            $(findstring command line,$(origin $(1)))),,\
+    $(eval $(1) = $(2)))
+endef
+
+$(call allow-override,MESON,meson)
+$(call allow-override,MESON_BUILD_DIR,build)
+
+
+all: compile
+
+PHONY += compile
+compile: $(MESON_BUILD_DIR) force
+	$(MESON) compile -C $(MESON_BUILD_DIR)
+
+$(MESON_BUILD_DIR):
+	$(MESON) setup --prefix=$(prefix) $(MESON_BUILD_DIR)
+
+install: compile
+	$(MESON) install -C $(MESON_BUILD_DIR)
+
+docs: $(MESON_BUILD_DIR)
+	$(MESON) compile -C build docs
+
+PHONY += clean_meson
+clean_meson:
+	$(Q)$(RM) -rf $(MESON_BUILD_DIR)
+
+PHONY += force
+force: