fetch.mk 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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 ${PKG_NOCHECKSUM}),)
  23. ${_CHECKSUM_COOKIE}: ${FULLDISTFILES}
  24. -rm -rf ${WRKDIR}
  25. ifneq ($(ADK_DISABLE_CHECKSUM),y)
  26. @if [ ! -e $(firstword ${FULLDISTFILES}).nohash ]; then \
  27. OK=n; \
  28. allsums="$(strip ${PKG_HASH})"; \
  29. ($${SHA256} ${FULLDISTFILES}; echo exit) | while read sum name; do \
  30. if [[ $$sum = exit ]]; then \
  31. [[ $$OK = n ]] && echo >&2 "==> No distfile found!" || :; \
  32. [[ $$OK = 1 ]] || exit 1; \
  33. break; \
  34. fi; \
  35. cursum="$${allsums%% *}"; \
  36. allsums="$${allsums#* }"; \
  37. if [[ $$sum = "$$cursum" ]]; then \
  38. [[ $$OK = 0 ]] || OK=1; \
  39. continue; \
  40. fi; \
  41. echo >&2 "==> Checksum mismatch for $${name##*/} (SHA256)"; \
  42. echo >&2 ":---> should be '$$cursum'"; \
  43. echo >&2 ":---> really is '$$sum'"; \
  44. OK=0; \
  45. done; \
  46. fi
  47. endif
  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 url in "${PKG_SITES}"; do case $$$$url in \
  59. file://*|git://*|*.git) \
  60. echo "Trying to downloading from backup site first"; \
  61. if $${FETCHCMD} $$$$filename $${MASTER_SITE_BACKUP}/$$$$filename $(DL_TRACE); then \
  62. touch $$$$filename.nohash; \
  63. : check the size here; \
  64. [[ ! -e $$$$filename ]] || exit 0; \
  65. fi; \
  66. rm -rf $${PKG_NAME}-$${PKG_VERSION}; \
  67. if [ ! -z "$${PKG_GIT}" ]; then \
  68. echo "Using git ${PKG_GIT}: $${PKG_VERSION}" $(DL_TRACE); \
  69. case "$${PKG_GIT}" in \
  70. tag|branch) \
  71. git clone --progress --depth 1 --branch $${PKG_VERSION} $${PKG_SITES} $${PKG_NAME}-$${PKG_VERSION} $(DL_TRACE); \
  72. if [ $$$$? -ne 0 ]; then echo "git clone error"; exit 1; fi; \
  73. ;; \
  74. hash) \
  75. git clone --progress $${PKG_SITES} $${PKG_NAME}-$${PKG_VERSION} $(DL_TRACE); \
  76. if [ $$$$? -ne 0 ]; then echo "git clone error"; exit 1; fi; \
  77. (cd $${PKG_NAME}-$${PKG_VERSION}; git checkout $${PKG_VERSION}) $(DL_TRACE); \
  78. if [ $$$$? -ne 0 ]; then echo "git checkout error"; exit 1; fi; \
  79. ;; \
  80. esac ;\
  81. else \
  82. git clone --progress --depth 1 $${PKG_SITES} $${PKG_NAME}-$${PKG_VERSION} $(DL_TRACE); \
  83. if [ $$$$? -ne 0 ]; then echo "git clone error"; exit 1; fi; \
  84. fi; \
  85. if [ ! -z "$${PKG_GIT_SUBMODULE}" ]; then \
  86. (cd $${PKG_NAME}-$${PKG_VERSION}; git submodule update --init --recursive) $(DL_TRACE); \
  87. fi; \
  88. rm -rf $${PKG_NAME}-$${PKG_VERSION}/.git; \
  89. PATH='$(HOST_PATH)' tar cJf $${PKG_NAME}-$${PKG_VERSION}.tar.xz $${PKG_NAME}-$${PKG_VERSION}; \
  90. touch $$$${filename}.nohash; \
  91. rm -rf $${PKG_NAME}-$${PKG_VERSION}; \
  92. : check the size here; \
  93. [[ ! -e $$$$filename ]] || exit 0; \
  94. ;; \
  95. http://*|https://*|ftp://*) \
  96. for site in $${PKG_SITES} $${MASTER_SITE_BACKUP}; do \
  97. echo "$${FETCHCMD} $$$$site$$$$filename" $(DL_TRACE); \
  98. rm -f "$$$$filename"; \
  99. if $${FETCHCMD} $$$$filename $$$$site$$$$filename $(DL_TRACE); then \
  100. : check the size here; \
  101. [[ ! -e $$$$filename ]] || exit 0; \
  102. fi; \
  103. done; \
  104. ;; \
  105. *) \
  106. echo url schema not known; \
  107. false ;; \
  108. esac; \
  109. done
  110. endef
  111. $(foreach distfile,${FULLDISTFILES},$(eval $(call FETCH_template,$(distfile))))