1 ## ========================================
2 ## Commands for both workshop and lesson websites.
5 MAKEFILES=Makefile $(wildcard *.mk)
7 JEKYLL=bundle update && bundle exec jekyll
8 JEKYLL_DOCKER=${JEKYLL} serve --host 0.0.0.0
9 PARSER=bin/markdown_ast.rb
12 # Check Python 3 is installed and determine if it's called via python3 or python
13 # (https://stackoverflow.com/a/4933395)
14 PYTHON3_EXE := $(shell which python3 2>/dev/null)
15 ifneq (, $(PYTHON3_EXE))
16 ifeq (,$(findstring Microsoft/WindowsApps/python3,$(subst \,/,$(PYTHON3_EXE))))
22 PYTHON_EXE := $(shell which python 2>/dev/null)
23 ifneq (, $(PYTHON_EXE))
24 PYTHON_VERSION_FULL := $(wordlist 2,4,$(subst ., ,$(shell python --version 2>&1)))
25 PYTHON_VERSION_MAJOR := $(word 1,${PYTHON_VERSION_FULL})
26 ifneq (3, ${PYTHON_VERSION_MAJOR})
27 $(error "Your system does not appear to have Python 3 installed.")
31 $(error "Your system does not appear to have any Python installed.")
37 .PHONY : commands clean files
41 ## commands : show all commands.
43 @grep -h -E '^##' ${MAKEFILES} | sed -e "s/## //g"
45 ## docker-serve : use docker to build the site
47 docker run --rm -it -v ${PWD}:/srv/jekyll -p 4000:4000 jekyll/jekyll:${JEKYLL_VERSION} ${JEKYLL_DOCKER}
49 ## serve : run a local server.
53 ## site : build files but do not run a server.
57 # repo-check : check repository settings.
59 @bin/repo_check.py -s .
61 ## clean : clean up junk files.
65 @rm -rf bin/__pycache__
66 @find . -name .DS_Store -exec rm {} \;
67 @find . -name '*~' -exec rm {} \;
68 @find . -name '*.pyc' -exec rm {} \;
70 ## clean-rmd : clean intermediate R files (that need to be committed to the repo).
75 ## ----------------------------------------
76 ## Commands specific to workshop websites.
78 .PHONY : workshop-check
80 ## workshop-check : check workshop homepage.
82 @${PYTHON} bin/workshop_check.py .
84 ## ----------------------------------------
85 ## Commands specific to lesson websites.
87 .PHONY : lesson-check lesson-md lesson-files lesson-fixme
90 RMD_SRC = $(wildcard _episodes_rmd/??-*.Rmd)
91 RMD_DST = $(patsubst _episodes_rmd/%.Rmd,_episodes/%.md,$(RMD_SRC))
93 # Lesson source files in the order they appear in the navigation menu.
98 $(sort $(wildcard _episodes/*.md)) \
100 $(sort $(wildcard _extras/*.md)) \
103 # Generated lesson files in the order they appear in the navigation menu.
106 ${DST}/conduct/index.html \
107 ${DST}/setup/index.html \
108 $(patsubst _episodes/%.md,${DST}/%/index.html,$(sort $(wildcard _episodes/*.md))) \
109 ${DST}/reference/index.html \
110 $(patsubst _extras/%.md,${DST}/%/index.html,$(sort $(wildcard _extras/*.md))) \
111 ${DST}/license/index.html
113 ## lesson-md : convert Rmarkdown files to markdown
114 lesson-md : ${RMD_DST}
116 _episodes/%.md: _episodes_rmd/%.Rmd
117 @bin/knit_lessons.sh $< $@
119 ## lesson-check : validate lesson Markdown.
120 lesson-check : lesson-fixme
121 @${PYTHON} bin/lesson_check.py -s . -p ${PARSER} -r _includes/links.md
123 ## lesson-check-all : validate lesson Markdown, checking line lengths and trailing whitespace.
125 @${PYTHON} bin/lesson_check.py -s . -p ${PARSER} -r _includes/links.md -l -w --permissive
127 ## unittest : run unit tests on checking tools.
129 @${PYTHON} bin/test_lesson_check.py
131 ## lesson-files : show expected names of generated files for debugging.
133 @echo 'RMD_SRC:' ${RMD_SRC}
134 @echo 'RMD_DST:' ${RMD_DST}
135 @echo 'MARKDOWN_SRC:' ${MARKDOWN_SRC}
136 @echo 'HTML_DST:' ${HTML_DST}
138 ## lesson-fixme : show FIXME markers embedded in source files.
140 @fgrep -i -n FIXME ${MARKDOWN_SRC} || true
142 #-------------------------------------------------------------------------------
143 # Include extra commands if available.
144 #-------------------------------------------------------------------------------