From 800139e66e234ddc920764e9700922e8845a3a63 Mon Sep 17 00:00:00 2001 From: Mark Wooding Date: Mon, 10 Jun 2024 02:56:08 +0100 Subject: [PATCH] Makefile: Introduce and use some improved pathname manipulation functions. The main thing is that these ones don't care about trailing `/'s. --- Makefile | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 68f8bb5..9b52893 100644 --- a/Makefile +++ b/Makefile @@ -265,6 +265,24 @@ CLEANFILES += log/*.log SILENCE_LVM = \ LVM_SUPPRESS_FD_WARNINGS=1; export LVM_SUPPRESS_FD_WARNINGS +## $(call file-name,PATH) +## +## Strip any trailing `/' from the PATH. +file-name = $(1:/=) + +## $(call base-name,PATH) +## +## Expand to the last component of PATH, whether or not it's a directory +## name with a trailing `/'. +base-name = $(notdir $(call file-name,$1)) + +## $(call parent-dir,PATH) +## +## Expand to the parent directory of PATH, whether or not it's a directory +## name with a trailing `/'. +## `/'. +parent-dir = $(dir $(call file-name,$1)) + ## $(call definedp,VAR) ## ## Expand non-empty if and only if VAR is defined (but possibly empty). @@ -606,7 +624,7 @@ LOCAL_COMMON_DIRS = share/ src/ LOCAL_EXTRA_DIRS = share/man/ all: $(foreach d,$(LOCAL_COMMON_DIRS) $(LOCAL_EXTRA_DIRS),$(LOCAL)/$d) $(foreach d,$(LOCAL_COMMON_DIRS) $(LOCAL_EXTRA_DIRS),$(LOCAL)/$d): - $(V_AT)mkdir -p $(dir $(patsubst %/,%,$@)) + $(V_AT)mkdir -p $(call parent-dir $@) $(call v_tag,MKDIR)mkdir $@ LOCAL_ARCH_DIRS = bin/ etc/ games/ include/ include.aside/ @@ -623,18 +641,18 @@ $(foreach a,$(ALL_ARCHS),$(LOCAL)/$a/): $(call v_tag,MKDIR)mkdir $@ $(foreach a,$(ALL_ARCHS),\ $(foreach d,$(LOCAL_ARCH_DIRS),$(LOCAL)/$a/$d)): - $(V_AT)mkdir -p $(dir $(patsubst %/,%,$@)) + $(V_AT)mkdir -p $(call parent-dir,$@) $(call v_tag,MKDIR)mkdir $@ $(foreach a,$(ALL_ARCHS),\ $(foreach d,$(LOCAL_ARCH_LINKS),$(LOCAL)/$a/$d)): \ - $$(if $$(call symlink-ok-p,$$@,$$($$(notdir $$@)_LINKDEST)),,_force) - $(V_AT)mkdir -p $(dir $@) - $(call v_tag,SYMLINK)ln -sf $($(notdir $@)_LINKDEST) $@ + $$(if $$(call symlink-ok-p,$$@,$$($$(call base-name,$$@)_LINKDEST)),,_force) \ + $(V_AT)mkdir -p $(call parent-dir,$@) + $(call v_tag,SYMLINK)ln -sf $($(call base-name,$@)_LINKDEST) $@ $(foreach a,$(ALL_ARCHS),\ $(foreach d,$(LOCAL_COMMON_DIRS),$(LOCAL)/$a/$d)): \ - $$(if $$(call symlink-ok-p,$$@,../$$(notdir $$(patsubst %/,%,$$@))),,_force) - $(V_AT)mkdir -p $(dir $(patsubst %/,%,$@)) - $(call v_tag,SYMLINK)ln -sf ../$(notdir $(patsubst %/,%,$@)) $(patsubst %/,%,$@) + $$(if $$(call symlink-ok-p,$$@,../$$(call base-name,$$@)),,_force) \ + $(V_AT)mkdir -p $(call parent-dir,$@) + $(call v_tag,SYMLINK)ln -sf ../$(call base-name,$@) $(call file-name,$@) ###-------------------------------------------------------------------------- ### Main chroot maintenance. -- 2.11.0