depends.mk 1.3 KB

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