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