From patchwork Fri Mar 23 13:04:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 10304651 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1396260385 for ; Fri, 23 Mar 2018 13:07:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 03F5F28DFB for ; Fri, 23 Mar 2018 13:07:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ECE4C28E5F; Fri, 23 Mar 2018 13:07:21 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6CD5628DFB for ; Fri, 23 Mar 2018 13:07:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752826AbeCWNG4 (ORCPT ); Fri, 23 Mar 2018 09:06:56 -0400 Received: from conuserg-10.nifty.com ([210.131.2.77]:54082 "EHLO conuserg-10.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752681AbeCWNGy (ORCPT ); Fri, 23 Mar 2018 09:06:54 -0400 Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-10.nifty.com with ESMTP id w2ND4mgg011418; Fri, 23 Mar 2018 22:05:29 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com w2ND4mgg011418 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1521810332; bh=BMtc8wVlM6hbOTnDh8j/r54s+Kqgy4bjylMbPDxjgOs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ewzsHuEE09y4JYEK6T+OzFhKmj7rRuQDlJ8Tn+ao9/4IEsQQkaPK6TqBrpmNEWRpY Bfj6NZem0jCYLqk8COOWhCXLpSPiJBJ/KOeoGfUGnyTGtkuc6gYGt8FVd7qouATfQu T4c2NNVGBlwFyZ6YhTjkg1PtHuJOT7S7eVrFOuOC5WnAqJMIkpjz+mm5IDO3a/zgxZ tAUq1Ji3s/ghWFa8zLvGXuM1jJTEk0hSx5i2NXLbKWoJihKBBJy7AIP4J+X3IZoXHA TQ7eb+ABpPbek8HYv2hTW/OuJrx2yqEmOKELBQZl61KmNP2LeA00O8AkpRKjEk0azU dKsEPVS4loT5A== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Sam Ravnborg , Michal Marek , linux-kernel@vger.kernel.org, Arnd Bergmann , Laurent Pinchart , Frank Rowand , Geert Uytterhoeven , Masahiro Yamada Subject: [PATCH 10/10] kbuild: mark $(targets) as .SECONDARY and remove .PRECIOUS specifier Date: Fri, 23 Mar 2018 22:04:39 +0900 Message-Id: <1521810279-6282-10-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1521810279-6282-1-git-send-email-yamada.masahiro@socionext.com> References: <1521810279-6282-1-git-send-email-yamada.masahiro@socionext.com> Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP GNU Make automatically deletes intermediate files that are updated in a chain of pattern rules. Example 1) %.dtb.o <- %.dtb.S <- %.dtb.S <- %.dts Example 2) %.o <- %.c <- %.c_shipped A couple of makefiles mark such targets as .PRECIOUS to prevent Make from deleting them, but the correct way is to use .SECONDARY. .SECONDARY Prerequisites of this special target are treated as intermediate files but are never automatically deleted. .PRECIOUS When make is interrupted during execution, it may delete the target file it is updating if the file was modified since make started. If you mark the file as precious, make will never delete the file if interrupted. Both can avoid deletion of intermediate files, but the difference is the behavior when Make is interrupted; .SECONDARY deletes the target, but .PRECIOUS does not. The use of .PRECIOUS is relatively rare since we do not want to keep partially constructed (possibly corrupted) targets. Another difference is that .PRECIOUS works with pattern rules whereas .SECONDARY does not. .PRECIOUS: $(obj)/%.lex.c works, but .SECONDARY: $(obj)/%.lex.c has no effect. However, for the reason above, I do not want to use .PRECIOUS to avoid obscure build breakage. The targets specified as .SECONDARY must be explicit. $(targets) contains all targets that need to include .*.cmd files. So, the intermediates you want to keep are likely to be contained in $(targets). So, mark it as .SECONDARY. The exception is when they are created by $(call cmd,...) instead of $(call if_changed,...) since the former does not need to include .*.cmd file. In this case, makefiles need to mark them .SECONDARY by themselves, like arch/arm(64)/crypto/Makefile. Signed-off-by: Masahiro Yamada Acked-by: Frank Rowand --- arch/arc/boot/dts/Makefile | 2 -- arch/arm/crypto/Makefile | 2 +- arch/arm64/crypto/Makefile | 2 +- arch/metag/boot/dts/Makefile | 2 -- drivers/of/unittest-data/Makefile | 4 ---- scripts/Makefile.build | 6 ++++-- scripts/Makefile.lib | 3 --- 7 files changed, 6 insertions(+), 15 deletions(-) diff --git a/arch/arc/boot/dts/Makefile b/arch/arc/boot/dts/Makefile index 22a4c5d..a83c4f5 100644 --- a/arch/arc/boot/dts/Makefile +++ b/arch/arc/boot/dts/Makefile @@ -9,8 +9,6 @@ endif obj-y += $(builtindtb-y).dtb.o dtb-y := $(builtindtb-y).dtb -.SECONDARY: $(obj)/$(builtindtb-y).dtb.S - # for CONFIG_OF_ALL_DTBS test dtstree := $(srctree)/$(src) dtb- := $(patsubst $(dtstree)/%.dts,%.dtb, $(wildcard $(dtstree)/*.dts)) diff --git a/arch/arm/crypto/Makefile b/arch/arm/crypto/Makefile index 30ef8e2..3d59567 100644 --- a/arch/arm/crypto/Makefile +++ b/arch/arm/crypto/Makefile @@ -63,4 +63,4 @@ $(src)/sha256-core.S_shipped: $(src)/sha256-armv4.pl $(src)/sha512-core.S_shipped: $(src)/sha512-armv4.pl $(call cmd,perl) -.PRECIOUS: $(obj)/sha256-core.S $(obj)/sha512-core.S +.SECONDARY: $(obj)/sha256-core.S $(obj)/sha512-core.S diff --git a/arch/arm64/crypto/Makefile b/arch/arm64/crypto/Makefile index cee9b8d9..fceb638 100644 --- a/arch/arm64/crypto/Makefile +++ b/arch/arm64/crypto/Makefile @@ -76,4 +76,4 @@ $(src)/sha256-core.S_shipped: $(src)/sha512-armv8.pl $(src)/sha512-core.S_shipped: $(src)/sha512-armv8.pl $(call cmd,perlasm) -.PRECIOUS: $(obj)/sha256-core.S $(obj)/sha512-core.S +.SECONDARY: $(obj)/sha256-core.S $(obj)/sha512-core.S diff --git a/arch/metag/boot/dts/Makefile b/arch/metag/boot/dts/Makefile index f0a180f..16505aa 100644 --- a/arch/metag/boot/dts/Makefile +++ b/arch/metag/boot/dts/Makefile @@ -12,5 +12,3 @@ endif dtb-$(CONFIG_METAG_BUILTIN_DTB) += $(builtindtb-y).dtb obj-$(CONFIG_METAG_BUILTIN_DTB) += $(builtindtb-y).dtb.o - -.SECONDARY: $(obj)/$(builtindtb-y).dtb.S diff --git a/drivers/of/unittest-data/Makefile b/drivers/of/unittest-data/Makefile index 333bc4c..0fb87cb 100644 --- a/drivers/of/unittest-data/Makefile +++ b/drivers/of/unittest-data/Makefile @@ -12,7 +12,3 @@ DTC_FLAGS_overlay := -@ DTC_FLAGS_overlay_bad_phandle := -@ DTC_FLAGS_overlay_bad_symbol := -@ DTC_FLAGS_overlay_base := -@ - -.PRECIOUS: \ - $(obj)/%.dtb.S \ - $(obj)/%.dtb diff --git a/scripts/Makefile.build b/scripts/Makefile.build index cc081af..4397adb 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -430,8 +430,6 @@ quiet_cmd_asn1_compiler = ASN.1 $@ cmd_asn1_compiler = $(objtree)/scripts/asn1_compiler $< \ $(subst .h,.c,$@) $(subst .c,.h,$@) -.PRECIOUS: $(objtree)/$(obj)/%.asn1.c $(objtree)/$(obj)/%.asn1.h - $(obj)/%.asn1.c $(obj)/%.asn1.h: $(src)/%.asn1 \ $(objtree)/scripts/asn1_compiler FORCE $(call if_changed,asn1_compiler) @@ -590,6 +588,10 @@ $(shell mkdir -p $(obj-dirs)) endif endif +# Some contained in $(targets) are intermediate artifacts. +# We never want them to be removed automatically. +.SECONDARY: $(targets) + # Declare the contents of the .PHONY variable as phony. We keep that # information in a variable se we can use it in if_changed and friends. diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib index 7a1fa92..c114ce5 100644 --- a/scripts/Makefile.lib +++ b/scripts/Makefile.lib @@ -183,7 +183,6 @@ endef quiet_cmd_flex = LEX $@ cmd_flex = $(LEX) -o$@ -L $< -.PRECIOUS: $(obj)/%.lex.c $(obj)/%.lex.c: $(src)/%.l FORCE $(call if_changed,flex) @@ -192,14 +191,12 @@ $(obj)/%.lex.c: $(src)/%.l FORCE quiet_cmd_bison = YACC $@ cmd_bison = $(YACC) -o$@ -t -l $< -.PRECIOUS: $(obj)/%.tab.c $(obj)/%.tab.c: $(src)/%.y FORCE $(call if_changed,bison) quiet_cmd_bison_h = YACC $@ cmd_bison_h = bison -o/dev/null --defines=$@ -t -l $< -.PRECIOUS: $(obj)/%.tab.h $(obj)/%.tab.h: $(src)/%.y FORCE $(call if_changed,bison_h)