aboutsummaryrefslogtreecommitdiff
path: root/yomichan/makefile
blob: f8bc4a5e5417eb89e9c8358eff13fc41cc46a39d (plain)
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
.PHONY: clean patch download backup yomichan
all: patch
download: yomichan
backup: download
patch: backup

# template rules in this file do not have explicit dependencies, this is to
# allow dependencies regardless of subdirectory. the dependencies are commented
# out instead for readability

include ../common.mk

yomichan-chrome.zip:
	curl https://github.com/FooSoft/yomichan/releases/latest/download/$@ -Lso- > $@

yomichan/images/%.svg: # %.svg
	cp $< $@

yomichan/css/%.css: # %.css
	cp $< $@

yomichan/js/%.js: # %.js
	cp $< $@

yomichan/%.patched: # %.bak %.diff
	patch -so - $(@:.patched=.bak) < $< > $@

# this rule must not depend on the original file, or the .bak will be made from
# an already patched file
yomichan/%.bak: # %
	cp $(@:.bak=) $@

yomichan: yomichan-chrome.zip
	unzip -qo $< -d $@


info.html.diff: info.html.diff.m4

# .diff patches
backup: yomichan/search.html.bak
yomichan/search.html.patched: search.html.diff
backup: yomichan/settings.html.bak
yomichan/settings.html.patched: settings.html.diff
backup: yomichan/info.html.bak
yomichan/info.html.patched: info.html.diff
backup: yomichan/css/action-popup.css.bak
yomichan/css/action-popup.css.patched: action-popup.css.diff

# updated extension manifest (allow userscript loading)
backup: yomichan/manifest.json.bak
yomichan/manifest.json.patched: yomichan/manifest.json.bak
	jq '.content_scripts[0].js[.content_scripts[0].js | length] |= .+ "js/userscript-loader.js"' $< |\
	jq '.content_security_policy |= .+ "'"; script-src 'self' 'unsafe-eval'"'"' |\
	jq '.content_security_policy |= sub("img-src";"img-src data:")' > $@
# userscript loader files
yomichan/js/userscript-loader.js: userscript-loader.js
yomichan/images/script.svg: script.svg
yomichan/css/userscript-settings.css: userscript-settings.css


# install userscript loader
patch: yomichan/js/userscript-loader.js
patch: yomichan/images/script.svg
patch: yomichan/css/userscript-settings.css
# .diff patches
patch: yomichan/search.html.patched
patch: yomichan/settings.html.patched
patch: yomichan/manifest.json.patched
patch: yomichan/info.html.patched
patch: yomichan/css/action-popup.css.patched
# move .patched to original filenames
patch:
	mv yomichan/search.html.patched yomichan/search.html
	mv yomichan/settings.html.patched yomichan/settings.html
	mv yomichan/info.html.patched yomichan/info.html
	mv yomichan/manifest.json.patched yomichan/manifest.json
	mv yomichan/css/action-popup.css.patched yomichan/css/action-popup.css

yomichan-chrome-patched.zip: clean patch
	zip -qr $@ yomichan

clean:
	$(RM) -r sentence-export.min.js yomichan yomichan-chrome.zip yomichan-chrome-patched.zip info.html.diff