fetch.mk 1.8 KB

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