xref: /Universal-ctags/man/GNUmakefile.am (revision 72ae698186a95e6b87de4fb39d82b76eb3190c03)
1#
2# This is a Makefile.am read by the Autotools.
3# GNU Make is needed.
4#
5#	Copyright (c) 2017, Masatake YAMMATO
6#	Copyright (c) 2017, Red Hat, Inc.
7#
8#	This source code is released for free distribution under the terms
9#	of the GNU General Public License version 2 or (at your option) any
10#	later version.
11#
12
13# Note: RST2MAN, RST2HTML, RST2PDF, and RST2MAN_OPTIONS are defined by configure.ac
14RST2MAN_FLAGS = $(RST2MAN_OPTIONS)
15RST2HTML_FLAGS =
16RST2PDF_FLAGS =
17DOCS_DIR = ../docs/man
18
19SUFFIXES = .rst .html .pdf .in
20
21# The man_MANS or dist_man_MANS requires conventional file names for man files.
22# For example `$(basename $(files))` is not accepted.
23GEN_IN_MAN_FILES = \
24	ctags.1 \
25	ctags-optlib.7 \
26	ctags-incompatibilities.7 \
27	ctags-client-tools.7 \
28	ctags-faq.7 \
29	\
30	ctags-lang-gdscript.7 \
31	ctags-lang-iPythonCell.7 \
32	ctags-lang-julia.7 \
33	ctags-lang-python.7 \
34	ctags-lang-tcl.7 \
35	ctags-lang-verilog.7 \
36	ctags-lang-inko.7 \
37	ctags-lang-r.7 \
38	ctags-lang-rmarkdown.7 \
39	ctags-lang-sql.7 \
40	ctags-lang-elm.7 \
41	\
42	readtags.1 \
43	tags.5 \
44	\
45	$(NULL)
46
47man_pages  = $(GEN_IN_MAN_FILES)
48man_in_files = $(addsuffix .in,$(man_pages))
49rst_files  = $(addsuffix .rst,$(man_pages))
50html_pages = $(addsuffix .html,$(man_pages))
51pdf_pages  = $(addsuffix .pdf,$(man_pages))
52doc_files  = $(addprefix $(DOCS_DIR)/,$(rst_files))
53
54# for automake
55# generate man pages only when rst2man is installed
56if HAVE_RST2MAN
57man_MANS = $(man_pages)
58endif
59EXTRA_DIST = README $(addsuffix .rst.in,$(GEN_IN_MAN_FILES)) $(man_in_files)
60CLEANFILES = $(man_pages) $(addsuffix .rst,$(GEN_IN_MAN_FILES)) $(html_pages) $(pdf_pages)
61MAINTAINERCLEANFILES =  $(man_in_files)
62
63.PHONY: man man-in html pdf update-docs clean-docs
64
65all-am: update-docs
66
67man: $(man_pages)
68man-in: $(man_in_files)
69html: $(html_pages)
70pdf: $(pdf_pages)
71
72# use `[@]` not to be replaced by automake
73REPLACE_CONF_VARS =	sed \
74		-e s/[@]CTAGS_NAME_EXECUTABLE[@]/ctags/g \
75		-e s/[@]ETAGS_NAME_EXECUTABLE[@]/etags/g \
76		-e s/[@]VERSION[@]/$(VERSION)/g
77
78rst2man_verbose    = $(rst2man_verbose_@AM_V@)
79rst2man_verbose_   = $(rst2man_verbose_@AM_DEFAULT_V@)
80rst2man_verbose_0  = @echo RST2MAN "   $@";
81
82rst2html_verbose   = $(rst2html_verbose_@AM_V@)
83rst2html_verbose_  = $(rst2html_verbose_@AM_DEFAULT_V@)
84rst2html_verbose_0 = @echo RST2HTML "  $@";
85
86rst2pdf_verbose    = $(rst2pdf_verbose_@AM_V@)
87rst2pdf_verbose_   = $(rst2pdf_verbose_@AM_DEFAULT_V@)
88rst2pdf_verbose_0  = @echo RST2MAN "   $@";
89
90sed_verbose        = $(sed_verbose_@AM_V@)
91sed_verbose_       = $(sed_verbose_@AM_DEFAULT_V@)
92sed_verbose_0      = @echo SED "       $@";
93
94rm_verbose         = $(rm_verbose_@AM_V@)
95rm_verbose_        = $(rm_verbose_@AM_DEFAULT_V@)
96rm_verbose_0       = @echo RM "        $@";
97
98#
99# generate man
100#
101# generate *.in to be distributed
102%.in: %.rst.in
103if HAVE_RST2MAN
104	$(rst2man_verbose)$(RST2MAN) $(RST2MAN_FLAGS) $< > $@
105else
106	$(error Cannot make $@: rst2man is not installed)
107endif
108
109%: %.in
110	$(sed_verbose)$(REPLACE_CONF_VARS) < $< > $@
111
112#
113# generate HTML and PDF
114#
115%.rst: %.rst.in
116	$(sed_verbose)$(REPLACE_CONF_VARS) < $< > $@
117
118%.html: %.rst
119if HAVE_RST2HTML
120	$(rst2html_verbose)$(RST2HTML) $(RST2HTML_FLAGS) $< > $@
121else
122	$(error Cannot make $@: rst2html is not installed)
123endif
124
125%.pdf: %.rst
126if HAVE_RST2PDF
127	$(rst2pdf_verbose)$(RST2PDF) $(RST2PDF_FLAGS) $< -o $@
128else
129	$(error Cannot make $@: rst2pdf is not installed)
130endif
131
132#
133# generate $(DOCS_DIR)/*.rst for Sphinx document
134#
135update-docs: $(doc_files)
136
137# Convert the names of man page files (without suffix) to man page citations.
138#   ctags.1 tags.5 ... => ctags(1) tags(5) ...
139cites := ${subst .,(,${addsuffix ),${man_pages}}}
140
141# Convert the man page citations to sed patterns for making hyperlinks.
142#   ctags(1) tags(5) ...
143#     => -e 's/\<ctags(1)/:ref:`& <&>`/g' -e 's/\<ctags(5)/:ref:`& <&>`/g' ...
144if HAS_GNU_SED
145reppat := $(foreach m,$(cites),-e 's/\<$(m)/:ref:`& <&>`/g')
146else
147reppat := $(foreach m,$(cites),-e 's/[[:<:]]$(m)/:ref:`& <&>`/g')
148endif
149
150# Delete the line "------" in the first 10 lines of $(DOCS_DIR)/*.rst to
151# suppress unnecessary section indices.
152$(DOCS_DIR)/%.rst: %.rst
153	@$(MKDIR_P) $(DOCS_DIR)
154	$(sed_verbose)sed $(reppat) -e '1,10s/^-*$$//' < $< > $@
155
156# remove generated files to be commited (used for `make checkgen`)
157clean-local: clean-docs
158clean-docs:
159	$(rm_verbose)rm -f $(man_in_files) $(doc_files)
160