From patchwork Mon Mar 14 06:26:14 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 8576731 Return-Path: X-Original-To: patchwork-linux-kbuild@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 34647C0553 for ; Mon, 14 Mar 2016 06:26:29 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2EBB920461 for ; Mon, 14 Mar 2016 06:26:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 05CA420454 for ; Mon, 14 Mar 2016 06:26:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751716AbcCNG00 (ORCPT ); Mon, 14 Mar 2016 02:26:26 -0400 Received: from conssluserg001.nifty.com ([202.248.44.39]:51395 "EHLO conssluserg001-v.nifty.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750912AbcCNG0Z (ORCPT ); Mon, 14 Mar 2016 02:26:25 -0400 Received: from mail-yw0-f178.google.com (mail-yw0-f178.google.com [209.85.161.178]) (authenticated) by conssluserg001-v.nifty.com with ESMTP id u2E6QExu008473; Mon, 14 Mar 2016 15:26:15 +0900 X-Nifty-SrcIP: [209.85.161.178] Received: by mail-yw0-f178.google.com with SMTP id g3so155937096ywa.3; Sun, 13 Mar 2016 23:26:15 -0700 (PDT) X-Gm-Message-State: AD7BkJIRSb6T+rRb+ioiZBD4sT1pSjIPE+lDqqL8FnDzsFaY5XIr6qOJXwH01UUUEYLXEXkwFRScwXJDu4HDnw== MIME-Version: 1.0 X-Received: by 10.129.40.195 with SMTP id o186mr11058568ywo.51.1457936774446; Sun, 13 Mar 2016 23:26:14 -0700 (PDT) Received: by 10.37.208.211 with HTTP; Sun, 13 Mar 2016 23:26:14 -0700 (PDT) In-Reply-To: References: <1457828035-30584-1-git-send-email-yamada.masahiro@socionext.com> Date: Mon, 14 Mar 2016 15:26:14 +0900 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] kbuild: drop FORCE from PHONY targets From: Masahiro Yamada To: Andy Lutomirski Cc: Fenghua Yu , Thomas Gleixner , Ingo Molnar , Russell King , Michal Marek , "linux-kernel@vger.kernel.org" , "linux-kbuild@vger.kernel.org" , Nathan Lynch , Tony Luck , "linux-ia64@vger.kernel.org" , "linux-arm-kernel@lists.infradead.org" , "H. Peter Anvin" , X86 ML Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Hi Andy, 2016-03-14 13:44 GMT+09:00 Andy Lutomirski : > On Sun, Mar 13, 2016 at 9:36 PM, Masahiro Yamada > wrote: >> 2016-03-14 13:28 GMT+09:00 Andy Lutomirski : >>> On Sun, Mar 13, 2016 at 9:08 PM, Masahiro Yamada >>> wrote: >>>> >>>> Hi Andy >>>> >>>> 2016-03-14 9:39 GMT+09:00 Andy Lutomirski : >>>> > On Mar 12, 2016 4:14 PM, "Masahiro Yamada" >>>> > wrote: >>>> >> >>>> >> These targets are marked as PHONY. No need to add FORCE to their >>>> >> dependency. >>>> > >>>> > If this is, in fact, correct, can you update >>>> > Documentation/kbuild/makefiles.txt as well? >>>> >>>> Which line do you want me to update? >>>> >>> >>> All the references to FORCE should probably mention .PHONY as an alternative. >> >> I do not get your point. >> >> All the examples in the makefile.txt correctly reference to FORCE. >> They are not PHONY targets. >> No need to update. > > But they could be. For example: > > $(obj)/image: vmlinux FORCE > $(call if_changed,objcopy) > > could be: > > .PHONY: $(obj)/image > $(obj)/image: vmlinux > $(call if_changed,objcopy) > > I would at least change: > > Note: It is a typical mistake to forget the FORCE prerequisite. > > to: > > Note: if-changed is only useful if make executes it, which won't > happen if it determines that the inputs have not changed since the > output was built. This can be avoided by specifying FORCE as a > prerequisite or by making declaring the output as .PHONY. > No. This is absolutely wrong. PHONY and FORCE are not interchangeable. They have different behavior. I will show you how they behave differently. BTW, Linux 4.5 is out now. Let's try a simple experiment on it. The following shows that my source tree is v4.5 yamada@beagle:~/workspace/linux$ git describe v4.5 Example 1) Add the following code to the top Makefile. Please note "FORCE" is used here. yamada@beagle:~/workspace/linux$ git diff quiet_cmd_link-vmlinux = LINK $@ Let's try the same thing. yamada@beagle:~/workspace/linux$ git clean -x -f yamada@beagle:~/workspace/linux$ make -s defconfig yamada@beagle:~/workspace/linux$ make GREETING=GoodMorning foo scripts/kconfig/conf --silentoldconfig Kconfig BAR bar FOO foo yamada@beagle:~/workspace/linux$ make GREETING=GoodMorning foo BAR bar FOO foo yamada@beagle:~/workspace/linux$ make GREETING=GoodMorning foo BAR bar FOO foo yamada@beagle:~/workspace/linux$ make GREETING=GoodAfternoon foo BAR bar FOO foo yamada@beagle:~/workspace/linux$ make GREETING=GoodAfternoon foo BAR bar FOO foo yamada@beagle:~/workspace/linux$ make GREETING=GoodAfternoon foo BAR bar FOO foo Did you notice the difference? The "foo" and "bar" are always rebuilt regardless the command line is changed or not. It means $(call if_changed,...) is not working. diff --git a/Makefile b/Makefile index 7b3ecdc..89b7d0d 100644 --- a/Makefile +++ b/Makefile @@ -914,6 +914,22 @@ export KBUILD_ALLDIRS := $(sort $(filter-out arch/%,$(vmlinux- vmlinux-deps := $(KBUILD_LDS) $(KBUILD_VMLINUX_INIT) $(KBUILD_VMLINUX_MAIN) +quiet_cmd_gen_foo = FOO $@ + cmd_gen_foo = (cat $<; echo hello) > $@ + +foo: bar FORCE + $(call if_changed,gen_foo) + +quiet_cmd_gen_bar = BAR $@ + cmd_gen_bar = (cat $<; echo $(GREETING)) > $@ + +bar: baz FORCE + $(call if_changed,gen_bar) + +baz: + @touch $@ + + # Final link of vmlinux cmd_link-vmlinux = $(CONFIG_SHELL) $< $(LD) $(LDFLAGS) $(LDFLAGS_vmlinux) quiet_cmd_link-vmlinux = LINK $@ Try the following. yamada@beagle:~/workspace/linux$ git clean -x -f yamada@beagle:~/workspace/linux$ make -s defconfig yamada@beagle:~/workspace/linux$ make GREETING=GoodMorning foo scripts/kconfig/conf --silentoldconfig Kconfig BAR bar FOO foo yamada@beagle:~/workspace/linux$ make GREETING=GoodMorning foo make: `foo' is up to date. yamada@beagle:~/workspace/linux$ make GREETING=GoodAfternoon foo BAR bar FOO foo yamada@beagle:~/workspace/linux$ make GREETING=GoodAfternoon foo make: `foo' is up to date. yamada@beagle:~/workspace/linux$ make GREETING=GoodEvening foo BAR bar FOO foo yamada@beagle:~/workspace/linux$ make GREETING=GoodEvening foo make: `foo' is up to date. Please notice "foo" and "bar" were not rebuilt when I gave the same command line as the previous run. When I changed the command line, "bar" was update and "foo" was also updated because "foo" depends on "bar". It means $(call if_changed,...) is working as expected. Example 2) Add the following to the top Makefile. Please notice that I just replaced "FORCE" with ".PHONY". diff --git a/Makefile b/Makefile index 7b3ecdc..a0899c3 100644 --- a/Makefile +++ b/Makefile @@ -914,6 +914,24 @@ export KBUILD_ALLDIRS := $(sort $(filter-out arch/%,$(vmlinux- vmlinux-deps := $(KBUILD_LDS) $(KBUILD_VMLINUX_INIT) $(KBUILD_VMLINUX_MAIN) +quiet_cmd_gen_foo = FOO $@ + cmd_gen_foo = (cat $<; echo hello) > $@ + +.PHONY: foo +foo: bar + $(call if_changed,gen_foo) + +quiet_cmd_gen_bar = BAR $@ + cmd_gen_bar = (cat $<; echo $(GREETING)) > $@ + +.PHONY: bar +bar: baz + $(call if_changed,gen_bar) + +baz: + @touch $@ + + # Final link of vmlinux cmd_link-vmlinux = $(CONFIG_SHELL) $< $(LD) $(LDFLAGS) $(LDFLAGS_vmlinux)