-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
125 lines (92 loc) · 2.78 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
116
117
118
119
120
121
122
123
124
125
nginx = openresty
md2html = ./util/fmtMd.js
md2text = pandoc --from markdown_github-hard_line_breaks --to plain
md_files := $(wildcard en/*.md cn/*.md) $(patsubst %.md.tt2,%.md,$(wildcard en/*.md.tt2 cn/*.md.tt2))
html_files := $(patsubst %.md,html/%.html,$(md_files))
txt_files := $(patsubst %.md,text/%.txt,$(md_files))
i18n_lua = lua/openresty_org/i18n.lua
templates_lua = lua/openresty_org/templates.lua
lua_files := $(sort $(filter-out $(i18n_lua) $(templates_lua),$(wildcard lua/*.lua lua/openresty_org/*.lua)))
auto_tt2_files := templates/posts-slide-cn.tt2 templates/posts-slide-en.tt2
tt2_files := $(sort $(wildcard templates/*.tt2)) $(auto_tt2_files)
less_file = css/main.less
css_file = $(patsubst %.less, %.css, $(less_file))
extract_pl = ./util/extract.pl
gendata_pl = ./util/gen-data.pl
msginit_pl = ./util/msginit.pl
msgfmt_pl = ./util/msgfmt.pl
po_files = po/cn.po
tsv_files = posts-en.tsv posts-cn.tsv
tpage = tpage
.PRECIOUS: $(md_files)
.DELETE_ON_ERRORS: $(templates_lua) $(patsubst %.md.tt2,%.md,$(wildcard en/*.md.tt2)) $(patsubst %.md.tt2,%.md,$(wildcard cn/*.md.tt2))
.PHONY: all
all: templates css msgfmt
$(auto_tt2_files):
./util/gen-templates.js
.PHONY: check
check:
@echo $(md_files)
.PHONY: auto-templates
auto-templates: $(auto_tt2_files)
.PHONY: templates
templates: $(templates_lua)
$(templates_lua): $(tt2_files)
lemplate --compile $^ > $@
.PHONY: css
css: $(css_file)
$(css_file): $(less_file)
lessc $^ $@
.PHONY: run
run:
mkdir -p logs
$(nginx) -p $$PWD -c conf/nginx.conf
reload: logs/nginx.pid
$(nginx) -p $$PWD -c conf/nginx.conf -t
kill -HUP `cat $<`
stop: logs/nginx.pid
$(nginx) -p $$PWD -c conf/nginx.conf -t
kill -QUIT `cat $<`
.PHONY: clean
clean:
rm -f templates/posts-slide-*.tt2
rm -rf html text *.tsv
rm -f $(templates_lua)
.PHONY: html
html: $(html_files)
html/%.html: %.md
@mkdir -p html/en html/cn
$(md2html) $< > $@
.PHONY: text
text: $(txt_files)
text/%.txt: %.md
mkdir -p text/en text/cn
$(md2text) $< --output $@
%.md: %.md.tt2
$(tpage) $< > $@
# WARNING: this target will override existing .md files
# so any manual edits would get lost!
.PHONY: extract
extract:
$(extract_pl) ../v1/index.html en
$(extract_pl) ../v1/cn/index.html cn
.PHONY: gendata
gendata: $(tsv_files)
$(tsv_files): $(html_files) $(txt_files) $(gendata_pl)
$(gendata_pl) en
$(gendata_pl) cn
.PHONY: initdb
initdb: $(tsv_files)
psql -Uopenresty openresty_org -v "ON_ERROR_STOP=1" -f init.sql
.PHONY: deploy
deploy:
ls $(tsv_files)
psql -Uopenresty openresty_org -v "ON_ERROR_STOP=1" -f init.sql
.PHONY: msginit
msginit: $(po_files)
$(po_files): $(lua_files) $(tt2_files) $(msginit_pl)
$(msginit_pl) --outdir po --locale cn $(lua_files) $(tt2_files)
.PHONY: msgfmt
msgfmt: $(i18n_lua)
$(i18n_lua): $(po_files) $(msgfmt_pl)
$(msgfmt_pl) -o $(i18n_lua) $(po_files)