cachepath = ~/.mld filebase = $(basename $(notdir $(file))) suffix = $(subst .,,$(suffix $(file))) version ?= $(shell date +%Y.%m.%d) filelink = $(cachepath)/$(notdir $(file)) newfile = $(cachepath)/$(filebase)-$(version).$(suffix) makefilename := $(lastword $(MAKEFILE_LIST)) name ?= $(filebase) # file = src/name.tgz # url = "http://surce-file.tgz" # rule = src/create-source-file.tgz -include ../Makefile.config .PHONY: $(filelink) $(file): @$(MAKE) -f $(makefilename) $(filelink) @test -e $(filelink) && mkdir -p $(dir $@) @test -e $(filelink) && ln -fs $(cachepath)/$$(readlink $(filelink)) $@ $(filelink): $(newfile) @if [ "$$(readlink $@)" != "$(^F)" ]; then \ rm -rf $(cachepath)/t1 $(cachepath)/t2; \ mkdir $(cachepath)/t1 $(cachepath)/t2; \ if [ -e $@ -a -e $^ ]; then \ if tar -xf $@ -C $(cachepath)/t1 2>/dev/null; then \ tar -xf $^ -C $(cachepath)/t2 2>/dev/null; \ diff -r $(cachepath)/t1 $(cachepath)/t2 >/dev/null && rm $^; \ chmod -R +x $(cachepath)/t1 $(cachepath)/t2; \ rm -rf $(cachepath)/t1 $(cachepath)/t2; \ else \ diff -q $^ $@ >/dev/null && rm $^; \ fi; \ fi; \ test -e $@ -a -e $^ && rm -f $(cachepath)/$$(readlink $@); \ test -e $^ && ln -fs $(notdir $^) $@; \ fi || true $(newfile): @if [ -z "$(NO_UPDATES)" -o ! -e $(filelink) ]; then \ mkdir -p $(@D); \ if [ -n "$(url)" ]; then \ wget -T 30 -t 2 "$(url)" -O $@ || rm -f $@ || true; \ elif [ -n "$(rule)" ]; then \ $(MAKE) -sf Makefile $(rule) file=$@ version=$(version) >&2 || rm -f $@ || true; \ fi; \ else \ echo "No update check" >&2; \ fi version: $(file) @readlink $^ | sed "s/.*-\(.*\)\.$(suffix)/\\1/g" clean: rm -f $(cachepath)/$(name)-* $(cachepath)/$(name).* clean_all: rm -rf $(cachepath)/*