From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS53758 23.128.96.0/24 X-Spam-Status: No, score=-3.7 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_PASS, SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by dcvr.yhbt.net (Postfix) with ESMTP id B8A8A1F953 for ; Wed, 17 Nov 2021 10:21:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236272AbhKQKYF (ORCPT ); Wed, 17 Nov 2021 05:24:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56466 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236271AbhKQKXi (ORCPT ); Wed, 17 Nov 2021 05:23:38 -0500 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D545EC061764 for ; Wed, 17 Nov 2021 02:20:39 -0800 (PST) Received: by mail-wm1-x336.google.com with SMTP id f7-20020a1c1f07000000b0032ee11917ceso1707352wmf.0 for ; Wed, 17 Nov 2021 02:20:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=XKmWCiCaWjvjUcpm4uTFqMmQQhf1vsTAN00gj/kn0W0=; b=HTOSravBpaTNs5N9kMjfEXI2TvxaNf5e8FfZMReNmGetLLOmXIDvTSJwdSUZajgBS3 uAPR/9X+GEw0x/ea8gn/fYx9PWLBbBZhY1Chq2cIjJVjk+3VjDv5QX7fARQsavg+wEYI ewVWTZP2b+B/djSwxUPQAPO2hkxnfzWFh89UodlEuCbftDBhqBgUO8YgzanZU5rPOVAY YPUHg5WQ48bZD8POCpTkc0/GQBaCN9u69hHPqPbJJKYGD4vpryVcvmt2kynKhPTfBd/u /5coDFJcMG77fqx+G0DFrCy7+reoLMGO962HPvLr1HN4gsvstxsYUBs6zVzhYOv70meA Edjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=XKmWCiCaWjvjUcpm4uTFqMmQQhf1vsTAN00gj/kn0W0=; b=jU8pkY+p9EXDso+9aMHBLKDrcqeZ8zdVP7/Hj71RbkiODfYFSK9EvJ/tDkoVCsVow1 FxLljK84wXdaeqp/03YqZiMEU8G785c8zhRvD4klP7LpcsCuJe+QUAwO4qQeawmujEjS xup3Wsw07oLCPmllwZ3cXWC5Bwszg9tTYxa1ktJK22rLyfBpOdLQo5hWrGxvaoj/amt2 Sw217r11Q9Gt4WJf8cPhJkOVs2s+NU+HGOs+01aB8w9HwcNCf6L5nxcH7tP+5Z3f5JWN FIsWzl6ZGq4CCX7L2RHhBFPlGAy2X6PTZJPhIlo4lpB1UaVaoDaSZcintUrJ0cpm65EM 4QEQ== X-Gm-Message-State: AOAM532VgeZPU2vtWBY/LCgKmXu69ASZulhsb/iEtUBRK49UAc7S8rUn 5aYMp9iflmNH+rC/9ZBP7W7i7uISimi1bg== X-Google-Smtp-Source: ABdhPJw1zH6tREk5Dcab9Hc8b4Dc+u9PtQNXthHTuc+omKby08QoPjNknmVjGryGIiJ5ekf1iGilEw== X-Received: by 2002:a05:600c:3586:: with SMTP id p6mr78605229wmq.34.1637144438121; Wed, 17 Nov 2021 02:20:38 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id n32sm6456256wms.1.2021.11.17.02.20.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Nov 2021 02:20:37 -0800 (PST) From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= To: git@vger.kernel.org Cc: Junio C Hamano , Phillip Wood , Jeff King , Dan Jacques , Eric Wong , Jonathan Nieder , Mike Hommey , =?UTF-8?q?=C4=90o=C3=A0n=20Tr=E1=BA=A7n=20C=C3=B4ng=20Danh?= , =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Subject: [PATCH v4 15/23] Makefile: add a "TRACK_template" for GIT-*{FLAGS,DEFINES,...} Date: Wed, 17 Nov 2021 11:20:14 +0100 Message-Id: X-Mailer: git-send-email 2.34.0.796.g2c87ed6146a In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Move the mostly copy/pasted code in the "Makefile" and "Documentation/Makefile" which FORCE-generates a file based on a variable in play in the Makefile to use a template. This will make it easier later on to move these to rules that aren't FORCE-run using optional gmake 4.2+ features, but for now just getting rid of the repetition is worth it. The message for the new generated rule will say whether or not we're generating the file for the first time, as opposed to the old messages saying "new" whether we had flag modifications, or were building for the first time. Example output before: $ make clean [...] $ make GIT_VERSION = 2.34.0-rc1-dev * new build flags CC grep.o $ make CFLAGS=-I$RANDOM grep.o * new build flags CC grep.o After: $ make clean [...] $ make grep.o GIT_VERSION = 2.34.0-rc1-dev GIT-CFLAGS PARAMETERS (new) CC grep.o $ make CFLAGS=-I$RANDOM grep.o GIT-CFLAGS PARAMETERS (changed) CC grep.o Note: It's important that "@FLAGS" here be defined as '$$($(2))', and not the eagerly expanded '$($(2))'. The latter will break if e.g. curl-config isn't installed, since we'll end up recursively expanding that part of the variable even if NO_CURL isn't defined, which happens e.g. for the "check-docs" target in CI. We're also introducing a $(wspfx) variable here to control the whitespace prefixing. It matches the $(QUIET...) variables, who'll be using these variables in a subsequent commit. Note that it's important that we call the shell quote escaping macros inline (or equivalent), because if we'd like variables to be overridable we need to support e.g.: $ make CFLAGS=-I$RANDOM grep.o wspfx='$(space)->' -> GIT-CFLAGS PARAMETERS (changed) CC grep.o If we simply quoted and used $(wspfx) then the user would need to provide us with a quoted version, so there's still some use-cases for these $(*_sq) variables. It could also be done inline, but that's a lot more verbose. Signed-off-by: Ævar Arnfjörð Bjarmason --- Documentation/Makefile | 8 +------ Makefile | 51 ++++++------------------------------------ shared.mak | 22 ++++++++++++++++++ 3 files changed, 30 insertions(+), 51 deletions(-) diff --git a/Documentation/Makefile b/Documentation/Makefile index ba27456c86a..4a939cc2c25 100644 --- a/Documentation/Makefile +++ b/Documentation/Makefile @@ -343,13 +343,7 @@ mergetools-list.made: ../git-mergetool--lib.sh $(wildcard ../mergetools/*) date >$@ TRACK_ASCIIDOCFLAGS = $(subst ','\'',$(ASCIIDOC_COMMON):$(ASCIIDOC_HTML):$(ASCIIDOC_DOCBOOK)) - -GIT-ASCIIDOCFLAGS: FORCE - @FLAGS='$(TRACK_ASCIIDOCFLAGS)'; \ - if test x"$$FLAGS" != x"`cat GIT-ASCIIDOCFLAGS 2>/dev/null`" ; then \ - echo >&2 " * new asciidoc flags"; \ - echo "$$FLAGS" >GIT-ASCIIDOCFLAGS; \ - fi +$(eval $(call TRACK_template,GIT-ASCIIDOCFLAGS,TRACK_ASCIIDOCFLAGS)) clean: $(RM) -rf .build/ diff --git a/Makefile b/Makefile index b458c24d95e..c8a0a1586ca 100644 --- a/Makefile +++ b/Makefile @@ -2087,10 +2087,7 @@ endif GIT_USER_AGENT_SQ = $(subst ','\'',$(GIT_USER_AGENT)) GIT_USER_AGENT_CQ = "$(subst ",\",$(subst \,\\,$(GIT_USER_AGENT)))" GIT_USER_AGENT_CQ_SQ = $(subst ','\'',$(GIT_USER_AGENT_CQ)) -GIT-USER-AGENT: FORCE - @if test x'$(GIT_USER_AGENT_SQ)' != x"`cat GIT-USER-AGENT 2>/dev/null`"; then \ - echo '$(GIT_USER_AGENT_SQ)' >GIT-USER-AGENT; \ - fi +$(eval $(call TRACK_template,GIT-USER-AGENT,GIT_USER_AGENT_SQ)) ifdef DEFAULT_HELP_FORMAT BASIC_CFLAGS += -DDEFAULT_HELP_FORMAT='"$(DEFAULT_HELP_FORMAT)"' @@ -2238,12 +2235,7 @@ SCRIPT_DEFINES = $(SHELL_PATH_SQ):$(DIFF_SQ):\ $(localedir_SQ):$(USE_GETTEXT_SCHEME):$(SANE_TOOL_PATH_SQ):\ $(gitwebdir_SQ):$(PERL_PATH_SQ):$(PAGER_ENV):\ $(perllibdir_SQ) -GIT-SCRIPT-DEFINES: FORCE - @FLAGS='$(SCRIPT_DEFINES)'; \ - if test x"$$FLAGS" != x"`cat $@ 2>/dev/null`" ; then \ - echo >&2 " * new script parameters"; \ - echo "$$FLAGS" >$@; \ - fi +$(eval $(call TRACK_template,GIT-SCRIPT-DEFINES,SCRIPT_DEFINES)) define cmd_munge_script sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \ @@ -2355,13 +2347,7 @@ git-instaweb: git-instaweb.sh GIT-SCRIPT-DEFINES chmod +x $@+ && \ mv $@+ $@ endif # NO_PERL - -GIT-PERL-DEFINES: FORCE - @FLAGS='$(PERL_DEFINES)'; \ - if test x"$$FLAGS" != x"`cat $@ 2>/dev/null`" ; then \ - echo >&2 " * new perl-specific parameters"; \ - echo "$$FLAGS" >$@; \ - fi +$(eval $(call TRACK_template,GIT-PERL-DEFINES,PERL_DEFINES)) # As with NO_PERL=Y we'll still make GIT-PYTHON-DEFINES if "NO_PYTHON" # is defined, for creating the "unimplemented.sh" scripts. @@ -2390,12 +2376,7 @@ $(SCRIPT_PYTHON_GEN): % : %.py GIT-PYTHON-DEFINES mv $@+ $@ endif # NO_PYTHON -GIT-PYTHON-DEFINES: FORCE - @FLAGS='$(PYTHON_DEFINES)'; \ - if test x"$$FLAGS" != x"`cat $@ 2>/dev/null`" ; then \ - echo >&2 " * new python-specific parameters"; \ - echo "$$FLAGS" >$@; \ - fi +$(eval $(call TRACK_template,GIT-PYTHON-DEFINES,PYTHON_DEFINES)) CONFIGURE_RECIPE = sed -e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \ configure.ac >configure.ac+ && \ @@ -2751,31 +2732,13 @@ cscope: cscope.out ### Detect prefix changes TRACK_PREFIX = $(bindir_SQ):$(gitexecdir_SQ):$(template_dir_SQ):$(prefix_SQ):\ $(localedir_SQ) - -GIT-PREFIX: FORCE - @FLAGS='$(TRACK_PREFIX)'; \ - if test x"$$FLAGS" != x"`cat GIT-PREFIX 2>/dev/null`" ; then \ - echo >&2 " * new prefix flags"; \ - echo "$$FLAGS" >GIT-PREFIX; \ - fi +$(eval $(call TRACK_template,GIT-PREFIX,TRACK_PREFIX)) TRACK_CFLAGS = $(CC):$(subst ','\'',$(ALL_CFLAGS)):$(USE_GETTEXT_SCHEME) - -GIT-CFLAGS: FORCE - @FLAGS='$(TRACK_CFLAGS)'; \ - if test x"$$FLAGS" != x"`cat GIT-CFLAGS 2>/dev/null`" ; then \ - echo >&2 " * new build flags"; \ - echo "$$FLAGS" >GIT-CFLAGS; \ - fi +$(eval $(call TRACK_template,GIT-CFLAGS,TRACK_CFLAGS)) TRACK_LDFLAGS = $(subst ','\'',$(ALL_LDFLAGS)) - -GIT-LDFLAGS: FORCE - @FLAGS='$(TRACK_LDFLAGS)'; \ - if test x"$$FLAGS" != x"`cat GIT-LDFLAGS 2>/dev/null`" ; then \ - echo >&2 " * new link flags"; \ - echo "$$FLAGS" >GIT-LDFLAGS; \ - fi +$(eval $(call TRACK_template,GIT-LDFLAGS,TRACK_LDFLAGS)) # We need to apply sq twice, once to protect from the shell # that runs GIT-BUILD-OPTIONS, and then again to protect it diff --git a/shared.mak b/shared.mak index ef03c2bc094..97c8903f22c 100644 --- a/shared.mak +++ b/shared.mak @@ -29,3 +29,25 @@ shelldquote = '"$(call shdq,$(call shq,$(1)))"' comma = , empty = space = $(empty) $(empty) + +## wspfx: the whitespace prefix padding for $(QUIET...) and similarly +## aligned output. +wspfx = $(space)$(space)$(space) +wspfx_sq = $(call shellquote,$(wspfx)) + +### Templates + +## Template for making a GIT-SOMETHING, which changes if a +## TRACK_SOMETHING variable changes. +define TRACK_template +.PHONY: FORCE +$(1): FORCE + @FLAGS='$$($(2))'; \ + if ! test -f $(1) ; then \ + echo $(wspfx_sq) "$(1) PARAMETERS (new)"; \ + echo "$$$$FLAGS" >$(1); \ + elif test x"$$$$FLAGS" != x"`cat $(1) 2>/dev/null`" ; then \ + echo $(wspfx_sq) "$(1) PARAMETERS (changed)"; \ + echo "$$$$FLAGS" >$(1); \ + fi +endef -- 2.34.0.796.g2c87ed6146a