depends.mk 1.4 KB

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