Fix keymap-%.txt building; move FIXME about prefixes to elinkskeys.5.txt
[elinks.git] / doc / Makefile
blob85138f2167dca06ebf716da4405c8f386b4953e5
1 top_builddir=..
2 include $(top_builddir)/Makefile.config
4 SUBDIRS = man
6 # A little trick to simplify some of the rules.
7 VPATH = $(builddir):$(srcdir):$(top_srcdir)/contrib/perl
9 docdir = $(datadir)/doc
11 # Used by install-doc
12 HTML_DIR = $(DESTDIR)$(docdir)/$(PACKAGE)/html
13 PDF_DIR = $(DESTDIR)$(docdir)/$(PACKAGE)/pdf
15 #############################################################################
16 # Build files
18 TXT_DOCS = \
19 features.txt \
20 keymap-actions.txt \
21 keymap-defaults.txt \
22 option-command.txt \
23 option-config.txt
25 HTML_DOCS-$(CONFIG_ASCIIDOC) += \
26 elinks.1.html \
27 elinks.conf.5.html \
28 elinkskeys.5.html \
29 hacking.html \
30 manual.html
32 HTML_DOCS-$(CONFIG_XMLTO) += \
33 manual.html-chunked
35 HTML_DOCS-$(CONFIG_POD2HTML) += \
36 perl.html \
37 perl-hooks.html
39 MAN_DOCS-$(CONFIG_XMLTO) += \
40 elinks.1 \
41 elinks.conf.5 \
42 elinkskeys.5
44 # Use jw for generating PDF, since xmlto seems to freak out.
45 PDF_DOCS-$(CONFIG_JW) += \
46 manual.pdf
49 #############################################################################
50 ## Set the default doc rules
52 MAN_DOCS = $(MAN_DOCS-yes)
53 HTML_DOCS = $(HTML_DOCS-yes)
54 PDF_DOCS = $(PDF_DOCS-yes)
56 txt: $(TXT_DOCS)
57 html: txt $(HTML_DOCS)
58 pdf: txt $(PDF_DOCS)
59 man: txt $(MAN_DOCS)
61 all-docs: man html pdf
63 install-doc: all-docs update-man install
64 $(foreach doc,$(HTML_DOCS), \
65 if test -d $(doc); then \
66 $(MKINSTALLDIRS) $(DESTDIR)$(docdir)/$(PACKAGE)/html/$(doc); \
67 $(call ncmd,installdata,$(doc)/*,$(HTML_DIR)/$(doc)); \
68 else \
69 $(MKINSTALLDIRS) $(DESTDIR)$(docdir)/$(PACKAGE)/html; \
70 $(call ncmd,installdata,$(doc),$(HTML_DIR)); \
71 fi;)
72 $(foreach doc,$(PDF_DOCS), \
73 $(MKINSTALLDIRS) $(DESTDIR)$(docdir)/$(PACKAGE)/pdf; \
74 $(call ncmd,installdata,$(doc),$(PDF_DIR);))
76 update-man: man
77 $(if $(MAN_DOCS), \
78 $(call ncmd,installdata,elinks.1,man/man1/elinks.1.in); \
79 $(call ncmd,installdata,elinkskeys.5,man/man5/); \
80 $(call ncmd,installdata,elinks.conf.5,man/man5/))
82 clean-local:
83 @$(RM) -r api $(TXT_DOCS) $(MAN_DOCS) $(HTML_DOCS) $(PDF_DOCS) *.tmp *.xml
85 # TODO: perl.pod should be pod2ized during make install. --pasky
86 install-local:
89 #############################################################################
90 # Generated asciidoc files
92 # Scripts and Dependencies
93 CODE2DOC = $(srcdir)tools/code2doc
94 HELP2DOC = $(srcdir)tools/help2doc
95 CONF2DOC = $(srcdir)tools/conf2doc
96 KEYS2DOC = $(srcdir)tools/keys2doc
97 ELINKS = $(top_builddir)/src/elinks
98 FEATURES = $(top_srcdir)/features.conf
99 KBDBIND = $(top_srcdir)/src/config/kbdbind.c
101 # Locale env vars to override system one to ensure commands
102 # using elinks binary will generate texts in english
103 LOCALES = LC_ALL=C LANGUAGE=en
105 # FIXME: Keep generated .txt files relative to the source directory and files
106 # they are included in.
107 quiet_cmd_help2doc = ' [$(LINK_COLOR)HELP2DOC$(END_COLOR)] $(RELPATH)$@'
108 cmd_help2doc = $(LOCALES) $(HELP2DOC) $(ELINKS) $@ > $@
110 quiet_cmd_conf2doc = ' [$(LINK_COLOR)CONF2DOC$(END_COLOR)] $(RELPATH)$@'
111 cmd_conf2doc = $(LOCALES) $(CONF2DOC) > $@
113 quiet_cmd_keys2doc = ' [$(LINK_COLOR)KEYS2DOC$(END_COLOR)] $(RELPATH)$@'
114 cmd_keys2doc = $(LOCALES) $(KEYS2DOC) $(KBDBIND) $@ > $@
116 features.txt: $(FEATURES) $(CONF2DOC)
117 $(call cmd,conf2doc)
119 keymap-%.txt: $(KBDBIND) $(KEYS2DOC)
120 $(call cmd,keys2doc)
122 option-%.txt: $(ELINKS) $(HELP2DOC)
123 $(call cmd,help2doc)
126 # API Docs
128 ifeq ($(findstring api,$(MAKECMDGOALS)),api)
129 API = $(shell find $(top_srcdir)/src/ -name '*.h' -exec grep -q 'API Doc' \{\} \; -printf "%p " | sort)
130 endif
132 define api_doc
133 api/$(2).txt: $(1) $(CODE2DOC)
134 @test -d api || $(MKINSTALLDIRS) api
135 @$(CODE2DOC) $(1) > $$@
136 API_TXT += api/$(2).txt
137 endef
139 api_name = $(shell sed -n 's/.*API Doc\s*::\s*\([^ ]*\).*/\1/p' < $(1))
140 $(foreach api,$(API),$(eval $(call api_doc,$(api),$(call api_name,$(api)))))
142 api: $(patsubst %.txt,%.html,$(API_TXT))
145 #############################################################################
146 # Build commands and macros
148 quiet_cmd_jw = ' [$(LINK_COLOR)JW$(END_COLOR)] $(RELPATH)$@'
149 cmd_jw = $(JW) -b $(2) $<
151 quiet_cmd_xmlto = ' [$(LINK_COLOR)XMLTO$(END_COLOR)] $(RELPATH)$@'
152 cmd_xmlto = $(XMLTO) $(3) $(2) $<
154 quiet_cmd_pod2html = ' [$(LINK_COLOR)POD2HTML$(END_COLOR)] $(RELPATH)$@'
155 cmd_pod2html = $(POD2HTML) --outfile=$@ < $<
157 quiet_cmd_asciidoc = ' [$(LINK_COLOR)ASCIIDOC$(END_COLOR)] $(RELPATH)$@'
158 cmd_asciidoc = $(ASCIIDOC) -f asciidoc.conf -b $(2) -d $(call doctype,$<) -o $@ $<
160 # Based on filename in $(1) find out asciidoc doctype.
161 doctype = $(if $(findstring .1.,$(1)),manpage,$(if $(findstring .5.,$(1)),manpage,book))
163 # Loosely track dependencies via asciidoc includes.
164 asciidoc_dep = sed -n 's@include::\(.*\)\[.*@$@: \1@p' < $< > .deps/$(@F).asciidoc
166 -include .deps/*.asciidoc
168 # Do a little post-processing of man pages. Inserting title headers and date.
169 MAN_DATE = $(shell date -I)
170 man_desc = `sed -n 's/:Description:\s*\(.*\)/\1/p' < $(subst .xml,.txt,$<)`
171 man_hack = sed "s/^\(\.TH \"ELINKS[^\"]*\" [0-9] \).*/\1\"$(1)\" \"$(MAN_DATE)\" \"$(1)\"/" < $@ | \
172 sed "s/@squote@/\\\\'/g" > $@.tmp && mv $@.tmp $@
175 #############################################################################
176 # Build recipies
178 %.html: %.txt asciidoc.conf
179 $(call cmd,asciidoc,xhtml11)
180 $(call asciidoc_dep)
182 %.xml: %.txt asciidoc.conf
183 $(call cmd,asciidoc,docbook)
184 $(call asciidoc_dep)
186 %.1: %.1.xml
187 $(call cmd,xmlto,man)
188 $(call man_hack,$(call man_desc))
190 %.5: %.5.xml
191 $(call cmd,xmlto,man)
192 $(call man_hack,$(call man_desc))
194 %.html-chunked: %.xml
195 $(call cmd,xmlto,html,-o $@)
197 %.pdf: %.xml
198 $(call cmd,jw,pdf)
200 %.html: %.pod
201 $(call cmd,pod2html)
203 perl-%.html: %.pl
204 $(call cmd,pod2html)
207 include $(top_srcdir)/Makefile.lib