Subject: [PATCH] depend2: switch echo|sed to automatic vars

From: Mike Frysinger <[email-masked]>
Date: Tue, 3 Jan 2023 21:06:46 -0500

The echo|sed is used to split the dirname & filename so it can insert
$(DEPDIR) in the middle, and then chop the trailing object suffix.  In
the generic case, %OBJ% is $@, so we can leverage the POSIX vars $(@D)
and $(@F) to do the pathname splitting and insert $(DEPDIR) in between.
For chopping the object suffix, we can use the $(xxx:...=...) syntax.
This avoids invoking sed completely.

These dirname/filename vars have been in POSIX since at least 2004.
https://pubs.opengroup.org/onlinepubs/009695399/utilities/make.html
> Each of the internal macros has an alternative form. When an
> uppercase 'D' or 'F' is appended to any of the macros, the
> meaning shall be changed to the directory part for 'D' and
> filename part for 'F'. The directory part is the path prefix
> of the file without a trailing slash; for the current directory,
> the directory part is '.'.

* lib/am/depend2.am: Change echo|sed logic to make variables.
---
 lib/am/depend2.am | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/lib/am/depend2.am b/lib/am/depend2.am
index 507fa40b54a0..87546f9d8274 100644
--- a/lib/am/depend2.am
+++ b/lib/am/depend2.am
@@ -42,7 +42,7 @@ if %FASTDEP%
 ?!GENERIC?	%SILENT%$(am__mv) %DEPBASE%.Tpo %DEPBASE%.Po
 ?GENERIC??!SUBDIROBJ?	%VERBOSE%%COMPILE% -MT %OBJ% -MD -MP -MF %DEPBASE%.Tpo %-c% -o %OBJ% %SOURCEFLAG%%SOURCE%
 ?GENERIC??!SUBDIROBJ?	%SILENT%$(am__mv) %DEPBASE%.Tpo %DEPBASE%.Po
-?GENERIC??SUBDIROBJ?	%VERBOSE%depbase=`echo %OBJ% | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.o$$||'`;\
+?GENERIC??SUBDIROBJ?	%VERBOSE%depbase='$(@D)/$(DEPDIR)/$(@F:.o=)';\
 ?GENERIC??SUBDIROBJ?	%COMPILE% -MT %OBJ% -MD -MP -MF %DEPBASE%.Tpo %-c% -o %OBJ% %SOURCEFLAG%%SOURCE% &&\
 ?GENERIC??SUBDIROBJ?	$(am__mv) %DEPBASE%.Tpo %DEPBASE%.Po
 else !%FASTDEP%
@@ -69,7 +69,7 @@ if %FASTDEP%
 ?!GENERIC?	%SILENT%$(am__mv) %DEPBASE%.Tpo %DEPBASE%.Po
 ?GENERIC??!SUBDIROBJ?	%VERBOSE%%COMPILE% -MT %OBJOBJ% -MD -MP -MF %DEPBASE%.Tpo %-c% -o %OBJOBJ% %SOURCEFLAG%`$(CYGPATH_W) '%SOURCE%'`
 ?GENERIC??!SUBDIROBJ?	%SILENT%$(am__mv) %DEPBASE%.Tpo %DEPBASE%.Po
-?GENERIC??SUBDIROBJ?	%VERBOSE%depbase=`echo %OBJ% | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.obj$$||'`;\
+?GENERIC??SUBDIROBJ?	%VERBOSE%depbase='$(@D)/$(DEPDIR)/$(@F:.obj=)';\
 ?GENERIC??SUBDIROBJ?	%COMPILE% -MT %OBJOBJ% -MD -MP -MF %DEPBASE%.Tpo %-c% -o %OBJOBJ% %SOURCEFLAG%`$(CYGPATH_W) '%SOURCE%'` &&\
 ?GENERIC??SUBDIROBJ?	$(am__mv) %DEPBASE%.Tpo %DEPBASE%.Po
 else !%FASTDEP%
@@ -98,7 +98,7 @@ if %FASTDEP%
 ?!GENERIC?	%SILENT%$(am__mv) %DEPBASE%.Tpo %DEPBASE%.Plo
 ?GENERIC??!SUBDIROBJ?	%VERBOSE%%LTCOMPILE% -MT %LTOBJ% -MD -MP -MF %DEPBASE%.Tpo %-c% -o %LTOBJ% %SOURCEFLAG%%SOURCE%
 ?GENERIC??!SUBDIROBJ?	%SILENT%$(am__mv) %DEPBASE%.Tpo %DEPBASE%.Plo
-?GENERIC??SUBDIROBJ?	%VERBOSE%depbase=`echo %OBJ% | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.lo$$||'`;\
+?GENERIC??SUBDIROBJ?	%VERBOSE%depbase='$(@D)/$(DEPDIR)/$(@F:.lo=)';\
 ?GENERIC??SUBDIROBJ?	%LTCOMPILE% -MT %LTOBJ% -MD -MP -MF %DEPBASE%.Tpo %-c% -o %LTOBJ% %SOURCEFLAG%%SOURCE% &&\
 ?GENERIC??SUBDIROBJ?	$(am__mv) %DEPBASE%.Tpo %DEPBASE%.Plo
 else !%FASTDEP%
-- 
2.39.0