From 8bbaad10e0e5fd50f94214f5f55004fcbef28cc8 Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Mon, 6 Jul 2026 11:55:09 +0200 Subject: [PATCH] build: support git-src override for host builds Extend the git-src source tree override to host builds. It is opt-in via HOST_USE_GIT_SRC, since by default the host build keeps using the tarball. Move the git-src detection and checkout recipe into unpack.mk so both the target and host build reuse the same code. Signed-off-by: Felix Fietkau --- include/host-build.mk | 29 ++++++++++++++++++++++++++--- include/package.mk | 26 ++++---------------------- include/unpack.mk | 15 +++++++++++++++ 3 files changed, 45 insertions(+), 25 deletions(-) diff --git a/include/host-build.mk b/include/host-build.mk index 4dfa055db90..d78dbdd4c21 100644 --- a/include/host-build.mk +++ b/include/host-build.mk @@ -18,6 +18,20 @@ endif include $(INCLUDE_DIR)/unpack.mk include $(INCLUDE_DIR)/depends.mk + +# git-src is only honoured for the host build when a package opts in via +# HOST_USE_GIT_SRC, since by default the host build keeps using the tarball. +ifdef HOST_USE_GIT_SRC + ifneq ($(GIT_SRC_CHECKOUT_DIR),) + USE_HOST_GIT_SRC_CHECKOUT:=1 + HOST_QUILT:=1 + endif + ifneq ($(GIT_TREE_OVERRIDE_DIR),) + USE_HOST_GIT_TREE:=1 + HOST_QUILT:=1 + endif +endif + include $(INCLUDE_DIR)/quilt.mk BUILD_TYPES += host @@ -41,6 +55,13 @@ define Host/Prepare/Default $(Host/Patch) endef +ifdef USE_HOST_GIT_SRC_CHECKOUT + Host/Prepare/Default = $(call Prepare/git-src,$(HOST_BUILD_DIR),$(GIT_SRC_CHECKOUT_DIR)) +endif +ifdef USE_HOST_GIT_TREE + Host/Prepare/Default = $(call Prepare/git-src,$(HOST_BUILD_DIR),$(CURDIR)/git-src) +endif + define Host/Prepare $(call Host/Prepare/Default) endef @@ -226,9 +247,11 @@ endif define HostBuild $(HostBuild/Core) - $(if $(if $(PKG_HOST_ONLY),,$(if $(and $(filter host-%,$(MAKECMDGOALS)),$(PKG_SKIP_DOWNLOAD)),,$(STAMP_PREPARED))),, - $(if $(and $(CONFIG_AUTOREMOVE), $(wildcard $(HOST_STAMP_INSTALLED), $(wildcard $(HOST_STAMP_BUILT)))),, - $(if $(strip $(PKG_SOURCE_URL)),$(call Download,default)) + $(if $(USE_HOST_GIT_SRC_CHECKOUT)$(USE_HOST_GIT_TREE),, + $(if $(if $(PKG_HOST_ONLY),,$(if $(and $(filter host-%,$(MAKECMDGOALS)),$(PKG_SKIP_DOWNLOAD)),,$(STAMP_PREPARED))),, + $(if $(and $(CONFIG_AUTOREMOVE), $(wildcard $(HOST_STAMP_INSTALLED), $(wildcard $(HOST_STAMP_BUILT)))),, + $(if $(strip $(PKG_SOURCE_URL)),$(call Download,default)) + ) ) ) endef diff --git a/include/package.mk b/include/package.mk index cad8dc922f2..d4d67413ef9 100644 --- a/include/package.mk +++ b/include/package.mk @@ -76,11 +76,11 @@ include $(INCLUDE_DIR)/prereq.mk include $(INCLUDE_DIR)/unpack.mk include $(INCLUDE_DIR)/depends.mk -ifneq ($(wildcard $(TOPDIR)/git-src/$(PKG_NAME)/.git),) +ifneq ($(GIT_SRC_CHECKOUT_DIR),) USE_GIT_SRC_CHECKOUT:=1 QUILT:=1 endif -ifneq ($(if $(CONFIG_SRC_TREE_OVERRIDE),$(wildcard ./git-src)),) +ifneq ($(GIT_TREE_OVERRIDE_DIR),) USE_GIT_TREE:=1 QUILT:=1 endif @@ -199,28 +199,10 @@ ifeq ($(DUMP)$(filter prereq clean refresh update,$(MAKECMDGOALS)),) endif ifdef USE_GIT_SRC_CHECKOUT - define Build/Prepare/Default - mkdir -p $(PKG_BUILD_DIR) - ln -s $(TOPDIR)/git-src/$(PKG_NAME)/.git $(PKG_BUILD_DIR)/.git - ( cd $(PKG_BUILD_DIR); \ - git checkout .; \ - git submodule update --recursive; \ - git submodule foreach git config --unset core.worktree; \ - git submodule foreach git checkout .; \ - ) - endef + Build/Prepare/Default = $(call Prepare/git-src,$(PKG_BUILD_DIR),$(GIT_SRC_CHECKOUT_DIR)) endif ifdef USE_GIT_TREE - define Build/Prepare/Default - mkdir -p $(PKG_BUILD_DIR) - ln -s $(CURDIR)/git-src $(PKG_BUILD_DIR)/.git - ( cd $(PKG_BUILD_DIR); \ - git checkout .; \ - git submodule update --recursive; \ - git submodule foreach git config --unset core.worktree; \ - git submodule foreach git checkout .; \ - ) - endef + Build/Prepare/Default = $(call Prepare/git-src,$(PKG_BUILD_DIR),$(CURDIR)/git-src) endif ifdef USE_SOURCE_DIR define Build/Prepare/Default diff --git a/include/unpack.mk b/include/unpack.mk index 5959d55f4b1..62f99484982 100644 --- a/include/unpack.mk +++ b/include/unpack.mk @@ -70,3 +70,18 @@ endif endif # PKG_SOURCE +GIT_SRC_CHECKOUT_DIR = $(wildcard $(TOPDIR)/git-src/$(PKG_NAME)/.git) +GIT_TREE_OVERRIDE_DIR = $(if $(CONFIG_SRC_TREE_OVERRIDE),$(wildcard ./git-src)) + +# $1=build directory, $2=.git directory to link into it +define Prepare/git-src + mkdir -p $(1) + ln -s $(2) $(1)/.git + ( cd $(1); \ + git checkout .; \ + git submodule update --recursive; \ + git submodule foreach git config --unset core.worktree; \ + git submodule foreach git checkout .; \ + ) +endef +