• Bug#872381: dpkg-dev: optimize Makefile snippets for debian/rules (1/5)

    From Nicolas Boulenguez@1:229/2 to All on Wed Jan 10 22:10:01 2024
    XPost: linux.debian.bugs.dist
    From: nicolas@debian.org

    Package: dpkg-dev
    Followup-For: Bug #872381

    Hello.
    The attached commits rebase the suggestions, take your answers into
    account and slightly improved some style issues.
    There may remain typos, nothing is tested this time.

    From d56d5af7fa1a01a581d0cc1901572ca9c407f538 Mon Sep 17 00:00:00 2001
    From: Nicolas Boulenguez <nicolas@debian.org>
    Date: Mon, 29 Jul 2019 14:38:32 +0200
    Subject: [PATCH 1/8] scripts/mk: stop hard-coding dpkg_datadir, protect from
    double inclusion

    The Makefile snippets include each other from their common directory,
    but the path differ during tests and after installation. Instead of
    rewriting the file with a hardcoded path, compute it within Make.

    Use the same variables to avoid 'include' when possible, as it
    involves system calls.

    When setting dpkg_datadir, prefer 'ifndef' and ':=' to '?=', so that
    the value is computed at most once.
    ---
    build-aux/subst.am | 6 ------
    scripts/mk/Makefile.am | 21 ---------------------
    scripts/mk/architecture.mk | 5 +++++
    scripts/mk/buildapi.mk | 5 +++++
    scripts/mk/buildflags.mk | 6 ++++++
    scripts/mk/buildopts.mk | 5 +++++
    scripts/mk/buildtools.mk | 11 ++++++++++-
    scripts/mk/default.mk | 10 +++++++++-
    scripts/mk/pkg-info.mk | 5 +++++
    scripts/mk/vendor.mk | 11 ++++++++++-
    10 files changed, 55 insertions(+), 30 deletions(-)

    diff --git a/build-aux/subst.am b/build-aux/subst.am
    index 5515930d0..167a71257 100644
    --- a/build-aux/subst.am
    +++ b/build-aux/subst.am
    @@ -39,9 +39,3 @@ SUFFIXES += .pl
    @test -d `dirname $@` || $(MKDIR_P) `dirname $@`
    $(do_perl_subst) <$< >$@
    $(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
    diff --git a/scripts/mk/Makefile.am b/scripts/mk/Makefile.am
    index 257ba5252
  • From Nicolas Boulenguez@1:229/2 to All on Mon Mar 4 16:50:01 2024
    XPost: linux.debian.bugs.dist
    From: nicolas@debian.org

    Package: dpkg-dev
    Followup-For: Bug #872381

    This new version, based on c881a5a8,
    * splits protection from double inclusion and dpkg_datadir generation
    into separate commits
    * fixes an error in DEB_BUILD_OPTION_PARALLEL
    * removes a few dubious optimizations (like checking if dpkg_datadir
    is already computed in default.mk).
    * removes non-ASCII characters from comments

    From e29be20064687eee52fa9b6c1ee1cb722867d590 Mon Sep 17 00:00:00 2001
    From: Nicolas Boulenguez <nicolas@debian.org>
    Date: Mon, 29 Jul 2019 14:38:32 +0200
    Subject: [PATCH 01/10] scripts/mk: protect scripts from double inclusion

    Two such double inclusions already happen when default.mk is parsed.
    ---
    scripts/mk/architecture.mk | 5 +++++
    scripts/mk/buildapi.mk | 5 +++++
    scripts/mk/buildflags.mk | 6 ++++++
    scripts/mk/buildopts.mk | 5 +++++
    scripts/mk/buildtools.mk | 5 +++++
    scripts/mk/default.mk | 5 +++++
    scripts/mk/pkg-info.mk | 5 +++++
    scripts/mk/vendor.mk | 5 +++++
    8 files changed, 41 insertions(+)

    diff --git a/scripts/mk/architecture.mk b/scripts/mk/architecture.mk
    index c11cada16..2ffcee287 100644
    --- a/scripts/mk/architecture.mk
    +++ b/scripts/mk/architecture.mk
    @@ -2,6 +2,9 @@
    # DEB_BUILD_* variables that dpkg-architecture can return. Existing values
    # of those variables are preserved as per policy.

    +ifndef dpkg_architecture.mk_included
    +dpkg_architecture.mk_included :=
    +
    dpkg_lazy_eval ?= $$(or $$(value DPKG_CACHE_$(1)),$$(eval DPKG_CACHE_$(1) := $$(shell $(2)))$$(value DPKG_CACHE_$(1)))

    dpkg_architecture_setvar = export $(1) ?= $(call dpkg_lazy_eval,$(1),dpkg-architecture -q$(1))
    @@ -9,3 +12,5 @@ dpkg_architecture_setvar = export
  • From Nicolas Boulenguez@1:229/2 to All on Wed Apr 10 19:50:02 2024
    XPost: linux.debian.bugs.dist
    From: nicolas.boulenguez@free.fr

    The attached version
    fixes the spacing issue in tests with a more readable trick,
    splits the changes inside tests into small chunks,
    replaces - with _ in Make variable names,
    avoids non portable -r -E sed options.

    Without -r, sed in {buildflags,pkg-info}.mk should cause no
    regression. It has been present in pkg-info.mk since 2011.

    From 5b3d75fb604dae497406f19073d03ea094da8d07 Mon Sep 17 00:00:00 2001
    From: Nicolas Boulenguez <nicolas@debian.org>
    Date: Wed, 10 Apr 2024 00:41:42 +0200
    Subject: [PATCH 01/10] scripts/t/mk/buildflags.mk: fix test of _MAINT_APPEND
    when TEST_ is empty

    When TEST_CPPFLAGS is empty, the right hand side of the comparison
    starts with a space character.
    ---
    scripts/t/mk/buildflags.mk | 7 +++++--
    1 file changed, 5 insertions(+), 2 deletions(-)

    diff --git a/scripts/t/mk/buildflags.mk b/scripts/t/mk/buildflags.mk
    index 94d85a7e0..7cf798f73 100644
    --- a/scripts/t/mk/buildflags.mk
    +++ b/scripts/t/mk/buildflags.mk
    @@ -1,5 +1,8 @@
    DEB_CPPFLAGS_MAINT_APPEND = -DTEST_MK=test-host
    +TEST_CPPFLAGS += -DTEST_MK=test-host
    +
    DEB_CPPFLAGS_FOR_BUILD_MAINT_APPEND = -DTEST_MK=test-build +TEST_CPPFLAGS_FOR_BUILD += -DTEST_MK=test-build

    include $(srcdir)/mk/buildflags.mk

    @@ -8,8 +11,8 @@ test:
    test "$(ASFLAGS_FOR_BUILD)" = "$(TEST_ASFLAGS_FOR_BUILD)"
    test "$(CFLAGS)" = "$(TEST_CFLAGS)"
    test "$(CFLAGS_FOR_BUILD)" = "$(TEST_CFLAGS_FOR_BUILD)"
    - test "$(CPPFLAGS)" = "$(TEST_CPPFLAGS) -DTEST_MK=test-host"
    - test "$(CPPFLAGS_FOR_BUILD)" = "$(TEST_CPPFLAGS_FOR_BUILD)-DTEST_MK=test-build"
    + test "$(CPPFLAGS)" = "$(TEST_CPPFLAGS)"
    + test "$(CPPFLAGS_FOR_BUILD)" = "$(TEST_CXXFLAGS_FOR_BUILD)"
    test "$(CXXFLAGS)" = "$(TEST_CXXF