From 110e59049e73686a145921450c738733c9e79317 Mon Sep 17 00:00:00 2001
From: Kieran Bingham <kieran.bingham@ideasonboard.com>
Date: Thu, 17 Nov 2022 20:25:35 +0000
Subject: Makefile: Provide a make wrapper around meson

Provide a convenience wrapper around the build system to allow
auto-complete and simply targets.

'make help' will report the available options.

Reviewed-by: Daniel Scally <dan.scally@ideasonboard.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
---
 Makefile | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 55 insertions(+)
 create mode 100644 Makefile

diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..2f88df0
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,55 @@
+ifeq ("$(origin V)", "command line")
+  VERBOSE = $(V)
+endif
+ifeq ($(VERBOSE),1)
+  ninja_args = -v -j1
+endif
+
+ninja = ninja $(ninja_args)
+
+all: uvc-gadget
+
+BUILDDIR=build/
+
+.PHONY: help
+## MakeHelp: Discovered in gphotos-uploader-cli
+help: ## Show this help
+	@grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | \
+	 sort | \
+	 awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
+
+reconfigure: ## Reconfigure the build
+reconfigure: RECONFIGURE=--reconfigure
+
+asan: ## Reconfigure with the address sanitizer enabled
+asan: ASAN="-Db_sanitize=address,undefined"
+asan: reconfigure
+
+configure: ## Configure the build
+$(BUILDDIR)/build.ninja reconfigure configure:
+	meson $(BUILDDIR) \
+		$(RECONFIGURE) $(ASAN) \
+		-Dprefix=/usr
+
+uvc-gadget: ## Build the uvc-gadget library and application
+uvc-gadget: | $(BUILDDIR)/build.ninja
+	$(ninja) -C $(BUILDDIR)
+
+.PHONY: test
+test: ## Run tests
+install: ## Install the package on this system. (Or set DESTDIR)
+test install: | $(BUILDDIR)/build.ninja
+	$(ninja) -C $(BUILDDIR) $*
+
+iwyu: ## Generate include-what-you-use report
+	iwyu_tool -p $(BUILDDIR) -j4 > iwyu.report
+	echo "Generated iwyu.report"
+
+.PHONY: package
+package: ## Install to a temporary package/ directory
+	mkdir -p package
+	DESTDIR=$(shell pwd)/package \
+		$(ninja) -C $(BUILDDIR) install
+
+clean: ## Remove build entirely
+	rm -rf $(BUILDDIR)
-- 
cgit v1.2.3