]> git.ipfire.org Git - thirdparty/openwrt.git/commitdiff
build: support git-src override for host builds
authorFelix Fietkau <nbd@nbd.name>
Mon, 6 Jul 2026 09:55:09 +0000 (11:55 +0200)
committerFelix Fietkau <nbd@nbd.name>
Tue, 7 Jul 2026 08:46:12 +0000 (10:46 +0200)
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>
include/host-build.mk
include/package.mk
include/unpack.mk

index 4dfa055db903d035b39af71312c4f58fd5380d4a..d78dbdd4c21395f199082d044aac4674a6be04bf 100644 (file)
@@ -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
index cad8dc922f217218b757e71484977b1acc997019..d4d67413ef9cb2f3ffb55e9df0abc2248eb050df 100644 (file)
@@ -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
index 5959d55f4b1dc11f8a4a7f4d78ff6850f0506ba1..62f99484982fba4778c1048d0eca3d2c6f3bc6ae 100644 (file)
@@ -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
+