summaryrefslogtreecommitdiffstats
path: root/_build/Makefile
blob: 83a9ecf9fb847dfab3261adf179ed1d589949c74 (plain) (blame)
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
126
127
128
129
130
131
132
133
134
135
.PHONY: all clean docs

PROJECTS = $(sort $(notdir $(basename $(wildcard data/projects/*.toml))))

all: $(CURDIR)/deps/asciideck docs
	PATH=$(CURDIR)/deps/asciideck/scripts:$(PATH) hugo --theme=ninenines -d ..

server: $(CURDIR)/deps/asciideck
	PATH=$(CURDIR)/deps/asciideck/scripts:$(PATH) hugo server --theme=ninenines

$(CURDIR)/deps/asciideck:
	mkdir -p $(CURDIR)/deps
	git clone [email protected]:ninenines/asciideck.git $(CURDIR)/deps/asciideck
	$(MAKE) -C $(CURDIR)/deps/asciideck

clean: DOC_FILES = $(filter-out static/docs/en/cowboy/1.0/guide,$(wildcard static/docs/en/*/*/guide))
clean: OUTPUT_FILES = $(filter-out ../_build,$(wildcard ../*))
clean:
	rm -rf content/docs tmp
	$(if $(OUTPUT_FILES),rm -rf $(OUTPUT_FILES))
	$(if $(DOC_FILES),rm -rf $(DOC_FILES))

tmp: clean
	mkdir tmp/

# For substitution.
comma := ,

define docs-version-target

.PHONY: docs-$1-$2

docs-$1-$2: tmp/$1
	cd tmp/$1 && git checkout $4 && git reset --hard $4
	if [ -f tmp/$1/doc/src/guide/book.asciidoc ]; then \
		mkdir -p content/docs/en/$1/$3/guide/; \
		echo "+++" > content/docs/en/$1/$3/guide.asciidoc; \
		echo -n "title = \"" >> content/docs/en/$1/$3/guide.asciidoc; \
		echo -n `sed -n '1,/^= .*/ s/^= //p' tmp/$1/doc/src/guide/book.asciidoc` \
			>> content/docs/en/$1/$3/guide.asciidoc; \
		echo "\"" >> content/docs/en/$1/$3/guide.asciidoc; \
		printf "%s\n" "project = \"$1\"" "version = \"$3\"" "doctype = \"guide\"" \
			>> content/docs/en/$1/$3/guide.asciidoc; \
		echo "+++" >> content/docs/en/$1/$3/guide.asciidoc; \
		sed -E 's/include::([a-z0-9_.]*)\.asciidoc(.*)/* link:\1\/\2/' tmp/$1/doc/src/guide/book.asciidoc \
			| sed -n '/^= /,$$$$p' \
			| sed -n '/^$$$$/,$$$$p' \
			| sed 's/^= /== /' >> content/docs/en/$1/$3/guide.asciidoc; \
		mv tmp/$1/doc/src/guide/book.asciidoc tmp/$1/doc/src/guide/book.asciidoc.bak; \
		for f in tmp/$1/doc/src/guide/*.asciidoc; do \
			printf "%s\n" "+++" "project = \"$1\"" "version = \"$3\"" "doctype = \"guide\"" \
				> content/docs/en/$1/$3/guide/`basename $$$$f`; \
			echo -n "title = \"" >> content/docs/en/$1/$3/guide/`basename $$$$f`; \
			echo -n `sed -n '1,/^== .*/ s/^== //p' $$$$f` >> content/docs/en/$1/$3/guide/`basename $$$$f`; \
			echo "\"" >> content/docs/en/$1/$3/guide/`basename $$$$f`; \
			echo -n "weight = " >> content/docs/en/$1/$3/guide/`basename $$$$f`; \
			echo "`cat tmp/$1/doc/src/guide/book.asciidoc.bak | grep ^include:: | sed 's/include::\(.*.asciidoc\).*/\1/'` :`basename $$$$f`" | tr '\n' ' ' | awk -F: '{print index($$$$1, $$$$2)}' >> content/docs/en/$1/$3/guide/`basename $$$$f`; \
			echo "+++" >> content/docs/en/$1/$3/guide/`basename $$$$f`; \
			echo >> content/docs/en/$1/$3/guide/`basename $$$$f`; \
			sed '1,/^$$$$/d' $$$$f | sed 's/^=== /== /' \
				| sed 's/xref:/link:..\//g' | sed 's/image::/image::..\//g' \
				| sed 's/link:man:$1[(]7[)]/link:..\/$1_app/g' \
				| sed 's/\(link:man:[a-z0-9_]*\):/\1./g' \
				| sed 's/link:man:\([a-z0-9_.]*\)[1-9()]*/link:..\/\1/g' \
				>> content/docs/en/$1/$3/guide/`basename $$$$f`; \
		done; \
		rm tmp/$1/doc/src/guide/book.asciidoc.bak; \
		mkdir -p static/docs/en/$1/$3/guide/; \
		cp tmp/$1/doc/src/guide/* static/docs/en/$1/$3/guide/; \
	fi
	if [ -f tmp/$1/doc/src/manual/$1.asciidoc ]; then \
		mkdir -p content/docs/en/$1/$3/manual/; \
		printf "%s\n" "+++" "title = \"`sed 's/\(.\)/\U\1/' <<< $1` Function Reference\"" \
			"project = \"$1\"" "version = \"$3\"" "doctype = \"manual\"" "+++" "" \
			> content/docs/en/$1/$3/manual.asciidoc; \
		if [ "$1" = "cowboy" -o "$1" = "gun" ]; then \
			sed '1,/^$$$$/d' tmp/$1/doc/src/manual/$1_app.asciidoc | sed 's/xref:/link:..\//' \
				| sed 's/link:man:\([a-z0-9_]*\)(7)/link:\1_app/g' \
				| sed 's/\(link:man:[a-z0-9_]*\):/\1./g' \
				| sed 's/link:man:\([a-z0-9_.]*\)[1-9()]*/link:\1/g' \
				>> content/docs/en/$1/$3/manual.asciidoc; \
		else \
			for f in `ls tmp/$1/doc/src/manual/*.asciidoc | sort`; do \
				echo -n "* link:`basename $$$$f .asciidoc`[" >> content/docs/en/$1/$3/manual.asciidoc; \
				echo -n `sed -En '0,/^= / s/= (.*)/\1/ p' $$$$f` >> content/docs/en/$1/$3/manual.asciidoc; \
				echo "]" >> content/docs/en/$1/$3/manual.asciidoc; \
			done; \
		fi; \
		for f in tmp/$1/doc/src/manual/*.asciidoc; do \
			printf "%s\n" "+++" "project = \"$1\"" "version = \"$3\"" "doctype = \"manual\"" \
				> content/docs/en/$1/$3/manual/`basename $$$$f`; \
			echo -n "title = \"" >> content/docs/en/$1/$3/manual/`basename $$$$f`; \
			echo -n `sed -n '1,/^= .*/ s/^= //p' $$$$f` >> content/docs/en/$1/$3/manual/`basename $$$$f`; \
			echo "\"" >> content/docs/en/$1/$3/manual/`basename $$$$f`; \
			echo "+++" >> content/docs/en/$1/$3/manual/`basename $$$$f`; \
			echo >> content/docs/en/$1/$3/manual/`basename $$$$f`; \
			if [ "$1" = "cowboy" -o "$1" = "gun" ]; then \
				sed '1,/^$$$$/d' $$$$f | sed 's/xref:/link:..\//g' \
					| sed 's/link:man:$1(7)/link:../g' \
					| sed 's/\(link:man:[a-z0-9_]*\):/\1./g' \
					| sed 's/link:man:\([a-z0-9_.]*\)[1-9()]*/link:..\/\1/g' \
					>> content/docs/en/$1/$3/manual/`basename $$$$f`; \
			else \
				sed '1,/^$$$$/d' $$$$f | sed 's/xref:/link:..\//g' \
					| sed 's/link:man:$1(7)/link:..\/$1_app/g' \
					| sed 's/\(link:man:[a-z0-9_]*\):/\1./g' \
					| sed 's/link:man:\([a-z0-9_.]*\)[1-9()]*/link:..\/\1/g' \
					>> content/docs/en/$1/$3/manual/`basename $$$$f`; \
			fi \
		done \
	fi

endef

define docs-target

$(eval include data/projects/$1.toml)
$(eval VERSIONS := $(subst $(comma),,$(subst ],,$(subst [,,$(versions)))))
$(eval BRANCHES := $(subst $(comma),,$(subst ],,$(subst [,,$(branches)))))
$(eval TARGETS := $(shell echo "1 2 3 4 5 6 7 8 9" | cut -d' ' -f 1-$(words $(VERSIONS))))

tmp/$1:
	cd tmp && git clone $(repository)

.PHONY: docs-$1 $(foreach t,$(TARGETS),docs-$1-$t)

$(eval $(foreach t,$(TARGETS),$(call docs-version-target,$1,$t,$(word $t,$(VERSIONS)),$(word $t,$(BRANCHES)))))

docs-$1: tmp $(foreach t,$(TARGETS),docs-$1-$t)

docs:: docs-$1

endef

$(eval $(foreach p,$(PROJECTS),$(call docs-target,$p)))