summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarel Kočí <cynerd@email.cz>2018-08-24 18:34:01 +0200
committerKarel Kočí <cynerd@email.cz>2018-08-24 18:34:01 +0200
commit041418da93ee5c4711f5cff53d0c419ae4654765 (patch)
treecd83835d9b107a9739debcf85001f0a09e93f8ac
parent18c54a7a09959277b31c7671d87f94162da116af (diff)
downloadopenwrt-personal-pkgs-041418da93ee5c4711f5cff53d0c419ae4654765.tar.gz
openwrt-personal-pkgs-041418da93ee5c4711f5cff53d0c419ae4654765.tar.bz2
openwrt-personal-pkgs-041418da93ee5c4711f5cff53d0c419ae4654765.zip
Add autopkg machinery
-rw-r--r--autopkg-branch.mk24
-rw-r--r--autopkg-common.mk37
-rw-r--r--autopkg-tag.mk11
3 files changed, 72 insertions, 0 deletions
diff --git a/autopkg-branch.mk b/autopkg-branch.mk
new file mode 100644
index 0000000..871cffb
--- /dev/null
+++ b/autopkg-branch.mk
@@ -0,0 +1,24 @@
+# Autopkg tracking given branch
+AUTOPKG_VARIANT:=branch
+$(call include_mk, autopkg-common.mk)
+
+ifndef PKG_SOURCE_BRANCH
+$(error You have to define PKG_SOURCE_BRANCH before pkgauto.mk include)
+endif
+
+PKG_SOURCE_VERSION:=$(shell git $(GIT_ARGS) rev-parse "$(PKG_SOURCE_BRANCH)")
+PKG_VERSION:=$(shell git $(GIT_ARGS) describe --abbrev=0 --tags "$(PKG_SOURCE_BRANCH)")
+
+ifeq ($(PKG_VERSION),)
+# Count commits since initial commit.
+PKG_RELEASE:=$(shell git $(GIT_ARGS) rev-list --count "$(PKG_SOURCE_VERSION)")
+# No previous version found (no tag) so we use 9999 instead
+PKG_VERSION:=9999
+else
+# Count commits since last version tag
+PKG_RELEASE:=$(shell git $(GIT_ARGS) rev-list --count "$(PKG_VERSION)..$(PKG_SOURCE_VERSION)")
+# .9999 is appended to not collide with possible existing package versions in repository
+PKG_VERSION:=$(PKG_VERSION:v%=%).9999
+endif
+
+$(eval $(call AUTOPKG_TAIL))
diff --git a/autopkg-common.mk b/autopkg-common.mk
new file mode 100644
index 0000000..73cff51
--- /dev/null
+++ b/autopkg-common.mk
@@ -0,0 +1,37 @@
+ifndef AUTOPKG_VARIANT
+ $(error "Don't include autopkg-common.mk directly!")
+endif
+
+ifndef PKG_NAME
+$(error You have to define PKG_NAME before pkgauto.mk include)
+endif
+ifndef PKG_SOURCE_URL
+$(error You have to define PKG_SOURCE_URL before pkgauto.mk include)
+endif
+
+TMP_REPO_PATH=$(DL_DIR)/autopkg/$(PKG_NAME)
+GIT_ARGS=--git-dir='$(TMP_REPO_PATH)' --bare
+
+# Clone/update git history to bare repository
+# TODO it is possible that this won't fetch when there is force push to repository
+$(shell \
+ if [ ! -d "$(TMP_REPO_PATH)" ]; then \
+ git clone --bare "$(PKG_SOURCE_URL)" "$(TMP_REPO_PATH)"; \
+ else \
+ git $(GIT_ARGS) fetch --prune --prune-tags --force "$(PKG_SOURCE_URL)"; \
+ fi)
+
+
+define AUTOPKG_TAIL
+
+PKG_SOURCE_PROTO:=git
+PKG_SOURCE:=$(PKG_NAME)-$(PKG_SOURCE_VERSION).tar.gz
+PKG_SOURCE_SUBDIR:=$(PKG_NAME)
+PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)
+HOST_BUILD_DIR:=$(BUILD_DIR_HOST)/$(PKG_NAME)
+
+undefine TMP_REPO_PATH
+undefine GIT_ARGS
+undefine AUTOPKG_TAIL
+
+endef
diff --git a/autopkg-tag.mk b/autopkg-tag.mk
new file mode 100644
index 0000000..9e97ed7
--- /dev/null
+++ b/autopkg-tag.mk
@@ -0,0 +1,11 @@
+# Autopkg tracking latest version tag
+AUTOPKG_VARIANT:=tag
+$(call include_mk, autopkg-common.mk)
+
+# Explicitly fetch branch
+$(shell git $(GIT_ARGS) fetch --prune --prune-tags --force "$(PKG_SOURCE_URL)" "$(PKG_SOURCE_BRANCH):$(PKG_SOURCE_BRANCH)")
+
+PKG_SOURCE_VERSION:=$(shell git $(GIT_ARGS) tag | grep '^v' | sort | tail -1)
+PKG_VERSION:=$(subst v%,%,$(PKG_SOURCE_VERSION))
+
+$(eval $(call AUTOPKG_TAIL))