#
# Makefile for Hummy youtube-dl package
#
DISTPKG := python2.7/dist-packages

.PHONY: all clean opkg clean-opk clean-opkg release opkg-bin opkg-lib opkg-sav

MV ?= mv -f

clean-opk: $(wildcard *.opk)
	-$(RM) $?

clean-opkg: 
	-$(RM) -r opkg/bin
	-$(RM) -r opkg/lib

clean: clean-opk clean-opkg

opkg-lib: ../youtube_dl
	-$(RM) -r opkg/lib/$(DISTPKG)
	install -d opkg/lib/$(DISTPKG)
	cp -rpP $< opkg/lib/$(DISTPKG)

opkg-bin: $(wildcard ../bin/*) $(wildcard bin/*)
	install -d opkg/bin
	install -p $? opkg/bin

opkg-sav: $(wildcard *.opk)
	$(foreach opk,$^,-$(MV) "$(opk)" "$(opk).sav")

opkg: $(wildcard opkg/CONTROL/*) opkg-bin opkg-lib opkg-sav
	opkg-pack opkg
	-for opk in youtube-dl*.opk; do $(RM) "$${opk}.sav"; done

release: opkg
	tagname="$$(for opk in youtube-dl*.opk; do echo "$$opk"; break; done)" && \
	 tagname="$${tagname%_*.*}" && \
	 test -n "$${tagname}" && \
	 git tag -f -a -m "Release $${tagname}" "$${tagname}"
	
