• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# SPDX-License-Identifier: GPL-2.0
2
3# Include the utils
4include $(src)/scripts/utils.mk
5
6# This Makefile and manpage XSL files were taken from libtracefs
7# and modified for libtracecmd
8
9MAN1_TXT= \
10	$(wildcard trace-cmd*.1.txt)
11
12MAN5_TXT= \
13	$(wildcard trace-cmd*.5.txt)
14
15MAN_TXT = $(MAN1_TXT) $(MAN5_TXT)
16_MAN_XML=$(patsubst %.txt,%.xml,$(MAN_TXT))
17_MAN_HTML=$(patsubst %.txt,%.html,$(MAN_TXT))
18_DOC_MAN1=$(patsubst %.1.txt,%.1,$(MAN1_TXT))
19_DOC_MAN5=$(patsubst %.5.txt,%.5,$(MAN5_TXT))
20
21MAN_XML=$(addprefix $(OUTPUT),$(_MAN_XML))
22MAN_HTML=$(addprefix $(OUTPUT),$(_MAN_HTML))
23DOC_MAN1=$(addprefix $(OUTPUT),$(_DOC_MAN1))
24DOC_MAN5=$(addprefix $(OUTPUT),$(_DOC_MAN5))
25
26# Make the path relative to DESTDIR, not prefix
27ifndef DESTDIR
28prefix?=$(HOME)
29endif
30bindir?=$(prefix)/bin
31htmldir?=$(prefix)/share/doc/trace-cmd
32pdfdir?=$(prefix)/share/doc/trace-cmd
33mandir?=$(prefix)/share/man
34man1dir=$(mandir)/man1
35man5dir=$(mandir)/man5
36
37ifdef USE_ASCIIDOCTOR
38ASCIIDOC_EXTRA += -a mansource="libtracecmd" -a manmanual="libtracecmd Manual"
39endif
40
41all: check-man-tools html man
42
43man: man1 man5
44man1: $(DOC_MAN1)
45man5: $(DOC_MAN5)
46
47html: $(MAN_HTML)
48
49$(MAN_HTML) $(DOC_MAN1) $(DOC_MAN5): $(ASCIIDOC_CONF)
50
51install: check-man-tools install-man install-html
52
53check-man-tools:
54ifdef missing_tools
55	$(error "You need to install $(missing_tools) for man pages")
56endif
57
58install-%.1: $(OUTPUT)%.1
59	$(Q)$(call do_install_docs,$<,$(man1dir),644);
60
61install-%.5: $(OUTPUT)%.5
62	$(Q)$(call do_install_docs,$<,$(man5dir),644);
63
64do-install-man: man $(addprefix install-,$(wildcard $(OUTPUT)*.1)) \
65	$(addprefix install-,$(wildcard $(OUTPUT)*.5))
66
67install-man: man
68	$(Q)$(MAKE) -C . do-install-man
69
70install-%.txt: $(OUTPUT)%.html
71	$(Q)$(call do_install_docs,$<,$(htmldir),644);
72
73do-install-html: html $(addprefix install-,$(wildcard *.txt))
74
75install-html: html do-install-html
76
77uninstall: uninstall-man uninstall-html
78
79uninstall-man:
80	$(Q)$(RM) $(addprefix $(DESTDIR)$(man1dir)/,$(DOC_MAN1))
81	$(Q)$(RM) $(addprefix $(DESTDIR)$(man5dir)/,$(DOC_MAN5))
82
83uninstall-html:
84	$(Q)$(RM) $(addprefix $(DESTDIR)$(htmldir)/,$(MAN_HTML))
85
86ifdef missing_tools
87  DO_INSTALL_MAN = $(warning Please install $(missing_tools) to have the man pages installed)
88else
89  DO_INSTALL_MAN = do-install-man
90endif
91
92CLEAN_FILES =					\
93	$(MAN_XML) $(addsuffix +,$(MAN_XML))	\
94	$(MAN_HTML) $(addsuffix +,$(MAN_HTML))	\
95	$(DOC_MAN1) $(DOC_MAN5) *.1 *.5
96
97clean:
98	$(Q) $(RM) $(CLEAN_FILES)
99
100ifdef USE_ASCIIDOCTOR
101$(OUTPUT)%.1 : $(OUTPUT)%.1.txt
102	$(QUIET_ASCIIDOC)$(RM) $@+ $@ && \
103	$(ASCIIDOC) -b manpage -d manpage \
104		$(ASCIIDOC_EXTRA) -atracecmd_version=$(TRACECMD_VERSION) -o $@+ $< && \
105	mv $@+ $@
106
107$(OUTPUT)%.5 : $(OUTPUT)%.5.txt
108	$(QUIET_ASCIIDOC)$(RM) $@+ $@ && \
109	$(ASCIIDOC) -b manpage -d manpage \
110		$(ASCIIDOC_EXTRA) -atracecmd_version=$(TRACECMD_VERSION) -o $@+ $< && \
111	mv $@+ $@
112endif
113
114$(OUTPUT)%.1 : $(OUTPUT)%.1.xml
115	$(QUIET_XMLTO)$(RM) $@ && \
116	$(XMLTO) -o $(OUTPUT). -m $(MANPAGE_XSL) $(XMLTO_EXTRA) man $<; \
117
118$(OUTPUT)%.5 : $(OUTPUT)%.5.xml
119	$(QUIET_XMLTO)$(RM) $@ && \
120	$(XMLTO) -o $(OUTPUT). -m $(MANPAGE_XSL) $(XMLTO_EXTRA) man $<; \
121
122$(OUTPUT)%.xml : %.txt
123	$(QUIET_ASCIIDOC)$(RM) $@+ $@ && \
124	$(ASCIIDOC) -b docbook -d manpage \
125		$(ASCIIDOC_EXTRA) -atracecmd_version=$(TRACECMD_VERSION) -o $@+ $< && \
126	mv $@+ $@
127
128$(MAN_HTML): $(OUTPUT)%.html : %.txt
129	$(QUIET_ASCIIDOC)$(RM) $@+ $@ && \
130	$(ASCIIDOC) -b $(ASCIIDOC_HTML) -d manpage \
131		$(ASCIIDOC_EXTRA) -atracecmd_version=$(TRACECMD_VERSION) -o $@+ $< && \
132	mv $@+ $@
133