Merge with git+ssh://pasky.or.cz/srv/git/elinks.git
[elinks.git] / doc / Makefile
blob872fbeb64f1f024278268fd38537518f246c50e4
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 ASCIIDOC_CONF = $(srcdir)asciidoc.conf
16 ASCIIDOC_FLAGS += -f $(ASCIIDOC_CONF) -a "builddir=$(CURDIR)/"
18 #############################################################################
19 # Build files
21 TXT_DOCS = \
22 features.txt \
23 keymap-actions.txt \
24 keymap-defaults.txt \
25 option-command.txt \
26 option-config.txt
28 HTML_DOCS-$(CONFIG_ASCIIDOC) += \
29 elinks.1.html \
30 elinks.conf.5.html \
31 elinkskeys.5.html \
32 hacking.html \
33 manual.html
35 HTML_DOCS-$(CONFIG_XMLTO) += \
36 manual.html-chunked
38 HTML_DOCS-$(CONFIG_POD2HTML) += \
39 perl.html \
40 perl-hooks.html
42 MAN_DOCS-$(CONFIG_XMLTO) += \
43 elinks.1 \
44 elinks.conf.5 \
45 elinkskeys.5
47 # Use jw for generating PDF, since xmlto seems to freak out.
48 PDF_DOCS-$(CONFIG_JW) += \
49 manual.pdf
52 #############################################################################
53 ## Set the default doc rules
55 MAN_DOCS = $(MAN_DOCS-yes)
56 HTML_DOCS = $(HTML_DOCS-yes)
57 PDF_DOCS = $(PDF_DOCS-yes)
59 txt: $(TXT_DOCS)
60 html: txt $(HTML_DOCS)
61 pdf: txt $(PDF_DOCS)
62 man: txt $(MAN_DOCS)
64 all-docs: man html pdf
66 install-doc: all-docs update-man install
67 @$(foreach doc,$(HTML_DOCS), \
68 if test -d $(doc); then \
69 $(MKINSTALLDIRS) $(DESTDIR)$(docdir)/$(PACKAGE)/html/$(doc); \
70 $(call ncmd,installdata,$(doc)/*,$(HTML_DIR)/$(doc)); \
71 else \
72 $(MKINSTALLDIRS) $(DESTDIR)$(docdir)/$(PACKAGE)/html; \
73 $(call ncmd,installdata,$(doc),$(HTML_DIR)); \
74 fi;)
75 @$(foreach doc,$(PDF_DOCS), \
76 $(MKINSTALLDIRS) $(DESTDIR)$(docdir)/$(PACKAGE)/pdf; \
77 $(call ncmd,installdata,$(doc),$(PDF_DIR);))
79 update-man: man
80 @$(if $(MAN_DOCS), \
81 $(call ncmd,installdata,elinks.1,man/man1/elinks.1.in); \
82 $(call ncmd,installdata,elinkskeys.5,man/man5/); \
83 $(call ncmd,installdata,elinks.conf.5,man/man5/))
85 clean-local:
86 @$(RM) -r api $(TXT_DOCS) $(MAN_DOCS) $(HTML_DOCS) $(PDF_DOCS) *.tmp *.xml
88 # TODO: perl.pod should be pod2ized during make install. --pasky
89 install-local:
92 #############################################################################
93 # Generated asciidoc files
95 # Scripts and Dependencies
96 CODE2DOC = $(srcdir)tools/code2doc
97 HELP2DOC = $(srcdir)tools/help2doc
98 CONF2DOC = $(srcdir)tools/conf2doc
99 KEYS2DOC = $(srcdir)tools/keys2doc
100 ELINKS = $(top_builddir)/src/elinks
101 FEATURES = $(top_srcdir)/features.conf
102 KBDBIND = $(top_srcdir)/src/config/kbdbind.c
104 # Locale env vars to override system one to ensure commands
105 # using elinks binary will generate texts in english
106 LOCALES = LC_ALL=C LANGUAGE=en
108 # FIXME: Keep generated .txt files relative to the source directory and files
109 # they are included in.
110 quiet_cmd_help2doc = ' [$(LINK_COLOR)HELP2DOC$(END_COLOR)] $(RELPATH)$@'
111 cmd_help2doc = $(LOCALES) $(HELP2DOC) $(ELINKS) $@ > $@
113 quiet_cmd_conf2doc = ' [$(LINK_COLOR)CONF2DOC$(END_COLOR)] $(RELPATH)$@'
114 cmd_conf2doc = $(LOCALES) $(CONF2DOC) $(FEATURES) > $@
116 quiet_cmd_keys2doc = ' [$(LINK_COLOR)KEYS2DOC$(END_COLOR)] $(RELPATH)$@'
117 cmd_keys2doc = $(LOCALES) $(KEYS2DOC) $(KBDBIND) $@ > $@
119 quiet_cmd_code2doc = ' [$(LINK_COLOR)CODE2DOC$(END_COLOR)] $(RELPATH)$@'
120 cmd_code2doc = $(LOCALES) $(CODE2DOC) $< > $@
122 features.txt: $(FEATURES) $(CONF2DOC)
123 $(call cmd,conf2doc)
125 keymap-%.txt: $(KBDBIND) $(KEYS2DOC)
126 $(call cmd,keys2doc)
128 option-%.txt: $(ELINKS) $(HELP2DOC)
129 $(call cmd,help2doc)
132 # API Docs
134 ifeq ($(findstring api,$(MAKECMDGOALS)),api)
135 API = $(shell find $(top_srcdir)/src/ -name '*.h' -exec grep -q 'API Doc' \{\} \; -printf "%p " | sort)
136 endif
138 define api_doc
139 API_TXT += api/$(2).txt
140 api/$(2).txt: $(1) $(CODE2DOC)
141 @test -d api || $(MKINSTALLDIRS) api
142 $$(call cmd,code2doc)
143 endef
145 api_name = $(shell sed -n 's/.*API Doc\s*::\s*\([^ ]*\).*/\1/p' < $(1))
146 $(foreach api,$(API),$(eval $(call api_doc,$(api),$(call api_name,$(api)))))
148 api: $(patsubst %.txt,%.html,$(API_TXT))
151 #############################################################################
152 # Build commands and macros
154 quiet_cmd_jw = ' [$(LINK_COLOR)JW$(END_COLOR)] $(RELPATH)$@'
155 cmd_jw = $(JW) -b $(2) $<
157 quiet_cmd_xmlto = ' [$(LINK_COLOR)XMLTO$(END_COLOR)] $(RELPATH)$@'
158 cmd_xmlto = $(XMLTO) -o $(call outdir) $(3) $(2) $<
160 quiet_cmd_pod2html = ' [$(LINK_COLOR)POD2HTML$(END_COLOR)] $(RELPATH)$@'
161 cmd_pod2html = $(POD2HTML) --outfile=$@ < $<
163 quiet_cmd_asciidoc = ' [$(LINK_COLOR)ASCIIDOC$(END_COLOR)] $(RELPATH)$@'
164 cmd_asciidoc = $(ASCIIDOC) $(ASCIIDOC_FLAGS) -b $(call backend) -d $(call doctype) -o $@ $<
166 # Based on $@ find out asciidoc doctype or backend + xmlto output dir.
167 doctype = $(if $(findstring .1.,$@)$(findstring .5.,$@),manpage,book)
168 backend = $(if $(findstring .xml,$@),docbook,xhtml11)
169 outdir = $(if $(findstring -chunked,$@),$@,.)
171 # Loosely track dependencies via asciidoc includes.
172 asciidoc_dep = sed -n 's/[{]builddir}//g;s@include::\(.*\)\[.*@$@: $< \1@p' < $< > .deps/$(@F).asciidoc
174 -include .deps/*.asciidoc
176 # Do a little post-processing of man pages. Inserting title headers and date.
177 MAN_DATE = $(shell date -I)
178 man_desc = `sed -n 's/:Description:\s*\(.*\)/\1/p' < $(srcdir)$(subst .xml,.txt,$(<F))`
179 man_hack = sed "s/^\(\.TH \"ELINKS[^\"]*\" [0-9] \).*/\1\"$(1)\" \"$(MAN_DATE)\" \"$(1)\"/" < $@ | \
180 sed "s/@squote@/\\\\'/g" > $@.tmp && mv $@.tmp $@
183 #############################################################################
184 # Build recipies
186 %.html: %.txt $(ASCIIDOC_CONF)
187 $(call cmd,asciidoc,xhtml11)
188 @-$(call asciidoc_dep)
190 %.xml: %.txt $(ASCIIDOC_CONF)
191 $(call cmd,asciidoc,docbook)
192 @-$(call asciidoc_dep)
194 %.1: %.1.xml
195 $(call cmd,xmlto,man)
196 @$(call man_hack,$(call man_desc))
198 %.5: %.5.xml
199 $(call cmd,xmlto,man)
200 @$(call man_hack,$(call man_desc))
202 %.html-chunked: %.xml
203 $(call cmd,xmlto,html)
205 %.pdf: %.xml
206 $(call cmd,jw,pdf)
208 %.html: %.pod
209 $(call cmd,pod2html)
211 perl-%.html: %.pl
212 $(call cmd,pod2html)
215 include $(top_srcdir)/Makefile.lib