[PATCH 1/3] rules: add commitcount function

Paul Spooren mail at aparcar.org
Thu Jan 7 03:59:46 EST 2021


`commitcount` returns the number of commits affecting the current
folder. The newly added function can be used for packages that do not
follow a traditional versioning schema, most prominent `base-files`
which requires tedious `PKG_RELEASE` bumps.

Below a naming example:

	base-files_1399-r15385+75-c5d033a34d_x86_64.ipk

In cases where no Git system is used, a folder timestamp is used in
combination with the hardcoded $(REVISION) variable (set in releases).

	base-files_210107.30634-r1538581-c5d033a34d_x86_64.ipk

Signed-off-by: Paul Spooren <mail at aparcar.org>
---
 rules.mk | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/rules.mk b/rules.mk
index f79340b124..8ccecb89d5 100644
--- a/rules.mk
+++ b/rules.mk
@@ -408,6 +408,28 @@ endef
 # file extension
 ext=$(word $(words $(subst ., ,$(1))),$(subst ., ,$(1)))
 
+define commitcount
+	$(shell \
+		if git log -1 >/dev/null 2>/dev/null; then \
+			set -- $$(git rev-list --count HEAD .); \
+			if [ -n "$$1" ]; then
+				echo "$$1"; \
+			else \
+				echo "unknown"; \
+			fi; \
+		else \
+			ts=$$(find . -type f -printf '%T@\n' 2>/dev/null | sort -rn | head -n1 | cut -d. -f1); \
+			if [ -n "$$ts" ]; then \
+				secs="$$(($$ts % 86400))"; \
+				date="$$(date --utc --date="@$$ts" "+%y%m%d")"; \
+				printf '%s.%05d' "$$date" "$$secs"; \
+			else \
+				echo "unknown"; \
+			fi; \
+		fi \
+	)
+endef
+
 all:
 FORCE: ;
 .PHONY: FORCE
-- 
2.29.2




More information about the openwrt-devel mailing list