Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1021690ybt; Sun, 14 Jun 2020 07:46:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzBEZrWx0PlGFsuq7Jfi5k3GVORrDN3EKlz7t2MKCd4ApxT9I80vuSFfKR/Hceg5Fmb91oB X-Received: by 2002:a05:6402:221b:: with SMTP id cq27mr19582402edb.302.1592145994477; Sun, 14 Jun 2020 07:46:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592145994; cv=none; d=google.com; s=arc-20160816; b=ZNpaSuP9HjadMR5R2bQ7DQmvxFQ7MNEe++O2XVcyF3LJW0plQ12wfYbfPuhjSVTh2j RVzU/CA26Qd59zbzd7MMweo1RE1xVWFhDM5/Ia4wFWo5XnD8iJUZtbRyXvpNwEhYuEdU vMr4wEa9wc1LG16/DsaCbSjm3wwo1quU+qQzWyxDx0ebNchuMUJ/RHUKnJex/r6BsiPT eZxEP0Dj5JdIrL9CXwezJ7nDcKN7QJV89Vkd10jL6j29owmuLgT9tu45X9dOBlBCuBEX tpsgLErzqpWEHwjkfZc0DPmg60qf1fIaRbRL9vlsLy/j3+BTJoM26TwE7/HfcnCvZOW5 x6xQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature:dkim-filter; bh=WqbBHTeTcTELu7HZYZJkll6J0fXNCMEhU1vE64ROybI=; b=FbIYykblD5CtgTR5xQqoIfTSvDXNym1RKx1vgc//c5nr/fiHEOdIN61DGDFTwWRWoA rqi4Fueruse0WFeQLbUbLR6JGI5/w6oHG97S2OmlRF/azaAa32P8ND0C0+yOuHQIS+bi PEKWq7OE/TAgOJAlmrC0kYgnFYBE8p0Ol5lkOng4iJUYv6dq7P9Ca7uHUnzQJXa6oBvm qZtqeL6nlzDPuB/22GoHCeZSZTxs+e6IZ5vL3uiIk3QH+hzV3krjZvK/2sG6G+RYBhoX DtkWbg0NZsAApBb25vgmbR1Qagklpnlyix3V3Mf9hEaTPiDMZ7h8CK8BTnenhzVXLjuz E3pg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=xpYkCjJx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ly15si6995563ejb.649.2020.06.14.07.46.10; Sun, 14 Jun 2020 07:46:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=xpYkCjJx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726856AbgFNOob (ORCPT + 99 others); Sun, 14 Jun 2020 10:44:31 -0400 Received: from conuserg-11.nifty.com ([210.131.2.78]:54494 "EHLO conuserg-11.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725815AbgFNOoa (ORCPT ); Sun, 14 Jun 2020 10:44:30 -0400 Received: from oscar.flets-west.jp (softbank126090202047.bbtec.net [126.90.202.47]) (authenticated) by conuserg-11.nifty.com with ESMTP id 05EEhjq0024323; Sun, 14 Jun 2020 23:43:46 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-11.nifty.com 05EEhjq0024323 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1592145826; bh=WqbBHTeTcTELu7HZYZJkll6J0fXNCMEhU1vE64ROybI=; h=From:To:Cc:Subject:Date:From; b=xpYkCjJxeLziMPFOJzjg7ApXaz44bK6GCZaIVP+/fsukFsadvYzfqMxtnCFEsWFys pFjy6ZIRuYZPg+qkpJImx9ZBjxWwXhl3BSI4RCN34X+q2gP6T1/3COHiTwqS78RP31 s6H74dB4O65n0onYptUtbGF8DdKw30Oq2a38bABEHmNIIzPGPD96hz3XvFnOKeNA6x cBsHyLIPrgI+mvxizRJjTyoEmByvfHbwWXmkW2/6CeZ2p4scBiZchfOItor8Y+kQIx ef/rkj2BqA1/KnuSQdGQrxj+K9B4IA1S9Z5aGk71RM1V+sGM4NxaXdok9tnusRP+1w 2XCcv4LPFrwtQ== X-Nifty-SrcIP: [126.90.202.47] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Nick Desaulniers , Arvind Sankar , Masahiro Yamada , Michal Marek , linux-kernel@vger.kernel.org Subject: [PATCH 1/2] kbuild: improve cc-option to clean up all temporary files Date: Sun, 14 Jun 2020 23:43:40 +0900 Message-Id: <20200614144341.1077495-1-masahiroy@kernel.org> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When cc-option and friends evaluate compiler flags, the temporary file $$TMP is created as an output object, and automatically cleaned up. The actual file path of $$TMP is ..tmp, here is the process ID of $(shell ....) invoked from cc-option. (Please note $$$$ is the escape sequence of $$). Such garbage files are cleaned up in most cases, but some compiler flags create additional output files. For example, -gsplit-dwarf creates a .dwo file. When CONFIG_DEBUG_INFO_SPLIT=y, you will see a bunch of ..dwo files left in the top of build directories. You may not notice them unless you do 'ls -a', but the garbage files will increase every time you run 'make'. This commit changes the temporary object path to .tmp_/tmp, and removes .tmp_ directory when exiting. The additional files .tmp_/tmp.dwo, will be cleaned away altogether. When the compiler creates separate build artifacts, their file paths are usually determined based on the base name of the object. Another example is -ftest-coverage, which outputs the coverage data into .gcno Signed-off-by: Masahiro Yamada --- scripts/Kbuild.include | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include index 0c3dc983439b..5dfd224599b7 100644 --- a/scripts/Kbuild.include +++ b/scripts/Kbuild.include @@ -86,20 +86,21 @@ cc-cross-prefix = $(firstword $(foreach c, $(1), \ $(if $(shell command -v -- $(c)gcc 2>/dev/null), $(c)))) # output directory for tests below -TMPOUT := $(if $(KBUILD_EXTMOD),$(firstword $(KBUILD_EXTMOD))/) +TMPOUT = $(if $(KBUILD_EXTMOD),$(firstword $(KBUILD_EXTMOD))/).tmp_$$$$ # try-run # Usage: option = $(call try-run, $(CC)...-o "$$TMP",option-ok,otherwise) -# Exit code chooses option. "$$TMP" serves as a temporary file and is +# Exit code chooses option. "$$TMP" serves as a temporary directory and is # automatically cleaned up. try-run = $(shell set -e; \ - TMP="$(TMPOUT).$$$$.tmp"; \ - TMPO="$(TMPOUT).$$$$.o"; \ + TMP=$(TMPOUT)/tmp; \ + TMPO=$(TMPOUT)/tmp.o; \ + mkdir -p $(TMPOUT); \ + trap "rm -rf $(TMPOUT)" EXIT; \ if ($(1)) >/dev/null 2>&1; \ then echo "$(2)"; \ else echo "$(3)"; \ - fi; \ - rm -f "$$TMP" "$$TMPO") + fi) # as-option # Usage: cflags-y += $(call as-option,-Wa$(comma)-isa=foo,) -- 2.25.1