[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] *.mk: Handle files with ':' in their pathnames

From: Alejandro Colomar
Subject: [PATCH] *.mk: Handle files with ':' in their pathnames
Date: Wed, 26 Apr 2023 01:56:02 +0200

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

Link: <https://stackoverflow.com/a/76096683/6872717>
Cc: GNU Make <bug-make@gnu.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>


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

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.


 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(-)

diff --git a/share/mk/build/_.mk b/share/mk/build/_.mk
index a02301ff1..6cc820073 100644
--- a/share/mk/build/_.mk
+++ b/share/mk/build/_.mk
@@ -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')
diff --git a/share/mk/build/src.mk b/share/mk/build/src.mk
index fcee7fa43..4da142a74 100644
--- a/share/mk/build/src.mk
+++ b/share/mk/build/src.mk
@@ -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))
diff --git a/share/mk/dist.mk b/share/mk/dist.mk
index da76e7bf3..90e2870e5 100644
--- a/share/mk/dist.mk
+++ b/share/mk/dist.mk
@@ -27,7 +27,9 @@ 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))
diff --git a/share/mk/install/man.mk b/share/mk/install/man.mk
index f1043a9d6..caafe5e09 100644
--- a/share/mk/install/man.mk
+++ b/share/mk/install/man.mk
@@ -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);
diff --git a/share/mk/lint/man/man.mk b/share/mk/lint/man/man.mk
index 4b3d1db8b..a3f2ae960 100644
--- a/share/mk/lint/man/man.mk
+++ b/share/mk/lint/man/man.mk
@@ -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);
diff --git a/share/mk/src.mk b/share/mk/src.mk
index 256b6ca85..84ebcb97f 100644
--- a/share/mk/src.mk
+++ b/share/mk/src.mk
@@ -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))

reply via email to

[Prev in Thread] Current Thread [Next in Thread]