Makefile: detect Python 3
[rnaseq-cwl-training.git] / Makefile
1 ## ========================================
2 ## Commands for both workshop and lesson websites.
3
4 # Settings
5 MAKEFILES=Makefile $(wildcard *.mk)
6 JEKYLL=jekyll
7 JEKYLL_VERSION=3.8.5
8 PARSER=bin/markdown_ast.rb
9 DST=_site
10
11 # Check Python 3 (https://stackoverflow.com/a/4933395)
12 ifneq (, $(shell which python3))
13   PYTHON := python3
14 else ifneq (, $(shell which python))
15   PYTHON_VERSION_FULL := $(wordlist 2,4,$(subst ., ,$(shell python --version 2>&1)))
16   PYTHON_VERSION_MAJOR := $(word 1,${PYTHON_VERSION_FULL})
17   ifneq (3, ${PYTHON_VERSION_MAJOR})
18     $(error "Your system does not appear to have Python 3 installed.")
19   endif
20   PYTHON := python
21 else
22     $(error "Your system does not appear to have any Python installed.")
23 endif
24
25
26 # Controls
27 .PHONY : commands clean files
28 .NOTPARALLEL:
29 all : commands
30
31 ## commands         : show all commands.
32 commands :
33         @grep -h -E '^##' ${MAKEFILES} | sed -e 's/## //g'
34
35 ## docker-serve     : use docker to build the site
36 docker-serve :
37         docker run --rm -it -v ${PWD}:/srv/jekyll -p 127.0.0.1:4000:4000 jekyll/jekyll:${JEKYLL_VERSION} make serve
38
39 ## serve            : run a local server.
40 serve : lesson-md
41         ${JEKYLL} serve
42
43 ## site             : build files but do not run a server.
44 site : lesson-md
45         ${JEKYLL} build
46
47 # repo-check        : check repository settings.
48 repo-check :
49         @bin/repo_check.py -s .
50
51 ## clean            : clean up junk files.
52 clean :
53         @rm -rf ${DST}
54         @rm -rf .sass-cache
55         @rm -rf bin/__pycache__
56         @find . -name .DS_Store -exec rm {} \;
57         @find . -name '*~' -exec rm {} \;
58         @find . -name '*.pyc' -exec rm {} \;
59
60 ## clean-rmd        : clean intermediate R files (that need to be committed to the repo).
61 clean-rmd :
62         @rm -rf ${RMD_DST}
63         @rm -rf fig/rmd-*
64
65 ## ----------------------------------------
66 ## Commands specific to workshop websites.
67
68 .PHONY : workshop-check
69
70 ## workshop-check   : check workshop homepage.
71 workshop-check :
72         @${PYTHON} bin/workshop_check.py .
73
74 ## ----------------------------------------
75 ## Commands specific to lesson websites.
76
77 .PHONY : lesson-check lesson-md lesson-files lesson-fixme
78
79 # RMarkdown files
80 RMD_SRC = $(wildcard _episodes_rmd/??-*.Rmd)
81 RMD_DST = $(patsubst _episodes_rmd/%.Rmd,_episodes/%.md,$(RMD_SRC))
82
83 # Lesson source files in the order they appear in the navigation menu.
84 MARKDOWN_SRC = \
85   index.md \
86   CODE_OF_CONDUCT.md \
87   setup.md \
88   $(sort $(wildcard _episodes/*.md)) \
89   reference.md \
90   $(sort $(wildcard _extras/*.md)) \
91   LICENSE.md
92
93 # Generated lesson files in the order they appear in the navigation menu.
94 HTML_DST = \
95   ${DST}/index.html \
96   ${DST}/conduct/index.html \
97   ${DST}/setup/index.html \
98   $(patsubst _episodes/%.md,${DST}/%/index.html,$(sort $(wildcard _episodes/*.md))) \
99   ${DST}/reference/index.html \
100   $(patsubst _extras/%.md,${DST}/%/index.html,$(sort $(wildcard _extras/*.md))) \
101   ${DST}/license/index.html
102
103 ## lesson-md        : convert Rmarkdown files to markdown
104 lesson-md : ${RMD_DST}
105
106 _episodes/%.md: _episodes_rmd/%.Rmd
107         @bin/knit_lessons.sh $< $@
108
109 ## lesson-check     : validate lesson Markdown.
110 lesson-check : lesson-fixme
111         @${PYTHON} bin/lesson_check.py -s . -p ${PARSER} -r _includes/links.md
112
113 ## lesson-check-all : validate lesson Markdown, checking line lengths and trailing whitespace.
114 lesson-check-all :
115         @${PYTHON} bin/lesson_check.py -s . -p ${PARSER} -r _includes/links.md -l -w --permissive
116
117 ## unittest         : run unit tests on checking tools.
118 unittest :
119         @${PYTHON} bin/test_lesson_check.py
120
121 ## lesson-files     : show expected names of generated files for debugging.
122 lesson-files :
123         @echo 'RMD_SRC:' ${RMD_SRC}
124         @echo 'RMD_DST:' ${RMD_DST}
125         @echo 'MARKDOWN_SRC:' ${MARKDOWN_SRC}
126         @echo 'HTML_DST:' ${HTML_DST}
127
128 ## lesson-fixme     : show FIXME markers embedded in source files.
129 lesson-fixme :
130         @fgrep -i -n FIXME ${MARKDOWN_SRC} || true
131
132 #-------------------------------------------------------------------------------
133 # Include extra commands if available.
134 #-------------------------------------------------------------------------------
135
136 -include commands.mk