NetBSD Problem Report #43502

From Wolfgang.Stukenbrock@nagler-company.com  Thu Jun 24 10:14:55 2010
Return-Path: <Wolfgang.Stukenbrock@nagler-company.com>
Received: from mail.netbsd.org (mail.netbsd.org [204.152.190.11])
	by www.NetBSD.org (Postfix) with ESMTP id A5F2F63BA50
	for <gnats-bugs@gnats.NetBSD.org>; Thu, 24 Jun 2010 10:14:55 +0000 (UTC)
Message-Id: <20100624101450.630AC1E80CE@test-s0.nagler-company.com>
Date: Thu, 24 Jun 2010 12:14:50 +0200 (CEST)
From: Wolfgang.Stukenbrock@nagler-company.com
Reply-To: Wolfgang.Stukenbrock@nagler-company.com
To: gnats-bugs@gnats.NetBSD.org
Subject: make failes to stip suffix if target is phony
X-Send-Pr-Version: 3.95

>Number:         43502
>Category:       bin
>Synopsis:       make failes to stip suffix if target is phony
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Jun 24 10:15:00 +0000 2010
>Last-Modified:  Wed Jun 30 01:05:02 +0000 2010
>Originator:     Wolfgang Stukenbrock
>Release:        NetBSD 4.0
>Organization:
Dr. Nagler & Company GmbH

>Environment:


System: NetBSD test-s0 4.0 NetBSD 4.0 (NSW-WS) #2: Fri Nov 6 11:14:49 CET 2009 wgstuken@s012:/export/NetBSD-4.0/N+C-build/.OBJDIR_amd64/export/NetBSD-4.0/src/sys/arch/amd64/compile/NSW-WS amd64
Architecture: x86_64
Machine: amd64
>Description:
	The following makefile fails to do the rigth thing - at least from my understanding of make.

--- start of makefile
.SUFFIXES:
.SUFFIXES: .tg .ttg

.PHONY: t1.tg t2.tg t3.tg t4.tg t5.tg t2.ttg t4.ttg

all: t1.ttg t2.ttg t3.ttg

.tg.ttg:
	@echo "@ |$@|"
	@echo "* |$*|"

t1.ttg:t1.tg
	@echo "@ |$@|"
	@echo "* |$*|"

t2.ttg:t2.tg
	@echo "@ |$@|"
	@echo "* |$*|"

t1.tg:

t2.tg:

t3.tg:

t4.tg:

t5.tg:

tst: t5.ttg t4.ttg

--- end of makefile

	The problem seems to be, that if a target is marked PHONY the suffix detection stuff in make does not work
	anymore.
	Running "make all" reports the makro '$*' correctly for t1 and t3 but it is empty for t2.
	Running "make tst" will build t5 correctly but fails to build t4. The suffix rule ".tg.ttg:" is not found.
>How-To-Repeat:
	try to run the makefile above.
	$* is not setup correctly for t3 and it will fail to build t4
>Fix:
	not analysed up to now
	workaround: do not add the targets to the PHONY list

>Audit-Trail:
From: David Holland <dholland-bugs@netbsd.org>
To: gnats-bugs@NetBSD.org
Cc: 
Subject: Re: bin/43502: make failes to stip suffix if target is phony
Date: Sun, 27 Jun 2010 00:55:11 +0000

 On Thu, Jun 24, 2010 at 10:15:01AM +0000, Wolfgang.Stukenbrock@nagler-company.com wrote:
  > The following makefile fails to do the rigth thing - at least
  > from my understanding of make.
  > [...]
  > 	
  > The problem seems to be, that if a target is marked PHONY the
  > suffix detection stuff in make does not work anymore.

 Since suffix rules are based on matching against things that exist,
 I'm surprised this works even halfway. I would expect it to not find
 the PHONY .tg rules as valid sources for the suffix rule; but
 apparently it does.

 Note though that line 2412 of suff.c says

     * If this is a .PHONY target, we do not apply suffix rules.

 so the behavior you're seeing is apparently intentional, though
 underdocumented.

 That said, I would advise against relying on the detailed behavior of
 suffix rules because it isn't very portable. gmake, for example, does
 not exhibit the same behavior on your makefile. (Arguably it is even
 less useful in that it silently skips t4.) I don't have ready access
 to any of the various vendor variants of legacy System V make to test
 any more, but I wouldn't be surprised if those also did one or more
 different things.

 I'm finding it hard to guess what you're trying to really do that this
 is a simplified fragment of; but my guess is that you're better off
 approaching it some other way. Usually if you can afford to be
 bmake-specific, explicit rules defined with .for loops are the best
 way to tackle these sorts of issues. If you can't, it gets murkier.

 The fact that $* is not defined for t2 appears to be a legitimate bug;
 it seems to arise for all .PHONY targets. It's also not so obvious how
 to fix it. In order to avoid confusion I think I'm going to open a new
 PR for that.

 -- 
 David A. Holland
 dholland@netbsd.org

From: Wolfgang Stukenbrock <Wolfgang.Stukenbrock@nagler-company.com>
To: gnats-bugs@NetBSD.org
Cc: gnats-admin@NetBSD.org, netbsd-bugs@NetBSD.org,
        Wolfgang.Stukenbrock@nagler-company.com, dholland-bugs@NetBSD.org
Subject: Re: bin/43502: make failes to stip suffix if target is phony
Date: Mon, 28 Jun 2010 11:44:21 +0200

 Hi,

 OK.

 Can you please add me to the email-list in the new report.
 Thanks in advance.
 (Or at least send me the problem number, so I can track it myself.)
 If $* gets filled as expected (and documented) in the future this is of 
 interest for me.

 One very bad thing with make programs in general are, that they are all 
 incompartible to each other as soon as you start to use any of the more 
 high-level things in them.
 And there are not only general the syntax problems with differences in 
 key-words, variable subtition, sets of automatic variables, ...
 And if you try to have a protable version, you always have to enshure 
 that a specific make-variant is installed, because there is no common 
 make available on "all" systems (commertial, open-source).
 And the subset of functionality for all make version is poor and not 
 realy usable.


 The main reason why I've tagged the virtual targets .tg and .ttg as 
 PHONY is that they will never (or may not) exist in the filesystem and 
 make should not try to search for them. Normaly PHONY does it in the 
 expectec way, if a make program supports PHONY at all.
 The names are variants of main targets of the makefile and this makefile 
 should call some kind of sub-makes in sets of subdirectories to do the 
 main things. (Of cause removed from the makefile in the report in order 
 to keep it as small as possible.)
 This time I don't want to specify all possible targets of the sub-makes 
 in the top-level makefile as done before in order to reduce the required 
 work on toplevel if new targets are added or the rules themself gets 
 changed.
 I need to specify some common dependencies that are placed in the 
 virtual rules. It has been a nice way to use these kind of derived 
 targets in the past.
 Even if I use a for-loop (and that is one of the non-portable syntax 
 parts ...), I need to specify all target names and the advantage of the 
 pattern is lost.

 If the bmake family is designed to mix the pattern matching (or 
 construction) on the internal strings with the filesystem-search while 
 ignoreing other hint information from the makefile (as PHONY), it is OK 
 for me - but a hint in the man-page would have been nice.
 I think theese two things should be treeted completly independent from 
 each other, but that is my oppion and other people may see it in a 
 different way.

 Best reguards

 W. Stukenbrock


 David Holland wrote:

 > The following reply was made to PR bin/43502; it has been noted by GNATS.
 > 
 > From: David Holland <dholland-bugs@netbsd.org>
 > To: gnats-bugs@NetBSD.org
 > Cc: 
 > Subject: Re: bin/43502: make failes to stip suffix if target is phony
 > Date: Sun, 27 Jun 2010 00:55:11 +0000
 > 
 >  On Thu, Jun 24, 2010 at 10:15:01AM +0000, Wolfgang.Stukenbrock@nagler-company.com wrote:
 >   > The following makefile fails to do the rigth thing - at least
 >   > from my understanding of make.
 >   > [...]
 >   > 	
 >   > The problem seems to be, that if a target is marked PHONY the
 >   > suffix detection stuff in make does not work anymore.
 >  
 >  Since suffix rules are based on matching against things that exist,
 >  I'm surprised this works even halfway. I would expect it to not find
 >  the PHONY .tg rules as valid sources for the suffix rule; but
 >  apparently it does.
 >  
 >  Note though that line 2412 of suff.c says
 >  
 >      * If this is a .PHONY target, we do not apply suffix rules.
 >  
 >  so the behavior you're seeing is apparently intentional, though
 >  underdocumented.
 >  
 >  That said, I would advise against relying on the detailed behavior of
 >  suffix rules because it isn't very portable. gmake, for example, does
 >  not exhibit the same behavior on your makefile. (Arguably it is even
 >  less useful in that it silently skips t4.) I don't have ready access
 >  to any of the various vendor variants of legacy System V make to test
 >  any more, but I wouldn't be surprised if those also did one or more
 >  different things.
 >  
 >  I'm finding it hard to guess what you're trying to really do that this
 >  is a simplified fragment of; but my guess is that you're better off
 >  approaching it some other way. Usually if you can afford to be
 >  bmake-specific, explicit rules defined with .for loops are the best
 >  way to tackle these sorts of issues. If you can't, it gets murkier.
 >  
 >  The fact that $* is not defined for t2 appears to be a legitimate bug;
 >  it seems to arise for all .PHONY targets. It's also not so obvious how
 >  to fix it. In order to avoid confusion I think I'm going to open a new
 >  PR for that.
 >  
 >  -- 
 >  David A. Holland
 >  dholland@netbsd.org
 >  
 > 


From: David Holland <dholland-bugs@netbsd.org>
To: gnats-bugs@NetBSD.org
Cc: 
Subject: Re: bin/43502: make failes to stip suffix if target is phony
Date: Wed, 30 Jun 2010 00:59:00 +0000

 On Mon, Jun 28, 2010 at 09:45:02AM +0000, Wolfgang Stukenbrock wrote:
  >  Can you please add me to the email-list in the new report.
  >  Thanks in advance.
  >  (Or at least send me the problem number, so I can track it myself.)
  >  If $* gets filled as expected (and documented) in the future this is of 
  >  interest for me.

 It is 43534. I have attempted to add you but I'm not sure if it's
 going to work.

 I have just fixed that in HEAD. make on your example now prints

 @ |t1.ttg|
 * |t1|
 @ |t2.ttg|
 * |t2.ttg|
 @ |t3.ttg|
 * |t3|

 It doesn't strip the .ttg off for t2 because it's not doing suffix
 matching because it's PHONY. This seemed like the right behavior (and
 it was also a much easier fix) but I'm open to argument.

 The diff applies cleanly to both the -4 and -5 branches and I'll be
 filing pullups in a couple days, assuming it doesn't cause anyone's
 builds to turn to jelly or anything.

  >  One very bad thing with make programs in general are, that they are all 
  >  incompartible to each other as soon as you start to use any of the more 
  >  high-level things in them.
  >  And there are not only general the syntax problems with differences in 
  >  key-words, variable subtition, sets of automatic variables, ...
  >  And if you try to have a protable version, you always have to enshure 
  >  that a specific make-variant is installed, because there is no common 
  >  make available on "all" systems (commertial, open-source).
  >  And the subset of functionality for all make version is poor and not 
  >  realy usable.

 Yes indeed.

 One approach is to write for the common subset of gmake and BSD make,
 which is less feeble than trying to allow for legacy SVR4 make too,
 but that's still fairly cramped.

 For things I do that really need to be portable I generally use awk
 scripts to generate makefile fragments, mostly or entirely instead of
 using make's own text processing. This approach has problems but it
 appears to be the best alternative.

  >  The main reason why I've tagged the virtual targets .tg and .ttg as 
  >  PHONY is that they will never (or may not) exist in the filesystem and 
  >  make should not try to search for them. Normaly PHONY does it in the 
  >  expectec way, if a make program supports PHONY at all.

 Right. Although again, it doesn't work in gmake either...

  >  The names are variants of main targets of the makefile and this makefile 
  >  should call some kind of sub-makes in sets of subdirectories to do the 
  >  main things. (Of cause removed from the makefile in the report in order 
  >  to keep it as small as possible.)
  >  This time I don't want to specify all possible targets of the sub-makes 
  >  in the top-level makefile as done before in order to reduce the required 
  >  work on toplevel if new targets are added or the rules themself gets 
  >  changed.
  >  I need to specify some common dependencies that are placed in the 
  >  virtual rules. It has been a nice way to use these kind of derived 
  >  targets in the past.
  >  Even if I use a for-loop (and that is one of the non-portable syntax 
  >  parts ...), I need to specify all target names and the advantage of the 
  >  pattern is lost.

 Right.

 There is no good mechanism for writing pattern rules in bmake. Even
 ignoring the particular problem with .PHONY, suffix rules are not very
 general.

 In most cases writing a loop instead isn't a problem because you need
 some kind of "all" target that also needs the list of all target
 names. But it sounds like you aren't doing that here - instead you're
 relying on someone typing "make foo.tg", right?

 In that case there is a different approach :-)  The magic variable
 $(.TARGETS) contains the list of targets specified on the make command
 line. So you can write something like

 .for T in $(.TARGETS:M*.ttg)
 $(T): $(T:S/.ttg$/.tg/)
 	do-some-stuff
 .PHONY: $(T)
 .endfor

 and it should serve your purposes. Of course, this only works in
 BSD make... but judging from the CVS history it should work in any of
 the variants of BSD make, even the really old ones.

 .TARGETS seems to be undocumented, though. This is a bug.

  >  If the bmake family is designed to mix the pattern matching (or 
  >  construction) on the internal strings with the filesystem-search while 
  >  ignoreing other hint information from the makefile (as PHONY), it is OK 
  >  for me - but a hint in the man-page would have been nice.
  >  I think theese two things should be treeted completly independent from 
  >  each other, but that is my oppion and other people may see it in a 
  >  different way.

 I don't necessarily disagree with you; but since there doesn't seem to
 be any convention for the precise interaction of suffix rules and
 .PHONY it's not really safe to use it anyway, and because suffix rules
 are unsatisfactory in general I'm not entirely inclined to rush to
 make it work.

 -- 
 David A. Holland
 dholland@netbsd.org

From: "David A. Holland" <dholland@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/43502 CVS commit: src/usr.bin/make
Date: Wed, 30 Jun 2010 01:03:54 +0000

 Module Name:	src
 Committed By:	dholland
 Date:		Wed Jun 30 01:03:54 UTC 2010

 Modified Files:
 	src/usr.bin/make: make.1

 Log Message:
 Document that suffix rules are not applied to PHONY targets, and also
 document the .TARGETS builtin variable, which has existed since 4.4 days.
 Bump date. Arises from discussion in PR 43502.


 To generate a diff of this commit:
 cvs rdiff -u -r1.178 -r1.179 src/usr.bin/make/make.1

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2007 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.