Makefile: fix 'lesson-fixme' target for Windows (#486)
[rnaseq-cwl-training.git] / Makefile
1 ## ========================================
2 ## Commands for both workshop and lesson websites.
3
4 # Settings
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
8 DST=_site
9
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))))
15     PYTHON := python3
16   endif
17 endif
18
19 ifeq (,$(PYTHON))
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.")
26     endif
27     PYTHON := python
28   else
29       $(error "Your system does not appear to have any Python installed.")
30   endif
31 endif
32
33
34 # Controls
35 .PHONY : commands clean files
36
37 # Default target
38 .DEFAULT_GOAL := commands
39
40 ## I. Commands for both workshop and lesson websites
41 ## =================================================
42
43 ## * serve            : render website and run a local server
44 serve : lesson-md
45         ${JEKYLL} serve
46
47 ## * site             : build website but do not run a server
48 site : lesson-md
49         ${JEKYLL} build
50
51 ## * docker-serve     : use Docker to serve the site
52 docker-serve :
53         docker pull carpentries/lesson-docker:latest
54         docker run --rm -it \
55                 -v $${PWD}:/home/rstudio \
56                 -p 4000:4000 \
57                 -p 8787:8787 \
58                 -e USERID=$$(id -u) \
59                 -e GROUPID=$$(id -g) \
60                 carpentries/lesson-docker:latest
61
62 ## * repo-check       : check repository settings
63 repo-check :
64         @${PYTHON} bin/repo_check.py -s .
65
66 ## * clean            : clean up junk files
67 clean :
68         @rm -rf ${DST}
69         @rm -rf .sass-cache
70         @rm -rf bin/__pycache__
71         @find . -name .DS_Store -exec rm {} \;
72         @find . -name '*~' -exec rm {} \;
73         @find . -name '*.pyc' -exec rm {} \;
74
75 ## * clean-rmd        : clean intermediate R files (that need to be committed to the repo)
76 clean-rmd :
77         @rm -rf ${RMD_DST}
78         @rm -rf fig/rmd-*
79
80
81 ##
82 ## II. Commands specific to workshop websites
83 ## =================================================
84
85 .PHONY : workshop-check
86
87 ## * workshop-check   : check workshop homepage
88 workshop-check :
89         @${PYTHON} bin/workshop_check.py .
90
91
92 ##
93 ## III. Commands specific to lesson websites
94 ## =================================================
95
96 .PHONY : lesson-check lesson-md lesson-files lesson-fixme
97
98 # RMarkdown files
99 RMD_SRC = $(wildcard _episodes_rmd/??-*.Rmd)
100 RMD_DST = $(patsubst _episodes_rmd/%.Rmd,_episodes/%.md,$(RMD_SRC))
101
102 # Lesson source files in the order they appear in the navigation menu.
103 MARKDOWN_SRC = \
104   index.md \
105   CODE_OF_CONDUCT.md \
106   setup.md \
107   $(sort $(wildcard _episodes/*.md)) \
108   reference.md \
109   $(sort $(wildcard _extras/*.md)) \
110   LICENSE.md
111
112 # Generated lesson files in the order they appear in the navigation menu.
113 HTML_DST = \
114   ${DST}/index.html \
115   ${DST}/conduct/index.html \
116   ${DST}/setup/index.html \
117   $(patsubst _episodes/%.md,${DST}/%/index.html,$(sort $(wildcard _episodes/*.md))) \
118   ${DST}/reference/index.html \
119   $(patsubst _extras/%.md,${DST}/%/index.html,$(sort $(wildcard _extras/*.md))) \
120   ${DST}/license/index.html
121
122 ## * lesson-md        : convert Rmarkdown files to markdown
123 lesson-md : ${RMD_DST}
124
125 _episodes/%.md: _episodes_rmd/%.Rmd
126         @bin/knit_lessons.sh $< $@
127
128 ## * lesson-check     : validate lesson Markdown
129 lesson-check : lesson-fixme
130         @${PYTHON} bin/lesson_check.py -s . -p ${PARSER} -r _includes/links.md
131
132 ## * lesson-check-all : validate lesson Markdown, checking line lengths and trailing whitespace
133 lesson-check-all :
134         @${PYTHON} bin/lesson_check.py -s . -p ${PARSER} -r _includes/links.md -l -w --permissive
135
136 ## * unittest         : run unit tests on checking tools
137 unittest :
138         @${PYTHON} bin/test_lesson_check.py
139
140 ## * lesson-files     : show expected names of generated files for debugging
141 lesson-files :
142         @echo 'RMD_SRC:' ${RMD_SRC}
143         @echo 'RMD_DST:' ${RMD_DST}
144         @echo 'MARKDOWN_SRC:' ${MARKDOWN_SRC}
145         @echo 'HTML_DST:' ${HTML_DST}
146
147 ## * lesson-fixme     : show FIXME markers embedded in source files
148 lesson-fixme :
149         @grep --fixed-strings --word-regexp --line-number --no-messages FIXME ${MARKDOWN_SRC} || true
150
151 ##
152 ## IV. Auxililary (plumbing) commands
153 ## =================================================
154
155 ## * commands         : show all commands.
156 commands :
157         @sed -n -e '/^##/s|^##[[:space:]]*||p' $(MAKEFILE_LIST)