-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathMakefile
115 lines (98 loc) · 3.02 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
OBJ = public_html
VENV = .venv
PYTHON_INTERPRETER = python3
YAJSV = bin/yajsv
YAJSV_VERSION = 1.4.0
YAJSV_DOWNLOAD_URL = https://github.com/neilpa/yajsv/releases/download/v$(YAJSV_VERSION)
ifeq ($(VENV),.)
PYTHON = $(PYTHON_INTERPRETER)
else
PYTHON = $(VENV)/bin/python
endif
LANGS = \
$(patsubst %.md,%,$(wildcard [a-z][a-z].md)) \
$(patsubst %.md,%,$(wildcard [a-z][a-z]-[A-Z][a-z][a-z][a-z].md))
LANG_HREFS = $(patsubst %:en/,%:./,$(foreach f,$(LANGS),$(f):$(f)/))
TABLES = $(wildcard tables/*.yaml)
TEMPLATES = $(wildcard templates/*.html)
OBJ_FILES = \
$(patsubst %,$(OBJ)/%,$(wildcard *.css)) \
$(patsubst %,$(OBJ)/%,$(wildcard *.js)) \
$(patsubst %,$(OBJ)/%,$(wildcard *.svg)) \
$(patsubst $(OBJ)/en/%,$(OBJ)/%,$(LANGS:%=$(OBJ)/%/index.html)) \
$(OBJ)/.nojekyll
all: lint $(OBJ_FILES)
clean:
rm -rf $(OBJ_FILES) $(OBJ) $(YAJSV)
rmdir $(dir $(YAJSV)) || true
[ "$(VENV)" = "." ] || rm -rf $(VENV)
lint: yaml-schema mypy yamllint
validate-html5: $(VENV)/ $(OBJ_FILES)
$(VENV)/bin/html5validator \
--root $(OBJ) \
--ignore '"latn" does not match the format for any permissible subtag'
yaml-schema: $(YAJSV) table.schema.yaml $(TABLES)
$(YAJSV) -s table.schema.yaml $(TABLES)
yamllint: $(VENV)/ $(TABLES) .yamllint
$(PYTHON) -m yamllint -c .yamllint --strict $(TABLES)
mypy: $(VENV)/ build.py
$(PYTHON) -m mypy build.py
$(VENV)/: requirements.txt
if [ "$(VENV)" != "." ]; then \
if [ ! -d $(VENV) ]; then \
if ! $(PYTHON_INTERPRETER) -m venv $(VENV); then \
virtualenv -p $(PYTHON_INTERPRETER) venv; \
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py; \
$(VENV)/bin/python get-pip.py; \
rm get-pip.py; \
fi; \
fi; \
$(VENV)/bin/python -m pip install -U pip setuptools wheel; \
$(VENV)/bin/pip install -U -r requirements.txt; \
echo "*" > $(VENV)/.gitignore; \
fi
$(YAJSV):
mkdir -p $(dir $(YAJSV))
{ \
echo "#!$$(which sh)"; \
echo "echo 'yajsv was failed to be installed;' > /dev/stderr"; \
echo "echo 'lint was skipped...' > /dev/stderr"; \
} > $(YAJSV)
GOOS="$$(uname -s | tr '[:upper:]' '[:lower:]')"; \
case "$$(uname -m)" in \
x86_64) \
GOARCH=amd64; \
;; \
*) \
exit 0; \
;; \
esac; \
download_url=$(YAJSV_DOWNLOAD_URL)/yajsv.$$GOOS.$$GOARCH; \
if command -v curl > /dev/null; then \
curl -L -o $(YAJSV) $$download_url || exit 0; \
else \
wget -O $(YAJSV) $$download_url || exit 0; \
fi
chmod +x $(YAJSV)
$(OBJ)/:
mkdir -p $(OBJ)
$(OBJ)/.nojekyll: $(OBJ)/
touch $(OBJ)/.nojekyll
$(OBJ)/%.svg: %.svg | $(OBJ)/
cp $< $@
$(OBJ)/%.css: %.css | $(OBJ)/
cp $< $@
$(OBJ)/%.js: %.js | $(OBJ)/
cp $< $@
$(OBJ)/index.html: en.md $(VENV)/ build.py $(TABLES) $(TEMPLATES) | $(OBJ)/
$(PYTHON) build.py \
$(if $(URL_BASE),--base-href=$(URL_BASE),) \
$(LANG_HREFS:%=--lang=%$(if $(URL_BASE),,index.html)) en $< > $@
$(OBJ)/%/index.html: %.md $(VENV)/ build.py $(TABLES) $(TEMPLATES) | $(OBJ)/
mkdir -p $(dir $@)
$(PYTHON) build.py \
--base-href=$(or $(URL_BASE),../) \
$(LANG_HREFS:%=--lang=%$(if $(URL_BASE),,index.html)) \
$(basename $(notdir $<)) \
$< \
> $@