1 ## ========================================
2 ## Commands for both workshop and lesson websites.
5 MAKEFILES=Makefile $(wildcard *.mk)
8 PARSER=bin/markdown_ast.rb
11 # Check Python 3 (https://stackoverflow.com/a/4933395)
12 ifneq (, $(shell which python3))
14 else ifneq (, $(shell which python))
15 PYTHON_VERSION_FULL := $(wordlist 2,4,$(subst ., ,$(shell python --version 2>&1)))
16 PYTHON_VERSION_MAJOR := $(word 1,${PYTHON_VERSION_FULL})
17 ifneq (3, ${PYTHON_VERSION_MAJOR})
18 $(error "Your system does not appear to have Python 3 installed.")
22 $(error "Your system does not appear to have any Python installed.")
27 .PHONY : commands clean files
31 ## commands : show all commands.
33 @grep -h -E '^##' ${MAKEFILES} | sed -e 's/## //g'
35 ## docker-serve : use docker to build the site
37 docker run --rm -it -v ${PWD}:/srv/jekyll -p 127.0.0.1:4000:4000 jekyll/jekyll:${JEKYLL_VERSION} make serve
39 ## serve : run a local server.
43 ## site : build files but do not run a server.
47 # repo-check : check repository settings.
49 @bin/repo_check.py -s .
51 ## clean : clean up junk files.
55 @rm -rf bin/__pycache__
56 @find . -name .DS_Store -exec rm {} \;
57 @find . -name '*~' -exec rm {} \;
58 @find . -name '*.pyc' -exec rm {} \;
60 ## clean-rmd : clean intermediate R files (that need to be committed to the repo).
65 ## ----------------------------------------
66 ## Commands specific to workshop websites.
68 .PHONY : workshop-check
70 ## workshop-check : check workshop homepage.
72 @${PYTHON} bin/workshop_check.py .
74 ## ----------------------------------------
75 ## Commands specific to lesson websites.
77 .PHONY : lesson-check lesson-md lesson-files lesson-fixme
80 RMD_SRC = $(wildcard _episodes_rmd/??-*.Rmd)
81 RMD_DST = $(patsubst _episodes_rmd/%.Rmd,_episodes/%.md,$(RMD_SRC))
83 # Lesson source files in the order they appear in the navigation menu.
88 $(sort $(wildcard _episodes/*.md)) \
90 $(sort $(wildcard _extras/*.md)) \
93 # Generated lesson files in the order they appear in the navigation menu.
96 ${DST}/conduct/index.html \
97 ${DST}/setup/index.html \
98 $(patsubst _episodes/%.md,${DST}/%/index.html,$(sort $(wildcard _episodes/*.md))) \
99 ${DST}/reference/index.html \
100 $(patsubst _extras/%.md,${DST}/%/index.html,$(sort $(wildcard _extras/*.md))) \
101 ${DST}/license/index.html
103 ## lesson-md : convert Rmarkdown files to markdown
104 lesson-md : ${RMD_DST}
106 _episodes/%.md: _episodes_rmd/%.Rmd
107 @bin/knit_lessons.sh $< $@
109 ## lesson-check : validate lesson Markdown.
110 lesson-check : lesson-fixme
111 @${PYTHON} bin/lesson_check.py -s . -p ${PARSER} -r _includes/links.md
113 ## lesson-check-all : validate lesson Markdown, checking line lengths and trailing whitespace.
115 @${PYTHON} bin/lesson_check.py -s . -p ${PARSER} -r _includes/links.md -l -w --permissive
117 ## unittest : run unit tests on checking tools.
119 @${PYTHON} bin/test_lesson_check.py
121 ## lesson-files : show expected names of generated files for debugging.
123 @echo 'RMD_SRC:' ${RMD_SRC}
124 @echo 'RMD_DST:' ${RMD_DST}
125 @echo 'MARKDOWN_SRC:' ${MARKDOWN_SRC}
126 @echo 'HTML_DST:' ${HTML_DST}
128 ## lesson-fixme : show FIXME markers embedded in source files.
130 @fgrep -i -n FIXME ${MARKDOWN_SRC} || true
132 #-------------------------------------------------------------------------------
133 # Include extra commands if available.
134 #-------------------------------------------------------------------------------