This is an automated email from the git hooks/post-receive script.

guillem pushed a commit to branch main
in repository dpkg.

View the commit online:
https://git.dpkg.org/cgit/dpkg/dpkg.git/commit/?id=f1175056f53ec254b4234cb533881b671f7e5e35

commit f1175056f53ec254b4234cb533881b671f7e5e35
Author: Guillem Jover <guil...@debian.org>
AuthorDate: Thu Apr 11 04:32:39 2024 +0200

    build: Rework subst handling for built or installed artifacts
    
    Switch from sed to perl so that we can perform in-place substitutions in
    a portable way. Make the variable naming usage uniform.
    
    This reduces the amount of code duplication to deal with these
    substitutions.
    
    We do not use AM_V_GEN any longer for the subst_.*_file macros, as
    those get the filename as an argument, and are used in install-data-hook
    targets, which then generate very confusing output such as
    «  GEN    install-data-hook» for every modified file. And for the
    subst_.*_filter macros we use AM_V_GEN in the call sites, if needed,
    as that might not be appropriate if called after a pipe.
---
 build-aux/subst.am     | 54 +++++++++++++++++++++++++++++---------------------
 scripts/Makefile.am    |  6 +-----
 scripts/mk/Makefile.am | 19 ++++--------------
 utils/Makefile.am      | 10 ++++++----
 4 files changed, 42 insertions(+), 47 deletions(-)

diff --git a/build-aux/subst.am b/build-aux/subst.am
index 5515930d0..7785e4af7 100644
--- a/build-aux/subst.am
+++ b/build-aux/subst.am
@@ -4,44 +4,52 @@
 
 # Shell support.
 
-do_shell_subst = $(AM_V_GEN) $(SED) \
-       -e "s:^ADMINDIR=.*$$:ADMINDIR='$(admindir)':" \
-       -e "s:^BACKUPSDIR=.*$$:BACKUPSDIR='$(backupsdir)':" \
-       -e "s:^PKGDATADIR_DEFAULT=.*$$:PKGDATADIR_DEFAULT='$(pkgdatadir)':" \
-       -e "s:^version=['\"][^'\"]*[\"']:version=\"$(PACKAGE_VERSION)\":" \
-       -e "s:^TAR=.*$$:TAR='$(TAR)':" \
-       # EOL
+subst_shell_rules = "\
+       s{^ADMINDIR=.*$$}{ADMINDIR='$(admindir)'}; \
+       s{^BACKUPSDIR=.*$$}{BACKUPSDIR='$(backupsdir)'}; \
+       s{^PKGDATADIR_DEFAULT=.*$$}{PKGDATADIR_DEFAULT='$(pkgdatadir)'}; \
+       s{^version=['\"][^'\"]*[\"']}{version=\"$(PACKAGE_VERSION)\"}; \
+       s{^TAR=.*$$}{TAR='$(TAR)'}; \
+       "
+
+subst_shell_filter = $(PERL) -p -e $(subst_shell_rules)
+subst_shell_file = $(PERL) -i -p -e $(shell_subst_rules)
 
 SUFFIXES += .sh
 
 .sh: Makefile
        @test -d `dirname $@` || $(MKDIR_P) `dirname $@`
-       $(do_shell_subst) <$< >$@
+       $(AM_V_GEN) $(subst_shell_filter) <$< >$@
        $(AM_V_at) chmod +x $@
 
 # Perl support.
 
-do_perl_subst = $(AM_V_GEN) $(SED) \
-       -e "s:^\#![[:space:]]*/usr/bin/perl:\#!$(PERL):" \
-       -e "s:our \$$CONFDIR = .*;:our \$$CONFDIR = '$(pkgconfdir)';:" \
-       -e "s:our \$$ADMINDIR = .*;:our \$$ADMINDIR = '$(admindir)';:" \
-       -e "s:our \$$LIBDIR = .*;:our \$$LIBDIR = '$(pkglibexecdir)';:" \
-       -e "s:our \$$DATADIR = .*;:our \$$DATADIR = '$(pkgdatadir)';:" \
-       -e "s:our \$$PROGMAKE = .*;:our \$$PROGMAKE = '$(MAKE)';:" \
-       -e "s:our \$$PROGTAR = .*;:our \$$PROGTAR = '$(TAR)';:" \
-       -e "s:our \$$PROGPATCH = .*;:our \$$PROGPATCH = '$(PATCH)';:" \
-       -e "s:our \$$PROGVERSION = .*;:our \$$PROGVERSION = 
'$(PACKAGE_VERSION)';:" \
-       # EOL
+subst_perl_rules = "\
+       s{^\#!\s*/usr/bin/perl}{\#!$(PERL)}; \
+       s{our \\\$$CONFDIR = .*;}{our \\\$$CONFDIR = '$(pkgconfdir)';}; \
+       s{our \\\$$ADMINDIR = .*;}{our \\\$$ADMINDIR = '$(admindir)';}; \
+       s{our \\\$$LIBDIR = .*;}{our \\\$$LIBDIR = '$(pkglibexecdir)';}; \
+       s{our \\\$$DATADIR = .*;}{our \\\$$DATADIR = '$(pkgdatadir)';}; \
+       s{our \\\$$PROGMAKE = .*;}{our \\\$$PROGMAKE = '$(MAKE)';}; \
+       s{our \\\$$PROGTAR = .*;}{our \\\$$PROGTAR = '$(TAR)';}; \
+       s{our \\\$$PROGPATCH = .*;}{our \\\$$PROGPATCH = '$(PATCH)';}; \
+       s{our \\\$$PROGVERSION = .*;}{our \\\$$PROGVERSION = 
'$(PACKAGE_VERSION)';}; \
+       "
+
+subst_perl_filter = $(PERL) -p -e $(subst_perl_rules)
+subst_perl_file = $(PERL) -i -p -e $(subst_perl_rules)
 
 SUFFIXES += .pl
 
 .pl: Makefile
        @test -d `dirname $@` || $(MKDIR_P) `dirname $@`
-       $(do_perl_subst) <$< >$@
+       $(AM_V_GEN) $(subst_perl_filter) <$< >$@
        $(AM_V_at) chmod +x $@
 
 # Makefile support.
 
-do_make_subst = $(AM_V_GEN) $(SED) \
-       -e "s:dpkg_datadir[[:space:]]*=[[:space:]]*[^[:space:]]*:dpkg_datadir = 
$(pkgdatadir):" \
-       # EOL
+subst_make_rules = "\
+       s{dpkg_datadir\s*=\s*[^\s]*}{dpkg_datadir = $(pkgdatadir)}; \
+       "
+
+subst_make_file = $(PERL) -i -p -e $(subst_make_rules)
diff --git a/scripts/Makefile.am b/scripts/Makefile.am
index 027204792..2b79f6111 100644
--- a/scripts/Makefile.am
+++ b/scripts/Makefile.am
@@ -193,12 +193,8 @@ if BUILD_POD_DOC
        done
 endif
 
-# Ideally we'd use '$(SED) -i', but unfortunately that's not portable.
 install-data-hook:
-       $(do_perl_subst) <$(DESTDIR)$(perllibdir)/Dpkg.pm \
-                        >$(DESTDIR)$(perllibdir)/Dpkg.pm.new
-       mv $(DESTDIR)$(perllibdir)/Dpkg.pm.new \
-          $(DESTDIR)$(perllibdir)/Dpkg.pm
+       $(subst_perl_file) $(DESTDIR)$(perllibdir)/Dpkg.pm
 
 uninstall-local:
 if BUILD_POD_DOC
diff --git a/scripts/mk/Makefile.am b/scripts/mk/Makefile.am
index 257ba5252..be6076b2c 100644
--- a/scripts/mk/Makefile.am
+++ b/scripts/mk/Makefile.am
@@ -15,19 +15,8 @@ SUFFIXES =
 
 include $(top_srcdir)/build-aux/subst.am
 
-# Ideally we'd use '$(SED) -i', but unfortunately that's not portable.
 install-data-hook:
-       $(do_make_subst) <$(DESTDIR)$(pkgdatadir)/default.mk \
-                        >$(DESTDIR)$(pkgdatadir)/default.mk.new
-       mv $(DESTDIR)$(pkgdatadir)/default.mk.new \
-          $(DESTDIR)$(pkgdatadir)/default.mk
-
-       $(do_make_subst) <$(DESTDIR)$(pkgdatadir)/buildtools.mk \
-                        >$(DESTDIR)$(pkgdatadir)/buildtools.mk.new
-       mv $(DESTDIR)$(pkgdatadir)/buildtools.mk.new \
-          $(DESTDIR)$(pkgdatadir)/buildtools.mk
-
-       $(do_make_subst) <$(DESTDIR)$(pkgdatadir)/vendor.mk \
-                        >$(DESTDIR)$(pkgdatadir)/vendor.mk.new
-       mv $(DESTDIR)$(pkgdatadir)/vendor.mk.new \
-          $(DESTDIR)$(pkgdatadir)/vendor.mk
+       $(subst_make_file) $(DESTDIR)$(pkgdatadir)/default.mk
+       $(subst_make_file) $(DESTDIR)$(pkgdatadir)/buildtools.mk
+       $(subst_make_file) $(DESTDIR)$(pkgdatadir)/pkg-info.mk
+       $(subst_make_file) $(DESTDIR)$(pkgdatadir)/vendor.mk
diff --git a/utils/Makefile.am b/utils/Makefile.am
index 2ce3bceb8..b10961ac5 100644
--- a/utils/Makefile.am
+++ b/utils/Makefile.am
@@ -42,15 +42,17 @@ dist_bashcompletions_DATA +=
 polkitactions_DATA += org.dpkg.pkexec.update-alternatives.policy
 endif
 
-do_polkit_subst = $(SED) \
-       -e 's,[@]bindir[@],$(bindir),g' \
-       # EOL
+subst_polkit_rules = "\
+       s{[@]bindir[@]}{$(bindir)}g; \
+       "
+
+subst_polkit_filter = $(PERL) -p -e $(subst_polkit_rules)
 
 org.dpkg.pkexec.update-alternatives.policy: update-alternatives.polkit.in 
Makefile
        @test -d `dirname $@` || $(MKDIR_P) `dirname $@`
        $(AM_V_GEN) GETTEXTDATADIR="$(top_srcdir)/po" \
          $(MSGFMT) --xml --template $< -d $(top_srcdir)/po -o - \
-         | $(do_polkit_subst) >$@
+         | $(subst_polkit_filter) >$@
 
 EXTRA_DIST += \
        README.alternatives \

-- 
Dpkg.Org's dpkg

Reply via email to