]> git.ipfire.org Git - thirdparty/man-pages.git/blob - share/mk/install/man.mk
*.mk: gzip(1) doesn't need '-' to act as a filter
[thirdparty/man-pages.git] / share / mk / install / man.mk
1 ########################################################################
2 # Copyright 2021-2023, Alejandro Colomar <alx@kernel.org>
3 # SPDX-License-Identifier: GPL-3.0-or-later
4 ########################################################################
5
6
7 ifndef MAKEFILE_INSTALL_MAN_INCLUDED
8 MAKEFILE_INSTALL_MAN_INCLUDED := 1
9
10
11 include $(MAKEFILEDIR)/cmd.mk
12 include $(MAKEFILEDIR)/compress.mk
13 include $(MAKEFILEDIR)/install/_.mk
14 include $(MAKEFILEDIR)/src.mk
15
16
17 LINK_PAGES := .so
18 ifeq ($(LINK_PAGES),.so)
19 else ifeq ($(LINK_PAGES),symlink)
20 else
21 $(warning "LINK_PAGES": "$(LINK_PAGES)")
22 $(error Valid values for "LINK_PAGES": [".so", "symlink"])
23 endif
24
25
26 mandir := $(datarootdir)/man
27 $(foreach s, $(MANSECTIONS), \
28 $(eval man$(s)dir := $(mandir)/man$(s)))
29 $(foreach s, $(MANSECTIONS), \
30 $(eval man$(s)ext := .$(s)$(Z)))
31
32
33 _mandir := $(DESTDIR)$(mandir)
34 $(foreach s, $(MANSECTIONS), \
35 $(eval _man$(s)dir := $(DESTDIR)$(man$(s)dir)))
36
37 _manintropages := $(patsubst $(MANDIR)/%, $(_mandir)/%$(Z), $(MANINTROPAGES))
38 $(foreach s, $(MANSECTIONS), \
39 $(eval _man$(s)pages := \
40 $(patsubst $(MANDIR)/man$(s)/%, $(_man$(s)dir)/%$(Z), \
41 $(MAN$(s)PAGES))))
42 _manpages := $(_manintropages) $(foreach s, $(MANSECTIONS), $(_man$(s)pages))
43
44 _manintropages_rm := $(addsuffix -rm, $(wildcard $(_manintropages)))
45 $(foreach s, $(MANSECTIONS), \
46 $(eval _man$(s)pages_rm := \
47 $(addsuffix -rm, \
48 $(wildcard $(_man$(s)pages)))))
49
50
51 $(_manintropages): $(_mandir)/%$(Z): $(MANDIR)/% | $$(@D)/
52 $(foreach s, $(MANSECTIONS), \
53 $(eval $(_man$(s)pages): $(_man$(s)dir)/%$(Z): $(MAN$(s)DIR)/% | $$$$(@D)/))
54
55
56 $(_manpages):
57 $(info INSTALL $@)
58 <$< \
59 $(SED) \
60 -e '/^\.so /s, man1/\(.*\)\.1$$, $(notdir $(man1dir))/\1$(man1ext),' \
61 -e '/^\.so /s, man2/\(.*\)\.2$$, $(notdir $(man2dir))/\1$(man2ext),' \
62 -e '/^\.so /s, man2type/\(.*\)\.2type$$, $(notdir $(man2typedir))/\1$(man2typeext),' \
63 -e '/^\.so /s, man3/\(.*\)\.3$$, $(notdir $(man3dir))/\1$(man3ext),' \
64 -e '/^\.so /s, man3const/\(.*\)\.3const$$, $(notdir $(man3constdir))/\1$(man3constext),' \
65 -e '/^\.so /s, man3head/\(.*\)\.3head$$, $(notdir $(man3headdir))/\1$(man3headext),' \
66 -e '/^\.so /s, man3type/\(.*\)\.3type$$, $(notdir $(man3typedir))/\1$(man3typeext),' \
67 -e '/^\.so /s, man4/\(.*\)\.4$$, $(notdir $(man4dir))/\1$(man4ext),' \
68 -e '/^\.so /s, man5/\(.*\)\.5$$, $(notdir $(man5dir))/\1$(man5ext),' \
69 -e '/^\.so /s, man6/\(.*\)\.6$$, $(notdir $(man6dir))/\1$(man6ext),' \
70 -e '/^\.so /s, man7/\(.*\)\.7$$, $(notdir $(man7dir))/\1$(man7ext),' \
71 -e '/^\.so /s, man8/\(.*\)\.8$$, $(notdir $(man8dir))/\1$(man8ext),' \
72 | $(INSTALL_DATA) -T /dev/stdin $@
73 ifeq ($(LINK_PAGES),symlink)
74 if $(GREP) '^\.so ' <$@ >/dev/null; then \
75 $(GREP) '^\.so ' <$@ \
76 | $(SED) 's,^\.so \(.*\),../\1,' \
77 | $(XARGS) -I tgt $(LN) -fsT tgt $@; \
78 fi
79 endif
80 ifeq ($(Z),.bz2)
81 if ! $(TEST) -L $@; then \
82 $(BZIP2) $(BZIP2FLAGS) <$@ \
83 | $(SPONGE) $@; \
84 fi
85 else ifeq ($(Z),.gz)
86 if ! $(TEST) -L $@; then \
87 $(GZIP) $(GZIPFLAGS) <$@ \
88 | $(SPONGE) $@; \
89 fi
90 else ifeq ($(Z),.lz)
91 if ! $(TEST) -L $@; then \
92 $(LZIP) $(LZIPFLAGS) <$@ \
93 | $(SPONGE) $@; \
94 fi
95 else ifeq ($(Z),.xz)
96 if ! $(TEST) -L $@; then \
97 $(XZ) $(XZFLAGS) <$@ \
98 | $(SPONGE) $@; \
99 fi
100 endif
101
102
103 .PHONY: install-manintro
104 install-manintro: $(_manintropages);
105 $(foreach s, $(MANSECTIONS), \
106 $(eval .PHONY: install-man$(s)))
107 $(foreach s, $(MANSECTIONS), \
108 $(eval install-man$(s): $(_man$(s)pages);))
109 .PHONY: install-man
110 install-man: install-manintro $(foreach s, $(MANSECTIONS), install-man$(s));
111
112 .PHONY: uninstall-manintro
113 uninstall-manintro: $(_manintropages_rm);
114 $(foreach s, $(MANSECTIONS), \
115 $(eval .PHONY: uninstall-man$(s)))
116 $(foreach s, $(MANSECTIONS), \
117 $(eval uninstall-man$(s): $(_man$(s)pages_rm);))
118 .PHONY: uninstall-man
119 uninstall-man: uninstall-manintro $(foreach s, $(MANSECTIONS), uninstall-man$(s));
120
121
122 endif # include guard