summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlejandro Colomar <alx@kernel.org>2023-04-23 00:35:12 +0200
committerAlejandro Colomar <alx@kernel.org>2023-04-23 00:38:37 +0200
commit7569a9f692e42d2addd8164d3b088cfbe1832a27 (patch)
tree14f82bc90ebcb538d990e9e46ff18d48c4e4485e
parentb8d2c8398e1a3a7be2c9a7efac29ad19d82c1bb3 (diff)
*/mk: mkdir -p (and install -d) are safe to use
There are no race conditions, contrary to what some sources say. Previously, we had each directory depend on its parent directory, so that only a few parent-most directories would be created with parents, and all others would be created when their parents exist. That was due to FUD about TOCTOU race conditions with mkdir -p and parallel make, but it was just FUD. This patch makes it so that each directory is directly created with parents without specifying any dependency. This simplifies the makefile at some cost: calling mkdir -p so many times is a bit slower. However, it's only about 5%, so we can live with it, since we're talking about hundreds of a second for creating all the directories that this build system knows about. Reported-by: Ahelenia ZiemiaƄska <nabijaczleweli@nabijaczleweli.xyz> Signed-off-by: Alejandro Colomar <alx@kernel.org>
-rw-r--r--share/mk/build/_.mk4
-rw-r--r--share/mk/build/html.mk3
-rw-r--r--share/mk/build/src.mk6
-rw-r--r--share/mk/install/_.mk2
-rw-r--r--share/mk/install/html.mk4
-rw-r--r--share/mk/install/man.mk2
6 files changed, 5 insertions, 16 deletions
diff --git a/share/mk/build/_.mk b/share/mk/build/_.mk
index b5fbca92a..41b3a8ab9 100644
--- a/share/mk/build/_.mk
+++ b/share/mk/build/_.mk
@@ -31,10 +31,6 @@ NONSO_MDOC := $(shell $(FIND) $(MANDIR)/man*/ -type f \
| $(GREP) '$(MANEXT)' \
| $(XARGS) $(GREP) -l '^\.Dt ' \
| $(SORT))
-_MANDIRS := $(patsubst $(MANDIR)/%,$(_MANDIR)/%/,$(MANDIRS))
-
-
-$(_MANDIRS): %/: | $$(dir %) $(_MANDIR)/
$(builddir)/%/:
diff --git a/share/mk/build/html.mk b/share/mk/build/html.mk
index cf8e54107..b68f97213 100644
--- a/share/mk/build/html.mk
+++ b/share/mk/build/html.mk
@@ -24,7 +24,6 @@ MAN2HTML := man2html
_HTMLPAGES := $(patsubst $(MANDIR)/%,$(_HTMLDIR)/%$(htmlext),$(MANPAGES))
-_HTMLDIRS := $(patsubst $(MANDIR)/%,$(_HTMLDIR)/%/,$(MANDIRS))
# Use with
@@ -35,8 +34,6 @@ $(_HTMLPAGES): $(_HTMLDIR)/%$(htmlext): $(MANDIR)/% | $$(@D)/
$(MAN2HTML) $(MAN2HTMLFLAGS) $< \
| $(SED) -e 1,2d >$@
-$(_HTMLDIRS): %/: | $$(dir %) $(_HTMLDIR)/
-
.PHONY: build-html html
build-html html: $(_HTMLPAGES)
diff --git a/share/mk/build/src.mk b/share/mk/build/src.mk
index ee429eb21..e273fbf4e 100644
--- a/share/mk/build/src.mk
+++ b/share/mk/build/src.mk
@@ -54,7 +54,7 @@ CC := cc
LD := $(CC) $(CFLAGS)
-_SRCPAGEDIRS := $(patsubst $(MANDIR)/%,$(_MANDIR)/%.d,$(NONSO_MAN))
+_SRCPAGEDIRS := $(patsubst $(MANDIR)/%,$(_MANDIR)/%.d/,$(NONSO_MAN))
_UNITS_src_src := $(patsubst $(MANDIR)/%,$(_MANDIR)/%,$(shell \
$(FIND) $(MANDIR)/man*/ -type f \
@@ -69,12 +69,12 @@ _UNITS_src_o := $(patsubst %.c,%.o,$(_UNITS_src_c))
_UNITS_src_bin := $(patsubst %.c,%,$(_UNITS_src_c))
-$(_SRCPAGEDIRS): $(_MANDIR)/%.d: $(MANDIR)/% | $$(@D)/
+$(_SRCPAGEDIRS): $(_MANDIR)/%.d/: $(MANDIR)/%
+$(info MKDIR $@)
+$(MKDIR) $@
+touch $@
-$(_UNITS_src_src): $$(patsubst $(_MANDIR)/%.d,$(MANDIR)/%,$$(@D)) | $$(@D)
+$(_UNITS_src_src): $$(patsubst $(_MANDIR)/%.d,$(MANDIR)/%,$$(@D)) | $$(@D)/
$(_UNITS_src_c): $$(filter $$(@D)/%.h,$(_UNITS_src_h))
$(_UNITS_src_src):
$(info SED $@)
diff --git a/share/mk/install/_.mk b/share/mk/install/_.mk
index bffce03fb..66788d8f7 100644
--- a/share/mk/install/_.mk
+++ b/share/mk/install/_.mk
@@ -19,7 +19,7 @@ docdir := $(datarootdir)/doc
%/:
- +$(info INSTALL $@/)
+ +$(info INSTALL $@)
+$(INSTALL_DIR) $@
%-rm:
diff --git a/share/mk/install/html.mk b/share/mk/install/html.mk
index 2b1af838c..4b6dfa262 100644
--- a/share/mk/install/html.mk
+++ b/share/mk/install/html.mk
@@ -18,7 +18,7 @@ _htmldir := $(DESTDIR)$(htmldir_)
_htmlpages := $(patsubst $(_HTMLDIR)/%,$(_htmldir)/%,$(_HTMLPAGES))
-_htmldirs := $(patsubst $(_HTMLDIR)/%,$(_htmldir)/%,$(_HTMLDIRS))
+_htmldirs := $(patsubst $(MANDIR)/%,$(_htmldir)/%,$(MANDIRS))
_htmlpages_rm := $(addsuffix -rm,$(wildcard $(_htmlpages)))
_htmldirs_rmdir := $(addsuffix -rmdir,$(wildcard $(_htmldirs)))
_htmldir_rmdir := $(addsuffix -rmdir,$(wildcard $(_htmldir)/))
@@ -28,8 +28,6 @@ $(_htmlpages): $(_htmldir)/%: $(_HTMLDIR)/% | $$(@D)/
$(info INSTALL $@)
$(INSTALL_DATA) -T $< $@
-$(_htmldirs): %/: | $$(dir %) $(_htmldir)/
-
.PHONY: install-html
install-html: $(_htmlpages)
diff --git a/share/mk/install/man.mk b/share/mk/install/man.mk
index 0d81b657e..128f20833 100644
--- a/share/mk/install/man.mk
+++ b/share/mk/install/man.mk
@@ -187,8 +187,6 @@ else ifeq ($(Z),.xz)
fi
endif
-$(_mandirs): %/: | $$(dir %) $(_mandir)/
-
$(_mandirs_rmdir): $(_mandir)/man%/-rmdir: $$(_man%pages_rm) FORCE
$(_mandir_rmdir): $(uninstall_manX) FORCE