Makefile: improve commands target and commands categories (#450)
[rnaseq-cwl-training.git] / Makefile
1 # Use /bin/bash instead of /bin/sh
2 export SHELL = /bin/bash
3
4 ## ========================================
5 ## Commands for both workshop and lesson websites.
6
7 # Settings
8 MAKEFILES=Makefile $(wildcard *.mk)
9 JEKYLL_VERSION=3.8.5
10 JEKYLL=bundle install --path .vendor/bundle && bundle update && bundle exec jekyll
11 PARSER=bin/markdown_ast.rb
12 DST=_site
13
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))))
19     PYTHON := python3
20   endif
21 endif
22
23 ifeq (,$(PYTHON))
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.")
30     endif
31     PYTHON := python
32   else
33       $(error "Your system does not appear to have any Python installed.")
34   endif
35 endif
36
37
38 # Controls
39 .PHONY : commands clean files
40
41 # Default target
42 .DEFAULT_GOAL := commands
43
44 ## I. Commands for both workshop and lesson websites
45 ## =================================================
46
47 ## * serve            : render website and run a local server
48 serve : lesson-md
49         ${JEKYLL} serve
50
51 ## * site             : build website but do not run a server
52 site : lesson-md
53         ${JEKYLL} build
54
55 ## * docker-serve     : use Docker to serve the site
56 docker-serve :
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
62
63 ## * repo-check       : check repository settings
64 repo-check :
65         @${PYTHON} bin/repo_check.py -s .
66
67 ## * clean            : clean up junk files
68 clean :
69         @rm -rf ${DST}
70         @rm -rf .sass-cache
71         @rm -rf bin/__pycache__
72         @find . -name .DS_Store -exec rm {} \;
73         @find . -name '*~' -exec rm {} \;
74         @find . -name '*.pyc' -exec rm {} \;
75
76 ## * clean-rmd        : clean intermediate R files (that need to be committed to the repo)
77 clean-rmd :
78         @rm -rf ${RMD_DST}
79         @rm -rf fig/rmd-*
80
81
82 ##
83 ## II. Commands specific to workshop websites
84 ## =================================================
85
86 .PHONY : workshop-check
87
88 ## * workshop-check   : check workshop homepage
89 workshop-check :
90         @${PYTHON} bin/workshop_check.py .
91
92
93 ##
94 ## III. Commands specific to lesson websites
95 ## =================================================
96
97 .PHONY : lesson-check lesson-md lesson-files lesson-fixme
98
99 # RMarkdown files
100 RMD_SRC = $(wildcard _episodes_rmd/??-*.Rmd)
101 RMD_DST = $(patsubst _episodes_rmd/%.Rmd,_episodes/%.md,$(RMD_SRC))
102
103 # Lesson source files in the order they appear in the navigation menu.
104 MARKDOWN_SRC = \
105   index.md \
106   CODE_OF_CONDUCT.md \
107   setup.md \
108   $(sort $(wildcard _episodes/*.md)) \
109   reference.md \
110   $(sort $(wildcard _extras/*.md)) \
111   LICENSE.md
112
113 # Generated lesson files in the order they appear in the navigation menu.
114 HTML_DST = \
115   ${DST}/index.html \
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
122
123 ## * lesson-md        : convert Rmarkdown files to markdown
124 lesson-md : ${RMD_DST}
125
126 _episodes/%.md: _episodes_rmd/%.Rmd
127         @bin/knit_lessons.sh $< $@
128
129 # * lesson-check     : validate lesson Markdown
130 lesson-check : lesson-fixme
131         @${PYTHON} bin/lesson_check.py -s . -p ${PARSER} -r _includes/links.md
132
133 ## * lesson-check-all : validate lesson Markdown, checking line lengths and trailing whitespace
134 lesson-check-all :
135         @${PYTHON} bin/lesson_check.py -s . -p ${PARSER} -r _includes/links.md -l -w --permissive
136
137 ## * unittest         : run unit tests on checking tools
138 unittest :
139         @${PYTHON} bin/test_lesson_check.py
140
141 ## * lesson-files     : show expected names of generated files for debugging
142 lesson-files :
143         @echo 'RMD_SRC:' ${RMD_SRC}
144         @echo 'RMD_DST:' ${RMD_DST}
145         @echo 'MARKDOWN_SRC:' ${MARKDOWN_SRC}
146         @echo 'HTML_DST:' ${HTML_DST}
147
148 ## * lesson-fixme     : show FIXME markers embedded in source files
149 lesson-fixme :
150         @fgrep -i -n FIXME ${MARKDOWN_SRC} || true
151
152 ##
153 ## IV. Auxililary (plumbing) commands
154 ## =================================================
155
156 ## * commands         : show all commands.
157 commands :
158         @sed -n -e '/^##/s|^##[[:space:]]*||p' $(MAKEFILE_LIST)