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)
9 JEKYLL=bundle config --local set path .vendor/bundle && bundle install && bundle update && bundle exec jekyll
10 PARSER=bin/markdown_ast.rb
13 # Check Python 3 is installed and determine if it's called via python3 or python
14 # (https://stackoverflow.com/a/4933395)
15 PYTHON3_EXE := $(shell which python3 2>/dev/null)
16 ifneq (, $(PYTHON3_EXE))
17 ifeq (,$(findstring Microsoft/WindowsApps/python3,$(subst \,/,$(PYTHON3_EXE))))
23 PYTHON_EXE := $(shell which python 2>/dev/null)
24 ifneq (, $(PYTHON_EXE))
25 PYTHON_VERSION_FULL := $(wordlist 2,4,$(subst ., ,$(shell python --version 2>&1)))
26 PYTHON_VERSION_MAJOR := $(word 1,${PYTHON_VERSION_FULL})
27 ifneq (3, ${PYTHON_VERSION_MAJOR})
28 $(error "Your system does not appear to have Python 3 installed.")
32 $(error "Your system does not appear to have any Python installed.")
38 .PHONY : commands clean files
41 .DEFAULT_GOAL := commands
43 ## I. Commands for both workshop and lesson websites
44 ## =================================================
46 ## * serve : render website and run a local server
50 ## * site : build website but do not run a server
54 ## * docker-serve : use Docker to serve the site
56 docker pull carpentries/lesson-docker:latest
58 -v $${PWD}:/home/rstudio \
62 -e GROUPID=$$(id -g) \
63 carpentries/lesson-docker:latest
65 ## * repo-check : check repository settings
67 @${PYTHON} bin/repo_check.py -s .
69 ## * clean : clean up junk files
73 @rm -rf bin/__pycache__
74 @find . -name .DS_Store -exec rm {} \;
75 @find . -name '*~' -exec rm {} \;
76 @find . -name '*.pyc' -exec rm {} \;
78 ## * clean-rmd : clean intermediate R files (that need to be committed to the repo)
85 ## II. Commands specific to workshop websites
86 ## =================================================
88 .PHONY : workshop-check
90 ## * workshop-check : check workshop homepage
92 @${PYTHON} bin/workshop_check.py .
96 ## III. Commands specific to lesson websites
97 ## =================================================
99 .PHONY : lesson-check lesson-md lesson-files lesson-fixme
102 RMD_SRC = $(wildcard _episodes_rmd/??-*.Rmd)
103 RMD_DST = $(patsubst _episodes_rmd/%.Rmd,_episodes/%.md,$(RMD_SRC))
105 # Lesson source files in the order they appear in the navigation menu.
110 $(sort $(wildcard _episodes/*.md)) \
112 $(sort $(wildcard _extras/*.md)) \
115 # Generated lesson files in the order they appear in the navigation menu.
118 ${DST}/conduct/index.html \
119 ${DST}/setup/index.html \
120 $(patsubst _episodes/%.md,${DST}/%/index.html,$(sort $(wildcard _episodes/*.md))) \
121 ${DST}/reference/index.html \
122 $(patsubst _extras/%.md,${DST}/%/index.html,$(sort $(wildcard _extras/*.md))) \
123 ${DST}/license/index.html
125 ## * lesson-md : convert Rmarkdown files to markdown
126 lesson-md : ${RMD_DST}
128 _episodes/%.md: _episodes_rmd/%.Rmd
129 @bin/knit_lessons.sh $< $@
131 ## * lesson-check : validate lesson Markdown
132 lesson-check : lesson-fixme
133 @${PYTHON} bin/lesson_check.py -s . -p ${PARSER} -r _includes/links.md
135 ## * lesson-check-all : validate lesson Markdown, checking line lengths and trailing whitespace
137 @${PYTHON} bin/lesson_check.py -s . -p ${PARSER} -r _includes/links.md -l -w --permissive
139 ## * unittest : run unit tests on checking tools
141 @${PYTHON} bin/test_lesson_check.py
143 ## * lesson-files : show expected names of generated files for debugging
145 @echo 'RMD_SRC:' ${RMD_SRC}
146 @echo 'RMD_DST:' ${RMD_DST}
147 @echo 'MARKDOWN_SRC:' ${MARKDOWN_SRC}
148 @echo 'HTML_DST:' ${HTML_DST}
150 ## * lesson-fixme : show FIXME markers embedded in source files
152 @fgrep -i -n FIXME ${MARKDOWN_SRC} || true
155 ## IV. Auxililary (plumbing) commands
156 ## =================================================
158 ## * commands : show all commands.
160 @sed -n -e '/^##/s|^##[[:space:]]*||p' $(MAKEFILE_LIST)