fetch.mk 2.0 KB

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