1 # Use /bin/bash instead of /bin/sh
2 export SHELL = /bin/bash
4 ## ========================================
5 ## Commands for both workshop and lesson websites.
8 MAKEFILES=Makefile $(wildcard *.mk)
10 JEKYLL=bundle install --path .vendor/bundle && bundle update && bundle exec jekyll
11 PARSER=bin/markdown_ast.rb
14 # Check Python 3 is installed and determine if it's called via python3 or python
15 # (https://stackoverflow.com/a/4933395)
16 PYTHON3_EXE := $(shell which python3 2>/dev/null)
17 ifneq (, $(PYTHON3_EXE))
18 ifeq (,$(findstring Microsoft/WindowsApps/python3,$(subst \,/,$(PYTHON3_EXE))))
24 PYTHON_EXE := $(shell which python 2>/dev/null)
25 ifneq (, $(PYTHON_EXE))
26 PYTHON_VERSION_FULL := $(wordlist 2,4,$(subst ., ,$(shell python --version 2>&1)))
27 PYTHON_VERSION_MAJOR := $(word 1,${PYTHON_VERSION_FULL})
28 ifneq (3, ${PYTHON_VERSION_MAJOR})
29 $(error "Your system does not appear to have Python 3 installed.")
33 $(error "Your system does not appear to have any Python installed.")
39 .PHONY : commands clean files
43 ## commands : show all commands.
45 @grep -h -E '^##' ${MAKEFILES} | sed -e "s/## //g"
47 ## docker-serve : use docker to build the site
49 docker run --rm -it --volume ${PWD}:/srv/jekyll \
50 --volume=${PWD}/.docker-vendor/bundle:/usr/local/bundle \
51 -p 127.0.0.1:4000:4000 \
52 jekyll/jekyll:${JEKYLL_VERSION} \
53 bin/run-make-docker-serve.sh
55 ## serve : run a local server.
59 ## site : build files but do not run a server.
63 # repo-check : check repository settings.
65 @bin/repo_check.py -s .
67 ## clean : clean up junk files.
71 @rm -rf bin/__pycache__
72 @find . -name .DS_Store -exec rm {} \;
73 @find . -name '*~' -exec rm {} \;
74 @find . -name '*.pyc' -exec rm {} \;
76 ## clean-rmd : clean intermediate R files (that need to be committed to the repo).
81 ## ----------------------------------------
82 ## Commands specific to workshop websites.
84 .PHONY : workshop-check
86 ## workshop-check : check workshop homepage.
88 @${PYTHON} bin/workshop_check.py .
90 ## ----------------------------------------
91 ## Commands specific to lesson websites.
93 .PHONY : lesson-check lesson-md lesson-files lesson-fixme
96 RMD_SRC = $(wildcard _episodes_rmd/??-*.Rmd)
97 RMD_DST = $(patsubst _episodes_rmd/%.Rmd,_episodes/%.md,$(RMD_SRC))
99 # Lesson source files in the order they appear in the navigation menu.
104 $(sort $(wildcard _episodes/*.md)) \
106 $(sort $(wildcard _extras/*.md)) \
109 # Generated lesson files in the order they appear in the navigation menu.
112 ${DST}/conduct/index.html \
113 ${DST}/setup/index.html \
114 $(patsubst _episodes/%.md,${DST}/%/index.html,$(sort $(wildcard _episodes/*.md))) \
115 ${DST}/reference/index.html \
116 $(patsubst _extras/%.md,${DST}/%/index.html,$(sort $(wildcard _extras/*.md))) \
117 ${DST}/license/index.html
119 ## lesson-md : convert Rmarkdown files to markdown
120 lesson-md : ${RMD_DST}
122 _episodes/%.md: _episodes_rmd/%.Rmd
123 @bin/knit_lessons.sh $< $@
125 ## lesson-check : validate lesson Markdown.
126 lesson-check : lesson-fixme
127 @${PYTHON} bin/lesson_check.py -s . -p ${PARSER} -r _includes/links.md
129 ## lesson-check-all : validate lesson Markdown, checking line lengths and trailing whitespace.
131 @${PYTHON} bin/lesson_check.py -s . -p ${PARSER} -r _includes/links.md -l -w --permissive
133 ## unittest : run unit tests on checking tools.
135 @${PYTHON} bin/test_lesson_check.py
137 ## lesson-files : show expected names of generated files for debugging.
139 @echo 'RMD_SRC:' ${RMD_SRC}
140 @echo 'RMD_DST:' ${RMD_DST}
141 @echo 'MARKDOWN_SRC:' ${MARKDOWN_SRC}
142 @echo 'HTML_DST:' ${HTML_DST}
144 ## lesson-fixme : show FIXME markers embedded in source files.
146 @fgrep -i -n FIXME ${MARKDOWN_SRC} || true