#Makefile: Point the installer to youtube-dl.py
youtube_dl.lib:
	echo "import sys" > youtube_dl.lib
	echo "sys.path.insert(0, '`realpath --relative-to $(LIBDIR) $(BINDIR)`/youtube-dl')" >> youtube_dl.lib
	echo "for mod in ('youtube_dl', 'youtu`be_dl'):" >> youtube_dl.lib
	echo "	if mod in sys.modules.keys(): del sys.modules[mod]" >> youtube_dl.lib
	echo "import sys, youtube_dl" >> youtube_dl.lib
	echo "sys.modules['youtu`be_dl'] = sys.modules['youtube_dl']" >> youtube_dl.lib
	echo "sys.path.pop(0)" >> youtube_dl.lib

install: youtube_dl.lib youtube-dl.py youtube-dl.1 youtube-dl.bash-completion youtube-dl.zsh youtube-dl.fish
	install -d $(DESTDIR)$(BINDIR)
	install -m 755 youtube-dl.py $(DESTDIR)$(BINDIR)/youtube-dl
	install -d $(DESTDIR)$(LIBDIR)
	install -m 755 youtube_dl.lib $(DESTDIR)$(LIBDIR)/youtube_dl.py
	rm -Rf $(DESTDIR)$(BINDIR)/youtu`be-dl $(DESTDIR)$(LIBDIR)/youtu`be-dl
	ln -srv $(DESTDIR)$(BINDIR)/youtube-dl $(DESTDIR)$(BINDIR)/youtu`be-dl
	ln -srv $(DESTDIR)$(LIBDIR)/youtube_dl.py $(DESTDIR)$(LIBDIR)/youtu`be_dl.py