fetch.mk 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. # This file is part of the OpenADK project. OpenADK is copyrighted
  2. # material, please see the LICENCE file in the top-level directory.
  3. ifneq ($(strip ${DIST_SUBDIR}),)
  4. FULLDISTDIR?= ${DL_DIR}/${DIST_SUBDIR}
  5. else
  6. FULLDISTDIR?= ${DL_DIR}
  7. endif
  8. FULLDISTFILES= $(patsubst %,${FULLDISTDIR}/%,${DISTFILES})
  9. FETCH_STYLE?= auto
  10. #pre-fetch:
  11. do-fetch:
  12. #post-fetch:
  13. fetch:
  14. # @${MAKE} pre-fetch
  15. ifneq ($(filter auto,${FETCH_STYLE}),)
  16. ${MAKE} ${FULLDISTFILES}
  17. else
  18. ${MAKE} do-fetch
  19. endif
  20. # @${MAKE} post-fetch
  21. refetch:
  22. -rm -f ${FULLDISTFILES}
  23. ${MAKE} fetch
  24. _CHECKSUM_COOKIE?= ${WRKDIR}/.checksum_done
  25. checksum: ${_CHECKSUM_COOKIE}
  26. ifeq ($(strip ${NO_CHECKSUM}),)
  27. ${_CHECKSUM_COOKIE}: ${FULLDISTFILES}
  28. -rm -rf ${WRKDIR}
  29. @OK=n; \
  30. allsums="$(strip ${PKG_MD5SUM})"; \
  31. (md5sum ${FULLDISTFILES}; echo exit) | while read sum name; do \
  32. if [[ $$sum = exit ]]; then \
  33. [[ $$OK = n ]] && echo >&2 "==> No distfile found!" || :; \
  34. [[ $$OK = 1 ]] || exit 1; \
  35. break; \
  36. fi; \
  37. cursum="$${allsums%% *}"; \
  38. allsums="$${allsums#* }"; \
  39. if [[ $$sum = "$$cursum" ]]; then \
  40. [[ $$OK = 0 ]] || OK=1; \
  41. continue; \
  42. fi; \
  43. echo >&2 "==> Checksum mismatch for $${name##*/} (MD5)"; \
  44. echo >&2 ":---> should be '$$cursum'"; \
  45. echo >&2 ":---> really is '$$sum'"; \
  46. OK=0; \
  47. done
  48. mkdir -p ${WRKDIR}
  49. touch ${_CHECKSUM_COOKIE}
  50. endif
  51. # GNU make's poor excuse for loops
  52. define FETCH_template
  53. $(1):
  54. @fullname='$(1)'; \
  55. filename=$$$${fullname##*/}; \
  56. mkdir -p "$$$${fullname%%/$$$$filename}"; \
  57. cd "$$$${fullname%%/$$$$filename}"; \
  58. for site in $${PKG_SITES} $${MASTER_SITE_BACKUP}; do \
  59. : echo "$${FETCH_CMD} $$$$site$$$$filename"; \
  60. rm -f "$$$$filename"; \
  61. if $${FETCH_CMD} $$$$site$$$$filename; then \
  62. : check the size here; \
  63. [[ ! -e $$$$filename ]] || exit 0; \
  64. fi; \
  65. done; \
  66. exit 1
  67. endef
  68. $(foreach distfile,${FULLDISTFILES},$(eval $(call FETCH_template,$(distfile))))