INSTDIR := /usr/local/bin
LIBDIR := /usr/local/lib/site_perl
HTMLROOT=..
.PHONY : doc clean tags

EXES := dirWatcher.pl extractTorrents.pl gnomeGUI.pl gtkGUI.pl patternQuery.pl patternServer.pl

all:
	echo "call install or install-config"

install:
	for i in ${EXES}; do cp $i ${INSTDIR}; chmod a+x ${INSTDIR}/$i; done
	-mkdir -p ${LIBDIR}/POE/Component/goanseech
	-mkdir -p ${LIBDIR}/POE/Component/Leve
	cp POE/Component/goanseech/*.pm ${LIBDIR}/POE/Component/goanseech
	cp POE/Component/Leve/*.pm ${LIBDIR}/POE/Component/Leve

install-config:
	-mkdir -p ~/.goanseech
	echo $(shell for i in *sample; do if [  -a ~/.goanseech/`basename $i .sample` ]; then echo "leaving alone: $i"; else echo "moving over: $i"; cp $i ~/.goanseech/`basename $i .sample`; fi; done)
	cp shellCmds.pm ~/.goanseech/
	echo $(shell if [  -a ~/.goanseech/plain-cert.pem ]; then echo "cert keys installed"; else echo "creating cert keys";(cd ~/.goanseech/; openssl genrsa>privkey.pem; openssl genrsa -out plain-rsa.pem 2048;openssl req -new -key privkey.pem -out cert.csr; openssl req -new -x509 -key privkey.pem -out plain-cert.pem -days 1095) ; fi; done)

uninstall:
	for i in ${EXES}; do rm ${INSTDIR}/$i; done
	-rm -r ${LIBDIR}/POE/Component/goanseech
	-rm -r ${LIBDIR}/POE/Component/Leve

www/pod/%.html:%.pm
	pod2html --htmlroot=${HTMLROOT} --infile=$< --outfile=www/pod/$(patsubst %.pm,%,$<).html --title "pod documentation for $(patsubst %.pm,%,$<)" 
	./convertIndex.pl www/pod/$(patsubst %.pm,%,$<).html
	rm www/pod/*.bak

doc: $(patsubst %.pm,www/pod/%.html,$(wildcard *.pm))
	cd POE;$(MAKE) doc
	#for i in *.pm; do pod2html --infile=$$i --outfile=www/pod/$$i.html --title "pod documentation for `basename $$i .pm`"; done


clean: 
	cd POE;$(MAKE) clean

tags:
	ctags *.p* */*.pm */*/*.pm */*/*/*.pm */*/*/*/*.pm
