kernel/Makefile: check kernelsu driver version from online git repo first, if fails then check local .git and if that also fails then use hardcoded fallback

Co-authored-by: rifsxd <rifat.44.azad.rifs@gmail.com>
This commit is contained in:
ShirkNeko
2025-06-21 17:11:42 +08:00
parent aef862e91a
commit 4c4dce98f4

View File

@@ -18,19 +18,32 @@ obj-$(CONFIG_KSU) += kernelsu.o
obj-$(CONFIG_KPM) += kpm/ obj-$(CONFIG_KPM) += kpm/
REPO_OWNER := SukiSU-Ultra
REPO_NAME := SukiSU-Ultra
REPO_BRANCH := main
# .git is a text file while the module is imported by 'git submodule add'. GIT_BIN := /usr/bin/env PATH="$$PATH":/usr/bin:/usr/local/bin git
CURL_BIN := /usr/bin/env PATH="$$PATH":/usr/bin:/usr/local/bin curl
KSU_GITHUB_VERSION := $(shell $(CURL_BIN) -sI "https://api.github.com/repos/$(REPO_OWNER)/$(REPO_NAME)/commits?sha=$(REPO_BRANCH)&per_page=1" | grep -i "link:" | sed -n 's/.*page=\([0-9]*\)>; rel="last".*/\1/p')
ifeq ($(KSU_GITHUB_VERSION),)
ifeq ($(shell test -e $(srctree)/$(src)/../.git; echo $$?),0) ifeq ($(shell test -e $(srctree)/$(src)/../.git; echo $$?),0)
$(shell cd $(srctree)/$(src); /usr/bin/env PATH="$$PATH":/usr/bin:/usr/local/bin [ -f ../.git/shallow ] && git fetch --unshallow) $(shell cd $(srctree)/$(src); [ -f ../.git/shallow ] && $(GIT_BIN) fetch --unshallow)
KSU_GIT_VERSION := $(shell cd $(srctree)/$(src); /usr/bin/env PATH="$$PATH":/usr/bin:/usr/local/bin git rev-list --count main) KSU_LOCAL_VERSION := $(shell cd $(srctree)/$(src); $(GIT_BIN) rev-list --count HEAD)
# ksu_version: major * 10000 + git version + 606 for historical reasons $(eval KSU_VERSION := $(shell expr 10000 + $(KSU_LOCAL_VERSION) + 700))
$(eval KSU_VERSION=$(shell expr 10000 + $(KSU_GIT_VERSION) + 606)) $(info -- SukiSU-Ultra version (local .git): $(KSU_VERSION))
$(info -- SukiSU version: $(KSU_VERSION)) else
ccflags-y += -DKSU_VERSION=$(KSU_VERSION) $(eval KSU_VERSION := 13000)
else # If there is no .git file, the default version will be passed. $(warning -- Could not fetch version online or via local .git! Using fallback version: $(KSU_VERSION))
$(warning "KSU_GIT_VERSION not defined! It is better to make SukiSU a git submodule!")
ccflags-y += -DKSU_VERSION=12800
endif endif
else
$(eval KSU_VERSION := $(shell expr 10000 + $(KSU_GITHUB_VERSION) + 700))
$(info -- SukiSU-Ultra version (GitHub): $(KSU_VERSION))
endif
$(info -- SukiSU-Ultra version: $(KSU_VERSION))
ccflags-y += -DKSU_VERSION=$(KSU_VERSION)
# Checks hooks state # Checks hooks state
ifeq ($(strip $(CONFIG_KSU_MANUAL_HOOK)),y) ifeq ($(strip $(CONFIG_KSU_MANUAL_HOOK)),y)