Skip to contentSkip to conversation

*.mk: Handle files with ':' in their pathnames

PATCH New Alejandro Colomar 1 participant 1 message Apr 25, 2023 Man-pages: manual pages for Linux -- Sections 2, 3, 4, 5, and 7

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 *.mk: Handle files with ':' in their pathnames

Since make(1) uses ':' as a special character in rules, it needs to be handled carefully. A way to make it work is to escape it with '\:'. We can use sed(1) to do that right when we get the pathnames. The only problem with ':' is in rules' targets and prerequisites: everywhere else it's fine; so let's discuss what needs to be done in those places:

- In the targets, it's as easy as escaping.

- In prerequisites, we can't second-expand variables containing such pathnames, as the '\' would not be used by make(1) to escape the ':', but it would be interpreted as part of the pathname. This means we need to expand rules written using second expansion into several rules that only expand their variables once.

- $(wildcard ...) also performs the escape, so after using it the pathnames are not escaped. If we used those variables in targets, we would need to escape the ':'s again, but since we don't we can skip that. The trick to make this work is to second-expand these variables.

---

Hi!

Some man pages use ':' (or to be more precise, they use '::') in their file names. An example is Perl (3pm) pages. It's also conceivable that C++ manual pages (if somebody writes them) would use these characters, as that language also uses '::' in identifiers (for namespaces).

I want the Linux man-pages' build system to be usable with all manual pages that exist in a typical Unix system, so that all the linting capabilities that it supports can be used easily in pages from other projects.

So, I tested it by copying the makefiles into my system's /usr/share/man and run make lint check there, to see what would happen. I found this issue, which is why I'm solving it now. Apart from this issue, all looked good (except that I was blown by the number of warnings that the linters gave on the pages, but that is tangent to this).

I'm CCing GNU Make, since colons are a delicate thing with Makefiles, and I'd like confirmation from Make's maintainers that this patch is the right approach.

Cheers,
Alex

 share/mk/build/_.mk      |  6 ++++--
 share/mk/build/src.mk    |  3 ++-
 share/mk/dist.mk         |  4 +++-
 share/mk/install/man.mk  | 26 ++++++++++++++++++++++++--
 share/mk/lint/man/man.mk |  6 ++++--
 share/mk/src.mk          |  3 ++-
 6 files changed, 39 insertions(+), 9 deletions(-)
share/mk/build/_.mk +4 -2
index a02301ff1..6cc820073 100644
@@ -26,11 +26,13 @@ RM    := rm
 NONSO_MAN := $(shell $(FIND) $(MANDIR)/man*/ -type f \
 		| $(GREP) '$(MANEXT)' \
 		| $(XARGS) $(GREP) -l '^\.TH ' \
-		| $(SORT))
+		| $(SORT) \
+		| $(SED) 's,:,\\:,g')
 NONSO_MDOC := $(shell $(FIND) $(MANDIR)/man*/ -type f \
 		| $(GREP) '$(MANEXT)' \
 		| $(XARGS) $(GREP) -l '^\.Dt ' \
-		| $(SORT))
+		| $(SORT) \
+		| $(SED) 's,:,\\:,g')
 
 
 $(builddir)/%/:
share/mk/build/src.mk +2 -1
index fcee7fa43..4da142a74 100644
@@ -62,7 +62,8 @@ _UNITS_src_src := $(patsubst $(MANDIR)/%,$(_MANDIR)/%,$(shell \
 		| $(XARGS) $(GREP) -H '^\.\\" SRC BEGIN ' \
 		| $(SED) 's,:\.\\" SRC BEGIN (,.d/,' \
 		| $(SED) 's/)//' \
-		| $(SORT)))
+		| $(SORT) \
+		| $(SED) 's,:,\\:,g'))
 _UNITS_src_h   := $(filter %.h,$(_UNITS_src_src))
 _UNITS_src_c   := $(filter %.c,$(_UNITS_src_src))
 _UNITS_src_o   := $(patsubst %.c,%.o,$(_UNITS_src_c))
share/mk/dist.mk +3 -1
index da76e7bf3..90e2870e5 100644
@@ -27,7 +27,9 @@ EXTRA_TARFLAGS   :=
 TARFLAGS         := $(DEFAULT_TARFLAGS) $(EXTRA_TARFLAGS)
 
 
-DISTFILES   := $(shell $(GIT) ls-files $(HIDE_ERR) | $(SED) 's,^,$(srcdir)/,')
+DISTFILES   := $(shell $(GIT) ls-files $(HIDE_ERR) \
+			| $(SED) 's,^,$(srcdir)/,' \
+			| $(SED) 's,:,\\:,g')
 _DISTFILES  := $(patsubst $(srcdir)/%,$(_DISTDIR)/%,$(DISTFILES))
 _DISTPAGES  := $(filter     $(_DISTDIR)/man%,$(_DISTFILES))
 _DISTOTHERS := $(filter-out $(_DISTDIR)/man%,$(_DISTFILES))
share/mk/install/man.mk +24 -2
index f1043a9d6..caafe5e09 100644
@@ -191,8 +191,30 @@ $(_mandirs_rmdir): $(_mandir)/man%/-rmdir: $$(_man%pages_rm) FORCE
 $(_mandir_rmdir): $(uninstall_manX) FORCE
 
 
-.PHONY: $(install_manX)
-$(install_manX): install-man%: $$(_man%pages);
+.PHONY: install-man1
+install-man1:      $(_man1pages);
+.PHONY: install-man2
+install-man2:      $(_man2pages);
+.PHONY: install-man2type
+install-man2type:  $(_man2typepages);
+.PHONY: install-man3
+install-man3:      $(_man3pages);
+.PHONY: install-man3const
+install-man3const: $(_man3constpages);
+.PHONY: install-man3head
+install-man3head:  $(_man3headpages);
+.PHONY: install-man3type
+install-man3type:  $(_man3typepages);
+.PHONY: install-man4
+install-man4:      $(_man4pages);
+.PHONY: install-man5
+install-man5:      $(_man5pages);
+.PHONY: install-man6
+install-man6:      $(_man6pages);
+.PHONY: install-man7
+install-man7:      $(_man7pages);
+.PHONY: install-man8
+install-man8:      $(_man8pages);
 
 .PHONY: install-man
 install-man: $(install_manX);
share/mk/lint/man/man.mk +4 -2
index 4b3d1db8b..a3f2ae960 100644
@@ -60,8 +60,10 @@ $(_LINT_man_tbl): $(_MANDIR)/%.lint-man.tbl.touch: $(MANDIR)/% | $$(@D)/
 	touch $@
 
 
-.PHONY: $(lint_man)
-$(lint_man): lint-man-%: $$(_LINT_man_%);
+.PHONY: lint-man-mandoc
+lint-man-mandoc: $(_LINT_man_mandoc);
+.PHONY: lint-man-tbl
+lint-man-tbl:    $(_LINT_man_tbl);
 
 .PHONY: lint-man
 lint-man: $(lint_man);
share/mk/src.mk +2 -1
index 256b6ca85..84ebcb97f 100644
@@ -17,7 +17,8 @@ MANEXT := \.[0-9]\w*$
 
 MANPAGES := $(shell $(FIND) $(MANDIR)/man*/ -type f \
 		| $(GREP) '$(MANEXT)' \
-		| $(SORT))
+		| $(SORT) \
+		| $(SED) 's,:,\\:,g')
 MANDIRS  := $(shell $(FIND) $(MANDIR)/man* -type d \
 		| $(SORT))
 
Signature · 1 line
2.40.0