
KXEN_DISTFILES = ../../../distfiles
KXEN_DISTFILES_URL = http://www.xen.org/download/HostedXen/distfiles

E2FSPROGS_DISTFILES = e2fsprogs-1.41.4.tar.gz
E2FSPROGS_PATCH = patches/e2fsprogs-1.41.4-mingw.diff
E2FSPROGS_DIR = e2fsprogs/e2fsprogs-1.41.4

DISTFILES_ALL += $(E2FSPROGS_DISTFILES)

VPATH = $(KXEN_DISTFILES)

all: install/.uptodate

.PHONY: all distclean clean

distclean: clean
	rm -rf install

clean:
	rm -rf e2fsprogs

install/.uptodate: e2fsprogs/.installed
	@touch $@

e2fsprogs/.installed: e2fsprogs/.built
	cd $(E2FSPROGS_DIR)/lib/uuid && \
	  PATH=$(abspath install/bin):$$PATH \
	  make install
	@touch $@

e2fsprogs/.built: e2fsprogs/.configured
	cd $(E2FSPROGS_DIR)/lib/uuid && \
	  PATH=$(abspath install/bin):$$PATH \
	  make
	@touch $@

e2fsprogs/.configured: e2fsprogs/.patched
	cd $(E2FSPROGS_DIR) && \
	  PATH=$(abspath install/bin):$$PATH \
	  ./configure --prefix=$(abspath install)
	@touch $@

e2fsprogs/.patched: e2fsprogs/.extracted
#e2fsprogs/.patched: $(E2FSPROGS_PATCH)
#	cat $< | (cd $(E2FSPROGS_DIR) && patch -p1)
	@touch $@

e2fsprogs/.extracted: $(E2FSPROGS_DISTFILES)
	@rm -rf e2fsprogs
	@mkdir -p e2fsprogs/.hg
	cat $< | (cd e2fsprogs && tar zxf -)
	@touch $@

%/.exists:
	mkdir -p $(@D)/.hg
	@touch $@

.INTERMEDIATE: $(DISTFILES_ALL)
$(DISTFILES_ALL):
	@mkdir -p $(KXEN_DISTFILES)
	(cd $(KXEN_DISTFILES) && curl -O $(KXEN_DISTFILES_URL)/${@F})
	ln -fs $(KXEN_DISTFILES)/${@F}
