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 <nbd@nbd.name>
This commit is contained in:
Felix Fietkau 2026-07-06 11:55:09 +02:00
parent 37fad8b07e
commit 8bbaad10e0
3 changed files with 45 additions and 25 deletions

View file

@ -18,6 +18,20 @@ endif
include $(INCLUDE_DIR)/unpack.mk include $(INCLUDE_DIR)/unpack.mk
include $(INCLUDE_DIR)/depends.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 include $(INCLUDE_DIR)/quilt.mk
BUILD_TYPES += host BUILD_TYPES += host
@ -41,6 +55,13 @@ define Host/Prepare/Default
$(Host/Patch) $(Host/Patch)
endef 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 define Host/Prepare
$(call Host/Prepare/Default) $(call Host/Prepare/Default)
endef endef
@ -226,9 +247,11 @@ endif
define HostBuild define HostBuild
$(HostBuild/Core) $(HostBuild/Core)
$(if $(if $(PKG_HOST_ONLY),,$(if $(and $(filter host-%,$(MAKECMDGOALS)),$(PKG_SKIP_DOWNLOAD)),,$(STAMP_PREPARED))),, $(if $(USE_HOST_GIT_SRC_CHECKOUT)$(USE_HOST_GIT_TREE),,
$(if $(and $(CONFIG_AUTOREMOVE), $(wildcard $(HOST_STAMP_INSTALLED), $(wildcard $(HOST_STAMP_BUILT)))),, $(if $(if $(PKG_HOST_ONLY),,$(if $(and $(filter host-%,$(MAKECMDGOALS)),$(PKG_SKIP_DOWNLOAD)),,$(STAMP_PREPARED))),,
$(if $(strip $(PKG_SOURCE_URL)),$(call Download,default)) $(if $(and $(CONFIG_AUTOREMOVE), $(wildcard $(HOST_STAMP_INSTALLED), $(wildcard $(HOST_STAMP_BUILT)))),,
$(if $(strip $(PKG_SOURCE_URL)),$(call Download,default))
)
) )
) )
endef endef

View file

@ -76,11 +76,11 @@ include $(INCLUDE_DIR)/prereq.mk
include $(INCLUDE_DIR)/unpack.mk include $(INCLUDE_DIR)/unpack.mk
include $(INCLUDE_DIR)/depends.mk include $(INCLUDE_DIR)/depends.mk
ifneq ($(wildcard $(TOPDIR)/git-src/$(PKG_NAME)/.git),) ifneq ($(GIT_SRC_CHECKOUT_DIR),)
USE_GIT_SRC_CHECKOUT:=1 USE_GIT_SRC_CHECKOUT:=1
QUILT:=1 QUILT:=1
endif endif
ifneq ($(if $(CONFIG_SRC_TREE_OVERRIDE),$(wildcard ./git-src)),) ifneq ($(GIT_TREE_OVERRIDE_DIR),)
USE_GIT_TREE:=1 USE_GIT_TREE:=1
QUILT:=1 QUILT:=1
endif endif
@ -199,28 +199,10 @@ ifeq ($(DUMP)$(filter prereq clean refresh update,$(MAKECMDGOALS)),)
endif endif
ifdef USE_GIT_SRC_CHECKOUT ifdef USE_GIT_SRC_CHECKOUT
define Build/Prepare/Default Build/Prepare/Default = $(call Prepare/git-src,$(PKG_BUILD_DIR),$(GIT_SRC_CHECKOUT_DIR))
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
endif endif
ifdef USE_GIT_TREE ifdef USE_GIT_TREE
define Build/Prepare/Default Build/Prepare/Default = $(call Prepare/git-src,$(PKG_BUILD_DIR),$(CURDIR)/git-src)
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
endif endif
ifdef USE_SOURCE_DIR ifdef USE_SOURCE_DIR
define Build/Prepare/Default define Build/Prepare/Default

View file

@ -70,3 +70,18 @@ endif
endif # PKG_SOURCE 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