refactor use of docker
[rnaseq-cwl-training.git] / Makefile
1 ## ========================================
2 ## Commands for both workshop and lesson websites.
3
4 # Settings
5 MAKEFILES=Makefile $(wildcard *.mk)
6 JEKYLL_VERSION=3.8.5
7 JEKYLL=bundle install --path .vendor/bundle && bundle update && bundle exec jekyll
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 --volume ${PWD}:/srv/jekyll \
47            --volume=${PWD}/.docker-vendor/bundle:/usr/local/bundle \
48            -p 127.0.0.1:4000:4000 \
49            jekyll/jekyll:${JEKYLL_VERSION} \
50            bin/run-make-docker-serve.sh
51
52 ## serve            : run a local server.
53 serve : lesson-md
54         ${JEKYLL} serve
55
56 ## site             : build files but do not run a server.
57 site : lesson-md
58         ${JEKYLL} build
59
60 # repo-check        : check repository settings.
61 repo-check :
62         @bin/repo_check.py -s .
63
64 ## clean            : clean up junk files.
65 clean :
66         @rm -rf ${DST}
67         @rm -rf .sass-cache
68         @rm -rf bin/__pycache__
69         @find . -name .DS_Store -exec rm {} \;
70         @find . -name '*~' -exec rm {} \;
71         @find . -name '*.pyc' -exec rm {} \;
72
73 ## clean-rmd        : clean intermediate R files (that need to be committed to the repo).
74 clean-rmd :
75         @rm -rf ${RMD_DST}
76         @rm -rf fig/rmd-*
77
78 ## ----------------------------------------
79 ## Commands specific to workshop websites.
80
81 .PHONY : workshop-check
82
83 ## workshop-check   : check workshop homepage.
84 workshop-check :
85         @${PYTHON} bin/workshop_check.py .
86
87 ## ----------------------------------------
88 ## Commands specific to lesson websites.
89
90 .PHONY : lesson-check lesson-md lesson-files lesson-fixme
91
92 # RMarkdown files
93 RMD_SRC = $(wildcard _episodes_rmd/??-*.Rmd)
94 RMD_DST = $(patsubst _episodes_rmd/%.Rmd,_episodes/%.md,$(RMD_SRC))
95
96 # Lesson source files in the order they appear in the navigation menu.
97 MARKDOWN_SRC = \
98   index.md \
99   CODE_OF_CONDUCT.md \
100   setup.md \
101   $(sort $(wildcard _episodes/*.md)) \
102   reference.md \
103   $(sort $(wildcard _extras/*.md)) \
104   LICENSE.md
105
106 # Generated lesson files in the order they appear in the navigation menu.
107 HTML_DST = \
108   ${DST}/index.html \
109   ${DST}/conduct/index.html \
110   ${DST}/setup/index.html \
111   $(patsubst _episodes/%.md,${DST}/%/index.html,$(sort $(wildcard _episodes/*.md))) \
112   ${DST}/reference/index.html \
113   $(patsubst _extras/%.md,${DST}/%/index.html,$(sort $(wildcard _extras/*.md))) \
114   ${DST}/license/index.html
115
116 ## lesson-md        : convert Rmarkdown files to markdown
117 lesson-md : ${RMD_DST}
118
119 _episodes/%.md: _episodes_rmd/%.Rmd
120         @bin/knit_lessons.sh $< $@
121
122 ## lesson-check     : validate lesson Markdown.
123 lesson-check : lesson-fixme
124         @${PYTHON} bin/lesson_check.py -s . -p ${PARSER} -r _includes/links.md
125
126 ## lesson-check-all : validate lesson Markdown, checking line lengths and trailing whitespace.
127 lesson-check-all :
128         @${PYTHON} bin/lesson_check.py -s . -p ${PARSER} -r _includes/links.md -l -w --permissive
129
130 ## unittest         : run unit tests on checking tools.
131 unittest :
132         @${PYTHON} bin/test_lesson_check.py
133
134 ## lesson-files     : show expected names of generated files for debugging.
135 lesson-files :
136         @echo 'RMD_SRC:' ${RMD_SRC}
137         @echo 'RMD_DST:' ${RMD_DST}
138         @echo 'MARKDOWN_SRC:' ${MARKDOWN_SRC}
139         @echo 'HTML_DST:' ${HTML_DST}
140
141 ## lesson-fixme     : show FIXME markers embedded in source files.
142 lesson-fixme :
143         @fgrep -i -n FIXME ${MARKDOWN_SRC} || true
144
145 #-------------------------------------------------------------------------------
146 # Include extra commands if available.
147 #-------------------------------------------------------------------------------
148
149 -include commands.mk