b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame] | 1 | # SPDX-License-Identifier: GPL-2.0-only |
| 2 | # |
| 3 | # Copyright (C) 2007-2020 OpenWrt.org |
| 4 | |
| 5 | # define a dependency on a subtree |
| 6 | # parameters: |
| 7 | # 1: directories/files |
| 8 | # 2: directory dependency |
| 9 | # 3: tempfile for file listings |
| 10 | # 4: find options |
| 11 | |
| 12 | DEP_FINDPARAMS := -x "*/.svn*" -x ".*" -x "*:*" -x "*\!*" -x "* *" -x "*\\\#*" -x "*/.*_check" -x "*/.*.swp" -x "*/.pkgdir*" |
| 13 | |
| 14 | find_md5=find $(wildcard $(1)) -type f $(patsubst -x,-and -not -path,$(DEP_FINDPARAMS) $(2)) -printf "%p%T@\n" | sort | $(MKHASH) md5 |
| 15 | find_md5_reproducible=find $(wildcard $(1)) -type f $(patsubst -x,-and -not -path,$(DEP_FINDPARAMS) $(2)) -print0 | xargs -0 $(MKHASH) md5 | sort | $(MKHASH) md5 |
| 16 | |
| 17 | define rdep |
| 18 | .PRECIOUS: $(2) |
| 19 | .SILENT: $(2)_check |
| 20 | |
| 21 | $(2): $(2)_check |
| 22 | check-depends: $(2)_check |
| 23 | |
| 24 | ifneq ($(wildcard $(2)),) |
| 25 | $(2)_check:: |
| 26 | $(if $(3), \ |
| 27 | $(call find_md5,$(1),$(4)) > $(3).1; \ |
| 28 | { [ \! -f "$(3)" ] || diff $(3) $(3).1 >/dev/null; } && \ |
| 29 | ) \ |
| 30 | { \ |
| 31 | [ -f "$(2)_check.1" ] && mv "$(2)_check.1" "$(2)_check"; \ |
| 32 | $(TOPDIR)/scripts/timestamp.pl $(DEP_FINDPARAMS) $(4) -n $(2) $(1) && { \ |
| 33 | $(call debug_eval,$(SUBDIR),r,echo "No need to rebuild $(2)";) \ |
| 34 | touch -r "$(2)" "$(2)_check"; \ |
| 35 | } \ |
| 36 | } || { \ |
| 37 | $(call debug_eval,$(SUBDIR),r,echo "Need to rebuild $(2)";) \ |
| 38 | touch "$(2)_check"; \ |
| 39 | } |
| 40 | $(if $(3), mv $(3).1 $(3)) |
| 41 | else |
| 42 | $(2)_check:: |
| 43 | $(if $(3), rm -f $(3) $(3).1) |
| 44 | $(call debug_eval,$(SUBDIR),r,echo "Target $(2) not built") |
| 45 | endif |
| 46 | |
| 47 | endef |
| 48 | |
| 49 | ifeq ($(filter .%,$(MAKECMDGOALS)),$(if $(MAKECMDGOALS),$(MAKECMDGOALS),x)) |
| 50 | define rdep |
| 51 | $(2): $(2)_check |
| 52 | endef |
| 53 | endif |