summaryrefslogtreecommitdiff
path: root/Makefile
blob: 1b07df8e841306cf5e85d204cc5fb79456b36ea7 (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
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# List of all input files. Each file is converted into a .html file at the same path.
#
# The format of each line is: $path $URL $title
#
# If no $URL is given or the $URL is '-', then the input file is assumed to be
# in dat/, otherwise it will be fetched from $URL.
#
# A $title should be given for .pod and .log files, it is ignored for .md files
# because those already have a title embedded in the file.
#
# Supported file types:
#   .md:  Converted directly into .html with pandoc.
#   .pod: Perl's Plain Old Documentation, converted through HTML into a .md
#         file which is then converted into .html again with the proper template.
#   .log: A ChangeLog-formatted file, converted through .md into .html.
PAGES=\
	"contributing.md"\
	"doc.md"\
	"doc/commvis.md"\
	"doc/dcstats.md"\
	"doc/easyipc.md"\
	"doc/funcweb.md"\
	"doc/ncdu2.md"\
	"doc/pwlookup.md"\
	"doc/sqlaccess.md"\
	"doc/sqlobject.md"\
	"dump.md"\
	"dump/awshrink.md"\
	"dump/btrfssize.md"\
	"dump/demo.md"\
	"dump/grenamr.md"\
	"dump/insbench.md"\
	"dump/nccolour.md"\
	"globster.md"\
	"globster/api.pod           https://g.blicky.net/globster.git/plain/doc/api.pod             The Globster D-Bus API"\
	"globster/ctl.pod           https://g.blicky.net/globster.git/plain/doc/globsterctl.pod     The globsterctl(1) Man Page"\
	"globster/daemon.pod        https://g.blicky.net/globster.git/plain/doc/globster.pod        The globster(1) Man Page"\
	"globster/launch.pod        https://g.blicky.net/globster.git/plain/doc/globster-launch.pod The globster-launch(1) Man Page"\
	"index.md"\
	"ncdc.md"\
	"ncdc/changes.log           https://g.blicky.net/ncdc.git/plain/ChangeLog                   Ncdc Release History"\
	"ncdc/faq.md"\
	"ncdc/install.md"\
	"ncdc/man.pod               -                                                               Ncdc Manual"\
	"ncdc/scr.md"\
	"ncdu.md"\
	"ncdu/changes.log           https://g.blicky.net/ncdu.git/plain/ChangeLog                   Ncdu Release History"\
	"ncdu/jsonfmt.md"\
	"ncdu/man.pod               https://g.blicky.net/ncdu.git/plain/doc/ncdu.pod                Ncdu Manual"\
	"ncdu/scr.md"\
	"nginx-confgen.md"\
	"nginx-confgen/changes.log  https://g.blicky.net/nginx-confgen.git/plain/ChangeLog          Nginx-confgen Release History"\
	"nginx-confgen/man.pod      https://g.blicky.net/nginx-confgen.git/plain/nginx-confgen.pod  The nginx-confgen(1) Man Page"\
	"tuwf.md"\
	"tuwf/changes.log           https://g.blicky.net/tuwf.git/plain/ChangeLog                   TUWF Release History"\
	"tuwf/man.pod               https://g.blicky.net/tuwf.git/plain/lib/TUWF.pod                TUWF Documentation"\
	"tuwf/man/db.pod            https://g.blicky.net/tuwf.git/plain/lib/TUWF/DB.pod             TUWF::DB Documentation"\
	"tuwf/man/intro.pod         https://g.blicky.net/tuwf.git/plain/lib/TUWF/Intro.pod          TUWF::Intro Documentation"\
	"tuwf/man/misc.pod          https://g.blicky.net/tuwf.git/plain/lib/TUWF/Misc.pod           TUWF::Misc Documentation"\
	"tuwf/man/request.pod       https://g.blicky.net/tuwf.git/plain/lib/TUWF/Request.pod        TUWF::Request Documentation"\
	"tuwf/man/response.pod      https://g.blicky.net/tuwf.git/plain/lib/TUWF/Response.pod       TUWF::Response Documentation"\
	"tuwf/man/validate.pod      https://g.blicky.net/tuwf.git/plain/lib/TUWF/Validate.pod       TUWF::Validate Documentation"\
	"tuwf/man/xml.pod           https://g.blicky.net/tuwf.git/plain/lib/TUWF/XML.pod            TUWF::XML Documentation"\
	"ylib.pod                   https://g.blicky.net/ylib.git/plain/README.pod                  Ylib"\
	"yxml.md"\
	"yxml/man.md                https://g.blicky.net/yxml.git/plain/yxml.md"


# Files generated by mkfeed.pl
FEEDS=\
	pub/feed.atom\
	pub/globster/feed.atom\
	pub/ncdc/feed.atom\
	pub/ncdu/feed.atom\
	pub/tuwf/feed.atom\
	pub/yxml/feed.atom


# Files we need to download
FETCH      := $(shell for i in ${PAGES}; do echo "$$i" | grep -Eo '^[^ ]+ +[^ -][^ ]+' | sed -E 's/^([^ ]+).*/dat\/\1/'; done)

# List of generated .html files
HTML_OUT   := $(shell for i in ${PAGES}; do echo "$$i" | sed -E 's/^([^ ]+)\.[^\. ]+.*$$/pub\/\1.html/'; done)

# List of .md files generated from .pod files
POD_MD     := $(shell for i in ${PAGES}; do echo "$$i" | grep -Eo '^[^ ]+\.pod' | sed -E 's/(.+)\.pod$$/dat\/\1.md/'; done)

# List of .md files generated from .log files
CHANGES_MD := $(shell for i in ${PAGES}; do echo "$$i" | grep -Eo '^[^ ]+\.log' | sed -E 's/(.+)\.log$$/dat\/\1.md/'; done)

# All fetched & generated files
CLEAN      := ${FETCH} ${POD_MD} ${CHANGES_MD} ${HTML_OUT} ${FEEDS}


.PHONY: all clean

all: .gitignore ${HTML_OUT} ${FEEDS}


${FEEDS}: mkfeed.pl dat/index.md
	@echo "FEED   $@"
	@mkdir -p $$(dirname "$@")
	@./mkfeed.pl "$@" <dat/index.md >"$@"


${FETCH}: dat/%:
	@echo "FETCH  $*"
	@mkdir -p $$(dirname "$@")
	@curl -s ${shell for i in ${PAGES}; do case "$$i" in "$* "*) echo "$$i" | awk '{print$$2}';; esac; done} -o "$@"


# There is a 'pod2markdown' program, but going through HTML with a little bit
# of Perl magic tends to give better results, if only because definition lists
# are properly converted this way and I have more control over links.
# The final pass through perl is to fix a pandoc bug where a code block as the
# first thing inside a definition does not survive a round-trip.
${POD_MD}: dat/%.md: dat/%.pod mkpod.pl
	@echo "POD    $*"
	@cat "$<" | ./mkpod.pl |\
		pandoc -f html -t markdown -s \
			--metadata title="${shell for i in ${PAGES}; do case "$$i" in "$*.pod "*) echo "$$i" | sed -E 's/[^ ]+ +[^ ]+ +//';; esac; done}" |\
		perl -e '$$/=undef; print (scalar(<>) =~ s/:   ([^\s].*)\n        ([^\s].*)/:       $$1\n        $$2/gr)' >"$@"


${CHANGES_MD}: dat/%.md: dat/%.log mkchangelog.pl
	@echo "MD     $*"
	@./mkchangelog.pl "$*" "${shell for i in ${PAGES}; do case "$$i" in "$*.log "*) echo "$$i" | sed -E 's/[^ ]+ +[^ ]+ +//';; esac; done}" <"$<" >"$@"


# TODO: Add --strip-comments to pandoc when I have a version that supports it.
${HTML_OUT}: pub/%.html: dat/%.md template.html
	@echo "HTML   $*"
	@mkdir -p $$(dirname "$@")
	@cat "$<" |\
		./dllink.pl |\
		pandoc -f markdown -t html5 --template template.html \
			--metadata path1=$$(echo "$*" | sed 's/\/.*//') \
			--metadata path2=$$(echo "$*" | sed 's/\//-/' | sed 's/\/.*//') \
			--metadata path3=$$(echo "$*" | sed 's/\//-/g') \
			--variable menu-$$(case "$*" in\
					globster*)      echo "globster";;\
					ncdc*)          echo "ncdc";;\
					ncdu*)          echo "ncdu";;\
					nginx-confgen*) echo "nginx-confgen";;\
					tuwf*)          echo "tuwf";;\
					yxml*)          echo "yxml";;\
					*) echo "main";;\
				esac)\
			-o "$@"


.gitignore: Makefile
	@echo "GIT"
	@echo '*.zip'  >$@
	@echo '*.gz'  >>$@
	@echo '*.pdf' >>$@
	@for i in ${CLEAN}; do echo "$$i"; done | sort >>$@


clean:
	rm -rf ${CLEAN}
	find dat pub -type d -empty -print -delete