FILE:=$(notdir $(SOURCE))
UNZIP_OPTION=--use-compress-program $(shell file .cache/$(FILE) | cut -d ' ' -f 2)
DIR=$(shell tar -tf .cache/$(FILE) $(UNZIP_OPTION) | head -n 1 | sed 's/\(.*\)\/.*/\1/g')
PREFIX=$(HOME)/usr/local
ifeq ($(origin CONFIGURE), undefined)
    CONFIGURE:=./configure --prefix $(PREFIX) $(OPTIONS)
endif


all:: $(PREFIX)/$(TARGET)


clean:
	rm -rf $(DIR)
	# rm -rf .cache


$(PREFIX)/$(TARGET): .cache/$(FILE) $(DEPENDS)
	@echo Does everything needed to build and install $(NAME)
	tar -xf .cache/$(FILE) $(UNZIP_OPTION)
	$(PRE_BUILD_COMMAND)
	cd $(DIR) ; $(CONFIGURE)
	$(MAKE) -C $(DIR) all
	$(POST_BUILD_COMMAND)
	# sudo $(MAKE) -C $(DIR) install
	$(MAKE) -C $(DIR) install
	$(POST_INSTALL_COMMAND)
	@echo Done!


.cache/$(FILE):
	mkdir -p .cache
	cd .cache ; curl -O $(SOURCE)

