TXT_FILES = $(shell find . -type f -name '*.txt')
WORDLIST_FILES = $(patsubst %.txt,%.wordlist,$(TXT_FILES))

.PHONY = clean all

all: $(WORDLIST_FILES) wordCountByBook

wordCountByBook: $(WORDLIST_FILES) Makefile
	find . -name "*.wordlist" -exec cat {} \; | ./sortUniq.py > $@

%.wordlist: %.txt
	if grep 'Language: English' $<; then cat $< | tr [:upper:] [:lower:] | tr -c [:lower:] '\n' | ./sortUniq.py | awk '{print $$2}' > $@; else touch $@; fi

clean:
	find . -type f -name "*.wordlist" -delete
	rm -f wordCountByBook
