|
| 1 | +define _download-to-file |
| 2 | +$(1): $$(make-dirs) |
| 3 | + mkdir -p $$(dir $$@) |
| 4 | + curl -L $(2) > $$@ |
| 5 | +_retval := $(1) |
| 6 | +endef |
| 7 | + |
| 8 | +define download-to-file |
| 9 | +$(eval $(call _download-to-file,$(1),$(2)))$(_retval) |
| 10 | +endef |
| 11 | + |
| 12 | +define download-to |
| 13 | +$(call download-to-file,$(1)/$(notdir $(2)),$(2)) |
| 14 | +endef |
| 15 | + |
| 16 | +define download |
| 17 | +$(call download-to,$(WORKING),$(1)) |
| 18 | +endef |
| 19 | + |
| 20 | +KNOWN_TAR_EXTENSIONS := %.tar.gz %.tar.bz2 %.tar.xz %.tgz %.tar |
| 21 | + |
| 22 | +define archive-basename |
| 23 | +$(strip \ |
| 24 | + $(foreach ext,$(KNOWN_TAR_EXTENSIONS) %.zip,\ |
| 25 | + $(patsubst $(ext),%,$(filter $(ext),$(notdir $(1)))) \ |
| 26 | + ) \ |
| 27 | +) |
| 28 | +endef |
| 29 | + |
| 30 | +define _extract-to |
| 31 | +_base := $(if $(3),$(3),$$(call archive-basename,$(2))) |
| 32 | +ifneq ($$(filter %.zip,$(2)),) |
| 33 | +_cmd := unzip -qo |
| 34 | +else ifneq ($$(filter $$(KNOWN_TAR_EXTENSIONS),$(2)),) |
| 35 | +_cmd := tar xf |
| 36 | +else |
| 37 | +$$(error Don't know how to extract $(2)) |
| 38 | +endif |
| 39 | + |
| 40 | +_retval := $(1)/$$(_base) |
| 41 | +$$(_retval): _cmd := $$(_cmd) |
| 42 | +$$(_retval): $(2) $$(make-dirs) |
| 43 | + mkdir -p $$(dir $$@) |
| 44 | + cd $$(dir $$@) && $$(_cmd) $$(abspath $$<) |
| 45 | + touch $$@ |
| 46 | + |
| 47 | +$$(_retval).extracted: | $$(_retval) |
| 48 | + touch $$@ |
| 49 | + |
| 50 | +endef |
| 51 | + |
| 52 | +# 1 - destination directory |
| 53 | +# 2 - archive path |
| 54 | +# 3 - optional alternate archive base name. Default based on path |
| 55 | +define extract-to |
| 56 | +$(eval $(call _extract-to,$(1),$(2),$(3)))$(_retval) |
| 57 | +endef |
| 58 | + |
| 59 | +# 1 - archive path |
| 60 | +# 2 - optional alternate archive base name. Default based on path |
| 61 | +define extract |
| 62 | +$(call extract-to,$(WORKING),$(1),$(2)) |
| 63 | +endef |
| 64 | + |
| 65 | +# 1 - name |
| 66 | +define _define-one-stage |
| 67 | +$(1) := $$(STAGE_MARKERS)/$(1) |
| 68 | +$(1): $$($(1)) |
| 69 | +.PHONY: $(1) |
| 70 | +endef |
| 71 | + |
| 72 | +define define-stage |
| 73 | +$(foreach stage,$(1),$(eval $(call _define-one-stage,$(stage)))) |
| 74 | +endef |
| 75 | + |
| 76 | +$(STAGE_MARKERS)/%: | $(STAGE_MARKERS) |
| 77 | + touch $@ |
| 78 | + |
0 commit comments