(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.c    Thu 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");

Reply via email to