textdir = ./gutenberg datadir = ./data source = https://raw.githubusercontent.com/nltk/nltk_data/gh-pages/packages/corpora/gutenberg.zip GNUPLOT = gnuplot JULIA = julia GIT = git WGET = wget UNZIP = unzip .SUFFIXES: .SUFFIXES: .txt .dat .res .gp .PHONY: clean veryclean help settings count merge pdf png initialize texts = $(wildcard $(textdir)/*.txt) dats = $(patsubst %.txt,$(datadir)/%.dat,$(notdir $(texts))) jprog = wordcount.jl res = merged.res stem = $(basename $(res)) gplot = $(res:.res=.gp) figs = $(res:.res=.pdf) $(res:.res=.png) $(datadir)/%.dat: $(textdir)/%.txt $(jprog) $(JULIA) $(jprog) count $@ $< ## help : Default action is to show what commands are available. help: Makefile @sed -n 's/^##//p' $< @echo ' ' ## count : Count words in each text in the directory $(textdir) count: $(dats) ## merge : Merge all word counts stored in the directory $(datadir) merge: $(res) $(res): $(dats) $(JULIA) $(jprog) merge $(res) $^ ## (png|pdf) : Plot the word frequency distribution as png or pdf graphics png pdf: $(gplot) $(res) $(GNUPLOT) -c $< $@ $(stem) ## clean : Remove the auto-generated files clean: rm -f $(dats) ## veryclean : Remove the auto-generated files, the tests results, and the graphs veryclean: clean rm -f $(res) $(figs) ## settings : Show settings. settings: @echo ' ' @echo 'textdir :' $(textdir) @echo 'datadir :' $(datadir) @echo 'jprog :' $(jprog) @echo 'res :' $(res) @echo 'gplot :' $(gplot) @echo 'figs :' $(figs) @echo 'stem :' $(stem) @echo 'source :' $(source) @echo ' ' @echo 'JULIA :' $(JULIA) @echo 'GNUPLOT :' $(GNUPLOT) @echo 'WGET :' $(WGET) @echo 'UNZIP :' $(UNZIP) @echo ' ' ## list : List available text and data files list: @echo ' ' @echo 'texts :' @echo $(texts) | fmt -s | sed 's/^/ /' @echo 'dats :' @echo $(dats) | fmt -s | sed 's/^/ /' ## initialize : Download Gutenber corpus and create the directory structure initialize: test ! -d $(datadir) && mkdir $(datadir) || echo -n '' test ! -d $(textdir) && $(WGET) $(source) && $(UNZIP) -u $(notdir $(source)) || echo -n '' test ! -f $(notdir $(source)) && rm -f $(notdir $(source)) || echo ' '