makefilet-download-ondemand.mk 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. # include this makefile snippet for automatic discovery of a:
  2. # * system-wide 'makefilet' installation (e.g. via the deb package)
  3. # * project-wide inclusion as a git-submodule (or code copy)
  4. # * on-demand download (temporarily stored in the local 'build/' directory)
  5. # alternative version: "main" (the tip of the current development branch)
  6. MAKEFILET_DOWNLOAD_VERSION ?= v0.15.0
  7. ifneq ($(MAKEFILET_DOWNLOAD_URL_TEMPLATE),)
  8. $(warning 'MAKEFILET_DOWNLOAD_URL_TEMPLATE' is deprecated. Use 'MAKEFILET_DOWNLOAD_URL_TEMPLATES' instead.)
  9. MAKEFILET_DOWNLOAD_URL_TEMPLATES ?= $(MAKEFILET_DOWNLOAD_URL_TEMPLATE)
  10. else
  11. MAKEFILET_DOWNLOAD_URL_TEMPLATES ?= \
  12. https://notabug.org/sumpfralle/makefilet/archive/__VERSION__.tar.gz \
  13. https://git.hack-hro.de/kmohrf/makefilet/-/archive/__VERSION__/makefilet-__VERSION__.tar.gz
  14. endif
  15. ifneq ($(MAKEFILET_DOWNLOAD_URL),)
  16. $(warning 'MAKEFILET_DOWNLOAD_URL' is deprecated. Use 'MAKEFILET_DOWNLOAD_URLS' instead.)
  17. MAKEFILET_DOWNLOAD_URLS ?= $(MAKEFILET_DOWNLOAD_URL)
  18. else
  19. MAKEFILET_DOWNLOAD_URLS ?= $(foreach template,$(MAKEFILET_DOWNLOAD_URL_TEMPLATES),$(subst __VERSION__,$(MAKEFILET_DOWNLOAD_VERSION),$(template)))
  20. endif
  21. # first attempt: system-wide installation (e.g. deb package) or submodule of this project?
  22. -include makefilet/main.mk
  23. ifndef DIR_MAKEFILET
  24. # we failed - it is not available globally or as a submodule
  25. # second attempt: include a downloaded makefilet archive
  26. DIR_BUILD ?= build
  27. DIR_MAKEFILET_DOWNLOAD = $(DIR_BUILD)/makefilet
  28. -include $(DIR_MAKEFILET_DOWNLOAD)/main.mk
  29. ifndef DIR_MAKEFILET
  30. # third attempt: download and extract a known release
  31. $(info Downloading 'makefilet' ...)
  32. $(shell mkdir -p "$(DIR_MAKEFILET_DOWNLOAD)" \
  33. && for url in $(MAKEFILET_DOWNLOAD_URLS); do \
  34. printf >&2 "Trying to download 'makefilet' from $$url ... "; \
  35. if wget --timeout=3 --tries=2 --quiet --output-document - "$$url"; then \
  36. echo >&2 "OK"; \
  37. break; \
  38. else \
  39. echo >&2 "failed"; \
  40. fi; \
  41. done | tar -xz -C "$(DIR_MAKEFILET_DOWNLOAD)" --strip-components=1 -f -)
  42. # last include attempt
  43. -include $(DIR_MAKEFILET_DOWNLOAD)/main.mk
  44. ifndef DIR_MAKEFILET
  45. $(error Failed to initialize 'makefilet'. It seems like it is neither installed system-wide, as a submodule or available via download.)
  46. endif
  47. endif
  48. endif