1
0

depends.mk 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. find_md5_reproducible=find $(wildcard $(1)) -type f $(patsubst -x,-and -not -path,$(DEP_FINDPARAMS) $(2)) -print0 | xargs -0 $(MKHASH) md5 | sort | $(MKHASH) md5
  13. define rdep
  14. .PRECIOUS: $(2)
  15. .SILENT: $(2)_check
  16. $(2): $(2)_check
  17. check-depends: $(2)_check
  18. ifneq ($(wildcard $(2)),)
  19. $(2)_check::
  20. $(if $(3), \
  21. $(call find_md5,$(1),$(4)) > $(3).1; \
  22. { [ \! -f "$(3)" ] || diff $(3) $(3).1 >/dev/null; } && \
  23. ) \
  24. { \
  25. [ -f "$(2)_check.1" ] && mv "$(2)_check.1" "$(2)_check"; \
  26. $(TOPDIR)/scripts/timestamp.pl $(DEP_FINDPARAMS) $(4) -n $(2) $(1) && { \
  27. $(call debug_eval,$(SUBDIR),r,echo "No need to rebuild $(2)";) \
  28. touch -r "$(2)" "$(2)_check"; \
  29. } \
  30. } || { \
  31. $(call debug_eval,$(SUBDIR),r,echo "Need to rebuild $(2)";) \
  32. touch "$(2)_check"; \
  33. }
  34. $(if $(3), mv $(3).1 $(3))
  35. else
  36. $(2)_check::
  37. $(if $(3), rm -f $(3) $(3).1)
  38. $(call debug_eval,$(SUBDIR),r,echo "Target $(2) not built")
  39. endif
  40. endef
  41. ifeq ($(filter .%,$(MAKECMDGOALS)),$(if $(MAKECMDGOALS),$(MAKECMDGOALS),x))
  42. define rdep
  43. $(2): $(2)_check
  44. endef
  45. endif