1 ## ========================================
2 ## Commands for both workshop and lesson websites.
5 MAKEFILES=Makefile $(wildcard *.mk)
8 PARSER=bin/markdown_ast.rb
11 # Check Python 3 is installed and determine if it's called via python3 or python
12 # (https://stackoverflow.com/a/4933395)
13 ifneq (, $(shell which python3 2>/dev/null))
15 else ifneq (, $(shell which python))
16 PYTHON_VERSION_FULL := $(wordlist 2,4,$(subst ., ,$(shell python --version 2>&1)))
17 PYTHON_VERSION_MAJOR := $(word 1,${PYTHON_VERSION_FULL})
18 ifneq (3, ${PYTHON_VERSION_MAJOR})
19 $(error "Your system does not appear to have Python 3 installed.")
23 $(error "Your system does not appear to have any Python installed.")
28 .PHONY : commands clean files
32 ## commands : show all commands.
34 @grep -h -E '^##' ${MAKEFILES} | sed -e "s/## //g"
36 ## docker-serve : use docker to build the site
38 docker run --rm -it -v ${PWD}:/srv/jekyll -p 127.0.0.1:4000:4000 jekyll/jekyll:${JEKYLL_VERSION} make serve
40 ## serve : run a local server.
44 ## site : build files but do not run a server.
48 # repo-check : check repository settings.
50 @bin/repo_check.py -s .
52 ## clean : clean up junk files.
56 @rm -rf bin/__pycache__
57 @find . -name .DS_Store -exec rm {} \;
58 @find . -name '*~' -exec rm {} \;
59 @find . -name '*.pyc' -exec rm {} \;
61 ## clean-rmd : clean intermediate R files (that need to be committed to the repo).
66 ## ----------------------------------------
67 ## Commands specific to workshop websites.
69 .PHONY : workshop-check
71 ## workshop-check : check workshop homepage.
73 @${PYTHON} bin/workshop_check.py .
75 ## ----------------------------------------
76 ## Commands specific to lesson websites.
78 .PHONY : lesson-check lesson-md lesson-files lesson-fixme
81 RMD_SRC = $(wildcard _episodes_rmd/??-*.Rmd)
82 RMD_DST = $(patsubst _episodes_rmd/%.Rmd,_episodes/%.md,$(RMD_SRC))
84 # Lesson source files in the order they appear in the navigation menu.
89 $(sort $(wildcard _episodes/*.md)) \
91 $(sort $(wildcard _extras/*.md)) \
94 # Generated lesson files in the order they appear in the navigation menu.
97 ${DST}/conduct/index.html \
98 ${DST}/setup/index.html \
99 $(patsubst _episodes/%.md,${DST}/%/index.html,$(sort $(wildcard _episodes/*.md))) \
100 ${DST}/reference/index.html \
101 $(patsubst _extras/%.md,${DST}/%/index.html,$(sort $(wildcard _extras/*.md))) \
102 ${DST}/license/index.html
104 ## lesson-md : convert Rmarkdown files to markdown
105 lesson-md : ${RMD_DST}
107 _episodes/%.md: _episodes_rmd/%.Rmd
108 @bin/knit_lessons.sh $< $@
110 ## lesson-check : validate lesson Markdown.
111 lesson-check : lesson-fixme
112 @${PYTHON} bin/lesson_check.py -s . -p ${PARSER} -r _includes/links.md
114 ## lesson-check-all : validate lesson Markdown, checking line lengths and trailing whitespace.
116 @${PYTHON} bin/lesson_check.py -s . -p ${PARSER} -r _includes/links.md -l -w --permissive
118 ## unittest : run unit tests on checking tools.
120 @${PYTHON} bin/test_lesson_check.py
122 ## lesson-files : show expected names of generated files for debugging.
124 @echo 'RMD_SRC:' ${RMD_SRC}
125 @echo 'RMD_DST:' ${RMD_DST}
126 @echo 'MARKDOWN_SRC:' ${MARKDOWN_SRC}
127 @echo 'HTML_DST:' ${HTML_DST}
129 ## lesson-fixme : show FIXME markers embedded in source files.
131 @fgrep -i -n FIXME ${MARKDOWN_SRC} || true
133 #-------------------------------------------------------------------------------
134 # Include extra commands if available.
135 #-------------------------------------------------------------------------------