Re: PATCH: .SECONDARY target with no dependencies does not work correctly.

2000-06-16 Thread Paul D. Smith

%% Seth M LaForge [EMAIL PROTECTED] writes:

  sml (Make version 3.79.)  Consider:
  sml   % cat Makefile 
  sml   %.1: %.2
  sml   cp $ $@
  sml   %.2: %.3
  sml   cp $ $@
  sml   .SECONDARY:
  sml   % ls
  sml   Makefile  foo.3
  sml   % make foo.1
  sml   cp foo.3 foo.2
  sml   cp foo.2 foo.1
  sml   rm foo.2

  sml According to the documentation, the .SECONDARY target should
  sml cause all files to be considered secondary (and thus not
  sml deleted), but it doesn't work.

This is obliquely stated in the documentation:

 `.SECONDARY'
 The targets which `.SECONDARY' depends on are treated as
 intermediate files, except that they are never automatically
 deleted.  *Note Chains of Implicit Rules: Chained Rules.

 `.SECONDARY' with no prerequisites marks all file targets mentioned
  ^^
 in the makefile as secondary.
 ^^^

Note the second paragraph.  The targets you give aren't mentioned in the
makefile; they're built using implicit rules.

I agree with you, however, that this is a strange restriction and this
area needs to be revisited, for all of PRECIOUS, INTERMEDIATE, and
SECONDARY.

I'll file an enhancement request about it.

-- 
---
 Paul D. Smith [EMAIL PROTECTED]  Find some GNU make tips at:
 http://www.gnu.org  http://www.paulandlesley.org/gmake/
 "Please remain calm...I may be mad, but I am a professional." --Mad Scientist




Re: PATCH: .SECONDARY target with no dependencies does not work correctly.

2000-06-16 Thread Seth M LaForge

"Paul D. Smith" [EMAIL PROTECTED]:
 This is obliquely stated in the documentation:
 
  `.SECONDARY'
  The targets which `.SECONDARY' depends on are treated as
  intermediate files, except that they are never automatically
  deleted.  *Note Chains of Implicit Rules: Chained Rules.
 
  `.SECONDARY' with no prerequisites marks all file targets mentioned
   ^^
  in the makefile as secondary.
 
 Note the second paragraph.  The targets you give aren't mentioned in the
 makefile; they're built using implicit rules.

Yes, but aren't all explicitly mentioned targets considered secondary
anyway?  If so, it seems like ".SECONDARY: " serves no purpose...

For the complex Makefiles I'm working on now, intermediate deletion
was causing deletion of object files which should not be deleted, and
I decided to just turn it off entirely.  However, without .SECONDARY
behaving as I'd like it to, I don't see how to acheive this.

 I agree with you, however, that this is a strange restriction and this
 area needs to be revisited, for all of PRECIOUS, INTERMEDIATE, and
 SECONDARY.
 
 I'll file an enhancement request about it.

Thanks.

Seth




PATCH: .SECONDARY target with no dependencies does not work correctly.

2000-06-15 Thread Seth M LaForge

(Make version 3.79.)  Consider:

  % cat Makefile 
  %.1: %.2
  cp $ $@
  %.2: %.3
  cp $ $@
  .SECONDARY:
  % ls
  Makefile  foo.3
  % make foo.1
  cp foo.3 foo.2
  cp foo.2 foo.1
  rm foo.2

According to the documentation, the .SECONDARY target should cause all
files to be considered secondary (and thus not deleted), but it
doesn't work.  I think that this is because the code to handle the
.SECONDARY target with no dependencies marks all known files as
secondary, but is run before pattern rules are followed and thus
doesn't mark the results of pattern rules.  Since .SECONDARY is only
really useful on the targets of pattern rules, this rather defeats the
purpose.  At the end of this email is a rather crude patch to fix the
problem.

A more general issue: the documentation says:
  You can also list the target pattern of an implicit rule (such as
  `%.o') as a dependency file of the special target `.PRECIOUS' to
  preserve intermediate files created by rules whose target patterns
  match that file's name.
This documents rather bizarre behaviour: it only works for pattern
rules which specify the exact pattern mentioned (`%.o') and not ones
which mention a different pattern which matches the same filenames
(say, `%.foo.o').  It's easy for a user to expect different behaviour
- e.g. that '.PRECIOUS: %' would make all files precious.  It's also
odd that .SECONDARY and .INTERMEDIATE don't seem to do anything useful
with pattern dependencies.

I propose that for special targets with pattern dependencies, all
files should be matched against the patterns, and any files which
match should have the special behaviour.  Then the no-dependency case
of .SECONDARY would be equivalent to '.SECONDARY: %'.

Anyway, here's the patch:

diff -rc /x/sethml/src/make-3.79/file.c ./file.c
*** /x/sethml/src/make-3.79/file.c  Mon Mar 27 08:20:40 2000
--- ./file.cThu Jun 15 16:09:10 2000
***
*** 34,39 
--- 34,42 
  #endif
  static struct file *files[FILE_BUCKETS];
  
+ /* Are all files considered secondary? */
+ static int all_secondary = 0;
+ 
  /* Number of files with the `intermediate' flag set.  */
  
  unsigned int num_intermediates = 0;
***
*** 384,390 
register struct file *f;
char doneany;
  
!   if (question_flag || touch_flag)
  return;
if (sig  just_print_flag)
  return;
--- 387,393 
register struct file *f;
char doneany;
  
!   if (question_flag || touch_flag || all_secondary)
  return;
if (sig  just_print_flag)
  return;
***
*** 504,517 
for (f2 = d-file; f2 != 0; f2 = f2-prev)
  f2-intermediate = f2-secondary = 1;
}
!   /* .SECONDARY with no deps listed marks *all* files that way.  */
else
!   {
! int i;
! for (i = 0; i  FILE_BUCKETS; i++)
!   for (f2 = files[i]; f2; f2= f2-next)
! f2-intermediate = f2-secondary = 1;
!   }
  }
  
f = lookup_file (".EXPORT_ALL_VARIABLES");
--- 507,516 
for (f2 = d-file; f2 != 0; f2 = f2-prev)
  f2-intermediate = f2-secondary = 1;
}
!   /* .SECONDARY with no deps listed marks *all* files that way. 
!* We haven't seen all intermediate files yet, use a global flag. */
else
!   all_secondary = 1;
  }
  
f = lookup_file (".EXPORT_ALL_VARIABLES");