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
42 .DEFAULT_GOAL := commands
44 ## I. Commands for both workshop and lesson websites
45 ## =================================================
47 ## * serve : render website and run a local server
51 ## * site : build website but do not run a server
55 ## * docker-serve : use Docker to serve the site
57 docker run --rm -it --volume ${PWD}:/srv/jekyll \
58 --volume=${PWD}/.docker-vendor/bundle:/usr/local/bundle \
59 -p 127.0.0.1:4000:4000 \
60 jekyll/jekyll:${JEKYLL_VERSION} \
61 bin/run-make-docker-serve.sh
63 ## * repo-check : check repository settings
65 @${PYTHON} 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)
83 ## II. Commands specific to workshop websites
84 ## =================================================
86 .PHONY : workshop-check
88 ## * workshop-check : check workshop homepage
90 @${PYTHON} bin/workshop_check.py .
94 ## III. Commands specific to lesson websites
95 ## =================================================
97 .PHONY : lesson-check lesson-md lesson-files lesson-fixme
100 RMD_SRC = $(wildcard _episodes_rmd/??-*.Rmd)
101 RMD_DST = $(patsubst _episodes_rmd/%.Rmd,_episodes/%.md,$(RMD_SRC))
103 # Lesson source files in the order they appear in the navigation menu.
108 $(sort $(wildcard _episodes/*.md)) \
110 $(sort $(wildcard _extras/*.md)) \
113 # Generated lesson files in the order they appear in the navigation menu.
116 ${DST}/conduct/index.html \
117 ${DST}/setup/index.html \
118 $(patsubst _episodes/%.md,${DST}/%/index.html,$(sort $(wildcard _episodes/*.md))) \
119 ${DST}/reference/index.html \
120 $(patsubst _extras/%.md,${DST}/%/index.html,$(sort $(wildcard _extras/*.md))) \
121 ${DST}/license/index.html
123 ## * lesson-md : convert Rmarkdown files to markdown
124 lesson-md : ${RMD_DST}
126 _episodes/%.md: _episodes_rmd/%.Rmd
127 @bin/knit_lessons.sh $< $@
129 # * lesson-check : validate lesson Markdown
130 lesson-check : lesson-fixme
131 @${PYTHON} bin/lesson_check.py -s . -p ${PARSER} -r _includes/links.md
133 ## * lesson-check-all : validate lesson Markdown, checking line lengths and trailing whitespace
135 @${PYTHON} bin/lesson_check.py -s . -p ${PARSER} -r _includes/links.md -l -w --permissive
137 ## * unittest : run unit tests on checking tools
139 @${PYTHON} bin/test_lesson_check.py
141 ## * lesson-files : show expected names of generated files for debugging
143 @echo 'RMD_SRC:' ${RMD_SRC}
144 @echo 'RMD_DST:' ${RMD_DST}
145 @echo 'MARKDOWN_SRC:' ${MARKDOWN_SRC}
146 @echo 'HTML_DST:' ${HTML_DST}
148 ## * lesson-fixme : show FIXME markers embedded in source files
150 @fgrep -i -n FIXME ${MARKDOWN_SRC} || true
153 ## IV. Auxililary (plumbing) commands
154 ## =================================================
156 ## * commands : show all commands.
158 @sed -n -e '/^##/s|^##[[:space:]]*||p' $(MAKEFILE_LIST)