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