include $(CONFIG)

H=@

TGZ=$(shell ls *.tar.gz)
DIFF=$(shell ls *.diff 2>/dev/null)
ifeq "$(DIFF)" ""
	DIFF="nodiff"
endif

SUBDIR=$(subst .tar.gz,,$(TGZ))

all: $(SUBDIR)
	$(H)echo -n

$(SUBDIR):
	$(H)$(TAR) -xzf $(TGZ)
	$(H)if test ! "nodiff" = "$(DIFF)"; then \
		cd $(SUBDIR); \
		$(PATCH) -p1 < ../$(DIFF) 1>/dev/null; \
		if [ $$? != 0 ]; then \
			echo -e "\n ! error patching !\n";\
		fi;\
		find . -name makefile -exec rm \{\} \;;\
	fi
	$(H)cd $(SUBDIR);\
		$(MAKE) -f Makefile \
			PREFIX=$(PREFIX) TARGET=$(TARGET) CONFIG=$(CONFIG)

clean:
	$(H)rm -rf $(SUBDIR)

.PHONY: all
