1+ # Use /bin/bash instead of /bin/sh
2+ export SHELL = /bin/bash
3+
14# # ========================================
25# # Commands for both workshop and lesson websites.
36
47# Settings
58MAKEFILES =Makefile $(wildcard * .mk)
6- JEKYLL =jekyll
9+ JEKYLL =bundle config set path '.vendor/bundle' && bundle install && bundle update && bundle exec jekyll
710PARSER =bin/markdown_ast.rb
811DST =_site
912
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))))
18+ PYTHON := python3
19+ endif
20+ endif
21+
22+ ifeq (,$(PYTHON ) )
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.")
29+ endif
30+ PYTHON := python
31+ else
32+ $(error "Your system does not appear to have any Python installed.")
33+ endif
34+ endif
35+
36+
1037# Controls
1138.PHONY : commands clean files
12- .NOTPARALLEL :
13- all : commands
1439
15- # # commands : show all commands.
16- commands :
17- @grep -h -E ' ^##' ${MAKEFILES} | sed -e ' s/## //g'
40+ # Default target
41+ .DEFAULT_GOAL := commands
42+
43+ # # I. Commands for both workshop and lesson websites
44+ # # =================================================
1845
19- # # serve : run a local server.
46+ # # * serve : render website and run a local server
2047serve : lesson-md
2148 ${JEKYLL} serve
2249
23- # # site : build files but do not run a server.
50+ # # * site : build website but do not run a server
2451site : lesson-md
2552 ${JEKYLL} build
2653
27- # repo-check : check repository settings.
54+ # # * docker-serve : use Docker to serve the site
55+ docker-serve :
56+ docker pull carpentries/lesson-docker:latest
57+ docker run --rm -it \
58+ -v $$ {PWD}:/home/rstudio \
59+ -p 4000:4000 \
60+ -p 8787:8787 \
61+ -e USERID=$$(id -u ) \
62+ -e GROUPID=$$(id -g ) \
63+ carpentries/lesson-docker:latest
64+
65+ # # * repo-check : check repository settings
2866repo-check :
29- @bin/repo_check.py -s .
67+ @${PYTHON} bin/repo_check.py -s .
3068
31- # # clean : clean up junk files.
69+ # # * clean : clean up junk files
3270clean :
3371 @rm -rf ${DST}
3472 @rm -rf .sass-cache
@@ -37,22 +75,26 @@ clean :
3775 @find . -name ' *~' -exec rm {} \;
3876 @find . -name ' *.pyc' -exec rm {} \;
3977
40- # # clean-rmd : clean intermediate R files (that need to be committed to the repo).
41- clear -rmd :
78+ # # * clean-rmd : clean intermediate R files (that need to be committed to the repo)
79+ clean -rmd :
4280 @rm -rf ${RMD_DST}
4381 @rm -rf fig/rmd-*
4482
45- # # ----------------------------------------
46- # # Commands specific to workshop websites.
83+
84+ # #
85+ # # II. Commands specific to workshop websites
86+ # # =================================================
4787
4888.PHONY : workshop-check
4989
50- # # workshop-check : check workshop homepage.
90+ # # * workshop-check : check workshop homepage
5191workshop-check :
52- @bin/workshop_check.py .
92+ @${PYTHON} bin/workshop_check.py .
93+
5394
54- # # ----------------------------------------
55- # # Commands specific to lesson websites.
95+ # #
96+ # # III. Commands specific to lesson websites
97+ # # =================================================
5698
5799.PHONY : lesson-check lesson-md lesson-files lesson-fixme
58100
@@ -63,59 +105,56 @@ RMD_DST = $(patsubst _episodes_rmd/%.Rmd,_episodes/%.md,$(RMD_SRC))
63105# Lesson source files in the order they appear in the navigation menu.
64106MARKDOWN_SRC = \
65107 index.md \
66- CONDUCT .md \
108+ CODE_OF_CONDUCT .md \
67109 setup.md \
68- $(wildcard _episodes/* .md) \
110+ $(sort $( wildcard _episodes/* .md) ) \
69111 reference.md \
70- $(wildcard _extras/* .md) \
112+ $(sort $( wildcard _extras/* .md) ) \
71113 LICENSE.md
72114
73115# Generated lesson files in the order they appear in the navigation menu.
74116HTML_DST = \
75117 ${DST}/index.html \
76118 ${DST}/conduct/index.html \
77119 ${DST}/setup/index.html \
78- $(patsubst _episodes/% .md,${DST}/% /index.html,$(wildcard _episodes/* .md) ) \
120+ $(patsubst _episodes/% .md,${DST}/% /index.html,$(sort $( wildcard _episodes/* .md) ) ) \
79121 ${DST}/reference/index.html \
80- $(patsubst _extras/% .md,${DST}/% /index.html,$(wildcard _extras/* .md) ) \
122+ $(patsubst _extras/% .md,${DST}/% /index.html,$(sort $( wildcard _extras/* .md) ) ) \
81123 ${DST}/license/index.html
82124
83- # # lesson-md : convert Rmarkdown files to markdown
125+ # # * lesson-md : convert Rmarkdown files to markdown
84126lesson-md : ${RMD_DST}
85127
86- # Use of .NOTPARALLEL makes rule execute only once
87- ${RMD_DST} : ${RMD_SRC}
88- @bin/knit_lessons.sh ${RMD_SRC}
128+ _episodes/% .md : _episodes_rmd/% .Rmd
129+ @bin/knit_lessons.sh $< $@
89130
90- # # lesson-check : validate lesson Markdown.
91- lesson-check :
92- @bin/lesson_check.py -s . -p ${PARSER} -r _includes/links.md
131+ # * lesson-check : validate lesson Markdown
132+ lesson-check : lesson-fixme
133+ @${PYTHON} bin/lesson_check.py -s . -p ${PARSER} -r _includes/links.md
93134
94- # # lesson-check-all : validate lesson Markdown, checking line lengths and trailing whitespace.
135+ # # * lesson-check-all : validate lesson Markdown, checking line lengths and trailing whitespace
95136lesson-check-all :
96- @bin/lesson_check.py -s . -p ${PARSER} -l -w
137+ @${PYTHON} bin/lesson_check.py -s . -p ${PARSER} -r _includes/links.md - l -w --permissive
97138
98- # # lesson-figures : re-generate inclusion displaying all figures.
99- lesson-figures :
100- @bin/extract_figures.py -p ${PARSER} ${MARKDOWN_SRC} > _includes/all_figures.html
101-
102- # # unittest : run unit tests on checking tools.
139+ # # * unittest : run unit tests on checking tools
103140unittest :
104- python bin/test_lesson_check.py
141+ @ ${PYTHON} bin/test_lesson_check.py
105142
106- # # lesson-files : show expected names of generated files for debugging.
143+ # # * lesson-files : show expected names of generated files for debugging
107144lesson-files :
108145 @echo ' RMD_SRC:' ${RMD_SRC}
109146 @echo ' RMD_DST:' ${RMD_DST}
110147 @echo ' MARKDOWN_SRC:' ${MARKDOWN_SRC}
111148 @echo ' HTML_DST:' ${HTML_DST}
112149
113- # # lesson-fixme : show FIXME markers embedded in source files.
150+ # # * lesson-fixme : show FIXME markers embedded in source files
114151lesson-fixme :
115152 @fgrep -i -n FIXME ${MARKDOWN_SRC} || true
116153
117- # -------------------------------------------------------------------------------
118- # Include extra commands if available.
119- # -------------------------------------------------------------------------------
154+ # #
155+ # # IV. Auxililary (plumbing) commands
156+ # # =================================================
120157
121- -include commands.mk
158+ # # * commands : show all commands.
159+ commands :
160+ @sed -n -e ' /^##/s|^##[[:space:]]*||p' $(MAKEFILE_LIST )
0 commit comments