1 ## ========================================
2 ## Commands for both workshop and lesson websites.
5 MAKEFILES=Makefile $(wildcard *.mk)
6 JEKYLL=bundle config --local set path .vendor/bundle && bundle install && bundle update && bundle exec jekyll
7 PARSER=bin/markdown_ast.rb
10 # Check Python 3 is installed and determine if it's called via python3 or python
11 # (https://stackoverflow.com/a/4933395)
12 PYTHON3_EXE := $(shell which python3 2>/dev/null)
13 ifneq (, $(PYTHON3_EXE))
14 ifeq (,$(findstring Microsoft/WindowsApps/python3,$(subst \,/,$(PYTHON3_EXE))))
20 PYTHON_EXE := $(shell which python 2>/dev/null)
21 ifneq (, $(PYTHON_EXE))
22 PYTHON_VERSION_FULL := $(wordlist 2,4,$(subst ., ,$(shell python --version 2>&1)))
23 PYTHON_VERSION_MAJOR := $(word 1,${PYTHON_VERSION_FULL})
24 ifneq (3, ${PYTHON_VERSION_MAJOR})
25 $(error "Your system does not appear to have Python 3 installed.")
29 $(error "Your system does not appear to have any Python installed.")
35 .PHONY : commands clean files
38 .DEFAULT_GOAL := commands
40 ## I. Commands for both workshop and lesson websites
41 ## =================================================
43 ## * serve : render website and run a local server
47 ## * site : build website but do not run a server
51 ## * docker-serve : use Docker to serve the site
53 docker pull carpentries/lesson-docker:latest
55 -v $${PWD}:/home/rstudio \
59 -e GROUPID=$$(id -g) \
60 carpentries/lesson-docker:latest
62 ## * repo-check : check repository settings
64 @${PYTHON} bin/repo_check.py -s .
66 ## * clean : clean up junk files
70 @rm -rf bin/__pycache__
71 @find . -name .DS_Store -exec rm {} \;
72 @find . -name '*~' -exec rm {} \;
73 @find . -name '*.pyc' -exec rm {} \;
75 ## * clean-rmd : clean intermediate R files (that need to be committed to the repo)
82 ## II. Commands specific to workshop websites
83 ## =================================================
85 .PHONY : workshop-check
87 ## * workshop-check : check workshop homepage
89 @${PYTHON} bin/workshop_check.py .
93 ## III. Commands specific to lesson websites
94 ## =================================================
96 .PHONY : lesson-check lesson-md lesson-files lesson-fixme install-rmd-deps
99 RMD_SRC = $(wildcard _episodes_rmd/*.Rmd)
100 RMD_DST = $(patsubst _episodes_rmd/%.Rmd,_episodes/%.md,$(RMD_SRC))
102 # Lesson source files in the order they appear in the navigation menu.
107 $(sort $(wildcard _episodes/*.md)) \
109 $(sort $(wildcard _extras/*.md)) \
112 # Generated lesson files in the order they appear in the navigation menu.
115 ${DST}/conduct/index.html \
116 ${DST}/setup/index.html \
117 $(patsubst _episodes/%.md,${DST}/%/index.html,$(sort $(wildcard _episodes/*.md))) \
118 ${DST}/reference.html \
119 $(patsubst _extras/%.md,${DST}/%/index.html,$(sort $(wildcard _extras/*.md))) \
120 ${DST}/license/index.html
122 ## * install-rmd-deps : Install R packages dependencies to build the RMarkdown lesson
124 @${SHELL} bin/install_r_deps.sh
126 ## * lesson-md : convert Rmarkdown files to markdown
127 lesson-md : ${RMD_DST}
129 _episodes/%.md: _episodes_rmd/%.Rmd install-rmd-deps
131 @bin/knit_lessons.sh $< $@
133 ## * lesson-check : validate lesson Markdown
134 lesson-check : lesson-fixme
135 @${PYTHON} bin/lesson_check.py -s . -p ${PARSER} -r _includes/links.md
137 ## * lesson-check-all : validate lesson Markdown, checking line lengths and trailing whitespace
139 @${PYTHON} bin/lesson_check.py -s . -p ${PARSER} -r _includes/links.md -l -w --permissive
141 ## * unittest : run unit tests on checking tools
143 @${PYTHON} bin/test_lesson_check.py
145 ## * lesson-files : show expected names of generated files for debugging
147 @echo 'RMD_SRC:' ${RMD_SRC}
148 @echo 'RMD_DST:' ${RMD_DST}
149 @echo 'MARKDOWN_SRC:' ${MARKDOWN_SRC}
150 @echo 'HTML_DST:' ${HTML_DST}
152 ## * lesson-fixme : show FIXME markers embedded in source files
154 @grep --fixed-strings --word-regexp --line-number --no-messages FIXME ${MARKDOWN_SRC} || true
157 ## IV. Auxililary (plumbing) commands
158 ## =================================================
160 ## * commands : show all commands.
162 @sed -n -e '/^##/s|^##[[:space:]]*||p' $(MAKEFILE_LIST)